Exemplo n.º 1
0
        public void Connect(string userName)
        {
            //var id = Context.ConnectionId;

            Player player = new Player();
            player.Id = Context.ConnectionId;
            player.Name = userName;

            if (Players.Count(x => x.Id == player.Id) == 0)
            {
                //ConnectedUsers.Add(new UserDetail { ConnectionId = id, UserName = userName });
                Players.Add(player);

                // send to caller
                Clients.Caller.onConnected(player.Id, player.Name, Players);

                // send to all except caller client
                Clients.AllExcept(player.Id).onNewUserConnected(player.Id, player.Name);

            }
        }
Exemplo n.º 2
0
        public void SendPlayersState(Player you, Player opponent)
        {
            var player1 = Players.FirstOrDefault(player => player.Id == you.Id);
            player1 = you;
            var player2 = Players.FirstOrDefault(player => player.Id == opponent.Id);
            player2 = opponent;

            Clients.Client(player2.Id).updatePlayersState(player2, player1);
        }