MCPcopy Create free account
hub / github.com/cuberite/cuberite / ParsePacket

Method ParsePacket

Tools/RCONClient/RCONClient.cpp:149–192  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

147
148
149bool cRCONPacketizer::ParsePacket(cByteBuffer & a_Buffer, int a_PacketLength)
150{
151 // Check that the request ID is equal
152 bool IsValid = true;
153 int RequestID = 0;
154 VERIFY(a_Buffer.ReadLEInt(RequestID));
155 if (RequestID != m_RequestID)
156 {
157 if ((RequestID == -1) && (m_RequestID == 0))
158 {
159 fprintf(stderr, "Login failed. Aborting.");
160 IsValid = false;
161 // Continue, so that the payload is printed before the program aborts.
162 }
163 else
164 {
165 fprintf(stderr, "The server returned an invalid request ID, got %d, exp. %d. Aborting.", RequestID, m_RequestID);
166 return false;
167 }
168 }
169
170 // Check the packet type:
171 int PacketType = 0;
172 VERIFY(a_Buffer.ReadLEInt(PacketType));
173 if (PacketType != ptCommand)
174 {
175 fprintf(stderr, "The server returned an unknown packet type: %d. Aborting.", PacketType);
176 IsValid = false;
177 // Continue, so that the payload is printed before the program aborts.
178 }
179
180 AString Payload;
181 VERIFY(a_Buffer.ReadString(Payload, a_PacketLength - 10));
182
183 // Dump the payload to stdout, in a binary mode
184 fwrite(Payload.data(), Payload.size(), 1, stdout);
185
186 if (IsValid)
187 {
188 m_RequestID++;
189 return true;
190 }
191 return false;
192}
193
194
195

Callers

nothing calls this directly

Calls 3

ReadLEIntMethod · 0.80
sizeMethod · 0.80
ReadStringMethod · 0.45

Tested by

no test coverage detected