public void HandleOnPlayer(Messages.PlayerInterfaces.IConnection connection) { var msg = connection.Logic.AnswerForGameMessage(connection, this); var serializer = new Messages.XmlHandling.Serializer(msg); connection.SendMessage(serializer.Serialize()); }
public void HandleOnCommunicationServer(Messages.CommunicationServer.IConnection connection, Messages.CommunicationServer.IReceiver receiver = null) { IReceiver rec = connection.Receivers.Find(p => p.Id == this.playerId); var serializer = new Messages.XmlHandling.Serializer(this); rec.SendMessage(serializer.Serialize()); }
public void HandleOnCommunicationServer(Messages.CommunicationServer.IConnection server, IReceiver receiver) { var serializer = new Messages.XmlHandling.Serializer(this); ulong gameId = receiver.GameId; var game = server.Games[gameId]; this.gameId = gameId; game.GameMaster.SendMessage(serializer.Serialize()); }
public void HandleOnGameMaster(Messages.GameMaster.IConnection connection) { var guid = Guid.NewGuid(); var gameState = connection.GameState; var msg = new ConfirmJoiningGame(gameState.GameId, guid, this.playerId, new Player(this.playerId, this.preferredTeam, this.preferredRole)); connection.AddPlayer(guid, msg.playerId, this.preferredTeam, this.preferredRole); var serializer = new Messages.XmlHandling.Serializer(msg); connection.SendMessage(serializer.Serialize()); if (((ulong)gameState.RedPlayers.Count == gameState.RedTeamMax) && ((ulong)gameState.BluePlayers.Count == gameState.BlueTeamMax)) { gameState.GameStarted = true; var gameMsg = new Game(); gameMsg.Players = new Player[gameState.RedTeamMax + gameState.BlueTeamMax]; int index = 0; for (int i = 0; i < (int)gameState.RedTeamMax; i++, index++) { var p = gameState.RedPlayers[i]; gameMsg.Players[index] = new Player(p.Id, p.TeamColour, p.PlayerType); } for (int i = 0; i < (int)gameState.BlueTeamMax; i++, index++) { var p = gameState.BluePlayers[i]; gameMsg.Players[index] = new Player(p.Id, p.TeamColour, p.PlayerType); } connection.GameState.SetPlayerLocations(); Console.WriteLine("Sending game msg"); gameMsg.Board = new GameBoard(); gameMsg.Board.goalsHeight = (uint)connection.GameState.GoalAreaLength; gameMsg.Board.tasksHeight = (uint)connection.GameState.TaskAreaLength; gameMsg.Board.width = (uint)connection.GameState.BoardWidth; foreach (var player in connection.GameState.RedPlayers) { gameMsg.playerId = player.Id; gameMsg.PlayerLocation = player.Location; serializer = new Serializer(gameMsg); connection.SendMessage(serializer.Serialize()); } foreach (var player in connection.GameState.BluePlayers) { gameMsg.playerId = player.Id; gameMsg.PlayerLocation = player.Location; serializer = new Serializer(gameMsg); connection.SendMessage(serializer.Serialize()); } var gameStartedMsg = new GameStarted(connection.GameState.GameId); serializer = new Serializer(gameStartedMsg); connection.SendMessage(serializer.Serialize()); connection.GameState.StartSpawningPieces(); } }
public void HandleOnCommunicationServer(Messages.CommunicationServer.IConnection server, IReceiver receiver) { var player = server.Receivers.Find(p => p.Id == this.playerId); if (player == null) { return; } player.GameId = receiver.GameId; var serializer = new Messages.XmlHandling.Serializer(this); player.SendMessage(serializer.Serialize()); server.Games[receiver.GameId].Players.Add(player); }
public void HandleOnCommunicationServer(Messages.CommunicationServer.IConnection server, IReceiver receiver) { var serializer = new Messages.XmlHandling.Serializer(this); List <IReceiver> receivers = new List <IReceiver>(); foreach (Player p in this.Players) { receivers.Add(server.Receivers.Find(r => r.Id == p.id)); } var rec = server.Receivers.Find(r => r.Id == this.playerId); string msg = serializer.Serialize(); rec.SendMessage(msg); }
public void HandleOnPlayer(Messages.PlayerInterfaces.IConnection connection) { if (gameFinished == true) { Console.WriteLine("Game is finished"); return; } connection.Logic.SetReceivedData(this.TaskFields, this.GoalFields, this.gameFinished, this.Pieces, this.PlayerLocation); var msg = connection.Logic.ChooseNextMessage(connection, this); if (msg != null) { var serializer = new Messages.XmlHandling.Serializer(msg); connection.SendMessage(serializer.Serialize()); } }
public void HandleOnCommunicationServer(Messages.CommunicationServer.IConnection server, Messages.CommunicationServer.IReceiver receiver) { var game = server.CreateGame(receiver, this); if (game == null) { var msg = new RejectGameRegistration(); var serializer = new Messages.XmlHandling.Serializer(msg); receiver.SendMessage(serializer.Serialize()); } else { var msg = new ConfirmGameRegistration(game.GameId); var serializer = new Messages.XmlHandling.Serializer(msg); receiver.SendMessage(serializer.Serialize()); } }
public void HandleOnCommunicationServer(IConnection server, IReceiver receiver) { var msg = new RegisteredGames(); var count = (int)server.GameCount; msg.GameInfo = new GameInfo[count]; int i = 0; foreach (var pair in server.Games) { msg.GameInfo[i] = new GameInfo(pair.Value); i++; } var serializer = new Messages.XmlHandling.Serializer(msg); receiver.SendMessage(serializer.Serialize()); }
public void HandleOnPlayer(IConnection connection) { var gameInfo = this.GameInfo; //XmlSerializer xmlSerializer = null; Messages.CommunicationServer.ICommunicationServerHandler msg = null; if (gameInfo != null) { msg = new JoinGame(connection.GameName, connection.Team, connection.Role); } else { msg = new GetGames(); } var serializer = new Messages.XmlHandling.Serializer(msg); connection.SendMessage(serializer.Serialize()); }
public void HandleOnCommunicationServer(Messages.CommunicationServer.IConnection server, IReceiver receiver) { lock (server.PlayerCountLock) { server.PlayerCount++; receiver.Id = server.PlayerCount; } this.playerId = receiver.Id; this.playerIdSpecified = true; var gameList = server.Games.Where(g => g.Value.GameName == this.gameName).ToList(); if (gameList.Count == 1) { var game = gameList[0].Value; var serializer = new Messages.XmlHandling.Serializer(this); game.GameMaster.SendMessage(serializer.Serialize()); } //else send reject message when defined in specification }
// Handling is not done public void HandleOnCommunicationServer(Messages.CommunicationServer.IConnection server, IReceiver receiver) { var serializer = new Messages.XmlHandling.Serializer(this); string msg = serializer.Serialize(); try { ulong gameId = receiver.GameId; var game = server.Games[gameId]; foreach (var rec in game.Players) { rec.SendMessage(msg); } server.Receivers.Remove(receiver); server.Games.Remove(gameId); }catch (Exception) { Console.WriteLine("Error while notifying other clients, gm disconnected"); } }
public void HandleOnCommunicationServer(Messages.CommunicationServer.IConnection server, IReceiver receiver) { //gameid == 0 -> player is not assigned to any game if (receiver.GameId == 0) { server.Receivers.Remove(receiver); return; } var serializer = new Messages.XmlHandling.Serializer(this); string msg = serializer.Serialize(); ulong gameId = receiver.GameId; var game = server.Games[gameId]; game.Players.Remove(receiver); server.Receivers.Remove(receiver); try { foreach (var player in game.Players) { if (player.Status == true) { player.SendMessage(msg); } } game.GameMaster.SendMessage(msg); if (game.Players.Count == 0) { server.Games.Remove(game.GameId); } } catch (Exception) { Console.WriteLine("Error while notifying other clients"); } Console.WriteLine("Games: {0}", game.Players.Count); }