Exemple #1
0
        /// <summary>
        /// Tries to register a user to a particular lobby.
        /// </summary>
        private (bool, string) RegisterUser(string lobbyId, User user, string displayName, string selfPortrait)
        {
            string userIdentifier = Users.FirstOrDefault((kvp) => kvp.Value == user).Key;

            if (userIdentifier == null)
            {
                return(false, "Can't register unknown user. Refresh the page.");
            }
            if (string.IsNullOrWhiteSpace(lobbyId))
            {
                return(false, "Invalid Lobby Code.");
            }
            if (user.LobbyId != null)
            {
                return(false, "User already in a lobby.");
            }

            user.DisplayName  = displayName;
            user.SelfPortrait = selfPortrait;

            if (!LobbyIdToLobby.ContainsKey(lobbyId))
            {
                return(false, "Lobby not found.");
            }

            if (!LobbyIdToLobby[lobbyId].TryAddUser(user, out string errorMsg))
            {
                return(false, errorMsg);
            }

            return(true, string.Empty);
        }
Exemple #2
0
 public Lobby GetLobby(string lobbyId)
 {
     if (string.IsNullOrWhiteSpace(lobbyId))
     {
         return(null);
     }
     return(LobbyIdToLobby.GetValueOrDefault(lobbyId));
 }
Exemple #3
0
 public bool RegisterLobby(Lobby lobby)
 {
     if (lobby == null)
     {
         return(false);
     }
     return(LobbyIdToLobby.TryAdd(lobby.LobbyId, lobby));
 }
Exemple #4
0
        public void DeleteLobby(string lobbyId)
        {
            Lobby lobby = GetLobby(lobbyId);

            LobbyIdToLobby.TryRemove(lobbyId, out Lobby _);

            lobby?.UnregisterAllUsers();
            if (lobby?.Owner?.OwnedLobby != null)
            {
                lobby.Owner.OwnedLobby = null;
            }
            AbandonedLobbyIds.Add(lobbyId);
        }