Beispiel #1
0
        public static GameStateMessage Deserialize(ref BinaryReader reader)
        {
            GameStateMessage output = new GameStateMessage();

            output.state = (GAME_STATE)reader.ReadInt32();
            return(output);
        }
        public static NetworkMessage Deserialize(byte[] bytes)
        {
            BinaryReader   reader = new BinaryReader(new MemoryStream(bytes));
            NetworkMessage output = new NetworkMessage();

            output.data_type = (DataMessage_Type)reader.ReadInt32();

            switch (output.data_type)
            {
            case DataMessage_Type.GAME_STATE:
                output.data = GameStateMessage.Deserialize(ref reader);
                break;

            case DataMessage_Type.PLAYER_UPDATE:
                output.data = PlayerUpdateMessage.Deserialize(ref reader);
                break;

            case DataMessage_Type.PLAYER_INPUT:
                output.data = PlayerInputMessage.Deserialize(ref reader);
                break;


            default:
                Debug.Assert(false, "INVALID DATA TYPE");
                break;
            }

            return(output);
        }
Beispiel #3
0
        public void Update()
        {
            if (state == LOBBY_STATE.START)
            {
                if (Azul.Input.GetKeyState(Azul.AZUL_KEY.KEY_H))
                {
                    state = LOBBY_STATE.HOST;
                    GameManager.SetAsServer();

                    NetPeerConfiguration config = new NetPeerConfiguration("Connected Test");
                    config.AcceptIncomingConnections = true;
                    config.MaximumConnections        = 100;
                    config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
                    config.Port = 14240;

                    //server = new NetPeer(config);
                    //server.Start();

                    MyServer.Instance.Setup(config);
                }
            }
            else if (state == LOBBY_STATE.HOST)
            {
                if (Azul.Input.GetKeyState(Azul.AZUL_KEY.KEY_SPACE))
                {
                    GameStateMessage msg1 = new GameStateMessage(SEND_TYPE.LOCAL, GAME_STATE.PLAY);
                    GameStateMessage msg2 = new GameStateMessage(SEND_TYPE.NETWORKED, GAME_STATE.PLAY);

                    InputQueue.AddToQueue(msg1);
                    InputQueue.AddToQueue(msg2);
                }
            }
        }
Beispiel #4
0
        public void SendMessageToClient(DataMessage msg)
        {
            if (server.ConnectionsCount > 0)
            {
                NetworkMessage sm = new NetworkMessage();


                // Temporary
                switch (msg.type)
                {
                case DataMessage_Type.GAME_STATE:
                    GameStateMessage gameStateMsg = msg as GameStateMessage;
                    sm.Set_Data(gameStateMsg);
                    break;

                case DataMessage_Type.PLAYER_UPDATE:
                    PlayerUpdateMessage playerMsg = msg as PlayerUpdateMessage;
                    sm.Set_Data(playerMsg);
                    break;

                case DataMessage_Type.FENCE_HIT:
                    FenceHitMessage fMsg = msg as FenceHitMessage;
                    sm.Set_Data(fMsg);
                    break;

                case DataMessage_Type.MISSLE_MINE:
                    MissileMineMessage MMMsg = msg as MissileMineMessage;
                    sm.Set_Data(msg);
                    break;

                case DataMessage_Type.ROTATION:
                    RotationMessage rMsg = msg as RotationMessage;
                    sm.Set_Data(msg);
                    break;

                case DataMessage_Type.MISSILEUPDATE:
                    MissileUpdateMessage tmsg = msg as MissileUpdateMessage;
                    sm.Set_Data(msg);
                    break;

                case DataMessage_Type.GAME_OVER:
                    GAMEOVERMESSAGE gomsg = msg as GAMEOVERMESSAGE;
                    sm.Set_Data(msg);
                    break;

                default:
                    break;
                }

                NetOutgoingMessage om = server.CreateMessage();

                om.Write(sm.Serialize());
                server.SendMessage(om, server.Connections, NetDeliveryMethod.ReliableOrdered, 4);

                server.FlushSendQueue();
            }
        }
        public static NetworkMessage Deserialize(byte[] bytes)
        {
            BinaryReader   reader = new BinaryReader(new MemoryStream(bytes));
            NetworkMessage output = new NetworkMessage();

            output.data_type = (DataMessage_Type)reader.ReadInt32();

            switch (output.data_type)
            {
            case DataMessage_Type.GAME_STATE:
                output.data = GameStateMessage.Deserialize(ref reader);
                break;

            case DataMessage_Type.PLAYER_UPDATE:
                output.data = PlayerUpdateMessage.Deserialize(ref reader);
                break;

            case DataMessage_Type.MISSLE_MINE:
                output.data = MissileMineMessage.Deserialize(ref reader);
                break;

            case DataMessage_Type.ROTATION:
                output.data = RotationMessage.Deserialize(ref reader);
                break;

            case DataMessage_Type.FENCE_HIT:
                output.data = FenceHitMessage.Deserialize(ref reader);
                break;

            case DataMessage_Type.MISSILEUPDATE:
                output.data = MissileUpdateMessage.Deserialize(ref reader);
                break;

            case DataMessage_Type.GAME_OVER:
                output.data = GAMEOVERMESSAGE.Deserialize(ref reader);
                break;

            default:
                Debug.Assert(false, "INVALID DATA TYPE");
                break;
            }

            return(output);
        }
Beispiel #6
0
 void ProcessGameStateMessage(GameStateMessage msg)
 {
     state = GAME_STATE.PLAY;
 }