Esempio n. 1
0
        private bool VerifyPacket(Packet _packet, PacketVerification expectedVerification, PacketID packetIDforDebug, int clientIDforDebug)
        {
            PacketVerification verification = (PacketVerification)_packet.ReadByte();

            if (verification != expectedVerification)
            {
                Debug.LogError($"Packet ({packetIDforDebug}, from client: {clientIDforDebug}) verification did not match the expected verification! Discarding...");
                return(false);
            }

            switch (verification)
            {
            case PacketVerification.NONE:
                return(true);

            case PacketVerification.STRINGS:
                string app_id  = _packet.ReadString();
                string version = _packet.ReadString();
                if (app_id != NetworkManager.instance.APPLICATION_ID || version != NetworkManager.instance.VERSION)
                {
                    if (app_id != NetworkManager.instance.APPLICATION_ID)
                    {
                        Debug.Log($"Packet ({packetIDforDebug}) received from client {clientIDforDebug} with invalid APPLICATION_ID! Discarding...");
                        return(false);
                    }
                    if (version == NetworkManager.instance.VERSION)
                    {
                        Debug.Log($"Packet ({packetIDforDebug}) received from client {clientIDforDebug} with invalid VERSION! Discarding...");
                        return(false);
                    }
                }
                return(true);

            case PacketVerification.HASH:
                int app_idHash  = _packet.ReadInt();
                int versionHash = _packet.ReadInt();
                if (app_idHash != NetworkManager.instance.APPLICATION_ID.GetHashCode() || versionHash != NetworkManager.instance.VERSION.GetHashCode())
                {
                    if (app_idHash != NetworkManager.instance.APPLICATION_ID.GetHashCode())
                    {
                        Debug.Log($"Packet ({packetIDforDebug}) received from client {clientIDforDebug} with invalid APPLICATION_ID hash! Discarding...");
                        return(false);
                    }
                    if (versionHash != NetworkManager.instance.VERSION.GetHashCode())
                    {
                        Debug.Log($"Packet ({packetIDforDebug}) received from client {clientIDforDebug} with invalid VERSION hash! Discarding...");
                        return(false);
                    }
                }
                return(true);

            default:
                return(true);
            }
        }
Esempio n. 2
0
        private void PackVerification(PacketVerification verification)
        {
            Write((byte)verification);

            switch (verification)
            {
            case PacketVerification.NONE:
                break;

            case PacketVerification.STRINGS:
                Write(NetworkManager.instance.APPLICATION_ID);
                Write(NetworkManager.instance.VERSION);
                break;

            case PacketVerification.HASH:
                Write(NetworkManager.instance.APPLICATION_ID.GetHashCode());
                Write(NetworkManager.instance.VERSION.GetHashCode());
                break;
            }
        }
Esempio n. 3
0
        /// <summary>Creates a new packet with a given ID. Used for sending.</summary>
        /// <param name="_id">The packet ID.</param>
        public Packet(PacketID _id, PacketVerification verification)
        {
            //if (NetworkManager.GetDefaultPacketIDs().Contains()) // Doesn't work, default packets are made this way too :P

            buffer  = new List <byte>(); // Intitialize buffer
            readPos = 0;                 // Set readPos to 0

            if (!LegalPacketID(_id, NetworkManager.instance.packetIDType))
            {
                throw new InvalidOperationException("Invalid packet ID for set PacketIDType!");
            }

            if (NetworkManager.instance.packetIDType == PacketIDType.SHORT)
            {
                Write(_id.short_ID);                                                             // Write packet id to the buffer
            }
            else
            {
                Write(_id.string_ID);
            }
            PackVerification(verification);
        }
Esempio n. 4
0
 public VerifiedPacketHandler(PacketVerification expectedVerification, Server.PacketHandler packetHandler)
 {
     this.expectedVerification = expectedVerification;
     this.packetHandler        = packetHandler;
 }
Esempio n. 5
0
 public ServerReceiveAttribute(string string_packetID, short short_packetID, PacketVerification expectedVerification = PacketVerification.NONE)
 {
     PacketID             = new PacketID(string_packetID, short_packetID);
     ExpectedVerification = expectedVerification;
 }
Esempio n. 6
0
 public ServerReceiveAttribute(short packetID, PacketVerification expectedVerification = PacketVerification.NONE)
 {
     PacketID             = packetID;
     ExpectedVerification = expectedVerification;
 }
Esempio n. 7
0
 public ClientReceiveAttribute(string packetID, PacketVerification expectedVerification = PacketVerification.NONE)
 {
     PacketID             = packetID;
     ExpectedVerification = expectedVerification;
 }