diff --git a/src/org/emulinker/kaillera/controller/v086/action/AdminCommandAction.java b/src/org/emulinker/kaillera/controller/v086/action/AdminCommandAction.java index 6068c7c..27cf6bc 100644 --- a/src/org/emulinker/kaillera/controller/v086/action/AdminCommandAction.java +++ b/src/org/emulinker/kaillera/controller/v086/action/AdminCommandAction.java @@ -265,55 +265,76 @@ private void processHelp(String message, KailleraServerImpl server, KailleraUser { if(admin.getAccess() == AccessManager.ACCESS_MODERATOR) return; - clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", EmuLang.getString("AdminCommandAction.HelpVersion"))); //$NON-NLS-1$ //$NON-NLS-2$ - try { Thread.sleep(20); } catch(Exception e) {} - clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", EmuLang.getString("AdminCommandAction.HelpKick"))); //$NON-NLS-1$ //$NON-NLS-2$ - try { Thread.sleep(20); } catch(Exception e) {} - clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", EmuLang.getString("AdminCommandAction.HelpSilence"))); //$NON-NLS-1$ //$NON-NLS-2$ + + clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "Admin Commands")); //$NON-NLS-1$ //$NON-NLS-2$ try { Thread.sleep(20); } catch(Exception e) {} - clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", EmuLang.getString("AdminCommandAction.HelpBan"))); //$NON-NLS-1$ //$NON-NLS-2$ + clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "--------------")); //$NON-NLS-1$ //$NON-NLS-2$ try { Thread.sleep(20); } catch(Exception e) {} - if(admin.getAccess() == AccessManager.ACCESS_ADMIN){ - clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", EmuLang.getString("AdminCommandAction.HelpClear"))); //$NON-NLS-1$ //$NON-NLS-2$ - try { Thread.sleep(20); } catch(Exception e) {} - } - - clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", EmuLang.getString("AdminCommandAction.HelpCloseGame"))); //$NON-NLS-1$ //$NON-NLS-2$ - try { Thread.sleep(20); } catch(Exception e) {} clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", EmuLang.getString("AdminCommandAction.HelpAnnounce"))); //$NON-NLS-1$ //$NON-NLS-2$ try { Thread.sleep(20); } catch(Exception e) {} clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", EmuLang.getString("AdminCommandAction.HelpAnnounceAll"))); //$NON-NLS-1$ //$NON-NLS-2$ try { Thread.sleep(20); } catch(Exception e) {} clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", EmuLang.getString("AdminCommandAction.HelpAnnounceGame"))); //$NON-NLS-1$ //$NON-NLS-2$ try { Thread.sleep(20); } catch(Exception e) {} - try {clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "/finduser to get a user's info. or /finduser * for all users info. eg. /finduser sli ...will return Slink info.")); } catch(Exception e) {} + clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", EmuLang.getString("AdminCommandAction.HelpBan"))); //$NON-NLS-1$ //$NON-NLS-2$ try { Thread.sleep(20); } catch(Exception e) {} - clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "/findgame to get game info. or /findgame * to get all game info.")); //$NON-NLS-1$ //$NON-NLS-2$ + clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "/clear to remove any temp ban, silence, elevated, moderator or admin.")); //$NON-NLS-1$ //$NON-NLS-2$ try { Thread.sleep(20); } catch(Exception e) {} - clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "/triviaon to start the trivia bot- /triviapause to pause the bot- /triviaresume to resume the bot after pause- /triviasave to save the bot's scores- /triviatime <#> to change the question delay")); //$NON-NLS-1$ //$NON-NLS-2$ + clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", EmuLang.getString("AdminCommandAction.HelpCloseGame"))); //$NON-NLS-1$ //$NON-NLS-2$ try { Thread.sleep(20); } catch(Exception e) {} - clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "/triviaoff to stop the bot- /triviascores to show top 3 scores- /triviawin to show a winner- /triviaupdate to update ip address")); //$NON-NLS-1$ //$NON-NLS-2$ + clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "/findgame to get game info. or /findgame * to get all game info.")); //$NON-NLS-1$ //$NON-NLS-2$ try { Thread.sleep(20); } catch(Exception e) {} - clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "/unscrambleon to start the unscramble bot- /unscramblepause to pause the bot- /unscrambleresume to resume the bot after pause- /unscramblesave to save the bot's scores- /unscrambletime <#> to change the question delay")); //$NON-NLS-1$ //$NON-NLS-2$ + try {clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "/finduser to get a user's info. or /finduser * for all users info. eg. /finduser sli ...will return Slink info.")); } catch(Exception e) {} try { Thread.sleep(20); } catch(Exception e) {} - clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "/unscrambleoff to stop the bot- /unscramblescores to show top 3 scores- /unscramblewin to show a winner")); //$NON-NLS-1$ //$NON-NLS-2$ + clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", EmuLang.getString("AdminCommandAction.HelpKick"))); //$NON-NLS-1$ //$NON-NLS-2$ + try { Thread.sleep(20); } catch(Exception e) {} + + if(admin.getAccess() >= AccessManager.ACCESS_SUPERADMIN){ + clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "/publicrules to display rules to everyone in main chat and game chat")); //$NON-NLS-1$ //$NON-NLS-2$ + try { Thread.sleep(20); } catch(Exception e) {} + } + + clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", EmuLang.getString("AdminCommandAction.HelpSilence"))); //$NON-NLS-1$ //$NON-NLS-2$ try { Thread.sleep(20); } catch(Exception e) {} clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "/stealthon /stealthoff to join a room invisibly.")); //$NON-NLS-1$ //$NON-NLS-2$ try { Thread.sleep(20); } catch(Exception e) {} if(admin.getAccess() >= AccessManager.ACCESS_SUPERADMIN){ + clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "/tempadmin to grant a user temporary admin access")); //$NON-NLS-1$ //$NON-NLS-2$ + try { Thread.sleep(20); } catch(Exception e) {} clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "/tempelevated to give a user temporary elevated access.")); //$NON-NLS-1$ //$NON-NLS-2$ try { Thread.sleep(20); } catch(Exception e) {} clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "/tempmod to give a user temporary moderator access.")); //$NON-NLS-1$ //$NON-NLS-2$ try { Thread.sleep(20); } catch(Exception e) {} - clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", EmuLang.getString("AdminCommandAction.HelpTempAdmin"))); //$NON-NLS-1$ //$NON-NLS-2$ - try { Thread.sleep(20); } catch(Exception e) {} - clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "/clear to remove any temp ban, silence, elevated, moderator or admin.")); //$NON-NLS-1$ //$NON-NLS-2$ - try { Thread.sleep(20); } catch(Exception e) {} - clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "/publicrules to display rules to everyone in main chat and game chat")); //$NON-NLS-1$ //$NON-NLS-2$ + } + + clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "/triviaon to start the trivia bot- /triviapause to pause the bot- /triviaresume to resume the bot after pause- /triviasave to save the bot's scores- /triviatime <#> to change the question delay")); //$NON-NLS-1$ //$NON-NLS-2$ + try { Thread.sleep(20); } catch(Exception e) {} + clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "/triviaoff to stop the bot- /triviascores to show top 3 scores- /triviawin to show a winner- /triviaupdate to update ip address")); //$NON-NLS-1$ //$NON-NLS-2$ + try { Thread.sleep(20); } catch(Exception e) {} + + clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "/unscrambleon to start the unscramble bot- /unscramblepause to pause the bot- /unscrambleresume to resume the bot after pause- /unscramblesave to save the bot's scores- /unscrambletime <#> to change the question delay")); //$NON-NLS-1$ //$NON-NLS-2$ + try { Thread.sleep(20); } catch(Exception e) {} + clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "/unscrambleoff to stop the bot- /unscramblescores to show top 3 scores- /unscramblewin to show a winner")); //$NON-NLS-1$ //$NON-NLS-2$ + try { Thread.sleep(20); } catch(Exception e) {} + + clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", EmuLang.getString("AdminCommandAction.HelpVersion"))); //$NON-NLS-1$ //$NON-NLS-2$ + try { Thread.sleep(20); } catch(Exception e) {} + + clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "Regular User Commands")); //$NON-NLS-1$ //$NON-NLS-2$ + try { Thread.sleep(20); } catch(Exception e) {} + clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "---------------------")); //$NON-NLS-1$ //$NON-NLS-2$ + try { Thread.sleep(20); } catch(Exception e) {} + + /* + if(admin.getAccess() == AccessManager.ACCESS_ADMIN){ + clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", EmuLang.getString("AdminCommandAction.HelpClear"))); //$NON-NLS-1$ //$NON-NLS-2$ try { Thread.sleep(20); } catch(Exception e) {} } + */ + + } diff --git a/src/org/emulinker/kaillera/controller/v086/action/ChatAction.java b/src/org/emulinker/kaillera/controller/v086/action/ChatAction.java index edbaab7..f23c942 100644 --- a/src/org/emulinker/kaillera/controller/v086/action/ChatAction.java +++ b/src/org/emulinker/kaillera/controller/v086/action/ChatAction.java @@ -448,31 +448,41 @@ else if (((Chat) message).getMessage().equals("/rules")) { } } else if(((Chat) message).getMessage().equals("/help")){ - try {clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "/me to make personal message eg. /me is bored ...Slink is bored.")); } catch(Exception e) {} + try { clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "/alivecheck check to see if the server is still responsive with your client")); } catch(Exception e) {} try { Thread.sleep(20); } catch(Exception e) {} + + if(clientHandler.getUser().getAccess() < AccessManager.ACCESS_ADMIN){ + try {clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "/finduser to get a user's info. or /finduser * for all users info. eg. /finduser sli ...will return Slink info.")); } catch(Exception e) {} + try { Thread.sleep(20); } catch(Exception e) {} + } + try {clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "/ignore or /unignore or /ignoreall or /unignoreall to ignore users.")); } catch(Exception e) {} try { Thread.sleep(20); } catch(Exception e) {} + + if(clientHandler.getUser().getAccess() == AccessManager.ACCESS_MODERATOR) { + try {clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "/kick to kick a user.")); } catch(Exception e) {} + try { Thread.sleep(20); } catch(Exception e) {} + } + + try {clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "/me to make personal message eg. /me is bored ...Slink is bored.")); } catch(Exception e) {} + try { Thread.sleep(20); } catch(Exception e) {} try {clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "/msg to PM somebody. /msgoff or /msgon to turn pm off | on.")); } catch(Exception e) {} try { Thread.sleep(20); } catch(Exception e) {} try {clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "/myip to get your IP Address.")); } catch(Exception e) {} + try { Thread.sleep(20); } catch(Exception e) {} try { clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "/rules for the server's rule list.")); } catch(Exception e) {} try { Thread.sleep(20); } catch(Exception e) {} - try { clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "/alivecheck check to see if the server is still responsive with your client")); } catch(Exception e) {} - try { Thread.sleep(20); } catch(Exception e) {} - try { Thread.sleep(20); } catch(Exception e) {} + if(clientHandler.getUser().getAccess() == AccessManager.ACCESS_MODERATOR){ try {clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "/silence to silence a user. 15min max.")); } catch(Exception e) {} try { Thread.sleep(20); } catch(Exception e) {} - try {clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "/kick to kick a user.")); } catch(Exception e) {} - try { Thread.sleep(20); } catch(Exception e) {} } + if(clientHandler.getUser().getAccess() < AccessManager.ACCESS_ADMIN){ try {clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "/version to get server version.")); } catch(Exception e) {} - try { Thread.sleep(20); } catch(Exception e) {} - try {clientHandler.send(new InformationMessage(clientHandler.getNextMessageNumber(), "server", "/finduser to get a user's info. or /finduser * for all users info. eg. /finduser sli ...will return Slink info.")); } catch(Exception e) {} try { Thread.sleep(20); } catch(Exception e) {} - return; } + return; } else if(((Chat) message).getMessage().startsWith("/finduser") && clientHandler.getUser().getAccess() < AccessManager.ACCESS_ADMIN){ int space = ((Chat) message).getMessage().indexOf(' '); diff --git a/src/org/emulinker/kaillera/controller/v086/action/GameChatAction.java b/src/org/emulinker/kaillera/controller/v086/action/GameChatAction.java index af400e2..8330bca 100644 --- a/src/org/emulinker/kaillera/controller/v086/action/GameChatAction.java +++ b/src/org/emulinker/kaillera/controller/v086/action/GameChatAction.java @@ -12,6 +12,7 @@ import org.emulinker.kaillera.model.exception.ActionException; import org.emulinker.kaillera.model.exception.GameChatException; import org.emulinker.kaillera.model.impl.KailleraUserImpl; +import org.emulinker.util.EmuLang; public class GameChatAction implements V086Action, V086GameEventHandler { @@ -202,6 +203,11 @@ else if (((GameChat) message).getMessage().startsWith("/msg")){ 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); @@ -274,6 +280,11 @@ else if (((GameChat) message).getMessage().startsWith("/msg")){ 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); @@ -460,13 +471,17 @@ else if(((GameChat) message).getMessage().startsWith("/me")){ } else if(((GameChat) message).getMessage().equals("/help")){ KailleraUserImpl user = (KailleraUserImpl) clientHandler.getUser(); - user.getGame().announce("/me to make personal message eg. /me is bored ...Slink is bored.", user); - try { Thread.sleep(20); } catch(Exception e) {} - user.getGame().announce("/msg to PM somebody. /msgoff or /msgon to turn pm off | on.", user); + + user.getGame().announce(EmuLang.getString("Gameroom Guests Commands"), user); //$NON-NLS-1$ try { Thread.sleep(20); } catch(Exception e) {} + user.getGame().announce(EmuLang.getString("-----------------------"), user); //$NON-NLS-1$ + try { Thread.sleep(20); } catch(Exception e) {} + user.getGame().announce("/ignore or /unignore or /ignoreall or /unignoreall to ignore users.", user); try { Thread.sleep(20); } catch(Exception e) {} - user.getGame().announce("/p2pon or /p2poff this option ignores all server activity during gameplay.", user); + user.getGame().announce("/me to make personal message eg. /me is bored ...Slink is bored.", user); + try { Thread.sleep(20); } catch(Exception e) {} + user.getGame().announce("/msg to PM somebody. /msgoff or /msgon to turn pm off | on.", user); try { Thread.sleep(20); } catch(Exception e) {} 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..74812e8 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 void performAction(V086Message message, V086Controller.V086ClientHandler 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; } } @@ -238,28 +239,35 @@ private void processHelp(String message, KailleraGameImpl game, KailleraUserImpl //game.setIndividualGameAnnounce(admin.getPlayerNumber()); //game.announce(EmuLang.getString("GameOwnerCommandAction.AvailableCommands")); //$NON-NLS-1$ //try { Thread.sleep(20); } catch(Exception e) {} - game.announce(EmuLang.getString("GameOwnerCommandAction.SetAutofireDetection"), admin); //$NON-NLS-1$ + + game.announce(EmuLang.getString("Gameroom Owner Commands"), admin); //$NON-NLS-1$ try { Thread.sleep(20); } catch(Exception e) {} - game.announce("/maxusers <#> to set capacity of room", admin); //$NON-NLS-1$ + game.announce(EmuLang.getString("-----------------------"), admin); //$NON-NLS-1$ + try { Thread.sleep(20); } catch(Exception e) {} + + game.announce(EmuLang.getString("/detectautofire to set AutoFire detection"), admin); //$NON-NLS-1$ + try { Thread.sleep(20); } catch(Exception e) {} + game.announce("/kick or /kickall to kick a player(s).", admin); //$NON-NLS-1$ try { Thread.sleep(20); } catch(Exception e) {} + game.announce("/lagstat To check who has the most lag spikes or /lagreset to reset lagstat!", admin); //$NON-NLS-1$ + try { Thread.sleep(20); } catch(Exception e) {} game.announce("/maxping <#> to set maximum ping for room", admin); //$NON-NLS-1$ try { Thread.sleep(20); } catch(Exception e) {} - game.announce("/start or /startn <#> start game when n players are joined.", admin); //$NON-NLS-1$ + game.announce("/maxusers <#> to set capacity of room", admin); //$NON-NLS-1$ try { Thread.sleep(20); } catch(Exception e) {} game.announce("/mute /unmute or /muteall or /unmuteall to mute player(s).", admin); //$NON-NLS-1$ try { Thread.sleep(20); } catch(Exception e) {} - game.announce("/swap eg. 123..n {n = total # of players; Each slot = new player#}", admin); //$NON-NLS-1$ - try { Thread.sleep(20); } catch(Exception e) {} - game.announce("/kick or /kickall to kick a player(s).", admin); //$NON-NLS-1$ - try { Thread.sleep(20); } catch(Exception e) {} - game.announce("/setemu To restrict the gameroom to this emulator!", admin); //$NON-NLS-1$ + game.announce("/samedelay {true | false} to play at the same delay as player with highest ping. Default is false.", admin); //$NON-NLS-1$ try { Thread.sleep(20); } catch(Exception e) {} game.announce("/setconn To restrict the gameroom to this connection type!", admin); //$NON-NLS-1$ try { Thread.sleep(20); } catch(Exception e) {} - game.announce("/lagstat To check who has the most lag spikes or /lagreset to reset lagstat!", admin); //$NON-NLS-1$ + game.announce("/setemu To restrict the gameroom to this emulator!", admin); //$NON-NLS-1$ try { Thread.sleep(20); } catch(Exception e) {} - game.announce("/samedelay {true | false} to play at the same delay as player with highest ping. Default is false.", admin); //$NON-NLS-1$ + game.announce("/start or /startn <#> start game when n players are joined.", admin); //$NON-NLS-1$ + try { Thread.sleep(20); } catch(Exception e) {} + game.announce("/swap eg. 123..n {n = total # of players; Each slot = new player#}", admin); //$NON-NLS-1$ try { Thread.sleep(20); } catch(Exception e) {} + } private void autoFireHelp(KailleraGameImpl game, KailleraUserImpl admin) 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 String getMessage() 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 String toString() 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 int getVal1() 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 String getMessage() 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 String toString() 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 byte getConnectionType() 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 String toString() 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 String toString() 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 String getMessage() 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 int getUserID() 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..1f098ba 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 String toString() 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 String toString() 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 String getDescription() 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 String toString() 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 3ae0e55..a9ed49d 100644 --- a/src/org/emulinker/kaillera/controller/v086/protocol/V086Message.java +++ b/src/org/emulinker/kaillera/controller/v086/protocol/V086Message.java @@ -36,6 +36,12 @@ public int getLength() //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(); protected String getInfoString() diff --git a/src/org/emulinker/kaillera/model/impl/KailleraGameImpl.java b/src/org/emulinker/kaillera/model/impl/KailleraGameImpl.java index 75d63cf..87d200e 100644 --- a/src/org/emulinker/kaillera/model/impl/KailleraGameImpl.java +++ b/src/org/emulinker/kaillera/model/impl/KailleraGameImpl.java @@ -311,10 +311,13 @@ public synchronized void chat(KailleraUser user, String message) throws GameChat } message = message.trim(); + // Essential for spam protection if (message.length() == 0 || message.startsWith("�") || message.contains("\n")) return; + // Commented out for now ; Jgunishka removed this in the latest version of SF in order to improve MAME netplay + /* if (user.getAccess() == AccessManager.ACCESS_NORMAL) { if (server.getMaxGameChatLength() > 0 && message.length() > server.getMaxGameChatLength()) @@ -324,6 +327,7 @@ public synchronized void chat(KailleraUser user, String message) throws GameChat throw new GameChatException(EmuLang.getString("KailleraGameImpl.GameChatDeniedMessageTooLong")); } } + */ log.info(user + ", " + this + " gamechat: " + message); //$NON-NLS-1$ //$NON-NLS-2$ addEvent(new GameChatEvent(this, user, message)); diff --git a/src/org/emulinker/kaillera/model/impl/KailleraUserImpl.java b/src/org/emulinker/kaillera/model/impl/KailleraUserImpl.java index 08d096a..ef30fab 100644 --- a/src/org/emulinker/kaillera/model/impl/KailleraUserImpl.java +++ b/src/org/emulinker/kaillera/model/impl/KailleraUserImpl.java @@ -535,6 +535,12 @@ public synchronized void gameKick(int userID) throws GameKickException 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 synchronized void quitGame() throws DropGameException, QuitGameException, if (status == KailleraUser.STATUS_PLAYING) { - game.drop(this, playerNumber); + // First set STATUS_IDLE and then call game.drop(), otherwise if someone quits the game without manually dropping - 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 808605e..7c0f2bf 100644 --- a/src/org/emulinker/kaillera/release/KailleraServerReleaseInfo.java +++ b/src/org/emulinker/kaillera/release/KailleraServerReleaseInfo.java @@ -12,10 +12,10 @@ public final class KailleraServerReleaseInfo implements ReleaseInfo private final String productName = "EmuLinker X"; private final int majorVersion = 3; - private final int minorVersion = 4; + private final int minorVersion = 6; private final int buildNumber = 0; // not in use anymore - private final String releaseDate = "02-19-2023"; + private final String releaseDate = "02-20-2023"; private final String licenseInfo = "Usage of this sofware is subject to the terms found in the included license"; private final String website = "https://emxkaillera.net/index.html";