Skip to content

Commit

Permalink
Merge pull request #1574 from madsboddum/fix/sui/npe-encoding
Browse files Browse the repository at this point in the history
Fixed a NullPointerException when displaying SUI message boxes
  • Loading branch information
Josh-Larson committed Jul 5, 2024
2 parents 87e1ca6 + ea50f4c commit a4505bd
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@
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 {
Expand All @@ -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<>());
}
Expand Down Expand Up @@ -160,7 +158,7 @@ private void handleLogin(Player player, HoloLoginRequestPacket loginRequest) {
} 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);
Expand Down Expand Up @@ -263,7 +261,7 @@ private void sendLoginSuccessPacket(Player player) {
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);
}
Expand All @@ -279,13 +277,7 @@ private void sendLoginSuccessPacket(Player player) {
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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. *
* *
Expand All @@ -30,6 +29,8 @@
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;
Expand Down Expand Up @@ -82,14 +83,29 @@ public GenericPlayer() {
public void sendPacket(SWGPacket packet) {
packetLock.lock();
try {
encodeAndDecode(packet);
this.packets.add(packet);
packetLockCondition.signalAll();
} finally {
packetLock.unlock();
}
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.*

/**
Expand All @@ -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())
Expand Down

0 comments on commit a4505bd

Please sign in to comment.