Пример #1
0
        public void Remove(Guid guid)
        {
            guidPlayer.ContainsKey(guid);
            Player toDelete = guidPlayer[guid];

            guidPlayer.Remove(guid);
            nickPlayer.Remove(toDelete.Nickname);
            idToPlayer.Remove(toDelete.CurrentEntityId);
            OnRemovePlayer?.Invoke(this, toDelete);
        }
Пример #2
0
    public override void OnServerRemovePlayer(NetworkConnection conn, PlayerController player)
    {
        Player currentPlayer;

        if (players.TryGetValue(conn, out currentPlayer))
        {
            players.Remove(conn);
        }

        OnRemovePlayer?.Invoke(currentPlayer);
        base.OnServerRemovePlayer(conn, player);
    }
Пример #3
0
        public ScrumPokerHubClient(ILogger <ScrumPokerHubClient> logger, IJSRuntime jsRuntime, NavigationManager navigationManager, ProfileService profileService)
        {
            _logger         = logger;
            _profileService = profileService;

            _hubConnection = new HubConnectionBuilder()
                             .WithUrl(navigationManager.ToAbsoluteUri($"/{SignalRConstants.ScrumPokerHub}"))
                             .WithAutomaticReconnect()
                             .ConfigureLogging(builder =>
            {
                Assembly assembly = Assembly.LoadFrom("Blazor.Extensions.Logging.dll");
                Type logProvider  = assembly.GetType("Blazor.Extensions.Logging.BrowserConsoleLoggerProvider", true, true);
                ILoggerProvider loggingProvider = (ILoggerProvider)Activator.CreateInstance(logProvider, BindingFlags.CreateInstance, null, new[] { jsRuntime }, null);
                builder.AddProvider(loggingProvider);
            })
                             .Build();

            _hubConnection.Closed += ex =>
            {
                if (ex == null)
                {
                    _logger.LogWarning("SignalR connection closed without error");
                }
                else
                {
                    _logger.LogError(ex, "SignalR connection closed with error");
                }

                return(Task.CompletedTask);
            };

            _hubConnection.Reconnected += s =>
            {
                _logger.LogDebug($"Reconnected.");
                OnReconnected?.Invoke(this, s);
                return(Task.CompletedTask);
            };

            _hubConnection.On <PlayerVoted>(SignalRConstants.ReceiveVote, (evnt) =>
            {
                var encodedMsg = $"{evnt.UserId} {evnt.Vote}";
                _logger.LogDebug($"Vote Cast: {encodedMsg}");

                OnReceiveVote?.Invoke(this, evnt);
            });

            _hubConnection.On <PlayerJoined>(SignalRConstants.AddPlayer, (evnt) =>
            {
                _logger.LogDebug($"Player Joined: {evnt.UserName}");
                OnAddPlayer?.Invoke(this, evnt);
            });

            _hubConnection.On <PlayerEvent>(SignalRConstants.RemovePlayer, (evnt) =>
            {
                _logger.LogDebug($"Player Left: {evnt.UserId}");
                OnRemovePlayer?.Invoke(this, evnt);
            });

            _hubConnection.On <GameInfo>(SignalRConstants.ReceiveInitialGameState, (evnt) =>
            {
                _logger.LogDebug("Received GameInfo!");
                OnReceiveInitialGameState?.Invoke(this, evnt);
            });

            _hubConnection.On <PlayerEvent>(SignalRConstants.GameEnded, (evnt) =>
            {
                _logger.LogDebug("Game Deleted!");
                OnGameEnded?.Invoke(this, evnt);
            });

            _hubConnection.On <PlayerEvent>(SignalRConstants.ResetGame, (evnt) =>
            {
                _logger.LogDebug("Game Reset!");
                OnGameReset?.Invoke(this, evnt);
            });
        }
Пример #4
0
 public static void RemovePlayer(Player removedPlayer)
 {
     GetPlayerList.Remove(removedPlayer);
     OnRemovePlayer.Invoke(removedPlayer);
 }