[ADD] add updating lobbies on exiting window

This commit is contained in:
Sem van der Hoeven
2020-10-21 21:40:35 +02:00
parent c339746a82
commit 442cdccc49
6 changed files with 50 additions and 15 deletions

View File

@@ -166,6 +166,11 @@ namespace Server.Models
sendMessage(JSONConvert.ConstructLobbyJoinSuccessMessage());
ServerCommunication.INSTANCE.sendToAll(JSONConvert.ConstructLobbyListMessage(ServerCommunication.INSTANCE.lobbies.ToArray()));
break;
case LobbyIdentifier.LEAVE:
id = JSONConvert.GetLobbyID(payload);
ServerCommunication.INSTANCE.LeaveLobby(User, id);
ServerCommunication.INSTANCE.sendToAll(JSONConvert.ConstructLobbyListMessage(ServerCommunication.INSTANCE.lobbies.ToArray()));
break;
}
}

View File

@@ -161,6 +161,31 @@ namespace Server.Models
}
}
public void RemoveFromLobby(Lobby lobby, User user)
{
foreach (Lobby l in lobbies)
{
if (l == lobby)
{
if (lobby.Users.Contains(user))
{
Debug.WriteLine("[SERVERCOMM] removed user from lobby!");
lobby.Users.Remove(user);
foreach (ServerClient sc in serverClients)
{
if (sc.User.Username == user.Username)
{
serverClientsInlobbies[l].Remove(sc);
break;
}
}
}
}
break;
}
}
public int HostForLobby(User user)
{
Lobby lobby = new Lobby( lobbies.Count + 1,0, 8);
@@ -183,5 +208,16 @@ namespace Server.Models
}
}
}
public void LeaveLobby(User user, int id)
{
foreach (Lobby l in lobbies)
{
if (l.ID == id)
{
RemoveFromLobby(l, user);
}
}
}
}
}