feat: partial implementation of MessageRelay and LobbyConnection

This commit is contained in:
Yannik Bretschneider 2021-05-18 18:24:26 +02:00
parent ce71de5d25
commit 89a75f982b
3 changed files with 18 additions and 8 deletions

@ -1 +1 @@
Subproject commit 56a90f6bdffd13012d086bb05ca06426214edb40
Subproject commit 1348e342d6ec3685424244ceae6d920652239555

View File

@ -101,12 +101,11 @@ public class LobbyConnection {
// Methods to send events
public void sendEvents(MessageSource target, Event... events) {
// TODO: implement
MessageRelay.getInstance();
MessageRelay.getInstance().sendMessage(this, events, target);
}
public void broadcastEvents(Event... events) {
// TODO: implement
MessageRelay.getInstance();
MessageRelay.getInstance().broadcastEvents(this, events);
}
}

View File

@ -1,6 +1,7 @@
package uulm.teamname.marvelous.server.LobbyManager;
import org.java_websocket.WebSocket;
import uulm.teamname.marvelous.gamelibrary.events.Event;
import uulm.teamname.marvelous.server.Lobby.Lobby;
import java.util.HashMap;
@ -9,12 +10,10 @@ public class MessageRelay {
public static MessageRelay instance;
private final HashMap<WebSocket, Lobby> lobbies;
private final HashMap<Lobby, WebSocket> sockets;
private final HashMap<WebSocket, LobbyConnection> lobbies;
private MessageRelay() {
this.lobbies = new HashMap<>();
this.sockets = new HashMap<>();
}
public static MessageRelay getInstance() {
@ -30,7 +29,19 @@ public class MessageRelay {
// TODO: send to target lobby
}
public void broadcastEvents (Lobby origin/*, Event[] events*/) {
public void sendMessage (LobbyConnection origin, Event[] events, MessageSource target) {
switch (target) {
case Player1 -> {
}
case Player2 -> {
}
case Spectator -> {
}
}
}
public void broadcastEvents (LobbyConnection origin, Event[] events) {
// TODO: Create JSON
// TODO: send to target
}