diff --git a/deps/protobuf b/deps/protobuf index 3ee2e205..e35e2480 160000 --- a/deps/protobuf +++ b/deps/protobuf @@ -1 +1 @@ -Subproject commit 3ee2e20539294c0baff879d5c5164540c8749a2b +Subproject commit e35e24800fb8d694bdeea5fd63dc7d1b14d68723 diff --git a/src/Components/Modules/Network.cpp b/src/Components/Modules/Network.cpp index 36029923..25a55b53 100644 --- a/src/Components/Modules/Network.cpp +++ b/src/Components/Modules/Network.cpp @@ -267,8 +267,8 @@ namespace Components Utils::Hook::Set(0x4AEF08, 0x1FFFC); Utils::Hook::Set(0x4AEFA3, 0x1FFFC); - // increase max port binding attempts from 10 to 255 - Utils::Hook::Set(0x4FD48A, 0xFF); + // increase max port binding attempts from 10 to 100 + Utils::Hook::Set(0x4FD48A, 100); // Parse port as short in Net_AddrToString Utils::Hook::Set(0x4698E3, "%u.%u.%u.%u:%hu"); diff --git a/src/Components/Modules/Node.cpp b/src/Components/Modules/Node.cpp index d4522202..82e3a386 100644 --- a/src/Components/Modules/Node.cpp +++ b/src/Components/Modules/Node.cpp @@ -171,19 +171,16 @@ namespace Components } } - std::vector Node::GetDediList() + void Node::SyncNodeList() { - std::vector dedis; - - for (auto node : Node::Nodes) + for (auto& node : Node::Nodes) { - if (node.state == Node::STATE_VALID && node.registered && node.isDedi) + if (node.state == Node::STATE_VALID && node.registered) { - dedis.push_back(node.address); + node.state = Node::STATE_UNKNOWN; + node.registered = false; } } - - return dedis; } void Node::FrameHandler() @@ -423,9 +420,7 @@ namespace Components Network::Handle("nodeListRequest", [] (Network::Address address, std::string data) { - // Requesting a list is either possible, by being registered as node - // Or having a valid client session - // Client sessions do expire after some time or when having received a list + // Check if this is a registered node bool allowed = false; Node::NodeEntry* entry = Node::FindNode(address); if (entry && entry->registered) @@ -487,20 +482,26 @@ namespace Components Network::Handle("sessionRequest", [] (Network::Address address, std::string data) { - // Return if we already have a session for this address - if (Node::FindSession(address)) return; + // Search an active session, if we haven't found one, register a template + if (!Node::FindSession(address)) + { + Node::ClientSession templateSession; + templateSession.address = address; + Node::Sessions.push_back(templateSession); + } + + // Search our target session (this should not fail!) + Node::ClientSession* session = Node::FindSession(address); + if (!session) return; // Registering template session failed, odd... Logger::Print("Client %s is requesting a new session\n", address.GetString()); - Node::ClientSession session; - session.address = address; - session.challenge = Utils::VA("%X", Utils::Cryptography::Rand::GenerateInt()); - session.lastTime = Game::Com_Milliseconds(); - session.valid = false; + // Initialize session data + session->challenge = Utils::VA("%X", Utils::Cryptography::Rand::GenerateInt()); + session->lastTime = Game::Com_Milliseconds(); + session->valid = false; - Node::Sessions.push_back(session); - - Network::SendCommand(address, "sessionInitialize", session.challenge); + Network::SendCommand(address, "sessionInitialize", session->challenge); }); Network::Handle("sessionSynchronize", [] (Network::Address address, std::string data) @@ -572,6 +573,11 @@ namespace Components entry->lastTime = Game::Com_Milliseconds(); entry->lastListQuery = Game::Com_Milliseconds(); + if (!Dedicated::IsDedicated() && entry->isDedi && ServerList::IsOnlineList()) + { + ServerList::InsertRequest(entry->address, true); + } + for (int i = 0; i < list.address_size(); ++i) { Node::AddNode(list.address(i)); diff --git a/src/Components/Modules/Node.hpp b/src/Components/Modules/Node.hpp index 1791d41e..27614162 100644 --- a/src/Components/Modules/Node.hpp +++ b/src/Components/Modules/Node.hpp @@ -16,8 +16,8 @@ namespace Components const char* GetName() { return "Node"; }; bool UnitTest(); + static void SyncNodeList(); static void AddNode(Network::Address address); - static std::vector GetDediList(); private: enum EntryState diff --git a/src/Components/Modules/ServerList.cpp b/src/Components/Modules/ServerList.cpp index 31b70633..27c634f1 100644 --- a/src/Components/Modules/ServerList.cpp +++ b/src/Components/Modules/ServerList.cpp @@ -136,6 +136,32 @@ namespace Components } } + void ServerList::UpdateVisibleList() + { + auto list = ServerList::GetList(); + if (!list) return; + + std::vector tempList(*list); + + if (tempList.empty()) + { + ServerList::Refresh(); + } + else + { + list->clear(); + + ServerList::RefreshContainer.Mutex.lock(); + + for (auto server : tempList) + { + ServerList::InsertRequest(server.Addr, false); + } + + ServerList::RefreshContainer.Mutex.unlock(); + } + } + void ServerList::RefreshVisibleList() { Dvar::Var("ui_serverSelected").Set(false); @@ -146,7 +172,7 @@ namespace Components if (!list) return; // Refresh entirely, if there is no entry in the list - if (!list->size()) + if (list->empty()) { ServerList::Refresh(); return; @@ -227,16 +253,7 @@ namespace Components Network::SendCommand(ServerList::RefreshContainer.Host, "getservers", Utils::VA("IW4 %i full empty", PROTOCOL)); //Network::SendCommand(ServerList::RefreshContainer.Host, "getservers", "0 full empty"); #else - ServerList::RefreshContainer.Mutex.lock(); - - auto dedis = Node::GetDediList(); - - for (auto dedi : dedis) - { - ServerList::InsertRequest(dedi, false); - } - - ServerList::RefreshContainer.Mutex.unlock(); + Node::SyncNodeList(); #endif } else if (ServerList::IsFavouriteList()) @@ -393,6 +410,7 @@ namespace Components if (*j == k) { ServerList::VisibleList.erase(j); + break; } } @@ -604,7 +622,7 @@ namespace Components // Add required UIScripts UIScript::Add("UpdateFilter", ServerList::RefreshVisibleList); - UIScript::Add("RefreshFilter", ServerList::RefreshVisibleList); // TODO: Re-query the servers + UIScript::Add("RefreshFilter", ServerList::UpdateVisibleList); UIScript::Add("RefreshServers", ServerList::Refresh); UIScript::Add("JoinServer", [] () diff --git a/src/Components/Modules/ServerList.hpp b/src/Components/Modules/ServerList.hpp index d7c06805..66428ece 100644 --- a/src/Components/Modules/ServerList.hpp +++ b/src/Components/Modules/ServerList.hpp @@ -27,6 +27,7 @@ namespace Components static void Refresh(); static void RefreshVisibleList(); + static void UpdateVisibleList(); static void InsertRequest(Network::Address address, bool acquireMutex = true); static void Insert(Network::Address address, Utils::InfoString info); diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index 17a7b767..2c11eb38 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -217,8 +217,7 @@ namespace Game char* uiName = &arenas[i].uiName[0]; if ((uiName[0] == 'M' && uiName[1] == 'P') || (uiName[0] == 'P' && uiName[1] == 'A')) // MPUI/PATCH { - char* name = LocalizeMapString(uiName); - return name; + return LocalizeMapString(uiName); } return uiName; @@ -239,8 +238,7 @@ namespace Game { if (!_stricmp(gameTypes[i].gameType, gameType)) { - char* name = LocalizeMapString(gameTypes[i].uiName); - return name; + return LocalizeMapString(gameTypes[i].uiName); } }