Optimize serverlist + socket binding fixes
This commit is contained in:
parent
2a4c06ad5e
commit
b866f4caa1
2
deps/protobuf
vendored
2
deps/protobuf
vendored
@ -1 +1 @@
|
||||
Subproject commit 3ee2e20539294c0baff879d5c5164540c8749a2b
|
||||
Subproject commit e35e24800fb8d694bdeea5fd63dc7d1b14d68723
|
@ -267,8 +267,8 @@ namespace Components
|
||||
Utils::Hook::Set<DWORD>(0x4AEF08, 0x1FFFC);
|
||||
Utils::Hook::Set<DWORD>(0x4AEFA3, 0x1FFFC);
|
||||
|
||||
// increase max port binding attempts from 10 to 255
|
||||
Utils::Hook::Set<BYTE>(0x4FD48A, 0xFF);
|
||||
// increase max port binding attempts from 10 to 100
|
||||
Utils::Hook::Set<BYTE>(0x4FD48A, 100);
|
||||
|
||||
// Parse port as short in Net_AddrToString
|
||||
Utils::Hook::Set<char*>(0x4698E3, "%u.%u.%u.%u:%hu");
|
||||
|
@ -171,19 +171,16 @@ namespace Components
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<Network::Address> Node::GetDediList()
|
||||
void Node::SyncNodeList()
|
||||
{
|
||||
std::vector<Network::Address> 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));
|
||||
|
@ -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<Network::Address> GetDediList();
|
||||
|
||||
private:
|
||||
enum EntryState
|
||||
|
@ -136,6 +136,32 @@ namespace Components
|
||||
}
|
||||
}
|
||||
|
||||
void ServerList::UpdateVisibleList()
|
||||
{
|
||||
auto list = ServerList::GetList();
|
||||
if (!list) return;
|
||||
|
||||
std::vector<ServerList::ServerInfo> 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", [] ()
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user