diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/CRSMConfig.hpp | 2 | ||||
| -rw-r--r-- | src/crsm.cpp | 38 | ||||
| -rw-r--r-- | src/crsm.hpp | 7 |
3 files changed, 32 insertions, 15 deletions
diff --git a/src/CRSMConfig.hpp b/src/CRSMConfig.hpp index 30a5c0c..576447d 100644 --- a/src/CRSMConfig.hpp +++ b/src/CRSMConfig.hpp @@ -11,6 +11,7 @@ public: String StatsFile = "CrServerManager.stats"; String SessionFile = "CrServerManager.session"; String PacksFile = "CrServerManager.packs"; + Map(String, String) CommandAlias; } CRSM; struct { @@ -94,6 +95,7 @@ public: ConfigVal(CRSM.StatsFile), ConfigVal(CRSM.SessionFile), ConfigVal(CRSM.PacksFile), + ConfigVal(CRSM.CommandAlias), diff --git a/src/crsm.cpp b/src/crsm.cpp index cef3f83..021a63b 100644 --- a/src/crsm.cpp +++ b/src/crsm.cpp @@ -1207,24 +1207,35 @@ bool CRSM::cmdExists(const QString &name, ClientInterface interface) return cmds.contains(name) && cmds.value(name).interfaces & interface; } -CmdFunctionRef* CRSM::findCommand(const QString &cmd, ClientInterface interface) +CmdFunctionRef* CRSM::findCommand(const QString &cmd, ClientInterface interface, QString &args) { - return findCommand(cmd.split(QRegularExpression(R"(\s)"), QString::KeepEmptyParts), interface); + return findCommand(cmd.split(QRegularExpression(R"(\s)"), QString::KeepEmptyParts), interface, args); } -CmdFunctionRef* CRSM::findCommand(QStringList&& cmd, ClientInterface interface) +CmdFunctionRef* CRSM::findCommand(QStringList&& cmd, ClientInterface interface, QString &realCmd) { if(cmd.length() > 0) { - const QString& cmdPart = cmd.join(' '); + QString cmdPart = cmd.join(' '); + realCmd = cmdPart; + substituteCommandAlias(cmdPart); if(cmdExists(cmdPart, interface)) { return &cmds[cmdPart]; } else { - cmd.removeLast(); - return findCommand(std::move(cmd), interface); + removeCommandSuffixes(cmdPart); + substituteCommandAlias(cmdPart); + if(cmdExists(cmdPart, interface)) + { + return &cmds[cmdPart]; + } + else + { + cmd.removeLast(); + return findCommand(std::move(cmd), interface, realCmd); + } } } else @@ -1233,13 +1244,14 @@ CmdFunctionRef* CRSM::findCommand(QStringList&& cmd, ClientInterface interface) } } -bool CRSM::cmd(const QString &cmd, const ClientInfo &client) +bool CRSM::cmd(QString cmd, const ClientInfo &client) { CmdFunctionRef* cmdPtr; - if((cmdPtr = findCommand(cmd, client.interface)) != nullptr) + QString realCmd = cmd; + if((cmdPtr = findCommand(cmd, client.interface, realCmd)) != nullptr) { CmdFunctionRef cmdRef = *cmdPtr; - QString args = cmd.mid(cmdRef.name.length()).trimmed(); + QString args = cmd.mid(realCmd.length()).trimmed(); switch(client.interface) { case Clonk: @@ -1843,10 +1855,12 @@ CMD_FUNCTION_IMPL(help) } else { - if(cmdExists(args, client.interface)) + QString realCmdName = args; + substituteCommandAlias(realCmdName); + if(cmdExists(realCmdName, client.interface)) { - const CmdFunctionRef& cmd = cmds.value(args); - respond(client, Config.CRSM.CommandSigns.first() + cmd.name + " " + (!cmd.argList.isEmpty() ? cmd.argList + " " : "") + (!cmd.longDescription.isEmpty() ? "- " + cmd.longDescription : !cmd.shortDescription.isEmpty() ? "- " + cmd.shortDescription : "") + "\n"); + const CmdFunctionRef& cmd = cmds.value(realCmdName); + respond(client, Config.CRSM.CommandSigns.first() + args + " " + (!cmd.argList.isEmpty() ? cmd.argList + " " : "") + (!cmd.longDescription.isEmpty() ? "- " + cmd.longDescription : !cmd.shortDescription.isEmpty() ? "- " + cmd.shortDescription : "") + "\n"); if(cmdGroups.contains(args)) { bool first = true; diff --git a/src/crsm.hpp b/src/crsm.hpp index 247848f..56f2a29 100644 --- a/src/crsm.hpp +++ b/src/crsm.hpp @@ -256,9 +256,9 @@ private: void addCommand(const QString& name, CmdFunction func, int interfaces = Clonk | IRC, UserType userType = User, const QString& shortDescription = "", const QString &argList = "", const QString &longDescription = ""); inline void addCommandGroup(const QString& name, int interfaces = Clonk | IRC, UserType userType = User, const QString& shortDescription = "", const QString &longDescription = "", CmdFunction defaultFunc = &CRSM::groupinfo); bool cmdExists(const QString& name, ClientInterface interface); - CmdFunctionRef* findCommand(const QString& cmd, ClientInterface interface); - CmdFunctionRef* findCommand(QStringList &&cmd, ClientInterface interface); - bool cmd(const QString& cmd, const ClientInfo& client); + CmdFunctionRef* findCommand(const QString& cmd, ClientInterface interface, QString& args); + CmdFunctionRef* findCommand(QStringList &&cmd, ClientInterface interface, QString& args); + bool cmd(const QString &cmd, const ClientInfo& client); void rightsFailMessage(const ClientInfo& info, UserType minUserType); UserType clientUserType(const ClientInfo& client); @@ -291,6 +291,7 @@ private: int findWishFromUser(const ClientInfo& client); QString getCommand(const QString& message); bool isChannelName(const QString& name); + void substituteCommandAlias(QString& command); CMD_FUNCTION(help); CMD_FUNCTION(passToClonk); |
