Ejemplo n.º 1
0
 private bool LegalPacketID(PacketID _id, PacketIDType _packetIDType)
 {
     if (_packetIDType == PacketIDType.SHORT && _id.short_ID == -1)
     {
         Debug.LogError($"Packet with string ID ({_id.string_ID}) has short ID of -1 despite NetworkManager.packetIDType being set to PacketIDType.SHORT!");
         return(false);
     }
     else if (_packetIDType == PacketIDType.STRING && _id.string_ID == "")
     {
         Debug.LogError($"Packet with short ID ({_id.short_ID}) has string ID of null despite NetworkManager.packetIDType being set to PacketIDType.STRING!");
         return(false);
     }
     return(true);
 }
Ejemplo n.º 2
0
 private bool IsSameAs(PacketID id)
 {
     if (id.string_ID == "" || this.string_ID == "")
     {
         return(id.short_ID == this.short_ID);
     }
     else if (id.short_ID == -1 || this.short_ID == -1)
     {
         return(id.string_ID == this.string_ID);
     }
     else
     {
         return(id.short_ID == this.short_ID &&
                id.string_ID == this.string_ID);
     }
 }
Ejemplo 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);
        }
Ejemplo n.º 4
0
 public bool Equals(PacketID other)
 {
     return(IsSameAs(other));
 }
Ejemplo n.º 5
0
 public ServerReceiveAttribute(string string_packetID, short short_packetID, PacketVerification expectedVerification = PacketVerification.NONE)
 {
     PacketID             = new PacketID(string_packetID, short_packetID);
     ExpectedVerification = expectedVerification;
 }