protected void BindPacket <T>(SendType sendType) where T : Packet, new() { var packet = new T(); #if VOXCAKE_NET_DEBUG if (!PacketExists(packet)) { #endif packet.SetSendType(sendType); var packetType = packet.GetType(); if (packetType.GetInterface(I_BINDABLE_PACKET) != null) { #if VOXCAKE_NET_DEBUG Debug.Log($"Binding to {packetType.Name}"); #endif PacketBinder.BindVariablesToPacket(packet, this); } #if VOXCAKE_NET_DEBUG Debug.Log($"{packetType.Name}.Size = {packet.Size}"); #endif _packetCollection.Add(packet); #if VOXCAKE_NET_DEBUG } else { Debug.LogError("Packet already exist"); } #endif Size += 1; }
public Form1() { InitializeComponent(); _device = Device.GetInstance(); _packetBinder = PacketBinder.GetInstance(listView1); var thread = new Thread(WritePackets); thread.IsBackground = true; thread.Start(); }
/// <summary> /// Use this method to send packets to other clients /// WARNING! Be careful in sending packets with variables, be sure that you pass the right type values /// </summary> public void SendPacket <T>(params object[] packetVariables) where T : Packet { var packet = _protocol.GetPacketByType(typeof(T)); packet.SetPlayer(Client.steamID); if (packetVariables.Length > 0) { PacketBinder.SetVariablesToPacket(packet, packetVariables); } PacketExecutor.ExecutePacket(packet, true); switch (packet.SendType) { case SendType.Unreliable: PacketSetter.SetPacketToCollection(packet, _unreliablePackets); break; case SendType.Reliable: PacketSetter.SetPacketToCollection(packet, _reliablePackets); break; } }