Merge branch 'master' into feature/jsonForWords

This commit is contained in:
SemvdH
2020-10-22 17:01:28 +02:00
committed by GitHub
5 changed files with 27 additions and 8 deletions

View File

@@ -183,6 +183,10 @@ namespace Server.Models
int id = JSONConvert.GetLobbyID(payload);
ServerCommunication.INSTANCE.JoinLobby(this.User, id);
sendMessage(JSONConvert.ConstructLobbyJoinSuccessMessage());
bool isHost;
ServerCommunication.INSTANCE.JoinLobby(this.User,id, out isHost);
sendMessage(JSONConvert.ConstructLobbyJoinSuccessMessage(isHost));
ServerCommunication.INSTANCE.sendToAll(JSONConvert.ConstructLobbyListMessage(ServerCommunication.INSTANCE.lobbies.ToArray()));
//Task.Run(SendLobbyData);

View File

@@ -202,12 +202,18 @@ namespace Server.Models
return lobby.ID;
}
public void JoinLobby(User user, int id)
public void JoinLobby(User user, int id, out bool isHost)
{
isHost = false;
foreach (Lobby l in lobbies)
{
if (l.ID == id)
{
if (l.Users.Count == 0)
{
user.Host = true;
isHost = true;
}
AddToLobby(l, user);
Debug.WriteLine($"{user.Username} joined lobby with id {id}");
break;