Skip to content

Commit a4505bd

Browse files
authored
Merge pull request #1574 from madsboddum/fix/sui/npe-encoding
Fixed a NullPointerException when displaying SUI message boxes
2 parents 87e1ca6 + ea50f4c commit a4505bd

4 files changed

Lines changed: 42 additions & 24 deletions

File tree

src/main/java/com/projectswg/holocore/resources/support/global/zone/sui/SuiMessageBox.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ class SuiMessageBox : SuiWindow() {
9595
}
9696
}
9797

98+
init {
99+
super.suiScript = "Script.messageBox"
100+
}
101+
98102
private fun setShowRevertButton(shown: Boolean) {
99103
val value = shown.toString()
100104
setProperty("btnRevert", "Enabled", value)

src/main/java/com/projectswg/holocore/services/support/global/zone/LoginService.java

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,7 @@
6363
import me.joshlarson.jlcommon.control.Service;
6464

6565
import java.net.SocketAddress;
66-
import java.util.ArrayList;
67-
import java.util.Collections;
68-
import java.util.HashMap;
69-
import java.util.List;
70-
import java.util.Map;
66+
import java.util.*;
7167
import java.util.concurrent.CopyOnWriteArrayList;
7268

7369
public class LoginService extends Service {
@@ -77,12 +73,14 @@ public class LoginService extends Service {
7773

7874
private final Map<String, List<CreatureObject>> players;
7975
private final PswgUserDatabase userDatabase;
80-
76+
private final Collection<Galaxy> galaxies;
77+
8178
public LoginService() {
82-
this(PswgDatabase.INSTANCE.getUsers());
79+
this(Collections.singletonList(ProjectSWG.INSTANCE.getGalaxy()), PswgDatabase.INSTANCE.getUsers());
8380
}
8481

85-
public LoginService(PswgUserDatabase pswgUserDatabase) {
82+
public LoginService(Collection<Galaxy> galaxy, PswgUserDatabase pswgUserDatabase) {
83+
this.galaxies = galaxy;
8684
userDatabase = pswgUserDatabase;
8785
this.players = Collections.synchronizedMap(new HashMap<>());
8886
}
@@ -160,7 +158,7 @@ private void handleLogin(Player player, HoloLoginRequestPacket loginRequest) {
160158
} else if (isPasswordValid(user, loginRequest.getPassword())) {
161159
StandardLog.onPlayerEvent(this, player, "logged in from %s", loginRequest.getSocketAddress());
162160
onSuccessfulLogin(user, player);
163-
player.sendPacket(new HoloLoginResponsePacket(true, "", getGalaxies(), getCharacters(user.getUsername())));
161+
player.sendPacket(new HoloLoginResponsePacket(true, "", galaxies, getCharacters(user.getUsername())));
164162
} else {
165163
StandardLog.onPlayerEvent(this, player, "failed to login [incorrect password] from %s", loginRequest.getSocketAddress());
166164
onInvalidUserPass(player);
@@ -263,7 +261,7 @@ private void sendLoginSuccessPacket(Player player) {
263261
LoginEnumCluster cluster = new LoginEnumCluster();
264262
LoginClusterStatus clusterStatus = new LoginClusterStatus();
265263
List<SWGCharacter> characters = getCharacters(player.getAccountId());
266-
for (Galaxy g : getGalaxies()) {
264+
for (Galaxy g : galaxies) {
267265
cluster.addGalaxy(g);
268266
clusterStatus.addGalaxy(g);
269267
}
@@ -279,13 +277,7 @@ private void sendLoginSuccessPacket(Player player) {
279277
private boolean isPasswordValid(UserMetadata user, String password) {
280278
return userDatabase.authenticate(user, password);
281279
}
282-
283-
private List <Galaxy> getGalaxies() {
284-
List<Galaxy> galaxies = new ArrayList<>();
285-
galaxies.add(ProjectSWG.INSTANCE.getGalaxy());
286-
return galaxies;
287-
}
288-
280+
289281
private List<SWGCharacter> getCharacters(String accountId) {
290282
List<SWGCharacter> characters = new ArrayList<>();
291283
List<CreatureObject> creatures = this.players.get(accountId);

src/test/java/com/projectswg/holocore/test/resources/GenericPlayer.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
/***********************************************************************************
2-
* Copyright (c) 2023 /// Project SWG /// www.projectswg.com *
2+
* Copyright (c) 2024 /// Project SWG /// www.projectswg.com *
33
* *
4-
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
4+
* ProjectSWG is an emulation project for Star Wars Galaxies founded on *
55
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
6-
* Our goal is to create an emulator which will provide a server for players to *
7-
* continue playing a game similar to the one they used to play. We are basing *
8-
* it on the final publish of the game prior to end-game events. *
6+
* Our goal is to create one or more emulators which will provide servers for *
7+
* players to continue playing a game similar to the one they used to play. *
98
* *
109
* This file is part of Holocore. *
1110
* *
@@ -30,6 +29,8 @@
3029
import com.projectswg.common.data.CRC;
3130
import com.projectswg.common.data.encodables.tangible.Posture;
3231
import com.projectswg.common.data.location.Location;
32+
import com.projectswg.common.network.NetBuffer;
33+
import com.projectswg.common.network.NetworkProtocol;
3334
import com.projectswg.common.network.packets.SWGPacket;
3435
import com.projectswg.common.network.packets.swg.zone.*;
3536
import com.projectswg.common.network.packets.swg.zone.baselines.Baseline;
@@ -82,14 +83,29 @@ public GenericPlayer() {
8283
public void sendPacket(SWGPacket packet) {
8384
packetLock.lock();
8485
try {
86+
encodeAndDecode(packet);
8587
this.packets.add(packet);
8688
packetLockCondition.signalAll();
8789
} finally {
8890
packetLock.unlock();
8991
}
9092
handlePacket(packet);
9193
}
92-
94+
95+
private static void encodeAndDecode(SWGPacket packet) {
96+
try {
97+
// This doesn't actually test the encoding and decoding of the packet, but it does test that the packet can be encoded and decoded without throwing an exception
98+
NetBuffer data = NetworkProtocol.encode(packet);
99+
NetworkProtocol.decode(data);
100+
int remaining = data.remaining();
101+
if (remaining > 0) {
102+
throw new RuntimeException("Encoded packet buffer had more data that wasn't read during decoding. Bytes remaining: " + remaining);
103+
}
104+
} catch (Throwable t) {
105+
throw new RuntimeException("Failed to encode and decode packet", t);
106+
}
107+
}
108+
93109
@Override
94110
public void sendPacket(SWGPacket packet1, SWGPacket packet2) {
95111
sendPacket(packet1);

src/test/java/com/projectswg/holocore/test/runners/AcceptanceTest.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
***********************************************************************************/
2727
package com.projectswg.holocore.test.runners
2828

29+
import com.projectswg.common.data.encodables.galaxy.Galaxy
2930
import com.projectswg.common.data.location.Location
3031
import com.projectswg.holocore.headless.MemoryUserDatabase
3132
import com.projectswg.holocore.resources.support.data.server_info.loader.ServerData
@@ -65,6 +66,7 @@ import com.projectswg.holocore.services.support.objects.radials.RadialService
6566
import org.junit.jupiter.api.AfterEach
6667
import org.junit.jupiter.api.BeforeAll
6768
import org.junit.jupiter.api.BeforeEach
69+
import java.time.ZoneOffset
6870
import java.util.*
6971

7072
/**
@@ -82,11 +84,15 @@ abstract class AcceptanceTest : TestRunnerSynchronousIntents() {
8284

8385
@BeforeEach
8486
fun setUpServices() {
87+
val galaxy = Galaxy()
88+
galaxy.setZoneOffset(ZoneOffset.UTC)
89+
val galaxies = setOf(galaxy)
90+
8591
registerService(ClientAwarenessService())
8692
registerService(CharacterLookupService())
8793
registerService(SimulatedObjectStorage())
8894
registerService(AwarenessService())
89-
registerService(LoginService(memoryUserDatabase))
95+
registerService(LoginService(galaxies, memoryUserDatabase))
9096
registerService(ZoneService())
9197
registerService(CommandQueueService(5, DeterministicDie(0), DeterministicDie(0), DeterministicDie(0), skipWarmup = true))
9298
registerService(CommandExecutionService())

0 commit comments

Comments
 (0)