MCPcopy Create free account
hub / github.com/assaultcube/AC / checkpings

Function checkpings

source/src/serverbrowser.cpp:445–634  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

443#define MAXINFOLINELEN 100 // including color codes
444
445void checkpings()
446{
447 if(pingsock == ENET_SOCKET_NULL) return;
448 enet_uint32 events = ENET_SOCKET_WAIT_RECEIVE;
449 ENetBuffer buf;
450 ENetAddress addr;
451 static uchar ping[MAXTRANS];
452 static char text[MAXTRANS];
453 buf.data = ping;
454 buf.dataLength = sizeof(ping);
455 while(enet_socket_wait(pingsock, &events, 0) >= 0 && events)
456 {
457 int len = enet_socket_receive(pingsock, &addr, &buf, 1);
458 if(len <= 0) return;
459 serverinfo *si = NULL;
460 loopv(servers) if(addr.host == servers[i]->address.host && addr.port == servers[i]->address.port)
461 {
462 si = servers[i];
463 break;
464 }
465 if(!si && searchlan) si = newserver(NULL, addr.host, CUBE_SERVINFO_TO_SERV_PORT(addr.port));
466 if(!si) continue;
467
468 ucharbuf p(ping, len);
469 si->lastpingmillis = totalmillis;
470 int pingtm = pingbuf[(getint(p) - 1) % PINGBUFSIZE];
471 if(pingtm) si->ping = totalmillis - pingtm;
472 int query = getint(p);
473 switch(query)
474 { // cleanup additional query info
475 case EXTPING_SERVERINFO:
476 loopi(2) getint(p);
477 break;
478 }
479 si->protocol = getint(p);
480 if(si->protocol!=PROTOCOL_VERSION) si->ping = 9998;
481 si->mode = getint(p);
482 si->numplayers = getint(p);
483 si->minremain = getint(p);
484 getstring(text, p);
485 filtertext(si->map, behindpath(text), FTXT__MAPNAME);
486 getstring(text, p);
487 filtertext(si->sdesc, text, FTXT__SERVDESC);
488 copystring(si->description, si->sdesc);
489 si->maxclients = getint(p);
490 if(p.remaining())
491 {
492 si->pongflags = getint(p);
493 if(p.remaining() && getint(p) == query)
494 {
495 switch(query)
496 {
497 #define RESETINFOLINES() si->infotexts.setsize(0); \
498 ucharbuf q(si->textdata, sizeof(si->textdata))
499 #define ADDINFOLINE(msg) si->infotexts.add((char *)si->textdata + q.length()); \
500 sendstring(msg, q)
501 case EXTPING_NAMELIST:
502 {

Callers 1

refreshserversFunction · 0.85

Calls 15

newserverFunction · 0.85
getintFunction · 0.85
getstringFunction · 0.85
filtertextFunction · 0.85
behindpathFunction · 0.85
copystringFunction · 0.85
sendstringFunction · 0.85
cutcolorstringFunction · 0.85
concatformatstringFunction · 0.85
mmfullnameFunction · 0.85
setsizeMethod · 0.80
overreadMethod · 0.80

Tested by

no test coverage detected