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>(0x4AEF08, 0x1FFFC);
|
||||||
Utils::Hook::Set<DWORD>(0x4AEFA3, 0x1FFFC);
|
Utils::Hook::Set<DWORD>(0x4AEFA3, 0x1FFFC);
|
||||||
|
|
||||||
// increase max port binding attempts from 10 to 255
|
// increase max port binding attempts from 10 to 100
|
||||||
Utils::Hook::Set<BYTE>(0x4FD48A, 0xFF);
|
Utils::Hook::Set<BYTE>(0x4FD48A, 100);
|
||||||
|
|
||||||
// Parse port as short in Net_AddrToString
|
// Parse port as short in Net_AddrToString
|
||||||
Utils::Hook::Set<char*>(0x4698E3, "%u.%u.%u.%u:%hu");
|
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()
|
void Node::FrameHandler()
|
||||||
@ -423,9 +420,7 @@ namespace Components
|
|||||||
|
|
||||||
Network::Handle("nodeListRequest", [] (Network::Address address, std::string data)
|
Network::Handle("nodeListRequest", [] (Network::Address address, std::string data)
|
||||||
{
|
{
|
||||||
// Requesting a list is either possible, by being registered as node
|
// Check if this is a registered node
|
||||||
// Or having a valid client session
|
|
||||||
// Client sessions do expire after some time or when having received a list
|
|
||||||
bool allowed = false;
|
bool allowed = false;
|
||||||
Node::NodeEntry* entry = Node::FindNode(address);
|
Node::NodeEntry* entry = Node::FindNode(address);
|
||||||
if (entry && entry->registered)
|
if (entry && entry->registered)
|
||||||
@ -487,20 +482,26 @@ namespace Components
|
|||||||
|
|
||||||
Network::Handle("sessionRequest", [] (Network::Address address, std::string data)
|
Network::Handle("sessionRequest", [] (Network::Address address, std::string data)
|
||||||
{
|
{
|
||||||
// Return if we already have a session for this address
|
// Search an active session, if we haven't found one, register a template
|
||||||
if (Node::FindSession(address)) return;
|
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());
|
Logger::Print("Client %s is requesting a new session\n", address.GetString());
|
||||||
|
|
||||||
Node::ClientSession session;
|
// Initialize session data
|
||||||
session.address = address;
|
session->challenge = Utils::VA("%X", Utils::Cryptography::Rand::GenerateInt());
|
||||||
session.challenge = Utils::VA("%X", Utils::Cryptography::Rand::GenerateInt());
|
session->lastTime = Game::Com_Milliseconds();
|
||||||
session.lastTime = Game::Com_Milliseconds();
|
session->valid = false;
|
||||||
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)
|
Network::Handle("sessionSynchronize", [] (Network::Address address, std::string data)
|
||||||
@ -572,6 +573,11 @@ namespace Components
|
|||||||
entry->lastTime = Game::Com_Milliseconds();
|
entry->lastTime = Game::Com_Milliseconds();
|
||||||
entry->lastListQuery = 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)
|
for (int i = 0; i < list.address_size(); ++i)
|
||||||
{
|
{
|
||||||
Node::AddNode(list.address(i));
|
Node::AddNode(list.address(i));
|
||||||
|
@ -16,8 +16,8 @@ namespace Components
|
|||||||
const char* GetName() { return "Node"; };
|
const char* GetName() { return "Node"; };
|
||||||
bool UnitTest();
|
bool UnitTest();
|
||||||
|
|
||||||
|
static void SyncNodeList();
|
||||||
static void AddNode(Network::Address address);
|
static void AddNode(Network::Address address);
|
||||||
static std::vector<Network::Address> GetDediList();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum EntryState
|
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()
|
void ServerList::RefreshVisibleList()
|
||||||
{
|
{
|
||||||
Dvar::Var("ui_serverSelected").Set(false);
|
Dvar::Var("ui_serverSelected").Set(false);
|
||||||
@ -146,7 +172,7 @@ namespace Components
|
|||||||
if (!list) return;
|
if (!list) return;
|
||||||
|
|
||||||
// Refresh entirely, if there is no entry in the list
|
// Refresh entirely, if there is no entry in the list
|
||||||
if (!list->size())
|
if (list->empty())
|
||||||
{
|
{
|
||||||
ServerList::Refresh();
|
ServerList::Refresh();
|
||||||
return;
|
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", Utils::VA("IW4 %i full empty", PROTOCOL));
|
||||||
//Network::SendCommand(ServerList::RefreshContainer.Host, "getservers", "0 full empty");
|
//Network::SendCommand(ServerList::RefreshContainer.Host, "getservers", "0 full empty");
|
||||||
#else
|
#else
|
||||||
ServerList::RefreshContainer.Mutex.lock();
|
Node::SyncNodeList();
|
||||||
|
|
||||||
auto dedis = Node::GetDediList();
|
|
||||||
|
|
||||||
for (auto dedi : dedis)
|
|
||||||
{
|
|
||||||
ServerList::InsertRequest(dedi, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
ServerList::RefreshContainer.Mutex.unlock();
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else if (ServerList::IsFavouriteList())
|
else if (ServerList::IsFavouriteList())
|
||||||
@ -393,6 +410,7 @@ namespace Components
|
|||||||
if (*j == k)
|
if (*j == k)
|
||||||
{
|
{
|
||||||
ServerList::VisibleList.erase(j);
|
ServerList::VisibleList.erase(j);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -604,7 +622,7 @@ namespace Components
|
|||||||
|
|
||||||
// Add required UIScripts
|
// Add required UIScripts
|
||||||
UIScript::Add("UpdateFilter", ServerList::RefreshVisibleList);
|
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("RefreshServers", ServerList::Refresh);
|
||||||
UIScript::Add("JoinServer", [] ()
|
UIScript::Add("JoinServer", [] ()
|
||||||
|
@ -27,6 +27,7 @@ namespace Components
|
|||||||
|
|
||||||
static void Refresh();
|
static void Refresh();
|
||||||
static void RefreshVisibleList();
|
static void RefreshVisibleList();
|
||||||
|
static void UpdateVisibleList();
|
||||||
static void InsertRequest(Network::Address address, bool acquireMutex = true);
|
static void InsertRequest(Network::Address address, bool acquireMutex = true);
|
||||||
static void Insert(Network::Address address, Utils::InfoString info);
|
static void Insert(Network::Address address, Utils::InfoString info);
|
||||||
|
|
||||||
|
@ -217,8 +217,7 @@ namespace Game
|
|||||||
char* uiName = &arenas[i].uiName[0];
|
char* uiName = &arenas[i].uiName[0];
|
||||||
if ((uiName[0] == 'M' && uiName[1] == 'P') || (uiName[0] == 'P' && uiName[1] == 'A')) // MPUI/PATCH
|
if ((uiName[0] == 'M' && uiName[1] == 'P') || (uiName[0] == 'P' && uiName[1] == 'A')) // MPUI/PATCH
|
||||||
{
|
{
|
||||||
char* name = LocalizeMapString(uiName);
|
return LocalizeMapString(uiName);
|
||||||
return name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return uiName;
|
return uiName;
|
||||||
@ -239,8 +238,7 @@ namespace Game
|
|||||||
{
|
{
|
||||||
if (!_stricmp(gameTypes[i].gameType, gameType))
|
if (!_stricmp(gameTypes[i].gameType, gameType))
|
||||||
{
|
{
|
||||||
char* name = LocalizeMapString(gameTypes[i].uiName);
|
return LocalizeMapString(gameTypes[i].uiName);
|
||||||
return name;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user