Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/***********************************************************************************
* Copyright (c) 2024 /// Project SWG /// www.projectswg.com *
* Copyright (c) 2025 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* ProjectSWG is an emulation project for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
* Our goal is to create an emulator which will provide a server for players to *
* continue playing a game similar to the one they used to play. We are basing *
* it on the final publish of the game prior to end-game events. *
* Our goal is to create one or more emulators which will provide servers for *
* players to continue playing a game similar to the one they used to play. *
* *
* This file is part of Holocore. *
* *
Expand All @@ -30,6 +29,7 @@ import com.projectswg.common.network.packets.swg.login.ClientIdMsg
import com.projectswg.common.network.packets.swg.login.ClientPermissionsMessage
import com.projectswg.common.network.packets.swg.login.creation.*
import com.projectswg.common.network.packets.swg.zone.CmdSceneReady
import com.projectswg.common.network.packets.swg.zone.SceneEndBaselines
import com.projectswg.common.network.packets.swg.zone.insertion.SelectCharacter
import com.projectswg.holocore.test.resources.GenericPlayer
import java.lang.RuntimeException
Expand Down Expand Up @@ -75,6 +75,10 @@ class CharacterSelectionScreen internal constructor(val player: GenericPlayer) {
sendPacket(player, SelectCharacter(characterId))
sendPacket(player, ClientIdMsg())
player.waitForNextPacket(ClientPermissionsMessage::class.java) ?: throw IllegalStateException("Failed to receive client permissions message in time")
var waitForMoreObjects = true
while (waitForMoreObjects) {
waitForMoreObjects = player.waitForNextPacket(SceneEndBaselines::class.java, 50, TimeUnit.MILLISECONDS) != null
}
sendPacket(player, CmdSceneReady())
player.waitForNextPacket(CmdSceneReady::class.java) ?: throw IllegalStateException("Expected CmdSceneReady from server but did not receive it in time")

Expand Down
33 changes: 33 additions & 0 deletions src/test/java/com/projectswg/holocore/headless/awareness.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/***********************************************************************************
* Copyright (c) 2025 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is an emulation project for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
* Our goal is to create one or more emulators which will provide servers for *
* players to continue playing a game similar to the one they used to play. *
* *
* This file is part of Holocore. *
* *
* --------------------------------------------------------------------------------*
* *
* Holocore is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* Holocore is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with Holocore. If not, see <http://www.gnu.org/licenses/>. *
***********************************************************************************/
package com.projectswg.holocore.headless

import com.projectswg.common.network.packets.swg.zone.SceneDestroyObject
import java.util.concurrent.TimeUnit

fun ZonedInCharacter.waitUntilObjectDestroyed(objectId: Long) {
player.waitForNextPacket(SceneDestroyObject::class.java, 1, TimeUnit.SECONDS) { it.objectId == objectId }
}
18 changes: 14 additions & 4 deletions src/test/java/com/projectswg/holocore/headless/grouping.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
***********************************************************************************/
package com.projectswg.holocore.headless

import com.projectswg.common.network.packets.swg.zone.SceneCreateObjectByCrc
import com.projectswg.common.network.packets.swg.zone.SceneDestroyObject
import com.projectswg.common.network.packets.swg.zone.chat.ChatSystemMessage
import com.projectswg.holocore.resources.support.objects.swg.group.GroupObject
Expand All @@ -37,10 +36,21 @@ fun ZonedInCharacter.invitePlayerToGroup(other: ZonedInCharacter) {
player.waitForNextPacket(ChatSystemMessage::class.java, 1, TimeUnit.SECONDS) ?: throw IllegalStateException("No chat system message received")
}

fun ZonedInCharacter.acceptCurrentGroupInvitation() {
fun ZonedInCharacter.acceptCurrentGroupInvitation(from: ZonedInCharacter) {
sendCommand("join")
// GroupObject is created
player.waitForNextPacket(SceneCreateObjectByCrc::class.java, 1, TimeUnit.SECONDS) ?: throw IllegalStateException("Packet not received")
// GroupId is set away from 0
player.waitForNextObjectDelta(player.creatureObject.objectId, 6, 7, 1, TimeUnit.SECONDS) ?: throw IllegalStateException("Packet not received")
if (player.creatureObject.groupId == 0L) {
throw IllegalStateException("Group ID for $player should not still be 0")
}

if (from.player.creatureObject.groupId == 0L) {
// If the group has to be created, we need to pop the DeltasMessage for changing the GroupId of the leader.
from.player.waitForNextObjectDelta(from.player.creatureObject.objectId, 6, 7, 1, TimeUnit.SECONDS) ?: throw IllegalStateException("Packet not received")
if (from.player.creatureObject.groupId == 0L) {
throw IllegalStateException("Group ID for ${from.player} should not still be 0")
}
}
}

fun ZonedInCharacter.leaveCurrentGroup() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/***********************************************************************************
* Copyright (c) 2024 /// Project SWG /// www.projectswg.com *
* Copyright (c) 2025 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* ProjectSWG is an emulation project for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
* Our goal is to create an emulator which will provide a server for players to *
* continue playing a game similar to the one they used to play. We are basing *
* it on the final publish of the game prior to end-game events. *
* Our goal is to create one or more emulators which will provide servers for *
* players to continue playing a game similar to the one they used to play. *
* *
* This file is part of Holocore. *
* *
Expand Down Expand Up @@ -125,6 +124,7 @@ class TipCreditsTest : AcceptanceTest() {
y = zonedInCharacter1.player.creatureObject.y,
z = zonedInCharacter1.player.creatureObject.z
)
zonedInCharacter1.waitUntilObjectDestroyed(zonedInCharacter2.player.creatureObject.objectId)

val suiWindow = zonedInCharacter1.tip(zonedInCharacter2.player.creatureObject, 100)

Expand All @@ -141,6 +141,7 @@ class TipCreditsTest : AcceptanceTest() {
y = zonedInCharacter1.player.creatureObject.y,
z = zonedInCharacter1.player.creatureObject.z
)
zonedInCharacter1.waitUntilObjectDestroyed(zonedInCharacter2.player.creatureObject.objectId)

val suiWindow = zonedInCharacter1.tip(zonedInCharacter2.player.creatureObject, 100)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class GroupTest : AcceptanceTest() {
val zonedInCharacter2 = createZonedInCharacter("Chartwo")

zonedInCharacter1.invitePlayerToGroup(zonedInCharacter2)
zonedInCharacter2.acceptCurrentGroupInvitation()
zonedInCharacter2.acceptCurrentGroupInvitation(zonedInCharacter1)

assertTrue(zonedInCharacter1.isInGroupWith(zonedInCharacter2))
}
Expand All @@ -48,7 +48,7 @@ class GroupTest : AcceptanceTest() {
val zonedInCharacter1 = createZonedInCharacter("Charone")
val zonedInCharacter2 = createZonedInCharacter("Chartwo")
zonedInCharacter1.invitePlayerToGroup(zonedInCharacter2)
zonedInCharacter2.acceptCurrentGroupInvitation()
zonedInCharacter2.acceptCurrentGroupInvitation(zonedInCharacter1)

zonedInCharacter1.makeGroupLeader(zonedInCharacter2)

Expand All @@ -63,7 +63,7 @@ class GroupTest : AcceptanceTest() {
val zonedInCharacter1 = createZonedInCharacter("Charone")
val zonedInCharacter2 = createZonedInCharacter("Chartwo")
zonedInCharacter1.invitePlayerToGroup(zonedInCharacter2)
zonedInCharacter2.acceptCurrentGroupInvitation()
zonedInCharacter2.acceptCurrentGroupInvitation(zonedInCharacter1)

zonedInCharacter2.makeGroupLeader(zonedInCharacter2)

Expand All @@ -80,9 +80,9 @@ class GroupTest : AcceptanceTest() {
val zonedInCharacter3 = createZonedInCharacter("Charthree")

zonedInCharacter1.invitePlayerToGroup(zonedInCharacter2)
zonedInCharacter2.acceptCurrentGroupInvitation()
zonedInCharacter2.acceptCurrentGroupInvitation(zonedInCharacter1)
zonedInCharacter1.invitePlayerToGroup(zonedInCharacter3)
zonedInCharacter3.acceptCurrentGroupInvitation()
zonedInCharacter3.acceptCurrentGroupInvitation(zonedInCharacter1)

zonedInCharacter2.leaveCurrentGroup()

Expand All @@ -100,9 +100,9 @@ class GroupTest : AcceptanceTest() {
val zonedInCharacter3 = createZonedInCharacter("Charthree")

zonedInCharacter1.invitePlayerToGroup(zonedInCharacter2)
zonedInCharacter2.acceptCurrentGroupInvitation()
zonedInCharacter2.acceptCurrentGroupInvitation(zonedInCharacter1)
zonedInCharacter1.invitePlayerToGroup(zonedInCharacter3)
zonedInCharacter3.acceptCurrentGroupInvitation()
zonedInCharacter3.acceptCurrentGroupInvitation(zonedInCharacter1)

zonedInCharacter1.kickFromGroup(zonedInCharacter2)

Expand All @@ -120,9 +120,9 @@ class GroupTest : AcceptanceTest() {
val zonedInCharacter3 = createZonedInCharacter("Charthree")

zonedInCharacter1.invitePlayerToGroup(zonedInCharacter2)
zonedInCharacter2.acceptCurrentGroupInvitation()
zonedInCharacter2.acceptCurrentGroupInvitation(zonedInCharacter1)
zonedInCharacter1.invitePlayerToGroup(zonedInCharacter3)
zonedInCharacter3.acceptCurrentGroupInvitation()
zonedInCharacter3.acceptCurrentGroupInvitation(zonedInCharacter1)

zonedInCharacter1.leaveCurrentGroup()

Expand All @@ -141,9 +141,9 @@ class GroupTest : AcceptanceTest() {
val characters = listOf(zonedInCharacter1, zonedInCharacter2, zonedInCharacter3)

zonedInCharacter1.invitePlayerToGroup(zonedInCharacter2)
zonedInCharacter2.acceptCurrentGroupInvitation()
zonedInCharacter2.acceptCurrentGroupInvitation(zonedInCharacter1)
zonedInCharacter1.invitePlayerToGroup(zonedInCharacter3)
zonedInCharacter3.acceptCurrentGroupInvitation()
zonedInCharacter3.acceptCurrentGroupInvitation(zonedInCharacter1)

assertAll(
{ assertTrue(zonedInCharacter1.isInGroupWith(zonedInCharacter2)) },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***********************************************************************************
* Copyright (c) 2024 /// Project SWG /// www.projectswg.com *
* Copyright (c) 2025 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is an emulation project for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
Expand Down Expand Up @@ -55,6 +55,7 @@
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Predicate;

import static org.junit.jupiter.api.Assertions.*;

Expand Down Expand Up @@ -172,32 +173,11 @@ public <T extends SWGPacket> T waitForNextPacket(Class<T> type) {

@Nullable
public <T extends SWGPacket> T waitForNextPacket(Class<T> type, long timeout, TimeUnit unit) {
packetLock.lock();
try {
long startTime = System.nanoTime();
while (System.nanoTime() - startTime < unit.toNanos(timeout)) {
for (Iterator<SWGPacket> it = packets.iterator(); it.hasNext(); ) {
SWGPacket next = it.next();
if (type.isInstance(next)) {
it.remove();
return type.cast(next);
}
}
try {
//noinspection ResultOfMethodCallIgnored
packetLockCondition.awaitNanos(unit.toNanos(timeout) - (System.nanoTime() - startTime));
} catch (InterruptedException e) {
return null;
}
}
} finally {
packetLock.unlock();
}
return null;
return waitForNextPacket(type, timeout, unit, p -> true);
}

@Nullable
public DeltasMessage waitForNextObjectDelta(long objectId, int num, int update, long timeout, TimeUnit unit) {
Class<? extends SWGPacket> type = DeltasMessage.class;
public <T extends SWGPacket> T waitForNextPacket(Class<T> type, long timeout, TimeUnit unit, Predicate<T> filter) {
packetLock.lock();
try {
long startTime = System.nanoTime();
Expand All @@ -206,10 +186,9 @@ public DeltasMessage waitForNextObjectDelta(long objectId, int num, int update,
SWGPacket next = it.next();
if (type.isInstance(next)) {
it.remove();
DeltasMessage deltasMessage = (DeltasMessage) next;

if (deltasMessage.getObjectId() == objectId && deltasMessage.getNum() == num && deltasMessage.getUpdate() == update) {
return deltasMessage;
T packet = type.cast(next);
if (filter.test(packet)) {
return packet;
}
}
}
Expand All @@ -225,6 +204,11 @@ public DeltasMessage waitForNextObjectDelta(long objectId, int num, int update,
}
return null;
}
@Nullable
public DeltasMessage waitForNextObjectDelta(long objectId, int num, int update, long timeout, TimeUnit unit) {
Predicate<DeltasMessage> deltaPacketFilter = p -> p.getObjectId() == objectId && p.getNum() == num && p.getUpdate() == update;
return waitForNextPacket(DeltasMessage.class, timeout, unit, deltaPacketFilter);
}

@Nullable
public SWGPacket waitForNextPacket(Set<Class<? extends SWGPacket>> types, long timeout, TimeUnit unit) {
Expand Down
Loading