From 1ba7b44d4db3d3c32f7349227c364c698c00dc96 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Wed, 15 Feb 2017 14:11:36 +0100 Subject: [PATCH] [ServerList] Ignore patch version for filtering (only major/minor version) --- src/Components/Modules/ServerList.cpp | 22 +++++++++++++++++++++- src/Components/Modules/ServerList.hpp | 2 ++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Components/Modules/ServerList.cpp b/src/Components/Modules/ServerList.cpp index c3a311eb..63594daa 100644 --- a/src/Components/Modules/ServerList.cpp +++ b/src/Components/Modules/ServerList.cpp @@ -504,7 +504,7 @@ namespace Components if (info.get("gamename") == "IW4" && server.matchType #if !defined(DEBUG) && defined(VERSION_FILTER) - && server.shortversion == SHORTVERSION + && ServerList::CompareVersion(server.shortversion, SHORTVERSION) #endif ) { @@ -526,6 +526,26 @@ namespace Components } } + bool ServerList::CompareVersion(std::string version1, std::string version2) + { + std::vector subVersions1 = Utils::String::Explode(version1, '.'); + std::vector subVersions2 = Utils::String::Explode(version2, '.'); + + while (subVersions1.size() >= 3) subVersions1.pop_back(); + while (subVersions2.size() >= 3) subVersions2.pop_back(); + if (subVersions1.size() != subVersions2.size()) return false; + + for(unsigned int i = 0; i < subVersions1.size(); ++i) + { + if(atoi(subVersions1[i].data()) != atoi(subVersions2[i].data())) + { + return false; + } + } + + return true; + } + ServerList::ServerInfo* ServerList::GetCurrentServer() { return ServerList::GetServer(ServerList::CurrentServer); diff --git a/src/Components/Modules/ServerList.hpp b/src/Components/Modules/ServerList.hpp index 128fdd3f..3d5065b6 100644 --- a/src/Components/Modules/ServerList.hpp +++ b/src/Components/Modules/ServerList.hpp @@ -126,6 +126,8 @@ namespace Components static ServerInfo* GetServer(unsigned int index); static std::vector* GetList(); + static bool CompareVersion(std::string version1, std::string version2); + static int SortKey; static bool SortAsc;