Пример #1
0
    public async Task Initialize()
    {
        if (!_initialized)
        {
            _hubConnection = new HubConnectionBuilder()
                             .WithUrl(_hubUrl)
                             .Build();

            _hubConnection.On <string, string>("ReceiveMessage", (user, message) =>
                                               MessageReceived?.Invoke(user, message));

            _hubConnection.On <Room>("UpdatePlayerState", (room) =>
                                     PlayerStateUpdated?.Invoke(room));

            _hubConnection.On <Room>("RoomOpened", (room) =>
                                     RoomOpened?.Invoke(room));

            _hubConnection.On <Room>("UpdateRoom", (room) =>
                                     RoomUpdated?.Invoke(room));

            await _hubConnection.StartAsync();

            _initialized = true;
        }
    }
Пример #2
0
        public void HandlePause(NetworkMessage msg)
        {
            MsgPause pa = msg as MsgPause;
            Player   p  = GetPlayerByID(pa.PlayerID);

            if (p != null)
            {
                p.Paused = pa.Paused;

                if (PlayerPaused != null)
                {
                    PlayerStateUpdated.Invoke(this, p);
                }
            }
        }
Пример #3
0
        public void HandlePlayerUpdate(NetworkMessage msg)
        {
            MsgPlayerUpdateBase upd = msg as MsgPlayerUpdateBase;
            Player player           = GetPlayerByID(upd.PlayerID);

            if (player == null)
            {
                return;
            }

            player.LastUpdate = upd;
            if (PlayerStateUpdated != null)
            {
                PlayerStateUpdated.Invoke(this, player);
            }
        }