From 4e3af265dad57a27af4051cb574fb90539d287d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 16 Aug 2015 02:17:50 +0200 Subject: [PATCH] GH-1164 make sure the censor filter never contains empty keys --- logic/minecraft/LegacyInstance.cpp | 16 +------------ logic/minecraft/MinecraftInstance.cpp | 33 +++++++++++++++++++++++++++ logic/minecraft/MinecraftInstance.h | 3 +++ logic/minecraft/OneSixInstance.cpp | 16 +------------ 4 files changed, 38 insertions(+), 30 deletions(-) diff --git a/logic/minecraft/LegacyInstance.cpp b/logic/minecraft/LegacyInstance.cpp index ed0b1001..782135eb 100644 --- a/logic/minecraft/LegacyInstance.cpp +++ b/logic/minecraft/LegacyInstance.cpp @@ -170,21 +170,7 @@ std::shared_ptr LegacyInstance::createLaunchTask(AuthSessionPtr sess } if (session) { - QMap filter; - if (session->session != "-") - filter[session->session] = tr(""); - filter[session->access_token] = tr(""); - filter[session->client_token] = tr(""); - filter[session->uuid] = tr(""); - filter[session->player_name] = tr(""); - - auto i = session->u.properties.begin(); - while (i != session->u.properties.end()) - { - filter[i.value()] = "<" + i.key().toUpper() + ">"; - ++i; - } - process->setCensorFilter(filter); + process->setCensorFilter(createCensorFilterFromSession(session)); } return process; } diff --git a/logic/minecraft/MinecraftInstance.cpp b/logic/minecraft/MinecraftInstance.cpp index 13e696b9..d576ef4f 100644 --- a/logic/minecraft/MinecraftInstance.cpp +++ b/logic/minecraft/MinecraftInstance.cpp @@ -204,6 +204,39 @@ QProcessEnvironment MinecraftInstance::createEnvironment() return env; } +QMap MinecraftInstance::createCensorFilterFromSession(AuthSessionPtr session) +{ + if(!session) + { + return QMap(); + } + auto & sessionRef = *session.get(); + QMap filter; + auto addToFilter = [&filter](QString key, QString value) + { + if(key.trimmed().size()) + { + filter[key] = value; + } + }; + if (sessionRef.session != "-") + { + addToFilter(sessionRef.session, tr("")); + } + addToFilter(sessionRef.access_token, tr("")); + addToFilter(sessionRef.client_token, tr("")); + addToFilter(sessionRef.uuid, tr("")); + addToFilter(sessionRef.player_name, tr("")); + + auto i = sessionRef.u.properties.begin(); + while (i != sessionRef.u.properties.end()) + { + addToFilter(i.value(), "<" + i.key().toUpper() + ">"); + ++i; + } + return filter; +} + MessageLevel::Enum MinecraftInstance::guessLevel(const QString &line, MessageLevel::Enum level) { QRegularExpression re("\\[(?[0-9:]+)\\] \\[[^/]+/(?[^\\]]+)\\]"); diff --git a/logic/minecraft/MinecraftInstance.h b/logic/minecraft/MinecraftInstance.h index 7ed659a7..14a0f097 100644 --- a/logic/minecraft/MinecraftInstance.h +++ b/logic/minecraft/MinecraftInstance.h @@ -43,6 +43,9 @@ public: /// guess log level from a line of minecraft log virtual MessageLevel::Enum guessLevel(const QString &line, MessageLevel::Enum level); + +protected: + QMap createCensorFilterFromSession(AuthSessionPtr session); }; typedef std::shared_ptr MinecraftInstancePtr; diff --git a/logic/minecraft/OneSixInstance.cpp b/logic/minecraft/OneSixInstance.cpp index 3b2ff750..9a7ef99b 100644 --- a/logic/minecraft/OneSixInstance.cpp +++ b/logic/minecraft/OneSixInstance.cpp @@ -277,21 +277,7 @@ std::shared_ptr OneSixInstance::createLaunchTask(AuthSessionPtr sess } if (session) { - QMap filter; - if (session->session != "-") - filter[session->session] = tr(""); - filter[session->access_token] = tr(""); - filter[session->client_token] = tr(""); - filter[session->uuid] = tr(""); - filter[session->player_name] = tr(""); - - auto i = session->u.properties.begin(); - while (i != session->u.properties.end()) - { - filter[i.value()] = "<" + i.key().toUpper() + ">"; - ++i; - } - process->setCensorFilter(filter); + process->setCensorFilter(createCensorFilterFromSession(session)); } return process; }