Reformat server list
This commit is contained in:
parent
5bc79bac59
commit
14b52dbb51
@ -270,7 +270,7 @@ namespace Components
|
|||||||
if ((ui_browserMod == 0 && static_cast<int>(serverInfo->mod.size())) || (ui_browserMod == 1 && serverInfo->mod.empty())) continue;
|
if ((ui_browserMod == 0 && static_cast<int>(serverInfo->mod.size())) || (ui_browserMod == 1 && serverInfo->mod.empty())) continue;
|
||||||
|
|
||||||
// Filter by gametype
|
// Filter by gametype
|
||||||
if (ui_joinGametype > 0 && (ui_joinGametype - 1) < *Game::gameTypeCount && Game::gameTypes[(ui_joinGametype - 1)].gameType != serverInfo->gametype) continue;
|
if (ui_joinGametype > 0 && (ui_joinGametype - 1) < *Game::gameTypeCount && Game::gameTypes[(ui_joinGametype - 1)].gameType != serverInfo->gametype) continue;
|
||||||
|
|
||||||
VisibleList.push_back(i);
|
VisibleList.push_back(i);
|
||||||
}
|
}
|
||||||
@ -548,7 +548,7 @@ namespace Components
|
|||||||
container.target = address;
|
container.target = address;
|
||||||
|
|
||||||
auto alreadyInserted = false;
|
auto alreadyInserted = false;
|
||||||
for (auto &server : RefreshContainer.servers)
|
for (auto& server : RefreshContainer.servers)
|
||||||
{
|
{
|
||||||
if (server.target == container.target)
|
if (server.target == container.target)
|
||||||
{
|
{
|
||||||
@ -750,36 +750,36 @@ namespace Components
|
|||||||
if (!IsServerListOpen()) return;
|
if (!IsServerListOpen()) return;
|
||||||
|
|
||||||
std::ranges::stable_sort(VisibleList, [](const unsigned int& server1, const unsigned int& server2) -> bool
|
std::ranges::stable_sort(VisibleList, [](const unsigned int& server1, const unsigned int& server2) -> bool
|
||||||
{
|
|
||||||
ServerInfo* info1 = nullptr;
|
|
||||||
ServerInfo* info2 = nullptr;
|
|
||||||
|
|
||||||
auto* list = GetList();
|
|
||||||
if (!list) return false;
|
|
||||||
|
|
||||||
if (list->size() > server1) info1 = &(*list)[server1];
|
|
||||||
if (list->size() > server2) info2 = &(*list)[server2];
|
|
||||||
|
|
||||||
if (!info1) return false;
|
|
||||||
if (!info2) return false;
|
|
||||||
|
|
||||||
// Numerical comparisons
|
|
||||||
if (SortKey == static_cast<std::underlying_type_t<Column>>(Column::Ping))
|
|
||||||
{
|
{
|
||||||
return info1->ping < info2->ping;
|
ServerInfo* info1 = nullptr;
|
||||||
}
|
ServerInfo* info2 = nullptr;
|
||||||
|
|
||||||
if (SortKey == static_cast<std::underlying_type_t<Column>>(Column::Players))
|
auto* list = GetList();
|
||||||
{
|
if (!list) return false;
|
||||||
return info1->clients < info2->clients;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto text1 = Utils::String::ToLower(TextRenderer::StripColors(GetServerInfoText(info1, SortKey, true)));
|
if (list->size() > server1) info1 = &(*list)[server1];
|
||||||
auto text2 = Utils::String::ToLower(TextRenderer::StripColors(GetServerInfoText(info2, SortKey, true)));
|
if (list->size() > server2) info2 = &(*list)[server2];
|
||||||
|
|
||||||
// ASCII-based comparison
|
if (!info1) return false;
|
||||||
return text1.compare(text2) < 0;
|
if (!info2) return false;
|
||||||
});
|
|
||||||
|
// Numerical comparisons
|
||||||
|
if (SortKey == static_cast<std::underlying_type_t<Column>>(Column::Ping))
|
||||||
|
{
|
||||||
|
return info1->ping < info2->ping;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SortKey == static_cast<std::underlying_type_t<Column>>(Column::Players))
|
||||||
|
{
|
||||||
|
return info1->clients < info2->clients;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto text1 = Utils::String::ToLower(TextRenderer::StripColors(GetServerInfoText(info1, SortKey, true)));
|
||||||
|
auto text2 = Utils::String::ToLower(TextRenderer::StripColors(GetServerInfoText(info2, SortKey, true)));
|
||||||
|
|
||||||
|
// ASCII-based comparison
|
||||||
|
return text1.compare(text2) < 0;
|
||||||
|
});
|
||||||
|
|
||||||
if (!SortAsc) std::ranges::reverse(VisibleList);
|
if (!SortAsc) std::ranges::reverse(VisibleList);
|
||||||
}
|
}
|
||||||
@ -938,17 +938,17 @@ namespace Components
|
|||||||
VisibleList.clear();
|
VisibleList.clear();
|
||||||
|
|
||||||
Events::OnDvarInit([]
|
Events::OnDvarInit([]
|
||||||
{
|
{
|
||||||
UIServerSelected = Dvar::Register<bool>("ui_serverSelected", false,
|
UIServerSelected = Dvar::Register<bool>("ui_serverSelected", false,
|
||||||
Game::DVAR_NONE, "Whether a server has been selected in the serverlist");
|
Game::DVAR_NONE, "Whether a server has been selected in the serverlist");
|
||||||
UIServerSelectedMap = Dvar::Register<const char*>("ui_serverSelectedMap", "mp_afghan",
|
UIServerSelectedMap = Dvar::Register<const char*>("ui_serverSelectedMap", "mp_afghan",
|
||||||
Game::DVAR_NONE, "Map of the selected server");
|
Game::DVAR_NONE, "Map of the selected server");
|
||||||
|
|
||||||
NETServerQueryLimit = Dvar::Register<int>("net_serverQueryLimit", 1,
|
NETServerQueryLimit = Dvar::Register<int>("net_serverQueryLimit", 1,
|
||||||
1, 10, Dedicated::IsEnabled() ? Game::DVAR_NONE : Game::DVAR_ARCHIVE, "Amount of server queries per frame");
|
1, 10, Dedicated::IsEnabled() ? Game::DVAR_NONE : Game::DVAR_ARCHIVE, "Amount of server queries per frame");
|
||||||
NETServerFrames = Dvar::Register<int>("net_serverFrames", 30,
|
NETServerFrames = Dvar::Register<int>("net_serverFrames", 30,
|
||||||
1, 60, Dedicated::IsEnabled() ? Game::DVAR_NONE : Game::DVAR_ARCHIVE, "Amount of server query frames per second");
|
1, 60, Dedicated::IsEnabled() ? Game::DVAR_NONE : Game::DVAR_ARCHIVE, "Amount of server query frames per second");
|
||||||
});
|
});
|
||||||
|
|
||||||
// Fix ui_netsource dvar
|
// Fix ui_netsource dvar
|
||||||
Utils::Hook::Nop(0x4CDEEC, 5); // Don't reset the netsource when gametypes aren't loaded
|
Utils::Hook::Nop(0x4CDEEC, 5); // Don't reset the netsource when gametypes aren't loaded
|
||||||
@ -956,35 +956,35 @@ namespace Components
|
|||||||
Localization::Set("MPUI_SERVERQUERIED", "Servers: 0\nPlayers: 0 (0)");
|
Localization::Set("MPUI_SERVERQUERIED", "Servers: 0\nPlayers: 0 (0)");
|
||||||
|
|
||||||
Network::OnClientPacket("getServersResponse", [](const Network::Address& address, [[maybe_unused]] const std::string& data)
|
Network::OnClientPacket("getServersResponse", [](const Network::Address& address, [[maybe_unused]] const std::string& data)
|
||||||
{
|
|
||||||
if (RefreshContainer.host != address) return; // Only parse from host we sent to
|
|
||||||
|
|
||||||
RefreshContainer.awatingList = false;
|
|
||||||
|
|
||||||
std::lock_guard _(RefreshContainer.mutex);
|
|
||||||
|
|
||||||
auto offset = 0;
|
|
||||||
const auto count = RefreshContainer.servers.size();
|
|
||||||
MasterEntry* entry;
|
|
||||||
|
|
||||||
// Find first entry
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
entry = reinterpret_cast<MasterEntry*>(const_cast<char*>(data.data()) + offset++);
|
if (RefreshContainer.host != address) return; // Only parse from host we sent to
|
||||||
} while (!entry->HasSeparator() && !entry->IsEndToken());
|
|
||||||
|
|
||||||
for (int i = 0; !entry[i].IsEndToken() && entry[i].HasSeparator(); ++i)
|
RefreshContainer.awatingList = false;
|
||||||
{
|
|
||||||
Network::Address serverAddr = address;
|
|
||||||
serverAddr.setIP(entry[i].ip);
|
|
||||||
serverAddr.setPort(ntohs(entry[i].port));
|
|
||||||
serverAddr.setType(Game::NA_IP);
|
|
||||||
|
|
||||||
InsertRequest(serverAddr);
|
std::lock_guard _(RefreshContainer.mutex);
|
||||||
}
|
|
||||||
|
|
||||||
Logger::Print("Parsed {} servers from master\n", RefreshContainer.servers.size() - count);
|
auto offset = 0;
|
||||||
});
|
const auto count = RefreshContainer.servers.size();
|
||||||
|
MasterEntry* entry;
|
||||||
|
|
||||||
|
// Find first entry
|
||||||
|
do
|
||||||
|
{
|
||||||
|
entry = reinterpret_cast<MasterEntry*>(const_cast<char*>(data.data()) + offset++);
|
||||||
|
} while (!entry->HasSeparator() && !entry->IsEndToken());
|
||||||
|
|
||||||
|
for (int i = 0; !entry[i].IsEndToken() && entry[i].HasSeparator(); ++i)
|
||||||
|
{
|
||||||
|
Network::Address serverAddr = address;
|
||||||
|
serverAddr.setIP(entry[i].ip);
|
||||||
|
serverAddr.setPort(ntohs(entry[i].port));
|
||||||
|
serverAddr.setType(Game::NA_IP);
|
||||||
|
|
||||||
|
InsertRequest(serverAddr);
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger::Print("Parsed {} servers from master\n", RefreshContainer.servers.size() - count);
|
||||||
|
});
|
||||||
|
|
||||||
// Set default masterServerName + port and save it
|
// Set default masterServerName + port and save it
|
||||||
Utils::Hook::Set<const char*>(0x60AD92, "server.alterware.dev");
|
Utils::Hook::Set<const char*>(0x60AD92, "server.alterware.dev");
|
||||||
@ -1001,69 +1001,69 @@ namespace Components
|
|||||||
UIScript::Add("RefreshServers", Refresh);
|
UIScript::Add("RefreshServers", Refresh);
|
||||||
|
|
||||||
UIScript::Add("JoinServer", []([[maybe_unused]] const UIScript::Token& token, [[maybe_unused]] const Game::uiInfo_s* info)
|
UIScript::Add("JoinServer", []([[maybe_unused]] const UIScript::Token& token, [[maybe_unused]] const Game::uiInfo_s* info)
|
||||||
{
|
|
||||||
auto* serverInfo = GetServer(CurrentServer);
|
|
||||||
if (serverInfo)
|
|
||||||
{
|
{
|
||||||
Party::Connect(serverInfo->addr);
|
auto* serverInfo = GetServer(CurrentServer);
|
||||||
}
|
if (serverInfo)
|
||||||
});
|
{
|
||||||
|
Party::Connect(serverInfo->addr);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
UIScript::Add("ServerSort", []([[maybe_unused]] const UIScript::Token& token, [[maybe_unused]] const Game::uiInfo_s* info)
|
UIScript::Add("ServerSort", []([[maybe_unused]] const UIScript::Token& token, [[maybe_unused]] const Game::uiInfo_s* info)
|
||||||
{
|
|
||||||
const auto key = token.get<int>();
|
|
||||||
if (SortKey == key)
|
|
||||||
{
|
{
|
||||||
SortAsc = !SortAsc;
|
const auto key = token.get<int>();
|
||||||
}
|
if (SortKey == key)
|
||||||
else
|
{
|
||||||
{
|
SortAsc = !SortAsc;
|
||||||
SortKey = key;
|
}
|
||||||
SortAsc = true;
|
else
|
||||||
}
|
{
|
||||||
|
SortKey = key;
|
||||||
|
SortAsc = true;
|
||||||
|
}
|
||||||
|
|
||||||
Logger::Print("Sorting server list by token: {}\n", SortKey);
|
Logger::Print("Sorting server list by token: {}\n", SortKey);
|
||||||
SortList();
|
SortList();
|
||||||
});
|
});
|
||||||
|
|
||||||
UIScript::Add("CreateListFavorite", []([[maybe_unused]] const UIScript::Token& token, [[maybe_unused]] const Game::uiInfo_s* info)
|
UIScript::Add("CreateListFavorite", []([[maybe_unused]] const UIScript::Token& token, [[maybe_unused]] const Game::uiInfo_s* info)
|
||||||
{
|
|
||||||
auto* serverInfo = GetCurrentServer();
|
|
||||||
if (info && serverInfo && serverInfo->addr.isValid())
|
|
||||||
{
|
{
|
||||||
StoreFavourite(serverInfo->addr.getString());
|
auto* serverInfo = GetCurrentServer();
|
||||||
}
|
if (info && serverInfo && serverInfo->addr.isValid())
|
||||||
});
|
{
|
||||||
|
StoreFavourite(serverInfo->addr.getString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
UIScript::Add("CreateFavorite", []([[maybe_unused]] const UIScript::Token& token, [[maybe_unused]] const Game::uiInfo_s* info)
|
UIScript::Add("CreateFavorite", []([[maybe_unused]] const UIScript::Token& token, [[maybe_unused]] const Game::uiInfo_s* info)
|
||||||
{
|
|
||||||
const auto value = Dvar::Var("ui_favoriteAddress").get<std::string>();
|
|
||||||
if (!value.empty())
|
|
||||||
{
|
{
|
||||||
StoreFavourite(value);
|
const auto value = Dvar::Var("ui_favoriteAddress").get<std::string>();
|
||||||
}
|
if (!value.empty())
|
||||||
});
|
{
|
||||||
|
StoreFavourite(value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
UIScript::Add("CreateCurrentServerFavorite", []([[maybe_unused]] const UIScript::Token& token, [[maybe_unused]] const Game::uiInfo_s* info)
|
UIScript::Add("CreateCurrentServerFavorite", []([[maybe_unused]] const UIScript::Token& token, [[maybe_unused]] const Game::uiInfo_s* info)
|
||||||
{
|
|
||||||
if (Game::CL_IsCgameInitialized())
|
|
||||||
{
|
{
|
||||||
const auto addressText = Network::Address(*Game::connectedHost).getString();
|
if (Game::CL_IsCgameInitialized())
|
||||||
if (addressText != "0.0.0.0:0"s && addressText != "loopback"s)
|
|
||||||
{
|
{
|
||||||
StoreFavourite(addressText);
|
const auto addressText = Network::Address(*Game::connectedHost).getString();
|
||||||
|
if (addressText != "0.0.0.0:0"s && addressText != "loopback"s)
|
||||||
|
{
|
||||||
|
StoreFavourite(addressText);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
|
|
||||||
UIScript::Add("DeleteFavorite", []([[maybe_unused]] const UIScript::Token& token, [[maybe_unused]] const Game::uiInfo_s* info)
|
UIScript::Add("DeleteFavorite", []([[maybe_unused]] const UIScript::Token& token, [[maybe_unused]] const Game::uiInfo_s* info)
|
||||||
{
|
|
||||||
auto* serverInfo = GetCurrentServer();
|
|
||||||
if (serverInfo)
|
|
||||||
{
|
{
|
||||||
RemoveFavourite(serverInfo->addr.getString());
|
auto* serverInfo = GetCurrentServer();
|
||||||
}
|
if (serverInfo)
|
||||||
});
|
{
|
||||||
|
RemoveFavourite(serverInfo->addr.getString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Add required ownerDraws
|
// Add required ownerDraws
|
||||||
UIScript::AddOwnerDraw(220, UpdateSource);
|
UIScript::AddOwnerDraw(220, UpdateSource);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user