예제 #1
0
 public override void LoadWorldData(TagCompound tag)
 {
     byte[] bytes = tag.GetByteArray("WirelessCoords");
     for (int i = 0; i < bytes.Length; i += 8)
     {
         var transmitter = new Point16(BitConverter.ToInt16(bytes, i), BitConverter.ToInt16(bytes, i + 2));
         var receiver    = new Point16(BitConverter.ToInt16(bytes, i + 4), BitConverter.ToInt16(bytes, i + 6));
         //				Wireless.Log("{0}, {1}", transmitter, receiver);
         if (!WirelessUtils.AlreadyExists(transmitter, receiver))
         {
             Links.Add(transmitter, receiver);
         }
     }
 }
예제 #2
0
        public override void NetReceive(BinaryReader reader)
        {
            int linksCount = reader.ReadInt32();

            Links = new Dictionary <Point16, Point16>(linksCount);
            for (int i = 0; i < linksCount; i++)
            {
                Point16 transmitter = new Point16(reader.ReadInt16(), reader.ReadInt16());
                Point16 receiver    = new Point16(reader.ReadInt16(), reader.ReadInt16());
                if (!WirelessUtils.AlreadyExists(transmitter, receiver))
                {
                    Links.Add(new Point16(reader.ReadInt16(), reader.ReadInt16()), new Point16(reader.ReadInt16(), reader.ReadInt16()));
                }
            }
        }
예제 #3
0
        public override void HandlePacket(BinaryReader reader, int whoAmI)
        {
            var msgType = (MessageType)reader.ReadByte();

            switch (msgType)
            {
            case MessageType.AddLink:

                var transmitter = new Point16(reader.ReadInt16(), reader.ReadInt16());
                var receiver    = new Point16(reader.ReadInt16(), reader.ReadInt16());
                if (!WirelessUtils.AlreadyExists(transmitter, receiver))
                {
                    WirelessSystem.Links[transmitter] = receiver;
                    if (Main.netMode == NetmodeID.Server)                            //Server-side
                    {
                        SyncAddLink(transmitter, receiver, whoAmI);                  //Broadcast the change to other clients
                    }
                }
                break;

            case MessageType.RemoveLink:
                transmitter = new Point16(reader.ReadInt16(), reader.ReadInt16());
                WirelessSystem.Links.Remove(transmitter);

                if (Main.netMode == NetmodeID.Server)
                {
                    SyncRemoveLink(transmitter, whoAmI);
                }
                break;

            case MessageType.TripWire:
                receiver = new Point16(reader.ReadInt16(), reader.ReadInt16());
                ActivateReceiver(receiver);

                if (Main.netMode == NetmodeID.Server)
                {
                    RemoteClient.CheckSection(whoAmI, receiver.ToWorldCoordinates());
                }
                break;
            }
        }