feat: partial implementation of MessageRelay and LobbyConnection
This commit is contained in:
		
							
								
								
									
										2
									
								
								Gamelib
									
									
									
									
									
								
							
							
								
								
								
								
								
							
						
						
									
										2
									
								
								Gamelib
									
									
									
									
									
								
							 Submodule Gamelib updated: 56a90f6bdf...1348e342d6
									
								
							@ -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);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user