示例#1
0
文件: Packet.cs 项目: jhlllnd/Asgard
        public NetOutgoingMessage SendMessage(Connection connection)
        {
            NetPeer peer = connection.Peer;
            NetOutgoingMessage sendMsg = peer.CreateMessage();
            sendMsg.Write((uint)PacketId, 16);

            Bitstream stream = new Bitstream(sendMsg);
            Serialize(stream);
            return sendMsg;
        }
示例#2
0
文件: Packet.cs 项目: jhlllnd/Asgard
        public static Packet Get(NetIncomingMessage message)
        {
            var packetId = message.ReadUInt16();
            var pdata = PacketFactory.GetPacketType(packetId);

            var newPacket = (Packet)Activator
                .CreateInstance(pdata.PacketType);

            if (newPacket != null)
            {
                Bitstream stream = new Bitstream(message);
                newPacket.Deserialize(stream);
                return newPacket;
            }

            //TODO
            return null;
        }
示例#3
0
        public override void Deserialize(Bitstream msg)
        {
            State = new List<PlayerStateData>();
            int count = msg.ReadUInt16();
            for (int i = 0; i < count; ++i)
            {
                var o = new PlayerStateData();
                o.Forward = msg.ReadBool();
                o.Back = msg.ReadBool();
                o.Left = msg.ReadBool();
                o.Right = msg.ReadBool();

                o.Position = msg.ReadVector2();
                o.SimTick = (uint)msg.ReadInt32();

                State.Add(o);
            }
            SnapId = msg.ReadInt32();
        }
示例#4
0
 public override void Serialize(Bitstream msg)
 {
     msg.Write(Message);
     msg.Write(From);
 }
示例#5
0
 public override void Deserialize(Bitstream msg)
 {
     Message = msg.ReadString();
     From = msg.ReadString();
 }
示例#6
0
 public override void Serialize(Bitstream msg)
 {
 }
示例#7
0
 public override void Serialize(Bitstream msg)
 {
     msg.Write(Username);
 }
示例#8
0
 public override void Deserialize(Bitstream msg)
 {
     Username = msg.ReadString();
 }
示例#9
0
文件: Packet.cs 项目: jhlllnd/Asgard
 public abstract void Serialize(Bitstream msg);