chat packets sent to server and then sent back to all clients. #story[1246]

This commit is contained in:
Peter Galloway
2017-08-30 20:42:11 +12:00
parent 353dd48829
commit 4ebf7d6104
8 changed files with 68 additions and 108 deletions
+10 -16
View File
@@ -15,6 +15,7 @@ import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import seng302.gameServer.messages.BoatAction;
import seng302.gameServer.messages.BoatStatus;
import seng302.gameServer.messages.ChatterMessage;
import seng302.gameServer.messages.CustomizeRequestType;
import seng302.gameServer.messages.MarkRoundingMessage;
import seng302.gameServer.messages.MarkType;
@@ -41,7 +42,6 @@ public class GameState implements Runnable {
@FunctionalInterface
interface NewMessageListener {
void notify(Message message);
}
@@ -72,19 +72,9 @@ public class GameState implements Runnable {
private static Set<Mark> marks;
private static List<Limit> courseLimit;
private static List<NewMessageListener> markListeners;
private static List<NewMessageListener> messageListeners;
private static Map<Player, String> playerStringMap = new HashMap<>();
/*
Ideally I would like to make this class an object instantiated by the server and given to
it's created threads if necessary. Outside of that I think the dependencies on it
(atm only Yacht & GameClient) can be removed from most other classes. The observable list of
players could be pulled directly from the server by the GameClient since it instantiates it
and it is reasonable for it to pull data. The current setup of publicly available statics is
pretty meh IMO because anything can change it making it unreliable and like people did with
the old ServerParser class everything that needs shared just gets thrown in the static
collections and things become a real mess.
*/
public GameState(String hostIpAddress) {
windDirection = 180d;
@@ -100,7 +90,7 @@ public class GameState implements Runnable {
//set this when game stage changes to prerace
previousUpdateTime = System.currentTimeMillis();
markOrder = new MarkOrder(); //This could be instantiated at some point with a select map?
markListeners = new ArrayList<>();
messageListeners = new ArrayList<>();
resetStartTime();
@@ -671,8 +661,8 @@ public class GameState implements Runnable {
}
private static void notifyMessageListeners(Message message) {
for (NewMessageListener mpl : markListeners) {
mpl.notify(message);
for (NewMessageListener ml : messageListeners) {
ml.notify(message);
}
}
@@ -685,7 +675,7 @@ public class GameState implements Runnable {
public static void addMarkPassListener(NewMessageListener listener) {
markListeners.add(listener);
messageListeners.add(listener);
}
public static void setCustomizationFlag() {
@@ -699,4 +689,8 @@ public class GameState implements Runnable {
public static void resetCustomizationFlag() {
customizationFlag = false;
}
public static void broadcastChatter(ChatterMessage chatterMessage) {
notifyMessageListeners(chatterMessage);
}
}