From 36f600fe1a9aa698a3956d7c80b64c4af9d50c9b Mon Sep 17 00:00:00 2001 From: Jonn Date: Fri, 18 Feb 2022 21:53:56 +0900 Subject: [PATCH 1/5] Pull upstream changes into fork branch (#41) * v92.7 changes * v92.9 changes Co-authored-by: Jgunishka <53265225+Jgunishka@users.noreply.github.com> --- .../controller/v086/action/GameChatAction.java | 18 ++++++++++++++---- .../v086/action/GameOwnerCommandAction.java | 1 + .../controller/v086/protocol/Chat.java | 2 +- .../v086/protocol/ConnectionRejected.java | 2 +- .../controller/v086/protocol/CreateGame.java | 2 +- .../controller/v086/protocol/GameChat.java | 2 +- .../v086/protocol/InformationMessage.java | 2 +- .../controller/v086/protocol/JoinGame.java | 2 +- .../controller/v086/protocol/PlayerDrop.java | 2 +- .../v086/protocol/PlayerInformation.java | 2 +- .../controller/v086/protocol/Quit.java | 2 +- .../controller/v086/protocol/QuitGame.java | 2 +- .../controller/v086/protocol/ServerStatus.java | 4 ++-- .../v086/protocol/UserInformation.java | 2 +- .../controller/v086/protocol/UserJoined.java | 2 +- .../controller/v086/protocol/V086Message.java | 6 ++++++ .../kaillera/model/impl/KailleraUserImpl.java | 9 ++++++++- .../release/KailleraServerReleaseInfo.java | 4 ++-- 18 files changed, 45 insertions(+), 21 deletions(-) diff --git a/src/org/emulinker/kaillera/controller/v086/action/GameChatAction.java b/src/org/emulinker/kaillera/controller/v086/action/GameChatAction.java index a055299..7ac29bd 100644 --- a/src/org/emulinker/kaillera/controller/v086/action/GameChatAction.java +++ b/src/org/emulinker/kaillera/controller/v086/action/GameChatAction.java @@ -202,6 +202,11 @@ public class GameChatAction implements V086Action, V086GameEventHandler user1.getGame().announce("User not found!", user1); return; } + + if(user.getGame() != user1.getGame()) { + user1.getGame().announce("User not in this game!", user1); + return; + } if(user == clientHandler.getUser()){ user1.getGame().announce("You can't private message yourself!", user1); @@ -245,11 +250,11 @@ public class GameChatAction implements V086Action, V086GameEventHandler //user1.getServer().announce("TO: <" + user.getName() + ">(" + user.getID() + ") <" + clientHandler.getUser().getName() + "> (" + clientHandler.getUser().getID() + "): " + m, false, user1); //user.getServer().announce("<" + clientHandler.getUser().getName() + "> (" + clientHandler.getUser().getID() + "): " + m, false, user); - if(user1.getGame() != null && user1.getGame() == user.getGame()){ + if(user1.getGame() != null){ user1.getGame().announce("TO: <" + user.getName() + ">(" + user.getID() + ") <" + clientHandler.getUser().getName() + "> (" + clientHandler.getUser().getID() + "): " + m, user1); } - if(user.getGame() != null && user.getGame() == user1.getGame()){ + if(user.getGame() != null){ user.getGame().announce("<" + clientHandler.getUser().getName() + "> (" + clientHandler.getUser().getID() + "): " + m, user); } return; @@ -272,6 +277,11 @@ public class GameChatAction implements V086Action, V086GameEventHandler user1.getGame().announce("User not found!", user1); return; } + + if(user.getGame() != user1.getGame()) { + user1.getGame().announce("User not in this game!", user1); + return; + } if(user == clientHandler.getUser()){ user1.getGame().announce("You can't private message yourself!", user1); @@ -313,11 +323,11 @@ public class GameChatAction implements V086Action, V086GameEventHandler //user1.getServer().announce("TO: <" + user.getName() + ">(" + user.getID() + ") <" + clientHandler.getUser().getName() + "> (" + clientHandler.getUser().getID() + "): " + m, false, user1); //user.getServer().announce("<" + clientHandler.getUser().getName() + "> (" + clientHandler.getUser().getID() + "): " + m, false, user); - if(user1.getGame() != null && user1.getGame() == user.getGame()){ + if(user1.getGame() != null){ user1.getGame().announce("TO: <" + user.getName() + ">(" + user.getID() + ") <" + clientHandler.getUser().getName() + "> (" + clientHandler.getUser().getID() + "): " + m, user1); } - if(user.getGame() != null && user.getGame() == user1.getGame()){ + if(user.getGame() != null){ user.getGame().announce("<" + clientHandler.getUser().getName() + "> (" + clientHandler.getUser().getID() + "): " + m, user); } return; diff --git a/src/org/emulinker/kaillera/controller/v086/action/GameOwnerCommandAction.java b/src/org/emulinker/kaillera/controller/v086/action/GameOwnerCommandAction.java index edfd079..a62f6ac 100644 --- a/src/org/emulinker/kaillera/controller/v086/action/GameOwnerCommandAction.java +++ b/src/org/emulinker/kaillera/controller/v086/action/GameOwnerCommandAction.java @@ -148,6 +148,7 @@ public class GameOwnerCommandAction implements V086Action else { log.warn("GameOwner Command Denied: Not game owner: " + game + ": " + user + ": " + chat); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + game.announce("GameOwner Command Error: You are not an owner!", user); return; } } diff --git a/src/org/emulinker/kaillera/controller/v086/protocol/Chat.java b/src/org/emulinker/kaillera/controller/v086/protocol/Chat.java index 7397bbb..d303c52 100644 --- a/src/org/emulinker/kaillera/controller/v086/protocol/Chat.java +++ b/src/org/emulinker/kaillera/controller/v086/protocol/Chat.java @@ -43,7 +43,7 @@ public abstract class Chat extends V086Message public int getBodyLength() { //return (charset.encode(userName).remaining() + charset.encode(message).remaining() + 2); - return (userName.length() + message.length() + 2); + return (getNumBytes(userName) + getNumBytes(message) + 2); } public void writeBodyTo(ByteBuffer buffer) diff --git a/src/org/emulinker/kaillera/controller/v086/protocol/ConnectionRejected.java b/src/org/emulinker/kaillera/controller/v086/protocol/ConnectionRejected.java index 4bb6926..64e3504 100644 --- a/src/org/emulinker/kaillera/controller/v086/protocol/ConnectionRejected.java +++ b/src/org/emulinker/kaillera/controller/v086/protocol/ConnectionRejected.java @@ -65,7 +65,7 @@ public class ConnectionRejected extends V086Message public int getBodyLength() { //return (charset.encode(userName).remaining() + charset.encode(message).remaining() + 4); - return (userName.length() + message.length() + 4); + return (getNumBytes(userName) + getNumBytes(message) + 4); } public void writeBodyTo(ByteBuffer buffer) diff --git a/src/org/emulinker/kaillera/controller/v086/protocol/CreateGame.java b/src/org/emulinker/kaillera/controller/v086/protocol/CreateGame.java index d14b00b..baf4ba1 100644 --- a/src/org/emulinker/kaillera/controller/v086/protocol/CreateGame.java +++ b/src/org/emulinker/kaillera/controller/v086/protocol/CreateGame.java @@ -72,7 +72,7 @@ public abstract class CreateGame extends V086Message public int getBodyLength() { //return (charset.encode(userName).remaining() + charset.encode(romName).remaining() + charset.encode(clientType).remaining() + 7); - return (userName.length() + romName.length() + clientType.length() + 7); + return (getNumBytes(userName) + getNumBytes(romName) + getNumBytes(clientType) + 7); } public void writeBodyTo(ByteBuffer buffer) diff --git a/src/org/emulinker/kaillera/controller/v086/protocol/GameChat.java b/src/org/emulinker/kaillera/controller/v086/protocol/GameChat.java index c12ef93..2039d60 100644 --- a/src/org/emulinker/kaillera/controller/v086/protocol/GameChat.java +++ b/src/org/emulinker/kaillera/controller/v086/protocol/GameChat.java @@ -42,7 +42,7 @@ public abstract class GameChat extends V086Message public int getBodyLength() { //return (charset.encode(userName).remaining() + charset.encode(message).remaining() + 2); - return (userName.length() + message.length() + 2); + return (getNumBytes(userName) + getNumBytes(message) + 2); } public void writeBodyTo(ByteBuffer buffer) diff --git a/src/org/emulinker/kaillera/controller/v086/protocol/InformationMessage.java b/src/org/emulinker/kaillera/controller/v086/protocol/InformationMessage.java index f79ff7b..01701de 100644 --- a/src/org/emulinker/kaillera/controller/v086/protocol/InformationMessage.java +++ b/src/org/emulinker/kaillera/controller/v086/protocol/InformationMessage.java @@ -55,7 +55,7 @@ public class InformationMessage extends V086Message public int getBodyLength() { //return (charset.encode(source).remaining() + charset.encode(message).remaining() + 2); - return (source.length() + message.length() + 2); + return (getNumBytes(source) + getNumBytes(message) + 2); } public void writeBodyTo(ByteBuffer buffer) diff --git a/src/org/emulinker/kaillera/controller/v086/protocol/JoinGame.java b/src/org/emulinker/kaillera/controller/v086/protocol/JoinGame.java index cdef265..dbeb4d8 100644 --- a/src/org/emulinker/kaillera/controller/v086/protocol/JoinGame.java +++ b/src/org/emulinker/kaillera/controller/v086/protocol/JoinGame.java @@ -82,7 +82,7 @@ public abstract class JoinGame extends V086Message public int getBodyLength() { //return (charset.encode(userName).remaining() + 13); - return (userName.length() + 13); + return (getNumBytes(userName) + 13); } public void writeBodyTo(ByteBuffer buffer) diff --git a/src/org/emulinker/kaillera/controller/v086/protocol/PlayerDrop.java b/src/org/emulinker/kaillera/controller/v086/protocol/PlayerDrop.java index 129fb8d..5b45db5 100644 --- a/src/org/emulinker/kaillera/controller/v086/protocol/PlayerDrop.java +++ b/src/org/emulinker/kaillera/controller/v086/protocol/PlayerDrop.java @@ -48,7 +48,7 @@ public abstract class PlayerDrop extends V086Message public int getBodyLength() { //return (charset.encode(userName).remaining() + 2); - return (userName.length() + 2); + return (getNumBytes(userName) + 2); } public void writeBodyTo(ByteBuffer buffer) diff --git a/src/org/emulinker/kaillera/controller/v086/protocol/PlayerInformation.java b/src/org/emulinker/kaillera/controller/v086/protocol/PlayerInformation.java index 422a0fb..f353751 100644 --- a/src/org/emulinker/kaillera/controller/v086/protocol/PlayerInformation.java +++ b/src/org/emulinker/kaillera/controller/v086/protocol/PlayerInformation.java @@ -165,7 +165,7 @@ public class PlayerInformation extends V086Message public int getLength() { //return (charset.encode(userName).remaining() + 2); - return (userName.length() + 8); + return (getNumBytes(userName) + 8); } public void writeTo(ByteBuffer buffer) diff --git a/src/org/emulinker/kaillera/controller/v086/protocol/Quit.java b/src/org/emulinker/kaillera/controller/v086/protocol/Quit.java index 3234dbe..c670116 100644 --- a/src/org/emulinker/kaillera/controller/v086/protocol/Quit.java +++ b/src/org/emulinker/kaillera/controller/v086/protocol/Quit.java @@ -55,7 +55,7 @@ public abstract class Quit extends V086Message public int getBodyLength() { //return (charset.encode(userName).remaining() + charset.encode(message).remaining() + 4); - return (userName.length() + message.length() + 4); + return (getNumBytes(userName) + getNumBytes(message) + 4); } public void writeBodyTo(ByteBuffer buffer) diff --git a/src/org/emulinker/kaillera/controller/v086/protocol/QuitGame.java b/src/org/emulinker/kaillera/controller/v086/protocol/QuitGame.java index a1e8d70..b694dc3 100644 --- a/src/org/emulinker/kaillera/controller/v086/protocol/QuitGame.java +++ b/src/org/emulinker/kaillera/controller/v086/protocol/QuitGame.java @@ -43,7 +43,7 @@ public abstract class QuitGame extends V086Message public int getBodyLength() { //return (charset.encode(userName).remaining() + 3); - return (userName.length() + 3); + return (getNumBytes(userName) + 3); } public void writeBodyTo(ByteBuffer buffer) diff --git a/src/org/emulinker/kaillera/controller/v086/protocol/ServerStatus.java b/src/org/emulinker/kaillera/controller/v086/protocol/ServerStatus.java index 27ceece..e88ff5e 100644 --- a/src/org/emulinker/kaillera/controller/v086/protocol/ServerStatus.java +++ b/src/org/emulinker/kaillera/controller/v086/protocol/ServerStatus.java @@ -233,7 +233,7 @@ public class ServerStatus extends V086Message public int getLength() { //return (charset.encode(userName).remaining() + 9); - return (userName.length() + 9); + return (getNumBytes(userName) + 9); } public void writeTo(ByteBuffer buffer) @@ -318,7 +318,7 @@ public class ServerStatus extends V086Message public int getLength() { //return (charset.encode(romName).remaining() + 1 + 4 + charset.encode(clientType).remaining() + 1 + charset.encode(userName).remaining() + 1 + charset.encode(players).remaining() + 1 + 1); - return (romName.length() + 1 + 4 + clientType.length() + 1 + userName.length() + 1 + players.length() + 1 + 1); + return (getNumBytes(romName) + 1 + 4 + getNumBytes(clientType) + 1 + getNumBytes(userName) + 1 + getNumBytes(players) + 1 + 1); } public void writeTo(ByteBuffer buffer) diff --git a/src/org/emulinker/kaillera/controller/v086/protocol/UserInformation.java b/src/org/emulinker/kaillera/controller/v086/protocol/UserInformation.java index e2651db..5351c7d 100644 --- a/src/org/emulinker/kaillera/controller/v086/protocol/UserInformation.java +++ b/src/org/emulinker/kaillera/controller/v086/protocol/UserInformation.java @@ -40,7 +40,7 @@ public class UserInformation extends V086Message public int getBodyLength() { //return (charset.encode(userName).remaining() + charset.encode(clientType).remaining() + 3); - return (userName.length() + clientType.length() + 3); + return (getNumBytes(userName) + getNumBytes(clientType) + 3); } public String getUserName() diff --git a/src/org/emulinker/kaillera/controller/v086/protocol/UserJoined.java b/src/org/emulinker/kaillera/controller/v086/protocol/UserJoined.java index 27fb42f..91df80e 100644 --- a/src/org/emulinker/kaillera/controller/v086/protocol/UserJoined.java +++ b/src/org/emulinker/kaillera/controller/v086/protocol/UserJoined.java @@ -75,7 +75,7 @@ public class UserJoined extends V086Message public int getBodyLength() { //return (charset.encode(userName).remaining() + 8); - return (userName.length() + 8); + return (getNumBytes(userName) + 8); } public void writeBodyTo(ByteBuffer buffer) diff --git a/src/org/emulinker/kaillera/controller/v086/protocol/V086Message.java b/src/org/emulinker/kaillera/controller/v086/protocol/V086Message.java index 50dd605..7af205d 100644 --- a/src/org/emulinker/kaillera/controller/v086/protocol/V086Message.java +++ b/src/org/emulinker/kaillera/controller/v086/protocol/V086Message.java @@ -39,6 +39,12 @@ public abstract class V086Message extends ByteBufferMessage return (getBodyLength() + 1); //return (getBodyLength() + 5); } + + /** Gets the number of bytes to represent the string in the charset defined in emulinker.cfg **/ + protected static int getNumBytes(String s) + { + return s.getBytes(charset).length; + } public abstract int getBodyLength(); diff --git a/src/org/emulinker/kaillera/model/impl/KailleraUserImpl.java b/src/org/emulinker/kaillera/model/impl/KailleraUserImpl.java index b77fc6d..893b3f7 100644 --- a/src/org/emulinker/kaillera/model/impl/KailleraUserImpl.java +++ b/src/org/emulinker/kaillera/model/impl/KailleraUserImpl.java @@ -535,6 +535,12 @@ public final class KailleraUserImpl implements KailleraUser, Executable public synchronized KailleraGame createGame(String romName) throws CreateGameException, FloodException { updateLastActivity(); + + if (server.getUser(getID()) == null) + { + log.error(this + " create game failed: User don't exists!"); + return null; + } if (getStatus() == KailleraUser.STATUS_PLAYING) { @@ -664,8 +670,9 @@ public final class KailleraUserImpl implements KailleraUser, Executable if (status == KailleraUser.STATUS_PLAYING) { - game.drop(this, playerNumber); + //first set STATUS_IDLE and then call game.drop, otherwise if someone quit game whitout drop - game status will not change to STATUS_WAITING setStatus(KailleraUser.STATUS_IDLE); + game.drop(this, playerNumber); } game.quit(this, playerNumber); diff --git a/src/org/emulinker/kaillera/release/KailleraServerReleaseInfo.java b/src/org/emulinker/kaillera/release/KailleraServerReleaseInfo.java index b554000..232f03e 100644 --- a/src/org/emulinker/kaillera/release/KailleraServerReleaseInfo.java +++ b/src/org/emulinker/kaillera/release/KailleraServerReleaseInfo.java @@ -13,9 +13,9 @@ public final class KailleraServerReleaseInfo implements ReleaseInfo private final int majorVersion = 0; private final int minorVersion = 92; - private final int buildNumber = 4; + private final int buildNumber = 9; - private final String releaseDate = "05-06-2021"; + private final String releaseDate = "08-22-2021"; private final String licenseInfo = "Usage of this sofware is subject to the terms found in the included license"; private final String website = "https://www.EmuLinker.org"; From e566330d9896d14095b2a833d7dc46dbe27d1c42 Mon Sep 17 00:00:00 2001 From: Jonn Date: Fri, 18 Feb 2022 22:11:02 +0900 Subject: [PATCH 2/5] Remove broken import (unused), fix Ant build file, and add build instructions. --- .gitignore | 1 + README.md | 14 ++++++++++++++ build.xml | 2 +- .../controller/v086/protocol/V086Message.java | 4 ---- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index a1c2a23..4e35159 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Compiled class file *.class +build/ # Log file *.log diff --git a/README.md b/README.md index 852a01d..9cee126 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,17 @@ Original EmuLinker can be found here: https://github.com/monospacesoftware/emuli This is unofficially updated version of EmulinkeSF, based on original latest source v72.3 (09-20-2009). This version includes bug fixes and other improvements. ****************** + +## Development + +To build the jar using Ant (tested at version 1.10.7) run: + +```shell +$ ant build +``` + +To run the jar with Bash: + +```shell +$ java -Xms64m -Xmx128m -cp ./conf:./build/emulinker.jar:./lib/commons-collections-3.1.jar:./lib/commons-configuration-1.1.jar:./lib/commons-el.jar:./lib/commons-lang-2.1.jar:./lib/commons-logging.jar:./lib/commons-pool-1.2.jar:./lib/log4j-1.2.12.jar:./lib/nanocontainer-1.0-beta-3.jar:./lib/picocontainer-1.1.jar:./lib/xstream-1.1.2.jar:./lib/commons-codec-1.3.jar:./lib/commons-httpclient-3.0-rc3.jar org.emulinker.kaillera.pico.PicoStarter +``` diff --git a/build.xml b/build.xml index 3b4b9fd..ec34ccf 100644 --- a/build.xml +++ b/build.xml @@ -21,7 +21,7 @@ - + diff --git a/src/org/emulinker/kaillera/controller/v086/protocol/V086Message.java b/src/org/emulinker/kaillera/controller/v086/protocol/V086Message.java index 7af205d..0a07503 100644 --- a/src/org/emulinker/kaillera/controller/v086/protocol/V086Message.java +++ b/src/org/emulinker/kaillera/controller/v086/protocol/V086Message.java @@ -2,13 +2,9 @@ package org.emulinker.kaillera.controller.v086.protocol; import java.nio.ByteBuffer; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.emulinker.kaillera.controller.messaging.*; import org.emulinker.util.*; -import com.sun.corba.se.impl.encoding.BufferManagerFactory; - public abstract class V086Message extends ByteBufferMessage { protected int number; From df405130d18d3f7f04be97ddd571216b02b502a9 Mon Sep 17 00:00:00 2001 From: Jonn Date: Fri, 18 Feb 2022 22:21:59 +0900 Subject: [PATCH 3/5] Add github workflow to test that it compiles --- .github/workflows/ant.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/ant.yml diff --git a/.github/workflows/ant.yml b/.github/workflows/ant.yml new file mode 100644 index 0000000..73d6c00 --- /dev/null +++ b/.github/workflows/ant.yml @@ -0,0 +1,22 @@ +name: Java CI + +on: + push: + branches: [ master, add-instructions ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 11 + uses: actions/setup-java@v2 + with: + java-version: '11' + distribution: 'temurin' + - name: Build with Ant + run: ant build From 00cdce49ea19d34ffdbace8b3f2c6e0b856486cd Mon Sep 17 00:00:00 2001 From: Jonn Date: Fri, 18 Feb 2022 22:25:17 +0900 Subject: [PATCH 4/5] Add a .gitignore in build/ directory so we guarantee a build/ file exists --- .gitignore | 1 - build/.gitignore | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 build/.gitignore diff --git a/.gitignore b/.gitignore index 4e35159..a1c2a23 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ # Compiled class file *.class -build/ # Log file *.log diff --git a/build/.gitignore b/build/.gitignore new file mode 100644 index 0000000..5c77e8e --- /dev/null +++ b/build/.gitignore @@ -0,0 +1,3 @@ +# Ignore everything in this directory, but Ant will complain if we don't have a build/ directory, so leave this .gitignore as a placeholder. +* +!.gitignore From 311ffd3fb6ab908d2fb7485e7e8ebb9ef0a05b09 Mon Sep 17 00:00:00 2001 From: Jonn Date: Fri, 18 Feb 2022 22:30:01 +0900 Subject: [PATCH 5/5] Remove temporary branch now that we know it works. --- .github/workflows/ant.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ant.yml b/.github/workflows/ant.yml index 73d6c00..49c5b68 100644 --- a/.github/workflows/ant.yml +++ b/.github/workflows/ant.yml @@ -2,7 +2,7 @@ name: Java CI on: push: - branches: [ master, add-instructions ] + branches: [ master ] pull_request: branches: [ master ]