High score fully implemented.
This commit is contained in:
@@ -98,6 +98,9 @@ public class MessageFormatter {
|
||||
case "/s":
|
||||
stringBuilder.append(Protocol.startANewGame);
|
||||
break;
|
||||
case "/h":
|
||||
stringBuilder.append(Protocol.highScoreList);
|
||||
break;
|
||||
default:
|
||||
s = msg;
|
||||
}
|
||||
|
||||
@@ -138,6 +138,13 @@ public class Protocol {
|
||||
*/
|
||||
public static final String votedFor = "CVOTE";
|
||||
|
||||
/**
|
||||
* Client requests high score list.
|
||||
*/
|
||||
public static final String highScoreList = "HSCOR";
|
||||
|
||||
|
||||
|
||||
|
||||
//SERVER TO CLIENT COMMANDS
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
|
||||
import ch.unibas.dmi.dbis.cs108.gamelogic.Game;
|
||||
import ch.unibas.dmi.dbis.cs108.gamelogic.TrainOverflow;
|
||||
import ch.unibas.dmi.dbis.cs108.gamelogic.VoteHandler;
|
||||
import ch.unibas.dmi.dbis.cs108.highscore.OgGhostHighScore;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.ServerPinger;
|
||||
|
||||
@@ -594,4 +595,11 @@ public class ClientHandler implements Runnable {
|
||||
}
|
||||
|
||||
|
||||
public void sendHighScoreList() {
|
||||
String list = OgGhostHighScore.formatGhostHighscoreList();
|
||||
String[] listarray = list.split("\\R");
|
||||
for (String s: listarray) {
|
||||
sendAnnouncementToClient(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,6 +109,9 @@ public class JServerProtocolParser {
|
||||
case Protocol.listGames:
|
||||
h.listGames();
|
||||
break;
|
||||
case Protocol.highScoreList:
|
||||
h.sendHighScoreList();
|
||||
break;
|
||||
default:
|
||||
System.out.println("Received unknown command");
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.server;
|
||||
|
||||
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
|
||||
|
||||
import ch.unibas.dmi.dbis.cs108.highscore.OgGhostHighScore;
|
||||
import java.io.*;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
@@ -30,6 +31,7 @@ public class Server {
|
||||
public void startServer() {
|
||||
try {
|
||||
System.out.println("Port " + gamePort + " is open.");
|
||||
OgGhostHighScore.main(null);
|
||||
while (!serverSocket.isClosed()) {
|
||||
Socket socket = serverSocket.accept();
|
||||
ClientHandler nextClient = new ClientHandler(socket, socket.getInetAddress());
|
||||
|
||||
Reference in New Issue
Block a user