Exemple #1
0
 public override void Read(NetworkReader R)
 {
     Ids = new int[R.ReadInt()];
     for (int i = 0; i < Ids.Length; i++)
     {
         Ids[i] = R.ReadInt();
     }
 }
 public static TCServerResponse ReadServerResponse(this NetworkReader reader)
 {
     return(new TCServerResponse
     {
         CurrentAmountOfPlayers = reader.ReadInt(),
         GameName = CompressedNetworkString.Read(reader),
         MaxPlayers = reader.ReadInt(),
         SceneName = reader.ReadString()
     });
 }
Exemple #3
0
        public static int[] ReadMoveAction(this NetworkReader reader)
        {
            var moveActions = new int[reader.ReadInt()];

            for (var i = 0; i < moveActions.Length; i++)
            {
                moveActions[i] = reader.ReadInt();
            }

            return(moveActions);
        }
Exemple #4
0
        public static UpdateTileMessage.NetMessage Deserialize(this NetworkReader reader)
        {
            var message = new UpdateTileMessage.NetMessage();

            message.Changes         = new List <UpdateTileMessage.DelayedData>();
            message.MatrixSyncNetID = reader.ReadUInt();
            while (true)
            {
                var Continue = reader.ReadBool();
                if (Continue == false)
                {
                    break;
                }

                var WorkingOn = new UpdateTileMessage.DelayedData
                {
                    Position        = reader.ReadVector3Int(),
                    TileType        = (TileType)reader.ReadInt(),
                    layerType       = (LayerType)reader.ReadInt(),
                    TileName        = reader.ReadString(),
                    MatrixSyncNetID = message.MatrixSyncNetID,
                    TransformMatrix = Matrix4x4.identity,
                    Colour          = Color.white
                };



                while (true)
                {
                    byte Operation = reader.ReadByte();

                    if (Operation == (byte)EnumOperation.NoMoreData)
                    {
                        break;
                    }

                    if (Operation == (byte)EnumOperation.Colour)
                    {
                        WorkingOn.Colour = reader.ReadColor();
                    }

                    if (Operation == (byte)EnumOperation.Matrix4x4)
                    {
                        WorkingOn.TransformMatrix = reader.ReadMatrix4x4();
                    }
                }
                message.Changes.Add(WorkingOn);
            }

            return(message);
        }
Exemple #5
0
 public static Data Readdata(this NetworkReader reader)
 {
     return(new Data
     {
         Var1 = reader.ReadInt()
     });
 }
        public virtual void TransportReceive(ArraySegment <byte> data)
        {
            // unpack message
            NetworkReader reader = new NetworkReader(data);

            if (GetActiveInsight().UnpackMessage(reader, out int msgType))
            {
                Debug.Log("ConnectionRecv " + this + " msgType:" + msgType + " content:" + BitConverter.ToString(data.Array, data.Offset, data.Count));
#if MIRROR_39_0_OR_NEWER
                int callbackId = reader.ReadInt();
#else
                int callbackId = reader.ReadInt32();
#endif
                // try to invoke the handler for that message
                InsightNetworkMessageDelegate msgDelegate;
                if (m_MessageHandlers.TryGetValue(msgType, out msgDelegate))
                {
                    // create message here instead of caching it. so we can add it to queue more easily.
                    InsightNetworkMessage msg = new InsightNetworkMessage(this, callbackId);
                    msg.msgType = msgType;
                    msg.reader  = reader;

                    msgDelegate(msg);
                    lastMessageTime = Time.time;
                }
            }

            else
            {
                //NOTE: this throws away the rest of the buffer. Need moar error codes
                Debug.LogError("Unknown message ID " + msgType + " connId:" + connectionId);
            }
        }
Exemple #7
0
        void HandleData(int connectionId, ArraySegment <byte> data, int i)
        {
            NetworkReader reader = new NetworkReader(data);

#if MIRROR_39_0_OR_NEWER
            short msgType    = reader.ReadShort();
            int   callbackId = reader.ReadInt();
#else
            short msgType    = reader.ReadInt16();
            int   callbackId = reader.ReadInt32();
#endif
            InsightNetworkConnection insightNetworkConnection;
            if (!connections.TryGetValue(connectionId, out insightNetworkConnection))
            {
                Debug.LogError("HandleData: Unknown connectionId: " + connectionId, this);
                return;
            }

            if (callbacks.ContainsKey(callbackId))
            {
                InsightNetworkMessage msg = new InsightNetworkMessage(insightNetworkConnection, callbackId)
                {
                    msgType = msgType, reader = reader
                };
                callbacks[callbackId].callback.Invoke(msg);
                callbacks.Remove(callbackId);

                CheckForFinishedCallback(callbackId);
            }
            else
            {
                insightNetworkConnection.TransportReceive(data);
            }
        }
Exemple #8
0
        public static T[] ReadArray <T>(this NetworkReader reader)
        {
            int length = reader.ReadInt();

            //  we write -1 for null
            if (length < 0)
            {
                return(null);
            }

            // todo throw an exception for other negative values (we never write them, likely to be attacker)

            // this assumes that a reader for T reads at least 1 bytes
            // we can't know the exact size of T because it could have a user created reader
            // NOTE: don't add to length as it could overflow if value is int.max
            if (length > reader.Length - reader.Position)
            {
                throw new EndOfStreamException($"Received array that is too large: {length}");
            }

            T[] result = new T[length];
            for (int i = 0; i < length; i++)
            {
                result[i] = reader.Read <T>();
            }
            return(result);
        }
Exemple #9
0
        protected void HandleBytes(ArraySegment <byte> data, int i)
        {
            InsightNetworkMessageDelegate msgDelegate;
            NetworkReader reader = new NetworkReader(data);

            if (UnpackMessage(reader, out int msgType))
            {
#if MIRROR_39_0_OR_NEWER
                int callbackId = reader.ReadInt();
#else
                int callbackId = reader.ReadInt32();
#endif
                InsightNetworkMessage msg = new InsightNetworkMessage(insightNetworkConnection, callbackId)
                {
                    msgType = msgType,
                    reader  = reader
                };

                if (callbacks.ContainsKey(callbackId))
                {
                    callbacks[callbackId].callback.Invoke(msg);
                    callbacks.Remove(callbackId);
                }
                else if (messageHandlers.TryGetValue(msgType, out msgDelegate))
                {
                    msgDelegate(msg);
                }
            }
            else
            {
                //NOTE: this throws away the rest of the buffer. Need moar error codes
                Debug.LogError("Unknown message ID " + msgType);// + " connId:" + connectionId);
            }
        }
Exemple #10
0
 public override void Deserialize(NetworkReader reader)
 {
     base.Deserialize(reader);
     _id            = reader.ReadString();
     _revealOrder   = reader.ReadInt();
     _read          = reader.ReadBool();
     _newlyRevealed = reader.ReadBool();
 }
        public static WeaponProjectile OnDeserialize(NetworkReader reader)
        {
            string           weaponId = reader.ReadString();
            WeaponProjectile weapon   = WeaponsResourceManager.GetWeapon(weaponId) as WeaponProjectile;

            weapon.currentProjectileCount = reader.ReadInt();
            weapon.isReloading            = reader.ReadBool();
            return(weapon);
        }
        public override void OnDeserialize(NetworkReader reader, bool initialState)
        {
            base.OnDeserialize(reader, initialState);

            value     = reader.ReadInt();
            direction = reader.ReadVector3();

            OnDeserializeCalled?.Invoke();
        }
Exemple #13
0
        public static IData ReadData(this NetworkReader reader)
        {
            int id = reader.ReadInt();
            // do something with id

            SomeData someData = new SomeData();

            // read extra stuff depending on id here

            return(someData);
        }
        public static DataBase ReadData(this NetworkReader reader)
        {
            int id = reader.ReadInt();

            int      someField = reader.ReadInt();
            DataBase data      = null;

            if (data.id == 1)
            {
                SomeData someData = new SomeData()
                {
                    someField = someField
                };
                // read extra stuff depending on id here

                someData.anotherField = reader.ReadFloat();

                data = someData;
            }
            return(data);
        }
Exemple #15
0
 private static void unpackData(byte[] data)
 {
     using (var Stream = new MemoryStream(data))
     {
         NetworkReader r     = new NetworkReader(Stream);
         int           count = r.ReadInt();
         for (int i = 0; i < count; i++)
         {
             string key   = r.ReadUTF32();
             byte[] value = r.ReadBytes32();
             _CurrentData[key] = Convert(value);
         }
     }
 }
Exemple #16
0
        public static List <T> ReadList <T>(this NetworkReader reader)
        {
            int length = reader.ReadInt();

            if (length < 0)
            {
                return(null);
            }
            List <T> result = new List <T>(length);

            for (int i = 0; i < length; i++)
            {
                result.Add(reader.Read <T>());
            }
            return(result);
        }
 public override void Read(NetworkReader R)
 {
     Port = R.ReadInt();
 }
 public DefaultHudUpdateMessage(NetworkReader reader)
 {
     WeaponId       = reader.ReadString();
     CurrentBullets = reader.ReadInt();
     IsReloading    = reader.ReadBool();
 }
 public object Read(NetworkReader reader)
 {
     return((int)reader.ReadInt(32));
 }
 public override void OnDeserialize(NetworkReader reader, bool initialState)
 {
     value = reader.ReadInt();
 }
Exemple #21
0
        public static SpriteUpdateMessage.NetMessage Deserialize(this NetworkReader reader)
        {
            var message = new SpriteUpdateMessage.NetMessage();

            SpriteUpdateMessage.SpriteUpdateEntry UnprocessedData = null;
            while (true)
            {
                UnprocessedData = null;
                bool ProcessSection = true;
                uint NetID          = reader.ReadUInt();
                if (NetID == 0)
                {
                    break;
                }

                if (NetworkIdentity.spawned.ContainsKey(NetID) == false || NetworkIdentity.spawned[NetID] == null)
                {
                    ProcessSection = false;
                }

                string Name = reader.ReadString();
                if (ProcessSection == false ||
                    NetworkIdentity.spawned.ContainsKey(NetID) == false ||
                    SpriteHandlerManager.PresentSprites.ContainsKey(NetworkIdentity.spawned[NetID]) == false ||
                    SpriteHandlerManager.PresentSprites[NetworkIdentity.spawned[NetID]].ContainsKey(Name) == false)
                {
                    ProcessSection = false;
                }

                if (ProcessSection == false)
                {
                    UnprocessedData      = new SpriteUpdateMessage.SpriteUpdateEntry();
                    UnprocessedData.name = Name;
                    UnprocessedData.id   = NetID;
                }

                SpriteHandler SP = null;
                if (ProcessSection)
                {
                    SP = SpriteHandlerManager.PresentSprites[NetworkIdentity.spawned[NetID]][Name];
                }

                while (true)
                {
                    byte Operation = reader.ReadByte();

                    if (Operation == 255)
                    {
                        if (ProcessSection == false)
                        {
                            SpriteUpdateMessage.UnprocessedData.Add(UnprocessedData);
                        }

                        break;
                    }

                    if (Operation == 1)
                    {
                        int SpriteID = reader.ReadInt();
                        if (ProcessSection)
                        {
                            try
                            {
                                SP.SetSpriteSO(SpriteCatalogue.ResistantCatalogue[SpriteID], networked: false);
                            }
                            catch (Exception e)
                            {
                                Logger.Log(e.StackTrace);
                            }
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.PresentSpriteSet);
                            UnprocessedData.arg.Add(SpriteID);
                        }
                    }


                    if (Operation == 2)
                    {
                        int Variant = reader.ReadInt();
                        if (ProcessSection)
                        {
                            SP.ChangeSpriteVariant(Variant, networked: false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.VariantIndex);
                            UnprocessedData.arg.Add(Variant);
                        }
                    }

                    if (Operation == 3)
                    {
                        int Sprite = reader.ReadInt();
                        if (ProcessSection)
                        {
                            SP.ChangeSprite(Sprite, false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.CataloguePage);
                            UnprocessedData.arg.Add(Sprite);
                        }
                    }

                    if (Operation == 4)
                    {
                        int SpriteAnimate = reader.ReadInt();
                        if (ProcessSection)
                        {
                            SP.AnimateOnce(SpriteAnimate, false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.AnimateOnce);
                            UnprocessedData.arg.Add(SpriteAnimate);
                        }
                    }

                    if (Operation == 5)
                    {
                        if (ProcessSection)
                        {
                            SP.PushTexture(false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.PushTexture);
                        }
                    }

                    if (Operation == 6)
                    {
                        if (ProcessSection)
                        {
                            SP.Empty(false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.Empty);
                        }
                    }


                    if (Operation == 7)
                    {
                        if (ProcessSection)
                        {
                            SP.PushClear(false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.PushClear);
                        }
                    }

                    if (Operation == 8)
                    {
                        if (ProcessSection)
                        {
                            SP.ClearPalette(false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.ClearPallet);
                        }
                    }


                    if (Operation == 9)
                    {
                        Color TheColour = reader.ReadColor();
                        if (ProcessSection)
                        {
                            if (SP)
                            {
                                //TODO: remove this check - registering arrives after the sprite update, all clients will disconnect after a runtime
                                //removing and readding a bodypart through surgery would cause it, since the network identity already exists unlike the creation of a new human
                                SP.SetColor(TheColour, false);
                            }
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.SetColour);
                            UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(TheColour.r * 255)));
                            UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(TheColour.g * 255)));
                            UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(TheColour.b * 255)));
                            UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(TheColour.a * 255)));
                        }
                    }

                    if (Operation == 10)
                    {
                        int          paletteCount = reader.ReadByte();
                        List <Color> Colours      = new List <Color>();
                        for (int i = 0; i < paletteCount; i++)
                        {
                            Colours.Add(reader.ReadColor());
                        }

                        if (ProcessSection)
                        {
                            SP.SetPaletteOfCurrentSprite(Colours, false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.Pallet);
                            UnprocessedData.arg.Add(Convert.ToChar(paletteCount));
                            foreach (var color in Colours)
                            {
                                UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(color.r * 255)));
                                UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(color.g * 255)));
                                UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(color.b * 255)));
                                UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(color.a * 255)));
                            }
                        }
                    }
                }
            }

            return(message);
        }
Exemple #22
0
 public void Deserialize(NetworkReader reader)
 {
     IntValue    = reader.ReadInt();
     StringValue = reader.ReadString();
     DoubleValue = reader.ReadDouble();
 }
Exemple #23
0
 protected override void Deserialize(NetworkReader reader)
 {
     base.Deserialize(reader);
     _sectorId = reader.ReadInt();
 }
        public static RequestInteractMessage.NetMessage Deserialize(this NetworkReader reader)
        {
            var message = new RequestInteractMessage.NetMessage();

            var componentID = reader.ReadUShort();

            if (componentID == RequestInteractMessage.UNKNOWN_COMPONENT_TYPE_ID)
            {
                //client didn't know which to trigger, leave ComponentType null
                message.ComponentType = null;
            }
            else
            {
                //client requested a specific component.
                message.ComponentType = RequestInteractMessage.componentIDToComponentType[componentID];
            }

            message.InteractionType = RequestInteractMessage.interactionIDToInteractionType[reader.ReadByte()];
            if (componentID != RequestInteractMessage.UNKNOWN_COMPONENT_TYPE_ID)
            {
                // client specified exact component
                message.ProcessorObject = reader.ReadUInt();
            }
            else
            {
                // client requested server to check the interaction
                message.ProcessorObject = NetId.Invalid;
            }
            message.Intent = (Intent)reader.ReadByte();

            if (message.InteractionType == typeof(PositionalHandApply))
            {
                message.TargetObject   = reader.ReadUInt();
                message.TargetVector   = reader.ReadVector2();
                message.TargetBodyPart = (BodyPartType)reader.ReadUInt();
                message.IsAltUsed      = reader.ReadBool();
            }
            else if (message.InteractionType == typeof(HandApply))
            {
                message.TargetObject   = reader.ReadUInt();
                message.TargetBodyPart = (BodyPartType)reader.ReadUInt();
                message.IsAltUsed      = reader.ReadBool();
            }
            else if (message.InteractionType == typeof(AimApply))
            {
                message.TargetVector     = reader.ReadVector2();
                message.MouseButtonState = reader.ReadBool() ? MouseButtonState.PRESS : MouseButtonState.HOLD;
                message.TargetBodyPart   = (BodyPartType)reader.ReadUInt();
            }
            else if (message.InteractionType == typeof(MouseDrop))
            {
                message.TargetObject = reader.ReadUInt();
                message.UsedObject   = reader.ReadUInt();
            }
            else if (message.InteractionType == typeof(InventoryApply))
            {
                message.StorageIndexOnGameObject = reader.ReadUInt();
                message.UsedObject = reader.ReadUInt();
                message.Storage    = reader.ReadUInt();
                message.SlotIndex  = reader.ReadInt();
                message.NamedSlot  = (NamedSlot)reader.ReadInt();
                message.IsAltUsed  = reader.ReadBool();
            }
            else if (message.InteractionType == typeof(TileApply))
            {
                message.TargetVector = reader.ReadVector2();
            }
            else if (message.InteractionType == typeof(TileMouseDrop))
            {
                message.UsedObject   = reader.ReadUInt();
                message.TargetVector = reader.ReadVector2();
            }
            else if (message.InteractionType == typeof(ConnectionApply))
            {
                message.TargetObject     = reader.ReadUInt();
                message.TargetVector     = reader.ReadVector2();
                message.connectionPointA = (Connection)reader.ReadByte();
                message.connectionPointB = (Connection)reader.ReadByte();
            }
            else if (message.InteractionType == typeof(ContextMenuApply))
            {
                message.TargetObject    = reader.ReadUInt();
                message.RequestedOption = reader.ReadString();
            }
            else if (message.InteractionType == typeof(AiActivate))
            {
                message.TargetObject = reader.ReadUInt();
                message.ClickTypes   = (AiActivate.ClickTypes)reader.ReadByte();
            }

            return(message);
        }
Exemple #25
0
 public static EnumReadWriteTests.MyCustomEnum ReadMyCustomEnum(this NetworkReader networkReader)
 {
     return((EnumReadWriteTests.MyCustomEnum)networkReader.ReadInt());
 }
Exemple #26
0
 public static SomeDataWithWriter ReadSomeData(this NetworkReader reader)
 {
     return(new SomeDataWithWriter {
         usefulNumber = reader.ReadInt()
     });
 }
Exemple #27
0
 public static MockQuest WriteQuest(this NetworkReader reader)
 {
     return(new MockQuest(reader.ReadInt()));
 }
 public static MyType ReadMyType2(this NetworkReader reader)
 {
     return(new MyType {
         number = reader.ReadInt()
     });
 }
Exemple #29
0
 static IMyInterface DeserializeItem(this NetworkReader reader)
 {
     return(new MyUser {
         someNumber = reader.ReadInt()
     });
 }