[ADD] added joining lobbies

This commit is contained in:
Sem van der Hoeven
2020-10-20 22:49:25 +02:00
parent 7b30911cd7
commit 76cd392525
7 changed files with 72 additions and 32 deletions

View File

@@ -124,19 +124,7 @@ namespace Server.Models
case JSONConvert.LOBBY:
// lobby data
LobbyIdentifier l = JSONConvert.GetLobbyIdentifier(payload);
switch(l)
{
case LobbyIdentifier.REQUEST:
Debug.WriteLine("[SERVERCLIENT] got lobby request message, sending lobbies...");
sendMessage(JSONConvert.ConstructLobbyListMessage(ServerCommunication.INSTANCE.lobbies.ToArray()));
break;
case LobbyIdentifier.HOST:
// add new lobby and add this serverclient to it
Lobby created = ServerCommunication.INSTANCE.HostForLobby(this.User);
Debug.WriteLine("[SERVERCLIENT] created lobby");
sendMessage(JSONConvert.ConstructLobbyHostCreatedMessage(created));
break;
}
handleLobbyMessage(payload,l);
break;
case JSONConvert.CANVAS:
// canvas data
@@ -148,6 +136,28 @@ namespace Server.Models
}
}
private void handleLobbyMessage(byte[] payload, LobbyIdentifier l)
{
switch (l)
{
case LobbyIdentifier.REQUEST:
Debug.WriteLine("[SERVERCLIENT] got lobby request message, sending lobbies...");
sendMessage(JSONConvert.ConstructLobbyListMessage(ServerCommunication.INSTANCE.lobbies.ToArray()));
break;
case LobbyIdentifier.HOST:
// add new lobby and add this serverclient to it
Lobby created = ServerCommunication.INSTANCE.HostForLobby(this.User);
Debug.WriteLine("[SERVERCLIENT] created lobby");
sendMessage(JSONConvert.ConstructLobbyHostCreatedMessage(created));
break;
case LobbyIdentifier.JOIN:
int id = JSONConvert.GetLobbyID(payload);
ServerCommunication.INSTANCE.JoinLobby(this.User,id);
sendMessage(JSONConvert.ConstructLobbyJoinSuccessMessage());
break;
}
}
/// <summary>
/// sends a message to the tcp client
/// </summary>