Started building connection between game logic and sever-client. Added new Protocol msg and a s*** ton of todos for myself

This commit is contained in:
Seraina 2022-04-07 13:24:09 +02:00
parent 2789779d62
commit 7153563471
7 changed files with 62 additions and 4 deletions

View File

@ -22,6 +22,8 @@ Server Commands:
Implemented: Implemented:
* SPING Ping from server to client * SPING Ping from server to client
* PINGB Pingback from client to server. * PINGB Pingback from client to server.
* GVOTR Ghosts: Please vote now
* HVOTR Humans: Please vote now
Future / planned: Future / planned:
* MSGRS "Message received": Paramaters: a string detailing to the client that and what the server received as command. * MSGRS "Message received": Paramaters: a string detailing to the client that and what the server received as command.
@ -29,3 +31,4 @@ Future / planned:
* NOCMD No command found. * NOCMD No command found.

View File

@ -1,5 +1,7 @@
package ch.unibas.dmi.dbis.cs108.gamelogic; package ch.unibas.dmi.dbis.cs108.gamelogic;
import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Passenger;
/** /**
* Handles all communication Client to Server concerning games tate updates i.e. client a has voted * Handles all communication Client to Server concerning games tate updates i.e. client a has voted
* Maybe unnecessary, everything that is needed might already be implemented in ClientHandler. * Maybe unnecessary, everything that is needed might already be implemented in ClientHandler.
@ -8,4 +10,11 @@ package ch.unibas.dmi.dbis.cs108.gamelogic;
public class ClientGameInfoHandler { public class ClientGameInfoHandler {
/**
* sends a msg "" to Server stating who voted for who, this being the Client that votes
* @param position the position of the passenger that is voted for
*/
public void vote(int position) {
}
} }

View File

@ -1,5 +1,7 @@
package ch.unibas.dmi.dbis.cs108.gamelogic; package ch.unibas.dmi.dbis.cs108.gamelogic;
import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Passenger;
/** /**
* Handles all communications Server to Client concerning game state or game state related requests * Handles all communications Server to Client concerning game state or game state related requests
* - Needs a possibility to only send to Ghosts * - Needs a possibility to only send to Ghosts
@ -9,4 +11,25 @@ package ch.unibas.dmi.dbis.cs108.gamelogic;
public class ServerGameInfoHandler { public class ServerGameInfoHandler {
/**
* TODO(Seraina): Handle NPC's Maybe do that in Passenger send methode!
* Send a message "GVOTR" to a passenger urging them to vote for a human to infect
* Currently only handles only Players, so send a message to corresponding client
* @param passenger the passenger the message is meant to, should be a Ghost
*/
public void sendVoteRequestGhosts(Passenger passenger){
passenger.getClientHandler().sendMsgToClient("GVOTR");
}
/**
* TODO(Seraina): Handle NPC's
* Send a message "HVOTR" to a passenger urging them to vote for sm to kick off the train.
* Currently only handles only Players, so send a message to corresponding client
* @param passenger the passenger the message is meant to, can be either human or ghost
*/
public void sendVoteRequestHumans(Passenger passenger){
passenger.getClientHandler().sendMsgToClient("HVOTR");
}
} }

View File

@ -23,6 +23,7 @@ public class VoteHandler {
public static final Logger LOGGER = LogManager.getLogger(); public static final Logger LOGGER = LogManager.getLogger();
public static final BudaLogConfig l = new BudaLogConfig(LOGGER); public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
/** /**
* Handles the ghost vote during nighttime: passengers who are ghosts are being asked on who to * Handles the ghost vote during nighttime: passengers who are ghosts are being asked on who to
* ghostify, others are waiting. Results are being collected and the player with most votes is * ghostify, others are waiting. Results are being collected and the player with most votes is

View File

@ -1,6 +1,7 @@
package ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur; package ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur;
import ch.unibas.dmi.dbis.cs108.BudaLogConfig; import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
import ch.unibas.dmi.dbis.cs108.gamelogic.ServerGameInfoHandler;
import ch.unibas.dmi.dbis.cs108.multiplayer.server.ClientHandler; import ch.unibas.dmi.dbis.cs108.multiplayer.server.ClientHandler;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -20,13 +21,16 @@ public class Passenger {
protected int vote; //saves the number of the player this passenger voted for during voting (0-5) protected int vote; //saves the number of the player this passenger voted for during voting (0-5)
/** /**
* Sends a protocol message to the respective player. * Sends a protocol message to the respective player or NPC.
*
* @param msg the message that is sent to this player. * @param msg the message that is sent to this player.
**/ **/
public void send(String msg) { public void send(String msg) {
//todo(Seraina): send protocol message to the respective client OR process messages for NPCS if (isPlayer) {
this.vote = (int) (Math.random() * 6); //TODO: maybe put a formatter here, so protocol msg are only send between sever-client
clientHandler.sendMsgToClient(msg); //ToDO(Seraina): Make sure only the right kind of messages are sent
} else {
//TODO: call a method that identifies message for NPC and calls respective methode NPCParser
}
} }
/** /**

View File

@ -8,6 +8,15 @@ public class JClientProtocolParser {
public static final Logger LOGGER = LogManager.getLogger(); public static final Logger LOGGER = LogManager.getLogger();
public static final BudaLogConfig l = new BudaLogConfig(LOGGER); public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
/**
* Got a request from the Server to vote which human to infect.
*/
public static final String GVOTR = "GVOTR";
/**
* Got a request from Server to vote which player to throw of the train
*/
public static final String HVOTR = "HVOTR";
/** /**
* Used by the client to parse an incoming protocol message. * Used by the client to parse an incoming protocol message.
* *
@ -42,6 +51,14 @@ public class JClientProtocolParser {
case "QUITC": case "QUITC":
c.disconnectFromServer(); c.disconnectFromServer();
break; break;
case GVOTR:
System.out.println("Ghost received Vote request");
//TODO(Seraina): How can be enforced, that clients won't vote otherwise? Trigger a methode here that listens to input
break;
case HVOTR:
System.out.println("Human received Vote request");
//TODO(Seraina): How can be enforced, that clients won't vote otherwise? Trigger a methode here that listens to input
break;
default: default:
System.out.println("Received unknown command"); System.out.println("Received unknown command");
} }

View File

@ -14,6 +14,7 @@ public class JServerProtocolParser {
*/ */
public static final String CHATA = "CHATA"; public static final String CHATA = "CHATA";
/** /**
* Used by the server (i.e. ClientHandler) to parse an incoming protocol message. * Used by the server (i.e. ClientHandler) to parse an incoming protocol message.
* *