From 3e024d0b8929be540ed1ef5e81237893f700fa9e Mon Sep 17 00:00:00 2001 From: Steinar Aalstad Lillesund Date: Mon, 6 Apr 2020 16:15:44 +0200 Subject: [PATCH] =?UTF-8?q?La=20til=20noen=20metoder=20for=20=C3=A5=20gi?= =?UTF-8?q?=20spillernavn=20videre=20til=20de=20klassene=20som=20trenger?= =?UTF-8?q?=20dem.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../roborally/networking/RoboRallyClient.java | 9 ++++++-- .../roborally/networking/RoboRallyServer.java | 21 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/main/java/inf112/fiasko/roborally/networking/RoboRallyClient.java b/src/main/java/inf112/fiasko/roborally/networking/RoboRallyClient.java index d904c08..0c1f806 100644 --- a/src/main/java/inf112/fiasko/roborally/networking/RoboRallyClient.java +++ b/src/main/java/inf112/fiasko/roborally/networking/RoboRallyClient.java @@ -8,8 +8,9 @@ import inf112.fiasko.roborally.utility.NetworkUtil; import java.io.IOException; public class RoboRallyClient { + Client client; public RoboRallyClient(String IPaddresse) throws IOException { - Client client = new Client(); + client = new Client(); client.start(); NetworkUtil.registerClasses(client.getKryo()); client.connect(5000, IPaddresse, 54555, 54777); @@ -20,6 +21,9 @@ public class RoboRallyClient { client.addListener(new RoboRallyClientListener()); } + public void sendElement(Object obj) { + client.sendTCP(obj); + } } class RoboRallyClientListener extends Listener { @@ -33,4 +37,5 @@ class RoboRallyClientListener extends Listener { System.out.println(errorResponse.getErrorMessage()); } } -} \ No newline at end of file +} + diff --git a/src/main/java/inf112/fiasko/roborally/networking/RoboRallyServer.java b/src/main/java/inf112/fiasko/roborally/networking/RoboRallyServer.java index ad6ccf6..b0f8e22 100644 --- a/src/main/java/inf112/fiasko/roborally/networking/RoboRallyServer.java +++ b/src/main/java/inf112/fiasko/roborally/networking/RoboRallyServer.java @@ -30,6 +30,13 @@ public class RoboRallyServer { programmingCardDeck = DeckLoaderUtil.loadProgrammingCardsDeck(); } + public Map getRobotID() { + return listener.getRobotID(); + } + + public Map getPlayerNames() { + return listener.getPlayerNames(); + } /** * Sends an object to all clients * @param object The object to send @@ -54,10 +61,20 @@ public class RoboRallyServer { class RoboRallyServerListener extends Listener { protected Connection host; protected Map clients; + protected Map playerNames; public RoboRallyServerListener() { super(); clients = new HashMap<>(); + playerNames = new HashMap<>(); + } + + public Map getPlayerNames() { + return playerNames; + } + + public Map getRobotID() { + return clients; } @Override @@ -70,6 +87,10 @@ class RoboRallyServerListener extends Listener { response.text = "Thanks"; connection.sendTCP(response); } + else if (object instanceof String) { + String playerName = (String) object; + playerNames.put(connection, playerName); + } } @Override