Made several small adjustments:
-regarding disconnection handling -corrected import statements in GameFunctions.java
This commit is contained in:
parent
5b3af54720
commit
5010b66d4c
@ -1,8 +1,8 @@
|
|||||||
package ch.unibas.dmi.dbis.cs108.gamelogic;
|
package ch.unibas.dmi.dbis.cs108.gamelogic;
|
||||||
|
|
||||||
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
|
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
|
||||||
import ch.unibas.dmi.dbis.cs108.klassenstruktur.Human;
|
import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Human;
|
||||||
import ch.unibas.dmi.dbis.cs108.klassenstruktur.Passenger;
|
import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Passenger;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
|||||||
@ -32,7 +32,7 @@ public class MessageFormatter {
|
|||||||
break;
|
break;
|
||||||
case "/q":
|
case "/q":
|
||||||
stringBuilder.append("QUITS$");
|
stringBuilder.append("QUITS$");
|
||||||
s = msg.substring(3);
|
s = "";
|
||||||
break;
|
break;
|
||||||
case "/n":
|
case "/n":
|
||||||
stringBuilder.append("NAMEC$");
|
stringBuilder.append("NAMEC$");
|
||||||
|
|||||||
@ -89,7 +89,7 @@ public class ClientHandler implements Runnable {
|
|||||||
String msg;
|
String msg;
|
||||||
while (socket.isConnected()) {
|
while (socket.isConnected()) {
|
||||||
try {
|
try {
|
||||||
msg = in.readLine();
|
msg = in.readLine(); //todo: here is where the server throws an exception when the client quits
|
||||||
JServerProtocolParser.parse(msg, this);
|
JServerProtocolParser.parse(msg, this);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -132,7 +132,7 @@ public class ClientHandler implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Sends a given message to client
|
/** Sends a given message to client
|
||||||
*
|
* todo: check for exception if out is closed.
|
||||||
* @param msg the given message
|
* @param msg the given message
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
@ -9,6 +9,11 @@ public class JServerProtocolParser {
|
|||||||
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);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* jsdcjkhcsdjksdacjkn
|
||||||
|
*/
|
||||||
|
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.
|
||||||
*
|
*
|
||||||
@ -23,7 +28,7 @@ public class JServerProtocolParser {
|
|||||||
System.out.println("Received unknown command");
|
System.out.println("Received unknown command");
|
||||||
}
|
}
|
||||||
switch (header) {
|
switch (header) {
|
||||||
case "CHATA":
|
case CHATA:
|
||||||
//sends chat message to all connected clients
|
//sends chat message to all connected clients
|
||||||
h.broadcastMessage(msg.substring(6));
|
h.broadcastMessage(msg.substring(6));
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user