MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / MultiPollForLevelInfo

Function MultiPollForLevelInfo

Descent3/multi_connect.cpp:598–657  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

596// Client only
597
598int MultiPollForLevelInfo() {
599 float start_time, ask_time, initial_start_time;
600 int connected = 0;
601 uint8_t data[MAX_RECEIVE_SIZE];
602 network_address from_addr;
603
604 ShowProgressScreen(TXT_MLTWAITSERVER);
605
606 NetPlayers[Player_num].sequence = NETSEQ_WAITING_FOR_LEVEL;
607 Got_level_info = 0;
608 Got_heartbeat = false;
609
610 MultiSendReadyForLevel();
611
612 start_time = timer_GetTime();
613 ask_time = timer_GetTime();
614 initial_start_time = timer_GetTime();
615
616 // Go through this waiting period until the server times out or we get level info
617 while ((timer_GetTime() - start_time < LEVEL_POLL_TIME) && !Got_level_info &&
618 (timer_GetTime() - initial_start_time < (LEVEL_POLL_TIME * 5))) {
619 if (timer_GetTime() - ask_time > 5.0) {
620 ask_time = timer_GetTime();
621 MultiSendReadyForLevel();
622 }
623
624 int size;
625 while ((size = nw_ReceiveReliable(NetPlayers[Player_num].reliable_socket, data, MAX_RECEIVE_SIZE)) > 0) {
626 MultiProcessBigData(data, size, &Netgame.server_address);
627 }
628
629 while ((size = nw_Receive(data, &from_addr)) > 0) {
630 if (data[0] == MP_HEARTBEAT) {
631 mprintf(0, "Got a heart beat from the server.\n");
632 Got_heartbeat = true;
633 }
634 }
635
636 if (Got_heartbeat) {
637 // Reset timer because we got a heartbeat
638 start_time = timer_GetTime();
639 Got_heartbeat = false;
640 }
641 }
642
643 if (!Got_level_info) {
644 ShowProgressScreen(TXT_MLTNOLEVELINFO);
645 MultiLeaveGame();
646 Sleep(2000);
647 } else if (Got_level_info < 0) {
648 ShowProgressScreen(TXT(Join_response_strings[-Got_level_info]));
649 MultiLeaveGame();
650 Sleep(2000);
651 } else {
652 Got_level_info = 0;
653 return 1;
654 }
655

Callers 1

DoLevelIntroFunction · 0.85

Calls 7

ShowProgressScreenFunction · 0.85
MultiSendReadyForLevelFunction · 0.85
nw_ReceiveReliableFunction · 0.85
MultiProcessBigDataFunction · 0.85
nw_ReceiveFunction · 0.85
MultiLeaveGameFunction · 0.85
SleepFunction · 0.50

Tested by

no test coverage detected