MCPcopy Create free account
hub / github.com/cppla/ServerStatus / HandleMessage

Method HandleMessage

server/src/main.cpp:304–448  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

302}
303
304int CMain::HandleMessage(int ClientNetID, char *pMessage)
305{
306 CClient *pClient = ClientNet(ClientNetID);
307 if(!pClient)
308 return true;
309
310 if(str_comp_num(pMessage, "update", sizeof("update")-1) == 0)
311 {
312 char *pData = str_skip_whitespaces(&pMessage[sizeof("update")-1]);
313
314 // parse json data
315 json_settings JsonSettings;
316 mem_zero(&JsonSettings, sizeof(JsonSettings));
317 char aError[256];
318 json_value *pJsonData = json_parse_ex(&JsonSettings, pData, strlen(pData), aError);
319 if(!pJsonData)
320 {
321 dbg_msg("main", "JSON Error: %s", aError);
322 if(pClient->m_Stats.m_Pong)
323 m_Server.Network()->Send(ClientNetID, "1");
324 return 1;
325 }
326
327 // extract data
328 const json_value &rStart = (*pJsonData);
329 if(rStart["uptime"].type)
330 pClient->m_Stats.m_Uptime = rStart["uptime"].u.integer;
331 if(rStart["load_1"].type)
332 pClient->m_Stats.m_Load_1 = rStart["load_1"].u.dbl;
333 if(rStart["load_5"].type)
334 pClient->m_Stats.m_Load_5 = rStart["load_5"].u.dbl;
335 if(rStart["load_15"].type)
336 pClient->m_Stats.m_Load_15 = rStart["load_15"].u.dbl;
337 if(rStart["ping_10010"].type)
338 pClient->m_Stats.m_ping_10010 = rStart["ping_10010"].u.dbl;
339 if(rStart["ping_189"].type)
340 pClient->m_Stats.m_ping_189 = rStart["ping_189"].u.dbl;
341 if(rStart["ping_10086"].type)
342 pClient->m_Stats.m_ping_10086 = rStart["ping_10086"].u.dbl;
343 if(rStart["time_10010"].type)
344 pClient->m_Stats.m_time_10010 = rStart["time_10010"].u.integer;
345 if(rStart["time_189"].type)
346 pClient->m_Stats.m_time_189 = rStart["time_189"].u.integer;
347 if(rStart["time_10086"].type)
348 pClient->m_Stats.m_time_10086 = rStart["time_10086"].u.integer;
349 if(rStart["tcp"].type)
350 pClient->m_Stats.m_tcpCount = rStart["tcp"].u.integer;
351 if(rStart["udp"].type)
352 pClient->m_Stats.m_udpCount = rStart["udp"].u.integer;
353 if(rStart["process"].type)
354 pClient->m_Stats.m_processCount = rStart["process"].u.integer;
355 if(rStart["thread"].type)
356 pClient->m_Stats.m_threadCount = rStart["thread"].u.integer;
357 if(rStart["network_rx"].type)
358 pClient->m_Stats.m_NetworkRx = rStart["network_rx"].u.integer;
359 if(rStart["network_tx"].type)
360 pClient->m_Stats.m_NetworkTx = rStart["network_tx"].u.integer;
361 if(rStart["network_in"].type)

Callers 1

UpdateMethod · 0.80

Calls 10

str_comp_numFunction · 0.85
str_skip_whitespacesFunction · 0.85
mem_zeroFunction · 0.85
json_parse_exFunction · 0.85
dbg_msgFunction · 0.85
str_copyFunction · 0.85
json_value_freeFunction · 0.85
str_compFunction · 0.85
NetworkMethod · 0.80
SendMethod · 0.45

Tested by

no test coverage detected