MCPcopy Create free account
hub / github.com/deathkiller/jazz2-native / OnClientThread

Method OnClientThread

Sources/Jazz2/Multiplayer/ServerDiscovery.cpp:784–820  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

782 }
783
784 void ServerDiscovery::OnClientThread(void* param)
785 {
786 ServerDiscovery* _this = static_cast<ServerDiscovery*>(param);
787 IServerObserver* observer = _this->_observer;
788
789 NetworkManagerBase::InitializeBackend();
790
791 ENetSocket socket = TryCreateLocalSocket("ff02::1", _this->_localMulticastAddress);
792 _this->_socket = socket;
793
794 while (_this->_observer != nullptr) {
795 if (_this->_lastLocalRequestTime.secondsSince() > 10) {
796 _this->_lastLocalRequestTime = TimeStamp::now();
797 _this->SendLocalDiscoveryRequest(socket, _this->_localMulticastAddress);
798 }
799
800 if (_this->_lastOnlineRequestTime.secondsSince() > 60) {
801 _this->_lastOnlineRequestTime = TimeStamp::now();
802 _this->DownloadPublicServerList(observer);
803 }
804
805 ServerDescription discoveredServer;
806 if (_this->ProcessLocalDiscoveryResponses(socket, discoveredServer, 0)) {
807 observer->OnServerFound(std::move(discoveredServer));
808 } else {
809 // No responses, sleep for a while
810 Thread::Sleep(500);
811 }
812 }
813
814 if (_this->_socket != ENET_SOCKET_NULL) {
815 enet_socket_destroy(_this->_socket);
816 _this->_socket = ENET_SOCKET_NULL;
817 }
818
819 LOGD("[MP] Server discovery thread exited");
820 }
821
822 void ServerDiscovery::OnServerThread(void* param)
823 {

Callers

nothing calls this directly

Calls 6

enet_socket_destroyFunction · 0.85
secondsSinceMethod · 0.80
OnServerFoundMethod · 0.80

Tested by

no test coverage detected