Merge branch 'master' of ssh://git.scicore.unibas.ch:2222/cs108-fs22/Gruppe-8
This commit is contained in:
commit
22d356e361
@ -241,5 +241,11 @@ ToDo:
|
||||
Stand:
|
||||
Server - Client: Connection loss handling funktioniert nun.
|
||||
Lobby: ?
|
||||
Spiellogik:
|
||||
Spiellogik: VoteHandler wurde getestet und tut weitestgehenst was er soll
|
||||
|
||||
ToDo:
|
||||
Spiellogik: - Send() methode von Passenger mit Client-Server verknüpfen(Seraina)
|
||||
- NoiseHandler (Alex)
|
||||
- Game Zyklus implementieren (Seraina)
|
||||
|
||||
|
||||
|
||||
@ -190,6 +190,10 @@ public class VoteHandler {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Just a print Method for testing the VoteHandler
|
||||
* @param array the Passenger array to be visualized
|
||||
*/
|
||||
static void print(Passenger[] array) {
|
||||
System.out.println();
|
||||
String[] print = new String[6];
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package ch.unibas.dmi.dbis.cs108.multiplayer.client;
|
||||
|
||||
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -8,17 +9,12 @@ public class JClientProtocolParser {
|
||||
public static final Logger LOGGER = LogManager.getLogger();
|
||||
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.
|
||||
* For documentation on the individual Protocol messages, view the Protocol.java
|
||||
* class or hover over the commands (e.g. Protocol.chatMsgToAll) with your mouse
|
||||
* in this class.
|
||||
*
|
||||
* @param msg the encoded message that needs to be parsed
|
||||
* @param c this Client(required so this method can access the Client's methods)
|
||||
@ -33,29 +29,24 @@ public class JClientProtocolParser {
|
||||
e.printStackTrace();
|
||||
}
|
||||
switch (header) {
|
||||
case "SPING":
|
||||
//sends a pingback to the server
|
||||
c.sendMsgToServer("PINGB");
|
||||
case Protocol.pingFromServer:
|
||||
|
||||
c.sendMsgToServer(Protocol.pingBack);
|
||||
break;
|
||||
case "PINGB":
|
||||
//registers pingback from server
|
||||
case Protocol.pingBack:
|
||||
c.clientPinger.setGotPingBack(true);
|
||||
break;
|
||||
case "CHATM":
|
||||
/* prints out incoming chat messages / announcements into the user's console.
|
||||
* any string that follows CHATM$ is printed as is, so the message that follows
|
||||
* already has to be formatted the way it should be shown to the client.
|
||||
*/
|
||||
case Protocol.printToClientConsole:
|
||||
System.out.println(msg.substring(6));
|
||||
break;
|
||||
case "QUITC":
|
||||
case Protocol.serverConfirmQuit:
|
||||
c.disconnectFromServer();
|
||||
break;
|
||||
case GVOTR:
|
||||
case Protocol.serverRequestsGhostVote:
|
||||
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:
|
||||
case Protocol.serverRequestsHumanVote:
|
||||
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;
|
||||
|
||||
@ -39,7 +39,7 @@ public class ClientPinger implements Runnable {
|
||||
Thread.sleep(20000);
|
||||
while (socket.isConnected() && !socket.isClosed()) {
|
||||
gotPingBack = false;
|
||||
client.sendMsgToServer("CPING");
|
||||
client.sendMsgToServer(Protocol.pingFromClient);
|
||||
Thread.sleep(4000);
|
||||
if (gotPingBack) {
|
||||
if (!isConnected) { //if !isConnected, then the connection had been lost before.
|
||||
|
||||
@ -63,4 +63,35 @@ public class Protocol {
|
||||
*/
|
||||
public static final String clientQuitRequest = "QUITS";
|
||||
|
||||
//SERVER TO CLIENT COMMANDS
|
||||
|
||||
/**
|
||||
* todo: doc
|
||||
* //sends a pingback to the server
|
||||
*/
|
||||
public static final String pingFromServer = "SPING";
|
||||
|
||||
/**
|
||||
* prints out incoming chat messages / announcements into the user's console.
|
||||
* any string that follows CHATM$ is printed as is, so the message that follows
|
||||
* already has to be formatted the way it should be shown to the client.
|
||||
*/
|
||||
public static final String printToClientConsole = "CHATM";
|
||||
|
||||
/**
|
||||
* todo:doc
|
||||
*/
|
||||
public static final String serverConfirmQuit = "QUITC";
|
||||
|
||||
/**
|
||||
* todo:doc
|
||||
*/
|
||||
public static final String serverRequestsGhostVote = "GVOTR";
|
||||
|
||||
/**
|
||||
* todo:doc
|
||||
*/
|
||||
public static final String serverRequestsHumanVote = "HVOTR";
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ public class ServerPinger implements Runnable {
|
||||
Thread.sleep(2000);
|
||||
while (socket.isConnected() && !socket.isClosed()) {
|
||||
gotPingBack = false;
|
||||
c.sendMsgToClient("SPING");
|
||||
c.sendMsgToClient(Protocol.pingFromServer);
|
||||
Thread.sleep(4000);
|
||||
if (gotPingBack) {
|
||||
if (!isConnected) { //if !isConnected, then the connection had been lost before.
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package ch.unibas.dmi.dbis.cs108.multiplayer.server;
|
||||
|
||||
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.ServerPinger;
|
||||
import java.io.*;
|
||||
import java.net.InetAddress;
|
||||
@ -144,7 +145,7 @@ public class ClientHandler implements Runnable {
|
||||
*/
|
||||
public void broadcastChatMessage(String msg) {
|
||||
for (ClientHandler client : connectedClients) {
|
||||
client.sendMsgToClient("CHATM$" + clientUserName + ": " + msg);
|
||||
client.sendMsgToClient(Protocol.printToClientConsole + "$" + clientUserName + ": " + msg);
|
||||
}
|
||||
}
|
||||
|
||||
@ -159,7 +160,7 @@ public class ClientHandler implements Runnable {
|
||||
public void broadcastAnnouncement(String msg) {
|
||||
System.out.println(msg);
|
||||
for (ClientHandler client : connectedClients) {
|
||||
client.sendMsgToClient("CHATM$" + msg);
|
||||
client.sendMsgToClient(Protocol.printToClientConsole + "$" + msg);
|
||||
}
|
||||
}
|
||||
|
||||
@ -199,7 +200,7 @@ public class ClientHandler implements Runnable {
|
||||
*/
|
||||
public void removeClientOnLogout() {
|
||||
broadcastAnnouncement(getClientUserName() + " has left the server.");
|
||||
sendMsgToClient("QUITC");
|
||||
sendMsgToClient(Protocol.serverConfirmQuit); //todo: protocol
|
||||
connectedClients.remove(this);
|
||||
disconnectClient();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user