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

Method ProcessPacket

src/RCONServer.cpp:235–280  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

233
234
235bool cRCONServer::cConnection::ProcessPacket(int a_RequestID, int a_PacketType, int a_PayloadLength, const char * a_Payload)
236{
237 switch (a_PacketType)
238 {
239 case RCON_PACKET_LOGIN:
240 {
241 if (strncmp(a_Payload, m_RCONServer.m_Password.c_str(), a_PayloadLength) != 0)
242 {
243 LOGINFO("RCON: Invalid password from client %s, dropping connection.", m_IPAddress.c_str());
244 SendResponse(-1, RCON_PACKET_RESPONSE, 0, NULL);
245 return false;
246 }
247 m_IsAuthenticated = true;
248
249 LOGD("RCON: Client at %s has successfully authenticated", m_IPAddress.c_str());
250
251 // Send OK response:
252 SendResponse(a_RequestID, RCON_PACKET_RESPONSE, 0, NULL);
253 return true;
254 }
255
256 case RCON_PACKET_COMMAND:
257 {
258 if (!m_IsAuthenticated)
259 {
260 char AuthNeeded[] = "You need to authenticate first!";
261 SendResponse(a_RequestID, RCON_PACKET_RESPONSE, sizeof(AuthNeeded), AuthNeeded);
262 return false;
263 }
264
265 AString cmd(a_Payload, a_PayloadLength);
266 LOGD("RCON command from %s: \"%s\"", m_IPAddress.c_str(), cmd.c_str());
267 cRoot::Get()->ExecuteConsoleCommand(cmd, *(new cRCONCommandOutput(*this, a_RequestID)));
268
269 // Send an empty response:
270 SendResponse(a_RequestID, RCON_PACKET_RESPONSE, 0, NULL);
271 return true;
272 }
273 }
274
275 // Unknown packet type, drop the connection:
276 LOGWARNING("RCON: Client at %s has sent an unknown packet type %d, dropping connection.",
277 m_IPAddress.c_str(), a_PacketType
278 );
279 return false;
280}
281
282
283

Callers

nothing calls this directly

Calls 3

LOGINFOFunction · 0.85
c_strMethod · 0.80
ExecuteConsoleCommandMethod · 0.45

Tested by

no test coverage detected