private void OnGameStateUpdate(UpdatedGameStateMessage msg, DateTime timestamp) { // Update the current map state //map.UpdateScene(msg.UpdatedSceneObjects, timestamp); this.BroadcastGameState(); }
private static void Create_game_with_new_map_and_join() { WaitFor("Create game"); var postData = new CreateGameMessage { Title = "Wut a game", Password = "******" }; var result = HttpRequestHelper.PostAsync("http://127.0.0.1:4321/api/game/create/empty", postData, Token).Result; var gameId = JsonConvert.DeserializeObject <Guid>(result.Content.ReadAsStringAsync().Result); WaitFor("Join game"); var gameWebSocket = new WebSocketClient($"ws://127.0.0.1:6789/Game?auth_token={Token}&game_id={gameId}&game_password=123"); gameWebSocket.Connect(); WaitFor("Listen to game updates"); UdpGameClient.RegisterOnGameStateChangeListener((message, time) => { Console.WriteLine($"Scene update: {message.SceneObjects.Count} objects"); }); UdpGameClient.StartListening(); WaitFor("Send game update"); var gameUpdate = new UpdatedGameStateMessage { GameId = gameId, UserToken = Token, UpdatedSceneObjects = MapTests.GetNodes() }; UdpGameClient.Send(gameUpdate); WaitFor("Exit game"); UdpGameClient.StopListening(); gameWebSocket.Close(); }
private void OnGameStateUpdate(UpdatedGameStateMessage msg, DateTime timestamp) { if (!this.GameHosts.ContainsKey(msg.GameId)) { throw new Exception("This game id doesn't match any active game"); } var game = this.GameHosts[msg.GameId]; var userToken = JwtHelper.DecodeToken(msg.UserToken); if (userToken == null || game.Spectators.ContainsKey(userToken.UserId) || !game.Players.ContainsKey(userToken.UserId)) { throw new Exception("This user is not allowed to change the map state"); } // Update the current map state var stats = game.Map.UpdateScene(msg.UpdatedSceneObjects, userToken.UserId, timestamp); game.GameStatisticsUpdates.Add(stats); this.BroadcastGameState(game); }