private string sendCommand(string command, bool isMultipacketResponse) { RconSrcPacket senPacket = new RconSrcPacket() { Body = command, Id = (int)PacketId.ExecCmd, Type = (int)PacketType.Exec }; List <byte[]> recvData = socket.GetMultiPacketResponse(RconUtil.GetBytes(senPacket)); StringBuilder str = new StringBuilder(); try { for (int i = 0; i < recvData.Count; i++) { //consecutive rcon command replies start with an empty packet if (BitConverter.ToInt32(recvData[i], 4) == (int)PacketId.Empty) { continue; } if (recvData[i].Length - BitConverter.ToInt32(recvData[i], 0) == 4) { str.Append(RconUtil.ProcessPacket(recvData[i]).Body); } else { str.Append(RconUtil.ProcessPacket(recvData[i]).Body + Util.BytesToString(recvData[++i].Take(recvData[i].Length - 2).ToArray())); } } } catch (Exception e) { e.Data.Add("ReceivedData", recvData.SelectMany(x => x).ToArray()); throw; } return(str.ToString()); }
internal static Rcon Authorize(ConnectionInfo conInfo, string msg) { return(new QueryMasterBase().Invoke <Rcon>(() => { RconSource obj = new RconSource(conInfo); obj.socket = new TcpQuery(conInfo); byte[] recvData = new byte[50]; RconSrcPacket packet = new RconSrcPacket() { Body = msg, Id = (int)PacketId.ExecCmd, Type = (int)PacketType.Auth }; recvData = obj.socket.GetResponse(RconUtil.GetBytes(packet)); int header; try { header = BitConverter.ToInt32(recvData, 4); } catch (Exception e) { e.Data.Add("ReceivedData", recvData == null ? new byte[1] : recvData); throw; } if (header != -1) { return obj; } return obj; }, conInfo.Retries + 1, null, conInfo.ThrowExceptions)); }