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

Method DataReceived

src/RCONServer.cpp:172–209  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

170
171
172void cRCONServer::cConnection::DataReceived(const char * a_Data, size_t a_Size)
173{
174 // Append data to the buffer:
175 m_Buffer.append(a_Data, a_Size);
176
177 // Process the packets in the buffer:
178 while (m_Buffer.size() >= 14)
179 {
180 int Length = IntFromBuffer(m_Buffer.data());
181 if (Length > 1500)
182 {
183 // Too long, drop the connection
184 LOGWARNING("Received an invalid RCON packet length (%d), dropping RCON connection to %s.",
185 Length, m_IPAddress.c_str()
186 );
187 m_RCONServer.m_SocketThreads.RemoveClient(this);
188 m_Socket.CloseSocket();
189 delete this;
190 return;
191 }
192 if (Length > (int)(m_Buffer.size() + 4))
193 {
194 // Incomplete packet yet, wait for more data to come
195 return;
196 }
197
198 int RequestID = IntFromBuffer(m_Buffer.data() + 4);
199 int PacketType = IntFromBuffer(m_Buffer.data() + 8);
200 if (!ProcessPacket(RequestID, PacketType, Length - 10, m_Buffer.data() + 12))
201 {
202 m_RCONServer.m_SocketThreads.RemoveClient(this);
203 m_Socket.CloseSocket();
204 delete this;
205 return;
206 }
207 m_Buffer.erase(0, Length + 4);
208 } // while (m_Buffer.size() >= 14)
209}
210
211
212

Callers

nothing calls this directly

Calls 4

sizeMethod · 0.80
c_strMethod · 0.80
RemoveClientMethod · 0.45
CloseSocketMethod · 0.45

Tested by

no test coverage detected