MCPcopy Create free account
hub / github.com/GlobedGD/globed2 / threadGameWorkerLoop

Method threadGameWorkerLoop

src/core/net/NetworkManagerImpl.cpp:691–800  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

689}
690
691Future<> NetworkManagerImpl::threadGameWorkerLoop() {
692 using enum qn::ConnectionState;
693
694 // might happen when exiting, just wait and return (to not busy loop)
695 if (!m_gameConn) {
696 co_await arc::sleep(Duration::fromMillis(100));
697 co_return;
698 }
699
700 auto connState = m_gameConn->state();
701 auto prevState = m_gameWorkerState.prevGameState;
702 m_gameWorkerState.prevGameState = connState;
703
704 // do some logger things if connected / disconnected
705 if (connState == Connected && connState != prevState) {
706 co_await this->threadSetupLogger(false);
707 } else if (connState == Disconnected && connState != prevState) {
708 this->threadFlushLogger(false);
709 }
710
711 auto& cur = m_gameWorkerState.currentReq;
712 auto& lastReq = m_gameWorkerState.lastReq;
713 bool reauth = false;
714
715 if (m_gameMustReauth.exchange(false, ::acq_rel)) {
716 // a state reset happened, meaning we lost our session with the game server and have to reauth and rejoin
717 cur = std::move(lastReq);
718 lastReq.reset();
719 reauth = true;
720 }
721
722 if (cur) {
723 bool sameUrl, gameEstablished;
724 {
725 auto info = this->connInfo();
726 if (!info) {
727 cur.reset();
728 lastReq.reset();
729 co_return;
730 }
731
732 if (reauth) {
733 info->m_gameEstablished = false;
734 }
735
736 sameUrl = info->m_gameServerUrl == cur->url;
737 gameEstablished = info->m_gameEstablished;
738 }
739
740 if (connState == Connected) {
741 if (!sameUrl) {
742 // connected to a different server, disconnect and then connect to the needed one
743 m_gameConn->disconnect();
744 } else if (gameEstablished) {
745 // connected to the same server as requested, simply send a join request
746 this->sendGameJoinRequest(cur->id, cur->platformer, cur->editorCollab);
747 lastReq = std::move(cur);
748 cur.reset();

Callers 1

asyncInitMethod · 0.95

Calls 11

threadSetupLoggerMethod · 0.95
threadFlushLoggerMethod · 0.95
connInfoMethod · 0.95
sendGameJoinRequestMethod · 0.95
sendGameLoginRequestMethod · 0.95
getConnOptsFunction · 0.85
toastErrorFunction · 0.85
stateMethod · 0.80
asU64Method · 0.80
resetMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected