GH-1164 make sure the censor filter never contains empty keys

This commit is contained in:
Petr Mrázek 2015-08-16 02:17:50 +02:00
parent d7b3887fe1
commit 4e3af265da
4 changed files with 38 additions and 30 deletions

View File

@ -170,21 +170,7 @@ std::shared_ptr<LaunchTask> LegacyInstance::createLaunchTask(AuthSessionPtr sess
} }
if (session) if (session)
{ {
QMap<QString, QString> filter; process->setCensorFilter(createCensorFilterFromSession(session));
if (session->session != "-")
filter[session->session] = tr("<SESSION ID>");
filter[session->access_token] = tr("<ACCESS TOKEN>");
filter[session->client_token] = tr("<CLIENT TOKEN>");
filter[session->uuid] = tr("<PROFILE ID>");
filter[session->player_name] = tr("<PROFILE NAME>");
auto i = session->u.properties.begin();
while (i != session->u.properties.end())
{
filter[i.value()] = "<" + i.key().toUpper() + ">";
++i;
}
process->setCensorFilter(filter);
} }
return process; return process;
} }

View File

@ -204,6 +204,39 @@ QProcessEnvironment MinecraftInstance::createEnvironment()
return env; return env;
} }
QMap<QString, QString> MinecraftInstance::createCensorFilterFromSession(AuthSessionPtr session)
{
if(!session)
{
return QMap<QString, QString>();
}
auto & sessionRef = *session.get();
QMap<QString, QString> filter;
auto addToFilter = [&filter](QString key, QString value)
{
if(key.trimmed().size())
{
filter[key] = value;
}
};
if (sessionRef.session != "-")
{
addToFilter(sessionRef.session, tr("<SESSION ID>"));
}
addToFilter(sessionRef.access_token, tr("<ACCESS TOKEN>"));
addToFilter(sessionRef.client_token, tr("<CLIENT TOKEN>"));
addToFilter(sessionRef.uuid, tr("<PROFILE ID>"));
addToFilter(sessionRef.player_name, tr("<PROFILE NAME>"));
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) MessageLevel::Enum MinecraftInstance::guessLevel(const QString &line, MessageLevel::Enum level)
{ {
QRegularExpression re("\\[(?<timestamp>[0-9:]+)\\] \\[[^/]+/(?<level>[^\\]]+)\\]"); QRegularExpression re("\\[(?<timestamp>[0-9:]+)\\] \\[[^/]+/(?<level>[^\\]]+)\\]");

View File

@ -43,6 +43,9 @@ public:
/// guess log level from a line of minecraft log /// guess log level from a line of minecraft log
virtual MessageLevel::Enum guessLevel(const QString &line, MessageLevel::Enum level); virtual MessageLevel::Enum guessLevel(const QString &line, MessageLevel::Enum level);
protected:
QMap<QString, QString> createCensorFilterFromSession(AuthSessionPtr session);
}; };
typedef std::shared_ptr<MinecraftInstance> MinecraftInstancePtr; typedef std::shared_ptr<MinecraftInstance> MinecraftInstancePtr;

View File

@ -277,21 +277,7 @@ std::shared_ptr<LaunchTask> OneSixInstance::createLaunchTask(AuthSessionPtr sess
} }
if (session) if (session)
{ {
QMap<QString, QString> filter; process->setCensorFilter(createCensorFilterFromSession(session));
if (session->session != "-")
filter[session->session] = tr("<SESSION ID>");
filter[session->access_token] = tr("<ACCESS TOKEN>");
filter[session->client_token] = tr("<CLIENT TOKEN>");
filter[session->uuid] = tr("<PROFILE ID>");
filter[session->player_name] = tr("<PROFILE NAME>");
auto i = session->u.properties.begin();
while (i != session->u.properties.end())
{
filter[i.value()] = "<" + i.key().toUpper() + ">";
++i;
}
process->setCensorFilter(filter);
} }
return process; return process;
} }