public static void HandleMessage(RegisterGame request, CommunicationServer server, Socket handler) { if (request == null) { return; } Game.Game g; lock (joinLock) { g = new Game.Game(gameId: server.RegisteredGames.NextGameId(), name: request.NewGameInfo.gameName, bluePlayers: request.NewGameInfo.blueTeamPlayers, redPlayers: request.NewGameInfo.redTeamPlayers, gameMaster: handler ); try { server.RegisteredGames.RegisterGame(g); } catch { return; } } ConfirmGameRegistration gameRegistration = new ConfirmGameRegistration() { gameId = (ulong)g.Id }; var response = XmlMessageConverter.ToXml(gameRegistration); server.ConnectionEndpoint.SendFromServer(handler, response); }
public void HandleRequest(object insock) { Socket s = (Socket)insock; byte[] buffer; int readBytes; buffer = new byte[s.SendBufferSize]; readBytes = s.Receive(buffer); if (readBytes > 0) // assume all is read at once { string messageString = Encoding.ASCII.GetString(buffer); //Console.WriteLine("Thread: {0}, ListenerInfo: LEP: {1}, REP: {2}", Thread.CurrentThread.ManagedThreadId, listener.LocalEndPoint, listener.RemoteEndPoint); Console.WriteLine("Thread: {0}, LEP: {1}, REP: {2}", Thread.CurrentThread.ManagedThreadId, s.LocalEndPoint, s.RemoteEndPoint); Message tempMessage = MessageProject.Message.xmlIntoMessage(messageString); Type typer = tempMessage.GetType(); dynamic newMessage = Convert.ChangeType(tempMessage, typer); Console.WriteLine(newMessage.GetType().ToString()); RegisterGame mes = (RegisterGame)newMessage; Console.WriteLine("GameID: {0}, PlayersBlue: {1}, PlayersRed: {2}", mes.gameID, mes.blueTeamPlayers.ToString(), mes.redTeamPlayers.ToString()); ConfirmGameRegistration gameConfirmation = new ConfirmGameRegistration(mes.gameID); string respStr = MessageProject.Message.messageIntoXML(gameConfirmation); Console.WriteLine("Response type: {0}", gameConfirmation.GetType()); byte[] response = Encoding.ASCII.GetBytes(respStr); s.Send(response); } Thread.Sleep(10000); }
private string MakeGameCreationMessage() { // for main game only RegisterGame responseObj = new RegisterGame(game.gameId, game.settings.PlayersPerTeam, game.settings.PlayersPerTeam); // The same ammount of players in both teams atm! return(MessageProject.Message.messageIntoXML(responseObj)); }
public void RegisterGamesTest() { RegisterGame registerGame = new RegisterGame(); GameInfo gameInfo = new GameInfo(); gameInfo = new GameInfo() { gameName = "testname" }; registerGame.NewGameInfo = gameInfo; string xml = XmlMessageConverter.ToXml(registerGame); RegisterGame result = (RegisterGame)XmlMessageConverter.ToObject(xml); Assert.AreEqual("testname", result.NewGameInfo.gameName); }
private void RegisterNewGame(Socket socket) { //at the beginning both teams have same number of open player slots ulong noOfPlayersPerTeam = ulong.Parse(Settings.GameDefinition.NumberOfPlayersPerTeam); messageHandler.Clear(); RegisterGame registerGameMessage = new RegisterGame() { NewGameInfo = new GameInfo() { gameName = Settings.GameDefinition.GameName, blueTeamPlayers = noOfPlayersPerTeam, redTeamPlayers = noOfPlayersPerTeam } }; string registerGameString = XmlMessageConverter.ToXml(registerGameMessage); Connection.SendFromClient(socket, registerGameString); }