Example #1
0
 public void Join(Player player, string id)
 {
     lock (_syncLock)
     {
         Players[id] = player;
     }
 }
Example #2
0
        public void JoinRequest(string playerName, string characterClass)
        {
            if (GameState.Players.Values.ToList().Find(p => p.Name == playerName) != null)
            {
                Clients.Caller.passErrorMessage("Player with that name already exist!");
            }
            else if (ConnectionToId.ContainsKey(Context.ConnectionId))
            {
                Clients.Caller.passErrorMessage("You are already in the game!");
            }
            else
            {
                var playerId = Guid.NewGuid().ToString();
                var player = new Player(playerName);
                ConnectionToId[Context.ConnectionId] = playerId;
                GameState.Join(player, playerId);
                Clients.Others.playerJoined(playerId, player);
                Clients.Caller.youJoined(playerId, GameState);

            }
        }