/// <summary> /// Sends a packet and retrieves the response /// </summary> /// <param name="packet"></param> public void SendPacket(RconPacket packet) { try { Logger.Log(LogLevel.Verbose, "Sending command: '{0}'", packet.Command); Send(packet.Command); } catch (Exception e) { Logger.Log(running ? LogLevel.Warning : LogLevel.Verbose, "SendPacket failed. ({0})", e.ToString()); return; } lastMessage = null; DateTime start = DateTime.Now; while (lastMessage == null) { if ((DateTime.Now - start).TotalMilliseconds < PacketTimeout) { Thread.Sleep(SLEEP); } else { Logger.Log(running ? LogLevel.Warning : LogLevel.Verbose, "Rcon packet timeout. (running {0})", packet.Command); return; } } packet.HandleResponse(lastMessage); lastMessage = null; }
/// <summary> /// Sends a packet and retrieves the response /// </summary> /// <param name="packet"></param> public void SendPacket(RconPacket packet) { string lastMessageTemp; lock (rxLock) { lastMessage = null; } try { Logger.Log(LogLevel.Verbose, "Sending command: '{0}'", packet.Command); Send(packet.Command); } catch (Exception e) { Logger.Log(running ? LogLevel.Warning : LogLevel.Verbose, "SendPacket failed. ({0})", e.ToString()); return; } DateTime start = DateTime.Now; do { if ((DateTime.Now - start).TotalMilliseconds < PacketTimeout) { Thread.Sleep(SLEEP); } else { Logger.Log(LogLevel.Warning, "Rcon packet timeout. (running {0})", packet.Command); return; } lock (rxLock) { lastMessageTemp = lastMessage; } } while (lastMessageTemp == null); if (lastMessageTemp == STATUS_MESSAGE_SERVER_IS_BUSY) { Logger.Log(LogLevel.Verbose, "Server is busy - dropping rcon packet"); } else { packet.HandleResponse(lastMessageTemp); } lock (rxLock) { lastMessage = null; } }