mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Added garbage collection for disconnected players
- Heartbeat messages are sent out from their own thread to each player - If a heartbeat message can't be sent to a player, they are removed from the list of players - Added equals method for players Tags: #story[1047]
This commit is contained in:
@@ -24,7 +24,6 @@ public class Player {
|
||||
return socketChannel;
|
||||
}
|
||||
|
||||
|
||||
public Integer getLastMarkPassed() {
|
||||
return lastMarkPassed;
|
||||
}
|
||||
@@ -40,6 +39,11 @@ public class Player {
|
||||
@Override
|
||||
public String toString() {
|
||||
String playerAddress = null;
|
||||
|
||||
if (socketChannel == null){
|
||||
return "Disconnected Player";
|
||||
}
|
||||
|
||||
try {
|
||||
playerAddress = socketChannel.getRemoteAddress().toString();
|
||||
} catch (IOException e) {
|
||||
@@ -48,4 +52,22 @@ public class Player {
|
||||
|
||||
return playerAddress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null){
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(obj instanceof Player)){
|
||||
return false;
|
||||
}
|
||||
|
||||
return ((Player) obj).socketChannel.equals(socketChannel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode(){
|
||||
return socketChannel.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user