private void OnMessage(object sender, MessageRecieveEventArgs eventArgs) { var address = eventArgs.Handler.GetRemoteAddress(); if (address != null) { Console.WriteLine("New message from {0}: {1}", address, eventArgs.Message); } try { if (eventArgs.Message.Length == 0) //ETB keep alive packet { //send keep alive back ConnectionEndpoint.SendFromServer(eventArgs.Handler, String.Empty); } else { BehaviorChooser.HandleMessage((dynamic)XmlMessageConverter.ToObject(eventArgs.Message), this, eventArgs.Handler); } } catch (Exception e) { ConsoleDebug.Error(e.Message); } //ConnectionEndpoint.SendFromServer(eventArgs.Handler, eventArgs.Message); }
public void Move(MoveType direction) { if (previousLocation != null && game.Location != null && game.Location.x == previousLocation.x && game.Location.y == previousLocation.y) { ConsoleDebug.Error("Snake time! ====================================="); //if (direction==MoveType.up) // direction=MoveType.right; //else if (direction == MoveType.right) // direction = MoveType.down; //else if (direction == MoveType.down) // direction = MoveType.left; //else // direction = MoveType.up; direction = RandomMoveType(); } previousLocation = new Common.Schema.Location() { x = game.Location.x, y = game.Location.y }; Move m = new Move() { direction = direction, directionSpecified = true, gameId = game.GameId, playerGuid = game.Guid }; Send(XmlMessageConverter.ToXml(m)); }
public void HandleMessage(PlayerDisconnected message, Socket handler) { ConsoleDebug.Error($"Player disconnected! Player id: {message.playerId}"); var player = Players.First(p => p.Id == message.playerId); TeamBlue.Players.Remove(player); TeamRed.Players.Remove(player); if (TeamRed.Players.Count + TeamBlue.Players.Count == 0) { GameInProgress = false; } }
static void ValidationEventHandler(object sender, ValidationEventArgs e) { ConsoleDebug.Error("\n ERROR IN VALIDATION\n "); switch (e.Severity) { case XmlSeverityType.Error: Console.WriteLine("Error: {0}", e.Message); throw new XmlException(); break; case XmlSeverityType.Warning: Console.WriteLine("Warning {0}", e.Message); throw new XmlException(); break; } }
public static void HandleMessage(JoinGame request, CommunicationServer server, Socket handler) { if (request == null) { return; } //if (server.startedGames.Contains(request.gameName)) //{ // ConsoleDebug.Error("Game already started"); // return; //} Game.IGame g = server.RegisteredGames.GetGameByName(request.gameName); if (g == null) { ConsoleDebug.Error("Game with specified name not found"); return; } if (g.HasStarted) { ConsoleDebug.Error("Game already started"); return; } lock (joinLock) { request.playerId = server.IdForNewClient(); request.playerIdSpecified = true; server.Clients.Add(request.playerId, handler); g.Players.Add(new Game.Player { Id = request.playerId }); } var response = XmlMessageConverter.ToXml(request); server.ConnectionEndpoint.SendFromServer(g.GameMaster, response); return; }