diff options
| -rw-r--r-- | src/CRSMConfig.hpp | 3 | ||||
| -rw-r--r-- | src/ClientInfo.hpp | 11 | ||||
| -rw-r--r-- | src/ClientInterface.hpp | 10 | ||||
| -rw-r--r-- | src/CrServerManager.pro | 4 | ||||
| -rw-r--r-- | src/GreetingSetting.hpp | 100 | ||||
| -rw-r--r-- | src/crsm.cpp | 64 | ||||
| -rw-r--r-- | src/crsm.hpp | 1 |
7 files changed, 181 insertions, 12 deletions
diff --git a/src/CRSMConfig.hpp b/src/CRSMConfig.hpp index 3b43b6c..ceba46b 100644 --- a/src/CRSMConfig.hpp +++ b/src/CRSMConfig.hpp @@ -1,6 +1,7 @@ #pragma once #include "ConfigBase.hpp" +#include "GreetingSetting.hpp" class CRSMConfig : public ConfigBase { public: @@ -13,6 +14,7 @@ public: String PacksFile = "CrServerManager.packs"; Map(String, String) CommandAlias; List(String) CommandSuffixes; + List(GreetingSetting) Greeting = {GreetingSetting::clonk(), GreetingSetting::irc()}; } CRSM; struct { @@ -104,6 +106,7 @@ public: ConfigVal(CRSM.PacksFile), ConfigVal(CRSM.CommandAlias), ConfigVal(CRSM.CommandSuffixes), + ConfigVal(CRSM.Greeting), diff --git a/src/ClientInfo.hpp b/src/ClientInfo.hpp index eb39b82..5ab1160 100644 --- a/src/ClientInfo.hpp +++ b/src/ClientInfo.hpp @@ -6,16 +6,7 @@ #include <QTcpSocket> #include <CRSMConfig.hpp> - -enum ClientInterface { - Auto = 0, - Clonk = 1, - IRC = 1 << 1, - Management = 1 << 2, - First = Auto, - Last = Management -}; - +#include "ClientInterface.hpp" class ManagementConnection { public: diff --git a/src/ClientInterface.hpp b/src/ClientInterface.hpp new file mode 100644 index 0000000..e9f8879 --- /dev/null +++ b/src/ClientInterface.hpp @@ -0,0 +1,10 @@ +#pragma once + +enum ClientInterface { + Auto = 0, + Clonk = 1, + IRC = 1 << 1, + Management = 1 << 2, + First = Auto, + Last = Management +}; diff --git a/src/CrServerManager.pro b/src/CrServerManager.pro index 57d5f3b..cca74e8 100644 --- a/src/CrServerManager.pro +++ b/src/CrServerManager.pro @@ -36,7 +36,9 @@ HEADERS += \ Util.hpp \ CRSMStats.hpp \ CRSMPackCompatibility.hpp \ - CRSMLogging.hpp + CRSMLogging.hpp \ + GreetingSetting.hpp \ + ClientInterface.hpp equals(QT_ARCH, "x86_64"):linux-*: DEFINES += Q_OS_LINUX64 QMAKE_CXXFLAGS *= -std=c++11 -Wall -Wextra -Werror -Wunused diff --git a/src/GreetingSetting.hpp b/src/GreetingSetting.hpp new file mode 100644 index 0000000..d3d6617 --- /dev/null +++ b/src/GreetingSetting.hpp @@ -0,0 +1,100 @@ +#pragma once + +#include <QString> + +#include "ClientInterface.hpp" + +class GreetingSetting { +public: + ClientInterface interface; + QString target = ""; + bool negative = false; + + GreetingSetting() { } + inline bool operator==(const GreetingSetting& other) + { + return other.interface == interface && other.negative == negative && other.target == target; + } + inline bool operator!=(const GreetingSetting& other) + { + return !operator==(other); + } + + inline GreetingSetting& invert() + { + negative = !negative; + return *this; + } + + static GreetingSetting clonk() + { + GreetingSetting ret; + ret.interface = Clonk; + return ret; + } + + static GreetingSetting irc(QString target = "") + { + GreetingSetting ret; + ret.interface = IRC; + ret.target = target; + return ret; + } +}; + +template <> +class ConfigValue<GreetingSetting> : ConfigValueBase { + GreetingSetting& conf; +public: + ConfigValue(GreetingSetting& conf) : conf(conf) { } + + void setValue(const QString& value) + { + QString val = value; + bool negative = (value.at(0) == '!'); + if(negative) + { + val.remove(0, 1); + } + + const QStringList& parts = Util::splitEscaped(val, ':'); + if(parts.first() == "Clonk" && parts.length() == 1) + { + conf.interface = Clonk; + conf.target.clear(); + } + else if(parts.first() == "IRC" && parts.length() <= 2) + { + conf.interface = IRC; + if(parts.length() == 2) + { + conf.target = parts.at(1); + } + else + { + conf.target.clear(); + } + } + else + { + throw ConfigException("Can not parse corrupt GreetingSetting"); + } + + conf.negative = negative; + } + + QString value() + { + QString ret; + if(conf.negative) + { + ret = "!"; + } + QStringList parts = {(conf.interface == Clonk ? "Clonk" : "IRC")}; + if(!conf.target.isEmpty()) + { + parts.append(conf.target); + } + return ret + Util::joinEscape(parts, ':'); + } +}; diff --git a/src/crsm.cpp b/src/crsm.cpp index 5a7f0e4..894c9bb 100644 --- a/src/crsm.cpp +++ b/src/crsm.cpp @@ -477,7 +477,12 @@ void CRSM::ircMessageReceived(IrcMessage *message) { IrcJoinMessage* joinMessage = (IrcJoinMessage*) message; QString joinChannel = joinMessage->channel(); - sendIrcMessage("Hallo, " + message->nick() + "!", joinChannel, false, false); + + if(greetAllowed(ClientInfo::ircClient(joinMessage->nick(), joinMessage->channel()))) + { + sendIrcMessage("Hallo, " + message->nick() + "!", joinChannel, false, false); + } + if(joinChannel == Config.IRC.IngameChannel && Session.IRC.UseIngameChat) { writeToServer("[IRC] " + message->nick() + " hat den Channel betreten." + "\n"); @@ -548,8 +553,17 @@ void CRSM::ircConnected() void CRSM::greet(QString pcName) { if(!Session.Clonk.Clients.contains(pcName)) + { return; + } + const ClientInfo &info = Session.Clonk.Clients.value(pcName); + + if(!greetAllowed(info)) + { + return; + } + writeToServer(QString("Hallo, " + info.nick + "!\n")); if(Session.Clonk.LeaveAdmins.contains(info)) { @@ -1930,6 +1944,54 @@ void CRSM::sendIrcMessage(const QString& message, const QString& target, bool ac } } +bool CRSM::greetAllowed(const ClientInfo &client) +{ + if(client.interface == Clonk && Config.CRSM.Greeting.contains(GreetingSetting::clonk()) && !Config.CRSM.Greeting.contains(GreetingSetting::clonk().invert())) + { + return true; + } + else if(client.interface == IRC) + { + int nickSetting = -1; + int chanSetting = -1; + int ircSetting = -1; + foreach(const GreetingSetting& setting, Config.CRSM.Greeting) + { + if(setting.interface == IRC) + { + if(setting.target == client.nick) + { + nickSetting = !setting.negative; + } + else if(setting.target == client.target) + { + chanSetting = !setting.negative; + } + else if(setting.target.isEmpty()) + { + ircSetting = !setting.negative; + } + } + } + + if(nickSetting != -1) + { + return nickSetting != 0; + } + + if(chanSetting != -1) + { + return chanSetting != 0; + } + + if(ircSetting != -1) + { + return ircSetting != 0; + } + } + return false; +} + CMD_FUNCTION_IMPL(help) bool longHelp = (args == "long"); if(args.isEmpty() || longHelp) diff --git a/src/crsm.hpp b/src/crsm.hpp index 0e352f5..03e634d 100644 --- a/src/crsm.hpp +++ b/src/crsm.hpp @@ -294,6 +294,7 @@ private: void substituteCommandAlias(QString& command); QString clientModName(const ClientInfo& client); void sendIrcMessage(const QString& message, const QString& target, bool action, bool notice); + bool greetAllowed(const ClientInfo& client); CMD_FUNCTION(help); CMD_FUNCTION(passToClonk); |
