Ejemplo n.º 1
0
        public string Join(string user, string connectionId)
        {
            var existing = Players.Concat(WaitingRoom).FirstOrDefault(t => t.Name == user);

            if (existing != null)
            {
                if (existing.ConnectionId != connectionId)
                {
                    existing.ConnectionId = connectionId;
                    Message(user, $"re-joined the game");
                }
            }
            else if (string.IsNullOrEmpty(Owner))
            {
                Owner = user;
                Players.Add(CreatePlayer(user, connectionId));
            }
            else
            {
                if (Players.Count >= MaxPlayers)
                {
                    return($"Game already has maximum number of players");
                }
                WaitingRoom.Add(CreatePlayer(user, connectionId));
                Message(user, $"requested to join the game");
            }
            return(null);
        }