Extending CentralServerData to enable lobby creation and joining
This commit is contained in:
parent
4557b4801b
commit
b0ebbc9c77
@ -3,6 +3,7 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.server;
|
||||
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.ServerPinger;
|
||||
import ch.unibas.dmi.dbis.cs108.sebaschi.Lobby;
|
||||
import java.io.*;
|
||||
import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
@ -205,6 +206,10 @@ public class ClientHandler implements Runnable {
|
||||
disconnectClient();
|
||||
}
|
||||
|
||||
public void createNewLobby() {
|
||||
Lobby newGame = new Lobby(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the client's socket, in, and out.
|
||||
*/
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package ch.unibas.dmi.dbis.cs108.multiplayer.server;
|
||||
|
||||
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
|
||||
import ch.unibas.dmi.dbis.cs108.sebaschi.CentralServerData;
|
||||
import java.io.*;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
@ -12,6 +13,7 @@ import org.apache.logging.log4j.Logger;
|
||||
public class Server {
|
||||
public static final Logger LOGGER = LogManager.getLogger();
|
||||
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
|
||||
private static CentralServerData allData;
|
||||
|
||||
private static final int gamePort = 42069;
|
||||
private HashSet<ClientHandler> connectedClients = new HashSet<>();
|
||||
|
||||
@ -5,6 +5,10 @@ import ch.unibas.dmi.dbis.cs108.gamelogic.Game;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.Client;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.server.ClientHandler;
|
||||
import java.net.Socket;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@ -21,10 +25,52 @@ public class CentralServerData {
|
||||
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
|
||||
|
||||
private Set<ClientHandler> clientsOnServer;
|
||||
private Set<Game> activeGames;
|
||||
private Set<Game> gamesOpenToJoin;
|
||||
|
||||
private Map<ClientHandler, Socket> clientSocketMap;
|
||||
private Map<Socket, ClientHandler> socketClientMap;
|
||||
private Map<Game, ClientHandler> gameClientMap;
|
||||
private List<Lobby> allLobbies;
|
||||
private Map<Integer, Lobby> lobbyIDMap;
|
||||
|
||||
public CentralServerData() {
|
||||
clientsOnServer = new HashSet<>();
|
||||
allLobbies = new ArrayList<>();
|
||||
lobbyIDMap = new HashMap<>();
|
||||
}
|
||||
|
||||
//Getters
|
||||
|
||||
/**
|
||||
* Getter for set of all clients.
|
||||
* @return the set of all clients.
|
||||
*/
|
||||
public Set<ClientHandler> getClientsOnServer() {
|
||||
return clientsOnServer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to add the client to the set of all clients on server.
|
||||
* @param client
|
||||
*/
|
||||
public void addClientToSetOfAllClients(ClientHandler client) {
|
||||
this.getClientsOnServer().add(client);
|
||||
}
|
||||
|
||||
public void removeClientFromSetOfAllClients(){
|
||||
//TODO implement or make sure something equivalent is implemented somewhere else
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for List of all lobbies.
|
||||
* @return a list of all lobbies
|
||||
*/
|
||||
public List<Lobby> getAllLobbies() {
|
||||
return allLobbies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mapping from an Integer that repesents a LobbyID to the lobby
|
||||
* should be set in {@link Lobby} and is then used by clients to join a lobby.
|
||||
* @return a mapping from Integer to Lobby.
|
||||
*/
|
||||
public Map<Integer, Lobby> getLobbyIDMap() {
|
||||
return lobbyIDMap;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user