From 5033d46d8d0383b7d176fc33b18a280d41ed0d41 Mon Sep 17 00:00:00 2001 From: Markus Mittendrein Date: Sun, 8 Nov 2015 00:45:21 +0100 Subject: Check Channel-Names against CHANTYPES supported by IRC server --- src/crsm.cpp | 25 ++++++++++++++++++------- src/crsm.hpp | 1 + 2 files changed, 19 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/crsm.cpp b/src/crsm.cpp index 174fe71..cef3f83 100644 --- a/src/crsm.cpp +++ b/src/crsm.cpp @@ -457,11 +457,11 @@ void CRSM::ircMessageReceived(IrcMessage *message) { watchMsg += target + ":"; } - watchMsg += message->nick() + "> " + mess; + watchMsg += message->nick() + "> " + mess + "\n"; foreach(const ClientInfo& client, ircModWatchList) { - connection->sendCommand(IrcCommand::createMessage(client.nick, watchMsg)); + respond(client, watchMsg, RespondType::PrivateNotice); } } } @@ -1802,6 +1802,19 @@ QString CRSM::getCommand(const QString &message) return QString(); } +bool CRSM::isChannelName(const QString &name) +{ + if(connection == nullptr || name.length() < 1) + { + return false; + } + else + { + const QStringList& channelTypes = connection->network()->channelTypes(); + return channelTypes.contains(name.at(0)); + } +} + CMD_FUNCTION_IMPL(help) bool longHelp = (args == "long"); if(args.isEmpty() || longHelp) @@ -2356,13 +2369,12 @@ CMD_FUNCTION_IMPL(passToClonkOnOff) CMD_FUNCTION_IMPL(join) QStringList argList = args.split(' '); - static QRegExp chanExp("^#[^\\s]+$"); if(argList.size() < 1 || argList.first().isEmpty()) { respond(client, "Kein Channel angegeben!\n"); return SyntaxFail; } - else if(chanExp.exactMatch(argList.first())) + else if(isChannelName(argList.first())) { QString chan = argList.first(); argList.removeFirst(); @@ -2393,8 +2405,7 @@ CMD_FUNCTION_IMPL(leave) { reason = client.toString(); } - static QRegExp chanExp("^#[^\\s]+$"); - if(chanExp.exactMatch(chan)) + if(isChannelName(chan)) { connection->sendCommand(IrcCommand::createPart(chan, reason)); return Success; @@ -2533,7 +2544,7 @@ CMD_FUNCTION_IMPL(ircSay) QString target = parts.first(); parts.removeFirst(); QString message = parts.join(' '); - if(target.at(0) != '#') + if(!isChannelName(target)) { ircSayQueryFifos[target].append(message); ircCheckUserStatus(client, ClientInfo::ircClient(target), &CRSM::ircSayQuery); diff --git a/src/crsm.hpp b/src/crsm.hpp index 2e38ea0..247848f 100644 --- a/src/crsm.hpp +++ b/src/crsm.hpp @@ -290,6 +290,7 @@ private: void checkActivity(ClientInfo& client); int findWishFromUser(const ClientInfo& client); QString getCommand(const QString& message); + bool isChannelName(const QString& name); CMD_FUNCTION(help); CMD_FUNCTION(passToClonk); -- cgit v1.2.3-54-g00ecf