Beispiel #1
0
 void Instantiate(NetStream stream) {
     if (stream.ReadBool()) Die();
     if (!gameObject.activeSelf) gameObject.SetActive(true);
     float posX = stream.ReadFloat();
     float posZ = stream.ReadFloat();
     transform.position = new Vector3(posX, 0, posZ);
 }
Beispiel #2
0
        internal static NetMessage ReadNetMessage(NetStream stream)
        {
            List <Type> paramTypes;
            ushort      messageId = stream.ReadUShort(11);
            uint        viewId    = 0;

            if (stream.ReadBool())
            {
                viewId = stream.ReadUInt(20);
            }

            if (messageId == (int)Cmd.RequestResponse)
            {
                return(CreateResponseMessage(stream, messageId, viewId));
            }

            if (messageId > 1800)
            {
                if (!stream.Socket.Command.Exists(messageId))
                {
                    NetLog.Error("Cannot deserialize message, Command ID not found: " + messageId);
                    return(null);
                }
                paramTypes = stream.Socket.Command.ParamTypes(messageId);
            }
            else
            {
                if (!stream.Socket.Rpc.Exists(messageId))
                {
                    NetLog.Error("Cannot deserialize message, RPC ID not found: " + messageId);
                    return(null);
                }
                paramTypes = stream.Socket.Rpc.ParamTypes(messageId);
            }

            NetMessage netMessage = NetMessage.Create(messageId, viewId, paramTypes.Count, false);

            if (stream.Socket.Rpc.TakesRequests(messageId))
            {
                return(CreateRequestMessage(stream, netMessage, paramTypes));
            }

            for (int i = 0; i < paramTypes.Count; i++)
            {
                netMessage.Parameters[i] = ReadParam(stream, paramTypes[i]);
            }

            return(netMessage);
        }
Beispiel #3
0
        /// <summary> Updates receive time and forwards stream to proper channel for deserialization. </summary>
        internal void ReceiveStream(NetStream stream)
        {
            stream.Connection = this;
            LastReceiveTime   = NetTime.Milliseconds();
            bool reliable = stream.ReadBool();

            if (!reliable)
            {
                Unreliable.DeserializeStream(stream);
            }
            else
            {
                Reliable.RouteIncomingStream(stream);
            }
        }
Beispiel #4
0
        private static NetMessage CreateResponseMessage(NetStream stream, ushort messageId, uint viewId)
        {
            ushort requestId = stream.ReadUShort();

            if (!stream.Socket.Request.Exists(viewId, requestId))
            {
                return(null);
            }
            bool   isSuccessful = stream.ReadBool();
            object result       = null;

            if (isSuccessful)
            {
                Type resultType = stream.Socket.Request.Type(viewId, requestId);
                result = ReadParam(stream, resultType);
            }
            object[] requestParams = { requestId, isSuccessful, result };
            return(NetMessage.Create(messageId, viewId, requestParams, true));
        }
Beispiel #5
0
 void Instantiate(NetStream stream) {
     catAnimator.Dead = stream.ReadBool();
     PlayerName = stream.ReadString();
     transform.position = stream.ReadVector3();
     inventory.SetAllFromStream(stream);
 }
Beispiel #6
0
 public IInvItem Clone(int withQuantity, NetStream stream) {
     return new MeleeWeapon(DbId, Name, QuantityMax, withQuantity, Damage, Cooldown, stream.ReadBool());
 }
Beispiel #7
0
 public IInvItem Clone(int withQuantity, NetStream stream) {
     return new Armor(DbId, Name, QuantityMax, withQuantity, Protection, MountPoint, stream.ReadBool());
 }
Beispiel #8
0
 /// <summary> Updates receive time and forwards stream to proper channel for deserialization. </summary>
 internal void ReceiveStream(NetStream stream) {
     stream.Connection = this;
     LastReceiveTime = NetTime.Milliseconds();
     bool reliable = stream.ReadBool();
     if (!reliable) Unreliable.DeserializeStream(stream);
     else Reliable.RouteIncomingStream(stream);
 }
Beispiel #9
0
 private void ReadInstantiateData(NetStream stream) {
     if (!stream.ReadBool()) return;
     transform.position = stream.ReadVector3();
     item = (IInvItem)ExampleItems.ItemDeserializer(stream);
     SetMesh();
 }
Beispiel #10
0
        private static object ReadParam(NetStream stream, Type type)
        {
            if (type == typeof(bool))
            {
                return(stream.ReadBool());
            }
            if (type == typeof(byte))
            {
                return(stream.ReadByte());
            }
            if (type == typeof(short))
            {
                return(stream.ReadShort());
            }
            if (type == typeof(ushort))
            {
                return(stream.ReadUShort());
            }
            if (type == typeof(int))
            {
                return(stream.ReadInt());
            }
            if (type == typeof(uint))
            {
                return(stream.ReadUInt());
            }
            if (type == typeof(float))
            {
                return(stream.ReadFloat());
            }
            if (type == typeof(long))
            {
                return(stream.ReadLong());
            }
            if (type == typeof(ulong))
            {
                return(stream.ReadULong());
            }
            if (type == typeof(double))
            {
                return(stream.ReadDouble());
            }
            if (type == typeof(string))
            {
                return(stream.ReadString());
            }
            if (type == typeof(Vector2))
            {
                return(stream.ReadVector2());
            }
            if (type == typeof(Vector3))
            {
                return(stream.ReadVector3());
            }
            if (type == typeof(Quaternion))
            {
                return(stream.ReadQuaternion());
            }

            if (type == typeof(bool[]))
            {
                ushort length = stream.ReadUShort();
                bool[] arr    = new bool[length];
                for (int i = 0; i < length; i++)
                {
                    arr[i] = stream.ReadBool();
                }
                return(arr);
            }
            if (type == typeof(byte[]))
            {
                ushort length = stream.ReadUShort();
                byte[] arr    = new byte[length];
                for (int i = 0; i < length; i++)
                {
                    arr[i] = stream.ReadByte();
                }
                return(arr);
            }
            if (type == typeof(ushort[]))
            {
                ushort   length = stream.ReadUShort();
                ushort[] arr    = new ushort[length];
                for (int i = 0; i < length; i++)
                {
                    arr[i] = stream.ReadUShort();
                }
                return(arr);
            }
            if (type == typeof(int[]))
            {
                ushort length = stream.ReadUShort();
                int[]  arr    = new int[length];
                for (int i = 0; i < length; i++)
                {
                    arr[i] = stream.ReadInt();
                }
                return(arr);
            }
            if (type == typeof(uint[]))
            {
                ushort length = stream.ReadUShort();
                uint[] arr    = new uint[length];
                for (int i = 0; i < length; i++)
                {
                    arr[i] = stream.ReadUInt();
                }
                return(arr);
            }
            if (type == typeof(float[]))
            {
                ushort  length = stream.ReadUShort();
                float[] arr    = new float[length];
                for (int i = 0; i < length; i++)
                {
                    arr[i] = stream.ReadFloat();
                }
                return(arr);
            }
            if (type == typeof(string[]))
            {
                ushort   length = stream.ReadUShort();
                string[] arr    = new string[length];
                for (int i = 0; i < arr.Length; i++)
                {
                    arr[i] = stream.ReadString();
                }
                return(arr);
            }
            if (type == typeof(char[]))
            {
                ushort length = stream.ReadUShort();
                char[] arr    = new char[length];
                for (int i = 0; i < arr.Length; i++)
                {
                    arr[i] = stream.ReadChar();
                }
                return(arr);
            }
            if (type == typeof(NetMessage))
            {
                return(ReadNetMessage(stream));
            }
            if (type == typeof(NetMessage[]))
            {
                byte         length = stream.ReadByte();
                NetMessage[] arr    = new NetMessage[length];
                for (int i = 0; i < length; i++)
                {
                    arr[i] = ReadNetMessage(stream);
                }
                return(arr);
            }
            if (type == typeof(NetConnection))
            {
                return(stream.Connection);
            }
            if (type == typeof(IPAddress))
            {
                byte[] array = new byte[4];
                stream.ReadByteArray(array);
                return(new IPAddress(array));
            }
            if (type == typeof(IPEndPoint))
            {
                if (!stream.ReadBool())
                {
                    return(null);
                }
                return(new IPEndPoint((IPAddress)ReadParam(stream, typeof(IPAddress)), stream.ReadUShort()));
            }
            if (type == typeof(NetStream))
            {
                return(stream.ReadNetStream());
            }
            if (type == typeof(NetZone))
            {
                return(new NetZone {
                    Id = stream.ReadUInt(),
                    ServerEndpoint =
                        stream.ReadBool()
                            ? (IPEndPoint)ReadParam(stream, typeof(IPEndPoint))
                            : null,
                    Position = stream.ReadVector3(),
                    ViewIdMin = stream.ReadInt(),
                    ViewIdMax = stream.ReadInt()
                });
            }
            if (HasType(type))
            {
                return(Read(stream, type));
            }

            // We don't know how to deserialize this type
            throw new Exception("Deserializer not implemented for type: " + type);
        }