public void sendPacket(Packet packet) { if (client.IsConnectedToHost()) { var data = Packets.Packets.encode(packet); if (GetParent().GetNodeOrNull("GUI") != null) { var gui = (Control)GetParent().GetNodeOrNull("GUI"); gui.Call("recordSendPacket", data.Length); } client.PutData(data); GD.Print("Sent packet ID ", packet.id, " \"", packet.name, "\""); } }
private static void Send(NET_CMD cmd, JSONNode data) { var jData = CreateRequest(cmd, seq, UserId, CurToken, data); var bData = jData.ToString().ToUTF8(); var bufferSize = hdrSize + bData.Length; var buffer = new byte[bufferSize]; uint offset = 0; offset += Utilites.PushIntBE(buffer, bData.Length, offset); offset += Utilites.PushUShortBE(buffer, (ushort)cmd, offset); offset += Utilites.PushUShortBE(buffer, seq, offset); offset += Utilites.PushByteLE(buffer, bData, offset); var status = socket.PutData(buffer); Dbg.Log("send >> status:", status, " data: ", jData); seq++; }