protected override void OnUpdate(TimeSpan gameTime)
 {
     while((IncomeMessage = Client.ReadMessage()) != null)
     {
         switch(IncomeMessage.MessageType)
         {
             case NetIncomingMessageType.Error:
             case NetIncomingMessageType.ErrorMessage:
                 throw new Exception(IncomeMessage.ToString());
             case NetIncomingMessageType.Data:
                 ProcessMessage(IncomeMessage);
                 break;
         }
     }
 }
Example #2
0
        private void HandleAGameMessage(NetIncomingMessage msg)
        {
            string messageType = msg.ReadString();

            switch (messageType)
            {
                case "LIFE":
                    long UID_LIFE = msg.ReadInt64();
                    int hp = msg.ReadInt32();
                    HandleLifeMessage(UID_LIFE, hp);
                    break;

                case "NAME":
                    long UID_NAME = msg.ReadInt64();
                    string newName = msg.ReadString();
                    HandleNameMessage(UID_NAME, newName);
                    break;

                case "POS": //Update a player's position
                    long UID_POS = msg.ReadInt64();
                    float xPos = msg.ReadFloat();
                    float yPos = msg.ReadFloat();
                    int facing = msg.ReadInt32();
                    float aimAngle = msg.ReadFloat();
                    HandlePosMessage(UID_POS, xPos, yPos, facing, aimAngle);
                    break;

                case "JOIN": //Add a player
                    long UID_JOIN = msg.ReadInt64();
                    HandleJoinMessage(UID_JOIN);
                    break;

                case "CHAT": //Add chat
                    long UID_CHAT = msg.ReadInt64();
                    string message = msg.ReadString();
                    HandleChatMessage(UID_CHAT, message);
                    break;

                case "PART": //Remove a player
                    long UID_PART = msg.ReadInt64();
                    HandlePartMessage(UID_PART);
                    break;

                case "INFO": //Recieved when server has completed sending all newbie initialization
                    break;
                case "BULLET":
                    long UID_BULLET = msg.ReadInt64();
                    float xBULLET = msg.ReadFloat();
                    float yBULLET = msg.ReadFloat();
                    float BULLETangle = msg.ReadFloat();
                    Bullet b = new Bullet(UID_BULLET, BULLETangle, new Vector2f(xBULLET, yBULLET));
                    HandleBulletCreate(b, UID_BULLET);
                    break;
                case "RESPAWN":
                    long UID_RESPAWN = msg.ReadInt64();
                    HandleRespawnMessage(UID_RESPAWN);
                    break;
                case "COIN":
                    //long UID_COIN = msg.ReadInt64();
                    float xCOIN = msg.ReadFloat();
                    float yCOIN = msg.ReadFloat();
                    int countCOIN = msg.ReadInt32();

                    HandleCoinCreate(countCOIN, xCOIN, yCOIN);

                    break;
                case "SWITCHWEAPON":
                    long UID_WEPSWITCH = msg.ReadInt64();
                    int WEAPONID = msg.ReadInt32();
                    HandleNetPlayerWeaponSwitch(UID_WEPSWITCH, WEAPONID);
                    break;
                case "KILLER":
                    long UID_VICTIM = msg.ReadInt64();
                    long UID_KILLER = msg.ReadInt64();
                    HandleKillerMessage(UID_VICTIM, UID_KILLER);
                    break;
                case "LOOT":
                    Console.WriteLine("LOOT Recieved");
                    int LOOTseed = msg.ReadInt32();
                    Console.WriteLine(LOOTseed);
                    Random rand = new Random(LOOTseed);
                    MainGame.dm.GameObjects.Add(new TreasureBox(new Vector2f(rand.Next(40, 1600), 180)));
                    break;
                case "EMOTE":
                    long UID_EMOTE = msg.ReadInt64();
                    string EMOTE_TYPE = msg.ReadString();
                    MainGame.dm.GameObjects.Add(new EmoteBubble(EMOTE_TYPE, MainGame.dm.GetPlayerWithUID(UID_EMOTE))); ;
                    break;
                case "BOMB":
                    long UID_EXPLOSIVE = msg.ReadInt64();
                    float xEXP = msg.ReadFloat();
                    float yEXP = msg.ReadFloat();
                    float EXPangle = msg.ReadFloat();
                    BombInstance bomb = new BombInstance(UID_EXPLOSIVE, EXPangle, new Vector2f(xEXP, yEXP));
                    HandleBombCreate(bomb, UID_EXPLOSIVE);
                    break;
                case "TIME":
                    float TIME_MESSAGE = msg.ReadFloat();
                    HandleTimeMessage(TIME_MESSAGE);
                    break;
                case "MODEL":
                    Console.WriteLine("Model");
                    long UID_MODEL = msg.ReadInt64();
                    string MODEL_STR = msg.ReadString();
                    Console.WriteLine(MODEL_STR);
                    HandleModel(UID_MODEL, MODEL_STR);
                    break;
                case "GOLDCOUNT":
                    long UID_GOLDCOUNT = msg.ReadInt64();
                    int goldCount = msg.ReadInt32();
                    HandleGoldCountMessage(UID_GOLDCOUNT, goldCount);
                    break;
                case "LANDMINE":
                    long UID_MINEOWNER = msg.ReadInt64();
                    float xMINE = msg.ReadFloat();
                    float yMINE = msg.ReadFloat();
                    int MINE_ID = msg.ReadInt32();
                    HandleLandMineMessage(UID_MINEOWNER, xMINE, yMINE, MINE_ID);
                    break;
                case "LANDMINE_TRIGGER":
                    int LANDMINEID = msg.ReadInt32();
                    HandleLandMineTriggerMessage(LANDMINEID);
                    break;
                case "GENERATOR":
                    long UID_GENOWNER = msg.ReadInt64();
                    float xGEN = msg.ReadFloat();
                    float yGEN = msg.ReadFloat();
                    int type = msg.ReadInt32();
                    DateTime when = new DateTime(msg.ReadInt64());
                    HandleGeneratorMessage(xGEN, yGEN, type, when);
                    break;
                default:
                    Console.WriteLine("Unrecognized Game Message Recieved: {0}\n{1}", msg.ToString(), messageType);
                    break;
            }
        }
Example #3
0
        private void PeerConnected(NetIncomingMessage message)
        {
            string connectionId = null;

              if (message.SenderConnection.RemoteHailMessage != null)
            connectionId = message.SenderConnection.RemoteHailMessage.ReadString();

              if (connectionId == null)
              {
            ClientModel.Logger.WriteWarning("ConnectionId is null [Message: {0}, SenderEndPoint: {1}]", message.ToString(), message.SenderEndPoint);
            return;
              }

              message.SenderConnection.Tag = connectionId;

              lock (waitingCommands)
              {
            List<WaitingCommandContainer> commands;
            if (waitingCommands.TryGetValue(connectionId, out commands))
            {
              foreach (WaitingCommandContainer command in commands)
            SendMessage(connectionId, command.CommandId, command.MessageContent, command.Unreliable);

              waitingCommands.Remove(connectionId);
            }
              }

              ClientModel.Logger.WriteDebug("AsyncPeer.PeerConnected({0})", connectionId);
        }