Exemplo n.º 1
0
        public Blood(PacketReader reader)
        {
            this.Location =
                new Vector2(
                NetPacker.ShortToBigFloat(reader.ReadInt16()),
                NetPacker.ShortToBigFloat(reader.ReadInt16()));

            this.Trajectory =
                new Vector2(
                NetPacker.ShortToBigFloat(reader.ReadInt16()),
                NetPacker.ShortToBigFloat(reader.ReadInt16()));

            this.r = NetPacker.ByteToTinyFloat(reader.ReadByte());
            this.g = NetPacker.ByteToTinyFloat(reader.ReadByte());
            this.b = NetPacker.ByteToTinyFloat(reader.ReadByte());
            this.a = NetPacker.ByteToTinyFloat(reader.ReadByte());

            this.size = NetPacker.ShortToSmallFloat(reader.ReadInt16());
            this.flag = NetPacker.SbyteToInt(reader.ReadSByte());

            this.owner = -1;
            this.Exists = true;
            this.rotation = GlobalFunctions.GetAngle(new Vector2(), Trajectory);
            this.frame = Rand.GetRandomFloat(0.3f, 0.7f);
        }
Exemplo n.º 2
0
        public Smoke(PacketReader reader)
        {
            this.Location =
                new Vector2(
                NetPacker.ShortToBigFloat(reader.ReadInt16()),
                NetPacker.ShortToBigFloat(reader.ReadInt16()));

            this.Trajectory =
                new Vector2(
                NetPacker.ShortToBigFloat(reader.ReadInt16()),
                NetPacker.ShortToBigFloat(reader.ReadInt16()));

            this.r = NetPacker.ByteToTinyFloat(reader.ReadByte());
            this.g = NetPacker.ByteToTinyFloat(reader.ReadByte());
            this.b = NetPacker.ByteToTinyFloat(reader.ReadByte());
            this.a = NetPacker.ByteToTinyFloat(reader.ReadByte());

            this.size = NetPacker.ShortToSmallFloat(reader.ReadInt16());
            this.flag = NetPacker.SbyteToInt(reader.ReadSByte());

            this.owner = -1;
            this.Exists = true;
            this.frame = 1.0f;
        }
        protected override void UpdateFromNetwork(GameTime gameTime)
        {
            // read any available data and process it:
            while (localGamer_.IsDataAvailable)
            {
                PacketReader reader = new PacketReader();
                NetworkGamer sender;
                localGamer_.ReceiveData(reader, out sender);

                // only process remote data (ignore data sent from the local player):
                if (localGamer_.Id == sender.Id) continue;

                // also ignore data from wrong packet headers:
                if (reader.ReadByte() != PacketHeader.INGAME_DATA) continue;

                foreach (CarActor carActor in idTocarActorMap_[sender.Id]) carActor.updateFromNetwork(reader);
            }
        }
Exemplo n.º 4
0
 /* Given a highscores packet sent to a local player, handle that.
  * The packet itself is in the PacketReader r.
  */
 protected virtual void DoHighscoresPacket(LocalNetworkGamer to, PacketReader r, 
     NetworkGamer from, byte type)
 {
     PMR.Reader = r;
       byte n = 0;
       short tok = 0;
       switch (type)
       {
     case HighscoreItems:
       if (!from.IsLocal)
       {
     tok = r.ReadInt16();
     n = r.ReadByte();
     Trace.WriteLine(String.Format("Received {0} highscores in a packet from {1} (token {2})",
       n, from, tok));
     //  this happens during runtime, so I better not do too many scores at one time
     for (int i = 0; i != n; ++i)
     {
       Highscore hs = new Highscore();
       hs.MarshalThrough(PMR);
       Storage.Instance.AddHighscore(hs, true);
     }
     SendAck(tok, from);
       }
       break;
     case HighscoreItemsAck:
       tok = r.ReadInt16();
       Trace.WriteLine(String.Format("Received ack for pos {0} from {1}", tok, from));
       AckFrom(from, tok);
       break;
     default:
       Trace.WriteLine(String.Format("Swallowing packet type {0} from {1}", type, from));
       break;
       }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Deserialize from the packet into the current object.
        /// </summary>
        /// <param name="packetReader">The packet reader that has the data.</param>
        public void Deserialize(PacketReader packetReader)
        {
            // safety-check the parameter, as it must be valid.
            if (packetReader == null)
            {
                throw new ArgumentNullException("packetReader");
            }

            ShipColor = packetReader.ReadByte();
            ShipVariation = packetReader.ReadByte();
        }
 /// <summary>
 /// Update the sender's local player count from the network. 
 /// </summary>
 public static void UpdateFromNetwork(this NetworkGamer sender, PacketReader reader)
 {
     // ignore any packets with the wrong header (possibly delayed packets from a previous exchange)
     if (reader.ReadByte() == PacketHeader.LOBBY_DATA) sender.Tag = reader.ReadInt32();
 }