Added vote and hasVoted fields to ClientHandler for later transmission to corresponding Passenger
This commit is contained in:
parent
d373242486
commit
370e1e97fe
@ -21,6 +21,7 @@ public class ClientHandler implements Runnable {
|
|||||||
private Socket socket;
|
private Socket socket;
|
||||||
private InetAddress ip;
|
private InetAddress ip;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* notes if the client has formally logged in yet. If connecting through the normal Client class,
|
* notes if the client has formally logged in yet. If connecting through the normal Client class,
|
||||||
* the client is logged in automatically, if connecting though some external application, the
|
* the client is logged in automatically, if connecting though some external application, the
|
||||||
@ -34,6 +35,8 @@ public class ClientHandler implements Runnable {
|
|||||||
public static HashSet<ClientHandler> disconnectedClients = new HashSet<>(); //todo: implement re-connection
|
public static HashSet<ClientHandler> disconnectedClients = new HashSet<>(); //todo: implement re-connection
|
||||||
public static HashSet<ClientHandler> lobby = new HashSet<>();
|
public static HashSet<ClientHandler> lobby = new HashSet<>();
|
||||||
public static HashSet<ClientHandler> ghostClients = new HashSet<>();
|
public static HashSet<ClientHandler> ghostClients = new HashSet<>();
|
||||||
|
private int vote; //saves vote of clientHandler for later transmission to passenger, by default MAX_VALUE
|
||||||
|
private boolean hasVoted; //saves hasVoted status of clientHandler for later transmission to passenger, by default false
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements the login logic in client-server architecture.
|
* Implements the login logic in client-server architecture.
|
||||||
@ -48,6 +51,8 @@ public class ClientHandler implements Runnable {
|
|||||||
this.in = new BufferedReader(new InputStreamReader((socket.getInputStream())));
|
this.in = new BufferedReader(new InputStreamReader((socket.getInputStream())));
|
||||||
this.loggedIn = false;
|
this.loggedIn = false;
|
||||||
this.clientUserName = nameDuplicateChecker.checkName("U.N. Owen");
|
this.clientUserName = nameDuplicateChecker.checkName("U.N. Owen");
|
||||||
|
this.vote = Integer.MAX_VALUE;
|
||||||
|
this.hasVoted = false;
|
||||||
connectedClients.add(this);
|
connectedClients.add(this);
|
||||||
serverPinger = new ServerPinger(socket, this);
|
serverPinger = new ServerPinger(socket, this);
|
||||||
Thread sP = new Thread(serverPinger);
|
Thread sP = new Thread(serverPinger);
|
||||||
@ -86,15 +91,30 @@ public class ClientHandler implements Runnable {
|
|||||||
return loggedIn;
|
return loggedIn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getVote() {
|
||||||
|
return vote;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getHasVoted() {
|
||||||
|
return hasVoted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getClientUserName() {
|
||||||
|
return clientUserName;
|
||||||
|
}
|
||||||
|
//Setters:
|
||||||
|
|
||||||
public void setLoggedIn(boolean loggedIn) {
|
public void setLoggedIn(boolean loggedIn) {
|
||||||
this.loggedIn = loggedIn;
|
this.loggedIn = loggedIn;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Setters:
|
public void setVote(int vote) {
|
||||||
public String getClientUserName() {
|
this.vote = vote;
|
||||||
return clientUserName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setHasVoted(boolean hasVoted) {
|
||||||
|
this.hasVoted = hasVoted;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|||||||
@ -67,7 +67,7 @@ public class JServerProtocolParser {
|
|||||||
break;
|
break;
|
||||||
case Protocol.listLobbies:
|
case Protocol.listLobbies:
|
||||||
//TODO: add action
|
//TODO: add action
|
||||||
LOGGER.debug(Protocol.listLobbies + " command recieved from: " + h.getClientUserName());
|
LOGGER.debug(Protocol.listLobbies + " command received from: " + h.getClientUserName());
|
||||||
break;
|
break;
|
||||||
case Protocol.votedFor:
|
case Protocol.votedFor:
|
||||||
int vote = Integer.parseInt(msg.substring(6));
|
int vote = Integer.parseInt(msg.substring(6));
|
||||||
|
|||||||
Reference in New Issue
Block a user