コード例 #1
0
ファイル: GenericHub.cs プロジェクト: giraudgabriel/tg
        public override async Task OnConnectedAsync()
        {
            Console.ResetColor();
            var authKey = Context.User.Identity.Name;

            if (!string.IsNullOrEmpty(authKey))
            {
                var players = FilterPlayers(t => t.Value.AuthKey == authKey);

                foreach (var player in players)
                {
                    _hubConnection.RemovePlayer(player);
                    await Groups.RemoveFromGroupAsync(player, "Players");

                    Console.ForegroundColor = ConsoleColor.DarkYellow;
                    Console.WriteLine($"Desconectado {_hubName} - ConnectionId:{player} - AuthKey:{authKey}");
                }

                var authDto = new AuthHubDto
                {
                    AuthKey = authKey,
                    Hub     = _hubName
                };

                _hubConnection.AddOrUpdate(Context.ConnectionId, authDto);

                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine($"Conectado {_hubName} - ConnectionId:{Context.ConnectionId} - - AuthKey:{authKey}");

                await base.OnConnectedAsync();
            }
        }