mirror of
https://github.com/ProjectSWGCore/Holocore.git
synced 2026-01-17 00:06:00 -05:00
Merge pull request #1574 from madsboddum/fix/sui/npe-encoding
Fixed a NullPointerException when displaying SUI message boxes
This commit is contained in:
@@ -95,6 +95,10 @@ class SuiMessageBox : SuiWindow() {
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
super.suiScript = "Script.messageBox"
|
||||
}
|
||||
|
||||
private fun setShowRevertButton(shown: Boolean) {
|
||||
val value = shown.toString()
|
||||
setProperty("btnRevert", "Enabled", value)
|
||||
|
||||
@@ -63,11 +63,7 @@ import me.joshlarson.jlcommon.control.IntentHandler;
|
||||
import me.joshlarson.jlcommon.control.Service;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
public class LoginService extends Service {
|
||||
@@ -77,12 +73,14 @@ public class LoginService extends Service {
|
||||
|
||||
private final Map<String, List<CreatureObject>> players;
|
||||
private final PswgUserDatabase userDatabase;
|
||||
|
||||
private final Collection<Galaxy> galaxies;
|
||||
|
||||
public LoginService() {
|
||||
this(PswgDatabase.INSTANCE.getUsers());
|
||||
this(Collections.singletonList(ProjectSWG.INSTANCE.getGalaxy()), PswgDatabase.INSTANCE.getUsers());
|
||||
}
|
||||
|
||||
public LoginService(PswgUserDatabase pswgUserDatabase) {
|
||||
public LoginService(Collection<Galaxy> galaxy, PswgUserDatabase pswgUserDatabase) {
|
||||
this.galaxies = galaxy;
|
||||
userDatabase = pswgUserDatabase;
|
||||
this.players = Collections.synchronizedMap(new HashMap<>());
|
||||
}
|
||||
@@ -160,7 +158,7 @@ public class LoginService extends Service {
|
||||
} else if (isPasswordValid(user, loginRequest.getPassword())) {
|
||||
StandardLog.onPlayerEvent(this, player, "logged in from %s", loginRequest.getSocketAddress());
|
||||
onSuccessfulLogin(user, player);
|
||||
player.sendPacket(new HoloLoginResponsePacket(true, "", getGalaxies(), getCharacters(user.getUsername())));
|
||||
player.sendPacket(new HoloLoginResponsePacket(true, "", galaxies, getCharacters(user.getUsername())));
|
||||
} else {
|
||||
StandardLog.onPlayerEvent(this, player, "failed to login [incorrect password] from %s", loginRequest.getSocketAddress());
|
||||
onInvalidUserPass(player);
|
||||
@@ -263,7 +261,7 @@ public class LoginService extends Service {
|
||||
LoginEnumCluster cluster = new LoginEnumCluster();
|
||||
LoginClusterStatus clusterStatus = new LoginClusterStatus();
|
||||
List<SWGCharacter> characters = getCharacters(player.getAccountId());
|
||||
for (Galaxy g : getGalaxies()) {
|
||||
for (Galaxy g : galaxies) {
|
||||
cluster.addGalaxy(g);
|
||||
clusterStatus.addGalaxy(g);
|
||||
}
|
||||
@@ -279,13 +277,7 @@ public class LoginService extends Service {
|
||||
private boolean isPasswordValid(UserMetadata user, String password) {
|
||||
return userDatabase.authenticate(user, password);
|
||||
}
|
||||
|
||||
private List <Galaxy> getGalaxies() {
|
||||
List<Galaxy> galaxies = new ArrayList<>();
|
||||
galaxies.add(ProjectSWG.INSTANCE.getGalaxy());
|
||||
return galaxies;
|
||||
}
|
||||
|
||||
|
||||
private List<SWGCharacter> getCharacters(String accountId) {
|
||||
List<SWGCharacter> characters = new ArrayList<>();
|
||||
List<CreatureObject> creatures = this.players.get(accountId);
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
/***********************************************************************************
|
||||
* Copyright (c) 2023 /// Project SWG /// www.projectswg.com *
|
||||
* Copyright (c) 2024 /// 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. *
|
||||
* *
|
||||
@@ -30,6 +29,8 @@ package com.projectswg.holocore.test.resources;
|
||||
import com.projectswg.common.data.CRC;
|
||||
import com.projectswg.common.data.encodables.tangible.Posture;
|
||||
import com.projectswg.common.data.location.Location;
|
||||
import com.projectswg.common.network.NetBuffer;
|
||||
import com.projectswg.common.network.NetworkProtocol;
|
||||
import com.projectswg.common.network.packets.SWGPacket;
|
||||
import com.projectswg.common.network.packets.swg.zone.*;
|
||||
import com.projectswg.common.network.packets.swg.zone.baselines.Baseline;
|
||||
@@ -82,6 +83,7 @@ public class GenericPlayer extends Player {
|
||||
public void sendPacket(SWGPacket packet) {
|
||||
packetLock.lock();
|
||||
try {
|
||||
encodeAndDecode(packet);
|
||||
this.packets.add(packet);
|
||||
packetLockCondition.signalAll();
|
||||
} finally {
|
||||
@@ -89,7 +91,21 @@ public class GenericPlayer extends Player {
|
||||
}
|
||||
handlePacket(packet);
|
||||
}
|
||||
|
||||
|
||||
private static void encodeAndDecode(SWGPacket packet) {
|
||||
try {
|
||||
// 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
|
||||
NetBuffer data = NetworkProtocol.encode(packet);
|
||||
NetworkProtocol.decode(data);
|
||||
int remaining = data.remaining();
|
||||
if (remaining > 0) {
|
||||
throw new RuntimeException("Encoded packet buffer had more data that wasn't read during decoding. Bytes remaining: " + remaining);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
throw new RuntimeException("Failed to encode and decode packet", t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPacket(SWGPacket packet1, SWGPacket packet2) {
|
||||
sendPacket(packet1);
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
***********************************************************************************/
|
||||
package com.projectswg.holocore.test.runners
|
||||
|
||||
import com.projectswg.common.data.encodables.galaxy.Galaxy
|
||||
import com.projectswg.common.data.location.Location
|
||||
import com.projectswg.holocore.headless.MemoryUserDatabase
|
||||
import com.projectswg.holocore.resources.support.data.server_info.loader.ServerData
|
||||
@@ -65,6 +66,7 @@ import com.projectswg.holocore.services.support.objects.radials.RadialService
|
||||
import org.junit.jupiter.api.AfterEach
|
||||
import org.junit.jupiter.api.BeforeAll
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import java.time.ZoneOffset
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
@@ -82,11 +84,15 @@ abstract class AcceptanceTest : TestRunnerSynchronousIntents() {
|
||||
|
||||
@BeforeEach
|
||||
fun setUpServices() {
|
||||
val galaxy = Galaxy()
|
||||
galaxy.setZoneOffset(ZoneOffset.UTC)
|
||||
val galaxies = setOf(galaxy)
|
||||
|
||||
registerService(ClientAwarenessService())
|
||||
registerService(CharacterLookupService())
|
||||
registerService(SimulatedObjectStorage())
|
||||
registerService(AwarenessService())
|
||||
registerService(LoginService(memoryUserDatabase))
|
||||
registerService(LoginService(galaxies, memoryUserDatabase))
|
||||
registerService(ZoneService())
|
||||
registerService(CommandQueueService(5, DeterministicDie(0), DeterministicDie(0), DeterministicDie(0), skipWarmup = true))
|
||||
registerService(CommandExecutionService())
|
||||
|
||||
Reference in New Issue
Block a user