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

Function gets2c

source/src/client.cpp:520–580  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

518}
519
520void gets2c() // get updates from the server
521{
522 ENetEvent event;
523 if(!clienthost || (!curpeer && !connpeer)) return;
524 if(connpeer && totalmillis/3000 > connmillis/3000)
525 {
526 conoutf("attempting to connect...");
527 connmillis = totalmillis;
528 ++connattempts;
529 if(connattempts > 3)
530 {
531 conoutf("\f3could not connect to server");
532 abortconnect();
533 return;
534 }
535 }
536 while(clienthost!=NULL && enet_host_service(clienthost, &event, 0)>0)
537 switch(event.type)
538 {
539 case ENET_EVENT_TYPE_CONNECT:
540 disconnect(1);
541 curpeer = connpeer;
542 connpeer = NULL;
543 connected = 1;
544 conoutf("connected to server");
545 exechook(HOOK_SP_MP, "onConnect", "%d", -1);
546 throttle();
547 if(editmode) toggleedit(true);
548 break;
549
550 case ENET_EVENT_TYPE_RECEIVE:
551 {
552 extern packetqueue pktlogger;
553 pktlogger.queue(event.packet);
554
555 if(discmillis) conoutf("attempting to disconnect...");
556 else servertoclient(event.channelID, event.packet->data, (int)event.packet->dataLength);
557 // destroyed in logger
558 //enet_packet_destroy(event.packet);
559 break;
560 }
561
562 case ENET_EVENT_TYPE_DISCONNECT:
563 {
564 if(event.peer==connpeer)
565 {
566 conoutf("\f3could not connect to server");
567 abortconnect();
568 }
569 else
570 {
571 if(!discmillis || event.data) conoutf("\f3server network error, disconnecting (%s) ...", disc_reason(event.data));
572 disconnect();
573 }
574 return;
575 }
576
577 default:

Callers 1

updateworldFunction · 0.85

Calls 10

abortconnectFunction · 0.85
enet_host_serviceFunction · 0.85
disconnectFunction · 0.85
exechookFunction · 0.85
throttleFunction · 0.85
toggleeditFunction · 0.85
servertoclientFunction · 0.85
disc_reasonFunction · 0.85
queueMethod · 0.80
conoutfFunction · 0.70

Tested by

no test coverage detected