diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/CrServerManager.pro | 6 | ||||
| -rw-r--r-- | src/IrcIngameChat.cpp | 38 | ||||
| -rw-r--r-- | src/IrcIngameChat.hpp | 18 | ||||
| -rw-r--r-- | src/crsm.cpp | 37 | ||||
| -rw-r--r-- | src/crsm.hpp | 7 |
5 files changed, 84 insertions, 22 deletions
diff --git a/src/CrServerManager.pro b/src/CrServerManager.pro index fbfd003..b5a3459 100644 --- a/src/CrServerManager.pro +++ b/src/CrServerManager.pro @@ -28,7 +28,8 @@ SOURCES += main.cpp \ ClonkInterface.cpp \ PatchedClonkParser.cpp \ CRSMSession.cpp \ - PatchedClonkControl.cpp + PatchedClonkControl.cpp \ + IrcIngameChat.cpp HEADERS += \ CmdFunctionRef.hpp \ @@ -46,7 +47,8 @@ HEADERS += \ ClonkInterface.hpp \ PatchedClonkParser.hpp \ CRSMSession.hpp \ - PatchedClonkControl.hpp + PatchedClonkControl.hpp \ + IrcIngameChat.hpp equals(QT_ARCH, "x86_64"):linux-*: DEFINES += Q_OS_LINUX64 QMAKE_CXXFLAGS *= -std=c++11 -Wall -Wextra -Werror -Wunused diff --git a/src/IrcIngameChat.cpp b/src/IrcIngameChat.cpp new file mode 100644 index 0000000..30e2411 --- /dev/null +++ b/src/IrcIngameChat.cpp @@ -0,0 +1,38 @@ +#include "IrcIngameChat.hpp" +#include "crsm.hpp" + +IrcIngameChat::IrcIngameChat(const QString& channel, CRSM& crsm) : channel(channel), crsm(crsm) +{ + +} + +void IrcIngameChat::sendChannelMessage(const QString& message, bool action) +{ + crsm.sendIrcMessage(message, channel, action, false, false); +} + +bool IrcIngameChat::clientConnected(const ClientInfo& client) +{ + sendChannelMessage("[Clonk] " + client.toString() + " verbunden.", false); + return false; +} + +bool IrcIngameChat::clientMessage(ClientInfo& client, const QString& message, ClonkOutputInterface::MessageType type, const QTime& time) +{ + Q_UNUSED(time); + if(type == Action) + { + sendChannelMessage("[Clonk] " + client.nick + " " + message, true); + } + else if(type == Message) + { + sendChannelMessage("[Clonk]<" + client.nick+ "> " + message, false); + } + return false; +} + +bool IrcIngameChat::clientRemoved(const ClientInfo& client, const QString& reason) +{ + sendChannelMessage("[Clonk] " + client.toString() + " entfernt (" + reason + ").", false); + return false; +} diff --git a/src/IrcIngameChat.hpp b/src/IrcIngameChat.hpp new file mode 100644 index 0000000..2ced7e3 --- /dev/null +++ b/src/IrcIngameChat.hpp @@ -0,0 +1,18 @@ +#pragma once +#include "ClonkInterface.hpp" + +class CRSM; + +class IrcIngameChat : public ClonkOutputInterface { + const QString& channel; + CRSM& crsm; + +public: + IrcIngameChat(const QString& channel, CRSM& crsm); + bool clientConnected(const ClientInfo & client) override; + bool clientMessage(ClientInfo & client, const QString & message, ClonkOutputInterface::MessageType type, const QTime & time) override; + bool clientRemoved(const ClientInfo & client, const QString & reason) override; + +private: + void sendChannelMessage(const QString& message, bool action); +}; diff --git a/src/crsm.cpp b/src/crsm.cpp index 6adc72f..aa1ef13 100644 --- a/src/crsm.cpp +++ b/src/crsm.cpp @@ -12,7 +12,7 @@ #define MGMT_BUFFER_FILENAME "CRSM-MGMT-Buffer" CRSM::CRSM(QObject *parent) : - QObject(parent), Session(this), parser(Session) + QObject(parent), Session(this), parser(Session), ingameChat(Config.IRC.IngameChannel, *this) { control.setController(this); parser.addTarget(this); @@ -68,6 +68,7 @@ CRSM::CRSM(QObject *parent) : { watchdog(); } + unRegisterIngameChat(); } QFile sessionFile(Config.CRSM.SessionFile); if(sessionFile.exists()) sessionFile.remove(); @@ -286,14 +287,6 @@ bool CRSM::clientMessage(ClientInfo& client, const QString& message, ClonkOutput } return true; } - else if(Session.IRC.UseIngameChat) - { - sendIrcMessage("[Clonk]<" + client.nick+ "> " + message, Config.IRC.IngameChannel, false, false); - } - } - else if(Session.IRC.UseIngameChat) - { - sendIrcMessage("[Clonk] " + client.nick + " " + message, Config.IRC.IngameChannel, true, false); } } return false; @@ -306,10 +299,6 @@ bool CRSM::clientConnected(const ClientInfo& client) connect(timer, SIGNAL(timeout()), timer, SLOT(deleteLater())); greetMapper.setMapping(timer, client.pcName); timer->start(1000); - if(Session.IRC.UseIngameChat) - { - sendIrcMessage("[Clonk] " + client.toString() + " verbunden.", Config.IRC.IngameChannel, false, false); - } if(Session.CountDown != -1 && Session.CountDown <= Config.Clonk.Server.JoinStopCountDown) { control.abortCountdown(); @@ -319,13 +308,9 @@ bool CRSM::clientConnected(const ClientInfo& client) bool CRSM::clientRemoved(const ClientInfo& client, const QString& reason) { + Q_UNUSED(reason); control.serverMessage(client.nick + " ist ein L34V0R!"); - if(Session.IRC.UseIngameChat) - { - sendIrcMessage("[Clonk] " + client.toString() + " entfernt (" + reason + ").", Config.IRC.IngameChannel, false, false); - } - if(client == Session.Clonk.Admin) { Session.Clonk.LeaveAdmins.insert(client, QDateTime::currentDateTime()); @@ -859,6 +844,7 @@ void CRSM::startScen(const ScenarioSettings &scen, QStringList argList) Session.Scenario = scen; Session.IRC.UseIngameChat = Config.IRC.UseIngameChat; + unRegisterIngameChat(); Session.Clonk.Server.pcName = Config.Auto.Volatile.Clonk.ServerPCName; Session.Clonk.Server.nick = Config.Auto.Volatile.Clonk.ServerNick; @@ -1325,6 +1311,7 @@ QString CRSM::ircActivateIngameChat(bool activated) if(Session.IRC.UseIngameChat != activated) { Session.IRC.UseIngameChat = activated; + unRegisterIngameChat(); ircSetIngameChannelTopic(); return "Ingamechat wurde " + (Session.IRC.UseIngameChat ? QString("") : QString("de")) + "aktiviert."; } @@ -2377,6 +2364,18 @@ void CRSM::watchdog() } } +void CRSM::unRegisterIngameChat() +{ + if(Session.IRC.UseIngameChat) + { + parser.addTarget(&ingameChat); + } + else + { + parser.removeTarget(&ingameChat); + } +} + CMD_FUNCTION_IMPL(help) bool recursive = args.startsWith("recursive ") && client.interface == Management; ClientInterface interface = client.interface; @@ -2896,7 +2895,7 @@ CMD_FUNCTION_IMPL(io) CMD_FUNCTION_IMPL(passToClonkPcName) if(args == Config.Auto.Volatile.Clonk.ServerNick || args == Config.Auto.Volatile.Clonk.ServerPCName) - { + { // FIXME: wrong cmd for passToClonkPcNameGrouped respond(client, Config.CRSM.CommandSigns.first() + cmd + " kann nicht auf den Server angewendet werden!\n"); return Success; } diff --git a/src/crsm.hpp b/src/crsm.hpp index 61f3cca..4e3aa34 100644 --- a/src/crsm.hpp +++ b/src/crsm.hpp @@ -31,6 +31,8 @@ #include "PatchedClonkParser.hpp" #include "PatchedClonkControl.hpp" +#include "IrcIngameChat.hpp" + #define CONFIG_FILE_NAME "CrServerManager.conf" #define SESSION_FILE_NAME "CrServerManager.session" #define CUR_SCEN_FILE_NAME "curscen.txt" @@ -125,6 +127,7 @@ public: bool rawTimed(const QString& line, const QTime& time); bool playerRemoved(const QString &name); + void sendIrcMessage(const QString& message, const QString& target, bool action, bool notice, bool noticeOrDCC = false); signals: private slots: @@ -162,6 +165,8 @@ private: PatchedClonkParser parser; PatchedClonkControl control; + IrcIngameChat ingameChat; + QList<ScenarioSettings> userlist; QList<ScenarioSettings> autolist; QList<ScenarioSettings> nextAutoScens; @@ -229,6 +234,7 @@ private: QStringList listC4Folder(const QString &path); void ircSetIngameChannelTopic(); void setSessionState(CRSMSession::SessionState state); + void unRegisterIngameChat(); 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); @@ -276,7 +282,6 @@ private: void removeCommandSuffixes(QString& command); void substituteCommandAlias(QString& command); QString clientModName(const ClientInfo& client); - void sendIrcMessage(const QString& message, const QString& target, bool action, bool notice, bool noticeOrDCC = false); bool greetAllowed(const ClientInfo& client); void handleIrcMessage(const ClientInfo& client, QString message, const QString& target, bool privateMessage, bool action, bool own = false); |
