Ejemplo n.º 1
0
 public void Deserialize(NetDataReader reader)
 {
     serverUnixTime   = reader.GetLong();
     serverTime       = reader.GetLong();
     sendPackCount    = reader.GetULong();
     receivePackCount = reader.GetULong();
 }
Ejemplo n.º 2
0
        public object Deserialize(NetDataReader stream)
        {
            if (!stream.GetBool())
            {
                return(null);
            }

            DefIDFull defId = default;
            var       crcId = stream.GetULong();
            var       root  = stream.GetBool();

            if (root)
            {
                defId = DefsHolder.Instance.NetIDs.GetID(crcId, 0, 0, 0);
            }
            else
            {
                var line  = stream.GetShort();
                var col   = stream.GetShort();
                var proto = stream.GetByte();
                defId = DefsHolder.Instance.NetIDs.GetID(crcId, line, col, proto);
            }

            return(DefsHolder.Instance.LoadResource <IDef>(defId));
        }
Ejemplo n.º 3
0
 public EntityUpdateData Read(NetDataReader reader)
 {
     id  = reader.GetULong();
     pos = DataUtils.ReadPos(reader);
     //pos = new Vector2(reader.GetFloat(), reader.GetFloat());
     inputSequence = reader.GetByte();
     return(this);
 }
Ejemplo n.º 4
0
        public void WriteReadULong()
        {
            var ndw = new NetDataWriter();

            ndw.Put(64UL);

            var ndr       = new NetDataReader(ndw.Data);
            var readULong = ndr.GetULong();

            Assert.AreEqual(readULong, 64UL);
        }
Ejemplo n.º 5
0
        protected void InvokeEvent(NetDataReader reader, NetPeer sender, object tMessage)
        {
            var hash = reader.GetULong();
            TypeErasedEventHandler handler;

            if (!_eventHandlers.TryGetValue(hash, out handler))
            {
                throw new ParseException("Undefined packet in NetDataReader");
            }
            handler.Invoke(sender, "OnMessageReceived", tMessage);
        }
Ejemplo n.º 6
0
        static callbackDelegate getCallbackFromData(NetDataReader reader)
        {
            var hash = reader.GetULong();
            callbackDelegate action;

            if (!callbacks.TryGetValue(hash, out action))
            {
                throw new ParseException("undefined packet in NetDataReader");
            }

            return(action);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Reads all available data from NetDataReader and calls OnReceive delegates
 /// </summary>
 /// <param name="sender">Who sent the packet</param>
 /// <param name="reader">NetDataReader with packets data</param>
 public void ReadAllPackets(NetPeer sender, NetDataReader reader)
 {
     while (reader.AvailableBytes > 0)
     {
         ulong tHash = reader.GetULong();
         if (!_eventHandlers.ContainsKey(tHash))
         {
             throw new KeyNotFoundException($"Unknown message type: {tHash:X}");
         }
         else
         {
             var handler  = _eventHandlers[tHash];
             var tMessage = handler.DeserializeT(_netSerializer, reader);
             handler.Invoke(sender, "OnMessageReceived", tMessage);
         }
     }
 }
Ejemplo n.º 8
0
 public override void Deserialize(NetDataReader reader)
 {
     Value = reader.GetULong();
 }
 public ulong GetULong()
 {
     return(_networkReaderImplementation.GetULong());
 }
        private static object GetObject(this NetDataReader reader, Type type)
        {
            if (type == null)
            {
                return(null);
            }

            if (type.GetInterface("INetSerializable") != null)
            {
                var result = (INetSerializable)Activator.CreateInstance(type);
                result.Deserialize(reader);
                return(result);
            }
            else if (type.GetInterface("ISyncObject") != null)
            {
                return(reader.GetByte());
            }
            else if (type.IsEnum)
            {
                return(Enum.Parse(type, type.GetEnumName(reader.GetObject(type.GetEnumUnderlyingType()))));
            }
            else if (type == typeof(bool))
            {
                return(reader.GetBool());
            }
            else if (type == typeof(byte))
            {
                return(reader.GetByte());
            }
            else if (type == typeof(sbyte))
            {
                return(reader.GetSByte());
            }
            else if (type == typeof(char))
            {
                return(reader.GetChar());
            }
            else if (type == typeof(short))
            {
                return(reader.GetShort());
            }
            else if (type == typeof(ushort))
            {
                return(reader.GetUShort());
            }
            else if (type == typeof(int))
            {
                return(reader.GetInt());
            }
            else if (type == typeof(uint))
            {
                return(reader.GetUInt());
            }
            else if (type == typeof(long))
            {
                return(reader.GetLong());
            }
            else if (type == typeof(ulong))
            {
                return(reader.GetULong());
            }
            else if (type == typeof(float))
            {
                return(reader.GetFloat());
            }
            else if (type == typeof(double))
            {
                return(reader.GetBool());
            }
            else if (type == typeof(string))
            {
                return(reader.GetDouble());
            }
            else if (type == typeof(IPEndPoint))
            {
                return(reader.GetNetEndPoint());
            }
            else
            {
                throw new Exception("Unable to deserialize object of type " + type);
            }
        }
Ejemplo n.º 11
0
        /// <inheritdoc />
        public virtual void TinyDeserialize(NetDataReader reader, bool firstStateUpdate)
        {
            if (firstStateUpdate)
            {
                NetworkID = reader.GetInt();
            }

            if (!firstStateUpdate)
            {
                int dFlag = reader.GetInt();

                TinyNetStateSyncer.IntToDirtyFlag(dFlag, _dirtyFlag);
            }

            Type type;
            int  maxSyncVar = propertiesName.Length;

            for (int i = 0; i < maxSyncVar; i++)
            {
                if (!firstStateUpdate && _dirtyFlag[i] == false)
                {
                    continue;
                }

                type = propertiesTypes[i];

                if (type == typeof(byte))
                {
                    byteAccessor[propertiesName[i]].Set(this, reader.GetByte());
                }
                else if (type == typeof(sbyte))
                {
                    sbyteAccessor[propertiesName[i]].Set(this, reader.GetSByte());
                }
                else if (type == typeof(short))
                {
                    shortAccessor[propertiesName[i]].Set(this, reader.GetShort());
                }
                else if (type == typeof(ushort))
                {
                    ushortAccessor[propertiesName[i]].Set(this, reader.GetUShort());
                }
                else if (type == typeof(int))
                {
                    intAccessor[propertiesName[i]].Set(this, reader.GetInt());
                }
                else if (type == typeof(uint))
                {
                    uintAccessor[propertiesName[i]].Set(this, reader.GetUInt());
                }
                else if (type == typeof(long))
                {
                    longAccessor[propertiesName[i]].Set(this, reader.GetLong());
                }
                else if (type == typeof(ulong))
                {
                    ulongAccessor[propertiesName[i]].Set(this, reader.GetULong());
                }
                else if (type == typeof(float))
                {
                    floatAccessor[propertiesName[i]].Set(this, reader.GetFloat());
                }
                else if (type == typeof(double))
                {
                    doubleAccessor[propertiesName[i]].Set(this, reader.GetDouble());
                }
                else if (type == typeof(bool))
                {
                    boolAccessor[propertiesName[i]].Set(this, reader.GetBool());
                }
                else if (type == typeof(string))
                {
                    stringAccessor[propertiesName[i]].Set(this, reader.GetString());
                }
            }
        }
 public void Deserialize(NetDataReader reader)
 {
     Hash            = reader.GetULong();
     PeerId          = reader.GetUShort();
     NetworkObjectId = reader.GetUShort();
 }