protected Message ProcessIncomingEnvelope(Envelope env)
        {
            this.IncomingEnvelopes.Enqueue(env);
            Identifier messageNumber = new Identifier(SubSystem.ProcessID, SubSystem.GetNextSeqNumber());

            if (env.Message.GetType() == typeof(ResultMessage))
            {
                Logger.Info("Received a result message in RespondTurns convo");
                playerAppState = SubSystem.appState as PlayerAppState;

                ResultMessage message = env.Message as ResultMessage;
                playerAppState.lastShotHit = message.getHit();
                playerAppState.turn        = message.getMyTurn();
                playerAppState.end         = message.getEnd();
                playerAppState.won         = message.getWin();
                playerAppState.gameId      = message.getGameId();
                playerAppState.lastX       = message.getXcord();
                playerAppState.lastY       = message.getYcord();
                playerAppState.SetTurn();
                playerAppState.ColorButtonResult(playerAppState.turn, playerAppState.lastX, playerAppState.lastY, playerAppState.lastShotHit); //Setting gameScreen according to shot.

                return(new AckMessage(playerAppState.gameId, 1, messageNumber, this.ConversationId));
            }
            else
            {
                Logger.Error("Received an error message in RespondTurns convo");
                return(new ErrorMessage());
            }
        }
Beispiel #2
0
        protected override Message CreateFirstMessage()
        {
            Identifier messageNumber = new Identifier(SubSystem.ProcessID, SubSystem.GetNextSeqNumber());

            ConversationId = messageNumber;

            appState = SubSystem.appState as PlayerAppState;
            Logger.Info("Shot message created in Shot convo");
            return(new ShotMessage(appState.shotCoordinates.Item1, appState.shotCoordinates.Item2, appState.gameId, appState.playerID, messageNumber, ConversationId));
        }
        protected override Message CreateFirstMessage()
        {
            Identifier messageNumber = new Identifier(SubSystem.ProcessID, SubSystem.GetNextSeqNumber());

            ConversationId = messageNumber;

            playerAppState = SubSystem.appState as PlayerAppState;
            Logger.Info("Board message created in Board convo");
            return(new BoardMessage(playerAppState.gameId, playerAppState.planningGrid, messageNumber, ConversationId));
        }
Beispiel #4
0
        protected override void ExecuteDetails()
        {
            playerAppState = (PlayerAppState)this.SubSystem.appState;
            var      msg      = ProcessIncomingEnvelope(IncomingEnvelope);
            Envelope response = new Envelope(msg, null, RemoteEndPoint, IsTcpConversation);

            this.DoReliableRespondToRequest(response);

            playerAppState.MoveToPlanning();

            this.State = PossibleState.Successed;
        }
        static void Main()
        {
            XmlConfigurator.Configure();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            WaitingRoom         waitingRoom = new WaitingRoom();
            PlayerAppState      appState    = new PlayerAppState(waitingRoom);
            ConversationFactory conFact     = new ConversationFactory(); //Create conversation factory
            SubSystem           subsystem   = new SubSystem(conFact, appState);

            appState.subSystem = subsystem;
            subsystem.start();
            Application.Run(waitingRoom);

            //Conversation conversation2   = conFact.CreateFromConversationType<Board>();
            //conversation2.RemoteEndPoint = appState.GMEndPoint;
            //conversation2.Launch();
            //Needs ConversationFactory implementation
            //ConversationFactory conFact = new ConversationFactory(subsystem);
        }
Beispiel #6
0
        protected override void ProcessValidResponse(Envelope env)
        {
            playerAppState = this.SubSystem.appState as PlayerAppState;
            var message = env.Message as AssignIdMessage;

            SubSystem.ProcessID = message.getId();
            Logger.Debug($"encrypted sysmetric key is {BitConverter.ToString(message.getKey())}");
            Logger.Debug($"encrypted sysmetric IV is {BitConverter.ToString(message.getIV())}");
            playerAppState.InformConnectionSuccess();

            byte[] key = playerAppState.decrypt(message.getKey());
            byte[] IV  = playerAppState.decrypt(message.getIV());

            Logger.Debug($"decrypted sysmetric key is {BitConverter.ToString(key)}");
            Logger.Debug($"decrypted sysmetric IV is {BitConverter.ToString(IV)}");

            SubSystem.tcpcomm.setKeyAndIV(key, IV);
            SubSystem.udpcomm.setKeyAndIV(key, IV);

            Logger.Debug($" The Assigned process Id is {SubSystem.ProcessID}");
            playerAppState.playerID = SubSystem.ProcessID;
        }