Some fixes/improvements

This commit is contained in:
Jgunishka 2019-08-21 21:27:37 +03:00
parent 47d88d5395
commit b84d24fc64

View File

@ -29,13 +29,15 @@ public final class KailleraGameImpl implements KailleraGame
private int lastAddressCount = 0; private int lastAddressCount = 0;
private static int chatFloodTime = 3; private static int chatFloodTime = 3;
private int maxUsers = 16; private int maxUsers = 8;
private int delay; private int delay;
private String aEmulator = "any"; private String aEmulator = "any";
private String aConnection = "any";
private int maxPing = 1000; private int maxPing = 1000;
private int startN = -1; private int startN = -1;
private boolean p2P = false; private boolean p2P = false;
private boolean sameDelay = false; private boolean sameDelay = false;
public boolean swap = false;
private int highestPing = 0; private int highestPing = 0;
private int bufferSize; private int bufferSize;
@ -50,6 +52,7 @@ public final class KailleraGameImpl implements KailleraGame
private StatsCollector statsCollector; private StatsCollector statsCollector;
private List<String> kickedUsers = new ArrayList<String>(); private List<String> kickedUsers = new ArrayList<String>();
private List<String> mutedUsers = new ArrayList<String>();
private int status = KailleraGame.STATUS_WAITING; private int status = KailleraGame.STATUS_WAITING;
private boolean synched = false; private boolean synched = false;
@ -80,7 +83,9 @@ public final class KailleraGameImpl implements KailleraGame
return id; return id;
} }
public List<String> getMutedUsers() {
return mutedUsers;
}
public int getDelay(){ public int getDelay(){
return delay; return delay;
@ -93,6 +98,13 @@ public final class KailleraGameImpl implements KailleraGame
this.aEmulator = aEmulator; this.aEmulator = aEmulator;
} }
public String getAConnection(){
return aConnection;
}
public void setAConnection(String aConnection){
this.aConnection = aConnection;
}
public PlayerActionQueue[] getPlayerActionQueue(){ public PlayerActionQueue[] getPlayerActionQueue(){
return playerActionQueues; return playerActionQueues;
} }
@ -297,6 +309,31 @@ public final class KailleraGameImpl implements KailleraGame
log.warn(user + " game chat denied: not in " + this); //$NON-NLS-1$ log.warn(user + " game chat denied: not in " + this); //$NON-NLS-1$
throw new GameChatException(EmuLang.getString("KailleraGameImpl.GameChatErrorNotInGame")); //$NON-NLS-1$ throw new GameChatException(EmuLang.getString("KailleraGameImpl.GameChatErrorNotInGame")); //$NON-NLS-1$
} }
message = message.trim();
if (message.length() == 0 || message.startsWith(" ") || message.startsWith("­"))
return;
if (user.getAccess() == AccessManager.ACCESS_NORMAL)
{
char[] chars = message.toCharArray();
for (int i = 0; i < chars.length; i++)
{
if (chars[i] < 32)
{
log.warn(user + " gamechat denied: Illegal characters in message");
addEvent(new GameInfoEvent(this, EmuLang.getString("KailleraGameImpl.GameChatDeniedIllegalCharacters"), user));
throw new GameChatException(EmuLang.getString("KailleraGameImpl.GameChatDeniedIllegalCharacters"));
}
}
if (server.getMaxGameChatLength() > 0 && message.length() > server.getMaxGameChatLength())
{
log.warn(user + " gamechat denied: Message Length > " + server.getMaxGameChatLength());
addEvent(new GameInfoEvent(this, EmuLang.getString("KailleraGameImpl.GameChatDeniedMessageTooLong"), user));
throw new GameChatException(EmuLang.getString("KailleraGameImpl.GameChatDeniedMessageTooLong"));
}
}
log.info(user + ", " + this + " gamechat: " + message); //$NON-NLS-1$ //$NON-NLS-2$ log.info(user + ", " + this + " gamechat: " + message); //$NON-NLS-1$ //$NON-NLS-2$
addEvent(new GameChatEvent(this, user, message)); addEvent(new GameChatEvent(this, user, message));
@ -368,7 +405,7 @@ public final class KailleraGameImpl implements KailleraGame
if(access < AccessManager.ACCESS_ADMIN){ if(access < AccessManager.ACCESS_ADMIN){
kickedUsers.add(user.getConnectSocketAddress().getAddress().getHostAddress()); kickedUsers.add(user.getConnectSocketAddress().getAddress().getHostAddress());
try { user.quitGame(); } catch(Exception e) {} try { user.quitGame(); } catch(Exception e) {}
throw new JoinGameException("Join Game Error: Spam Protection"); //$NON-NLS-1$ throw new JoinGameException("Spam Protection"); //$NON-NLS-1$
} }
} }
} }
@ -386,20 +423,29 @@ public final class KailleraGameImpl implements KailleraGame
if(access < AccessManager.ACCESS_ELEVATED && getNumPlayers() >= getMaxUsers()) if(access < AccessManager.ACCESS_ELEVATED && getNumPlayers() >= getMaxUsers())
{ {
log.warn(user + " join game denied: max users reached " + this); //$NON-NLS-1$ log.warn(user + " join game denied: max users reached " + this); //$NON-NLS-1$
throw new JoinGameException("Join Game Denied: This room's user capacity has been reached."); //$NON-NLS-1$ throw new JoinGameException("This room's user capacity has been reached."); //$NON-NLS-1$
} }
if(access < AccessManager.ACCESS_ELEVATED && user.getPing() > getMaxPing()) if(access < AccessManager.ACCESS_ELEVATED && user.getPing() > getMaxPing())
{ {
log.warn(user + " join game denied: max ping reached " + this); //$NON-NLS-1$ log.warn(user + " join game denied: max ping reached " + this); //$NON-NLS-1$
throw new JoinGameException("Join Game Denied: Your ping is too high for this room."); //$NON-NLS-1$ throw new JoinGameException("Your ping is too high for this room."); //$NON-NLS-1$
} }
if(access < AccessManager.ACCESS_ELEVATED && !aEmulator.equals("any")) if(access < AccessManager.ACCESS_ELEVATED && !aEmulator.equals("any"))
{ {
if(!aEmulator.equals(user.getClientType())){ if(!aEmulator.equals(user.getClientType())){
log.warn(user + " join game denied: Owner doesn't allow that emulator! " + this); //$NON-NLS-1$ log.warn(user + " join game denied: owner doesn't allow that emulator: " + user.getClientType()); //$NON-NLS-1$
throw new JoinGameException("Join Game Denied: Owner only allows emulators that start with: " + aEmulator); //$NON-NLS-1$ throw new JoinGameException("Owner only allows emulator version: " + aEmulator); //$NON-NLS-1$
}
}
if(access < AccessManager.ACCESS_ELEVATED && !aConnection.equals("any"))
{
if (user.getConnectionType() != getOwner().getConnectionType())
{
log.warn(user + "join game denied: owner doesn't allow that connection type: " + KailleraUser.CONNECTION_TYPE_NAMES[user.getConnectionType()]); //$NON-NLS-1$
throw new JoinGameException("Owner only allows connection type: " + KailleraUser.CONNECTION_TYPE_NAMES[getOwner().getConnectionType()]); //$NON-NLS-1$
} }
} }
@ -415,6 +461,10 @@ public final class KailleraGameImpl implements KailleraGame
throw new JoinGameException(EmuLang.getString("KailleraGameImpl.JoinGameDeniedGameIsInProgress")); //$NON-NLS-1$ throw new JoinGameException(EmuLang.getString("KailleraGameImpl.JoinGameDeniedGameIsInProgress")); //$NON-NLS-1$
} }
if (mutedUsers.contains(user.getConnectSocketAddress().getAddress().getHostAddress()))
{
user.setMute(true);
}
players.add((KailleraUserImpl) user); players.add((KailleraUserImpl) user);
user.setPlayerNumber(players.size()); user.setPlayerNumber(players.size());
@ -426,15 +476,16 @@ public final class KailleraGameImpl implements KailleraGame
//SF MOD - /startn //SF MOD - /startn
if(getStartN() != -1){ if(getStartN() != -1){
if(players.size() >= getStartN()) if(players.size() >= getStartN()){
try { Thread.sleep(1000); } catch(Exception e) {} try { Thread.sleep(1000); } catch(Exception e) {}
try { start(getOwner()); } catch(Exception e) {} try { start(getOwner()); } catch(Exception e) {}
}
} }
//if(user.equals(owner)) //if(user.equals(owner))
//{ //{
announce("Help: " + getServer().getReleaseInfo().getProductName() + " v" + getServer().getReleaseInfo().getVersionString() + ": " + getServer().getReleaseInfo().getReleaseDate() + " - Visit: www.God-Weapon.com", user); announce("Help: " + getServer().getReleaseInfo().getProductName() + " v" + getServer().getReleaseInfo().getVersionString() + ": " + getServer().getReleaseInfo().getReleaseDate() + " - Visit: https://github.com/God-Weapon", user);
announce("************************", user); announce("************************", user);
announce("Type /p2pon to ignore ALL server activity during gameplay.", user); announce("Type /p2pon to ignore ALL server activity during gameplay.", user);
announce("This will reduce lag that you contribute due to a busy server.", user); announce("This will reduce lag that you contribute due to a busy server.", user);
@ -456,6 +507,10 @@ public final class KailleraGameImpl implements KailleraGame
} }
*/ */
//} //}
//new SF MOD - different emulator versions notifications
if (access < AccessManager.ACCESS_ADMIN && !user.getClientType().equals(owner.getClientType()) && !owner.getGame().getRomName().startsWith("*"))
addEvent(new GameInfoEvent(this, user.getName() + " using different emulator version: " + user.getClientType(), null));
return (players.indexOf(user) + 1); return (players.indexOf(user) + 1);
} }
@ -487,6 +542,10 @@ public final class KailleraGameImpl implements KailleraGame
log.warn(user + " start game denied: " + this + " needs at least 2 players"); //$NON-NLS-1$ //$NON-NLS-2$ log.warn(user + " start game denied: " + this + " needs at least 2 players"); //$NON-NLS-1$ //$NON-NLS-2$
throw new StartGameException(EmuLang.getString("KailleraGameImpl.StartGameDeniedSinglePlayerNotAllowed")); //$NON-NLS-1$ throw new StartGameException(EmuLang.getString("KailleraGameImpl.StartGameDeniedSinglePlayerNotAllowed")); //$NON-NLS-1$
} }
// do not start if not game
if(owner.getGame().getRomName().startsWith("*"))
return;
for (KailleraUser player : players) for (KailleraUser player : players)
{ {
@ -527,7 +586,7 @@ public final class KailleraGameImpl implements KailleraGame
KailleraUserImpl player = players.get(i); KailleraUserImpl player = players.get(i);
int playerNumber = (i + 1); int playerNumber = (i + 1);
player.setPlayerNumber(playerNumber); if(!swap) player.setPlayerNumber(playerNumber);
player.setTimeouts(0); player.setTimeouts(0);
player.setFrameCount(0); player.setFrameCount(0);
@ -552,9 +611,9 @@ public final class KailleraGameImpl implements KailleraGame
player.setP2P(true); player.setP2P(true);
announce("This game is ignoring ALL server activity during gameplay!", player); announce("This game is ignoring ALL server activity during gameplay!", player);
} }
else{ /*else{
player.setP2P(false); player.setP2P(false);
} }*/
log.info(this + ": " + player + " is player number " + playerNumber); //$NON-NLS-1$ //$NON-NLS-2$ log.info(this + ": " + player + " is player number " + playerNumber); //$NON-NLS-1$ //$NON-NLS-2$
@ -565,11 +624,11 @@ public final class KailleraGameImpl implements KailleraGame
if (statsCollector != null) if (statsCollector != null)
statsCollector.gameStarted(server, this); statsCollector.gameStarted(server, this);
if(user.getConnectionType() > KailleraUser.CONNECTION_TYPE_GOOD || user.getConnectionType() < KailleraUser.CONNECTION_TYPE_GOOD){ /*if(user.getConnectionType() > KailleraUser.CONNECTION_TYPE_GOOD || user.getConnectionType() < KailleraUser.CONNECTION_TYPE_GOOD){
//sameDelay = true; //sameDelay = true;
} }*/
timeoutMillis = highestPing; //timeoutMillis = highestPing;
addEvent(new GameStartedEvent(this)); addEvent(new GameStartedEvent(this));
} }
@ -612,7 +671,8 @@ public final class KailleraGameImpl implements KailleraGame
else{ else{
for (int i = 0; i < playerActionQueues.length && i < players.size(); i++){ for (int i = 0; i < playerActionQueues.length && i < players.size(); i++){
KailleraUserImpl player = players.get(i); KailleraUserImpl player = players.get(i);
if(player != null){ // do not show delay if stealth mode
if(player != null && !player.getStealth()){
frameDelay = ((player.getDelay() + 1) * player.getConnectionType()) - 1; frameDelay = ((player.getDelay() + 1) * player.getConnectionType()) - 1;
announce("P" + (i + 1) + " Delay = " + player.getDelay() + " (" + frameDelay + " frame delay)", null); announce("P" + (i + 1) + " Delay = " + player.getDelay() + " (" + frameDelay + " frame delay)", null);
} }
@ -685,6 +745,10 @@ public final class KailleraGameImpl implements KailleraGame
addEvent(new UserQuitGameEvent(this, user)); addEvent(new UserQuitGameEvent(this, user));
user.setP2P(false);
swap = false;
if(status == STATUS_WAITING){ if(status == STATUS_WAITING){
for(int i = 0; i < this.getNumPlayers(); i++){ for(int i = 0; i < this.getNumPlayers(); i++){
getPlayer(i + 1).setPlayerNumber(i + 1); getPlayer(i + 1).setPlayerNumber(i + 1);
@ -716,9 +780,13 @@ public final class KailleraGameImpl implements KailleraGame
} }
for (KailleraUserImpl player : players) for (KailleraUserImpl player : players){
player.setStatus(KailleraUser.STATUS_IDLE);
player.setMute(false);
player.setP2P(false);
player.setGame(null); player.setGame(null);
}
if(autoFireDetector != null) if(autoFireDetector != null)
autoFireDetector.stop(); autoFireDetector.stop();