| 101 | |
| 102 | |
| 103 | bool cRCONPacketizer::ReceiveResponse(void) |
| 104 | { |
| 105 | // Receive the response: |
| 106 | cByteBuffer Buffer(64 KiB); |
| 107 | while (true) |
| 108 | { |
| 109 | char buf[1024]; |
| 110 | int NumReceived = m_Socket.Receive(buf, sizeof(buf), 0); |
| 111 | if (NumReceived == 0) |
| 112 | { |
| 113 | fprintf(stderr, "The remote end closed the connection. Aborting."); |
| 114 | return false; |
| 115 | } |
| 116 | if (NumReceived < 0) |
| 117 | { |
| 118 | fprintf(stderr, "Network error while receiving response: %d, %d (%s). Aborting.", |
| 119 | NumReceived, cSocket::GetLastError(), cSocket::GetLastErrorString().c_str() |
| 120 | ); |
| 121 | return false; |
| 122 | } |
| 123 | Buffer.Write(buf, NumReceived); |
| 124 | Buffer.ResetRead(); |
| 125 | |
| 126 | // Check if the buffer contains the full packet: |
| 127 | if (!Buffer.CanReadBytes(14)) |
| 128 | { |
| 129 | // 14 is the minimum packet size for RCON |
| 130 | continue; |
| 131 | } |
| 132 | int PacketSize; |
| 133 | VERIFY(Buffer.ReadLEInt(PacketSize)); |
| 134 | if (!Buffer.CanReadBytes(PacketSize)) |
| 135 | { |
| 136 | // The packet is not complete yet |
| 137 | continue; |
| 138 | } |
| 139 | |
| 140 | // Parse the packet |
| 141 | return ParsePacket(Buffer, PacketSize); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | |
| 146 | |