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); }
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); } }
/// <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); }
public bool Equals(PacketID other) { return(IsSameAs(other)); }
public ServerReceiveAttribute(string string_packetID, short short_packetID, PacketVerification expectedVerification = PacketVerification.NONE) { PacketID = new PacketID(string_packetID, short_packetID); ExpectedVerification = expectedVerification; }