protected override void ExecuteDetails() { //This handles the Heartbeat and ack responce from GM. base.ExecuteDetails(); //Get the game and passoff data LobbyAppState lobAppState = (LobbyAppState)SubSystem.appState; LobbyGame game = lobAppState.getGame(this.gameID); //Starting Official Passoff. //Handling GameId to player1 Envelope envToPlayer1 = new Envelope(new GameIdMessage(this.gameID,game.Pl1.Id,game.Pl2.Id,game.GM.TCPEP.ToString(),game.Pl1.name,game.Pl2.name,false,false,false,false, new Identifier(this.SubSystem.ProcessID, SubSystem.GetNextSeqNumber()), this.ConversationId), null, Player1EP, IsTcpConversation); Envelope recievedFromPlayer1 = DoReliableRequestReply(envToPlayer1, this.ExceptedReplyType); if (recievedFromPlayer1 == null) { Logger.Error($"{this.GetType()}-{this.ConversationId}, Failed to recieve Env from player1. Ending Conversation Early."); return; //ending conversation early. } this.ProcessValidResponse(recievedFromPlayer1); //Handling GameId to player2 Envelope envToPlayer2 = new Envelope(new GameIdMessage(this.gameID, game.Pl1.Id, game.Pl2.Id, game.GM.TCPEP.ToString(), game.Pl1.name, game.Pl2.name, false, false, false, false, new Identifier(this.SubSystem.ProcessID, SubSystem.GetNextSeqNumber()), this.ConversationId), null, Player2EP, IsTcpConversation); Envelope recievedFromPlayer2 = DoReliableRequestReply(envToPlayer2, this.ExceptedReplyType); if (recievedFromPlayer2 == null) { Logger.Error($"{this.GetType()}-{this.ConversationId}, Failed to recieve Env from player2. Ending Conversation Early."); return; //ending conversation early. } this.ProcessValidResponse(recievedFromPlayer2); //Conversation ends in success. this.State = PossibleState.Successed; Logger.Info("Pass off ended in success!"); }
static void Main(string[] args) { XmlConfigurator.Configure(); ILog Logger = LogManager.GetLogger(typeof(Program)); //string player1Name = ""; LobbyAppState appstate = new LobbyAppState(); ConversationFactory conFact = new ConversationFactory(); SubSystem subSys = new SubSystem(conFact, appstate, new IPEndPoint(IPAddress.Any, 2201), new IPEndPoint(IPAddress.Any, 2201)); subSys.start(); // need to connect players to games // and bring them back after game is over while (true) { //appstate.gameIsReady(); //WAIT till a game is ready. if (!LobbyAppState.gameIsReadyEvent.WaitOne(10000)) { Logger.Debug("Timeout for checking if game is ready has been reached going to try again."); continue; } //Start the game. short gameIDToStart; gameIDToStart = appstate.startGame(); Logger.Debug("Started a game passoff conversation"); //Create initiator conversations and set the conversation. PassOff passOffLobby = new PassOff(); passOffLobby.SubSystem = subSys; passOffLobby.ConversationId = new Identifier(passOffLobby.SubSystem.ProcessID, SubSystem.GetNextSeqNumber()); passOffLobby.setEPs(gameIDToStart); passOffLobby.Launch(); //Note: remote Endpoint set in constructor of passOffLobby. } }