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; } }
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); } } }
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); } }