[ADD] added hosting a lobby

This commit is contained in:
Sem van der Hoeven
2020-10-20 22:16:19 +02:00
parent 671951c35b
commit 7b30911cd7
6 changed files with 93 additions and 17 deletions

View File

@@ -1,4 +1,5 @@

using Client;
using SharedClientServer;
using System;
using System.Collections.Generic;
@@ -129,6 +130,12 @@ namespace Server.Models
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;
}
break;
case JSONConvert.CANVAS:

View File

@@ -148,5 +148,14 @@ namespace Server.Models
}
}
}
public Lobby HostForLobby(User user)
{
Lobby lobby = new Lobby( lobbies.Count + 1,0, 8);
lobbies.Add(lobby);
serverClientsInlobbies.Add(lobby, new List<ServerClient>());
AddToLobby(lobby, user);
return lobby;
}
}
}