diff options
| author | Markus Mittendrein <git@maxmitti.tk> | 2017-05-30 20:25:44 +0200 |
|---|---|---|
| committer | Markus Mittendrein <git@maxmitti.tk> | 2017-05-30 20:26:41 +0200 |
| commit | c20ac02beb8520953d90d0d9114371fe36187ed0 (patch) | |
| tree | 770c8d981ab8b09ff4ea322530e15da1d8cdb7c2 | |
| parent | f6c25c0dce53a751b0664d954552f7c711d54667 (diff) | |
| download | manager-c20ac02beb8520953d90d0d9114371fe36187ed0.tar.gz manager-c20ac02beb8520953d90d0d9114371fe36187ed0.zip | |
Allow ClonkOutputInterface to stop further propagation if the return value of the callback is true
| -rw-r--r-- | src/ClonkInterface.cpp | 34 | ||||
| -rw-r--r-- | src/ClonkInterface.hpp | 28 | ||||
| -rw-r--r-- | src/crsm.cpp | 40 | ||||
| -rw-r--r-- | src/crsm.hpp | 25 |
4 files changed, 72 insertions, 55 deletions
diff --git a/src/ClonkInterface.cpp b/src/ClonkInterface.cpp index 036b931..2642568 100644 --- a/src/ClonkInterface.cpp +++ b/src/ClonkInterface.cpp @@ -3,33 +3,34 @@ ClonkOutputInterface::~ClonkOutputInterface() { } -void ClonkOutputInterface::raw(const QString &msg) { Q_UNUSED(msg); } +bool ClonkOutputInterface::raw(const QString &msg) { Q_UNUSED(msg); return false; } -void ClonkOutputInterface::rawTimed(const QString &msg, const QTime &time) { Q_UNUSED(msg); Q_UNUSED(time); } +bool ClonkOutputInterface::rawTimed(const QString &msg, const QTime &time) { Q_UNUSED(msg); Q_UNUSED(time); return false; } -void ClonkOutputInterface::lobbyCountdown(unsigned int seconds) { Q_UNUSED(seconds); } +bool ClonkOutputInterface::lobbyCountdown(unsigned int seconds) { Q_UNUSED(seconds); return false; } -void ClonkOutputInterface::lobbyCountdownAborted() {} +bool ClonkOutputInterface::lobbyCountdownAborted() { return false; } -void ClonkOutputInterface::playerRemoved(const QString &name) { Q_UNUSED(name); } +bool ClonkOutputInterface::playerRemoved(const QString &name) { Q_UNUSED(name); return false; } -void ClonkOutputInterface::playerJoined(const ClientInfo &client, const QString &name) { Q_UNUSED(client); Q_UNUSED(name); } +bool ClonkOutputInterface::playerJoined(const ClientInfo &client, const QString &name) { Q_UNUSED(client); Q_UNUSED(name); return false; } -void ClonkOutputInterface::watchdog(const QString &id) { Q_UNUSED(id); } +bool ClonkOutputInterface::watchdog(const QString &id) { Q_UNUSED(id); return false; } -void ClonkOutputInterface::clientMessage(ClientInfo &client, const QString &message, ClonkOutputInterface::MessageType type, const QTime &time) { Q_UNUSED(client); Q_UNUSED(message); Q_UNUSED(type); Q_UNUSED(time); } +bool ClonkOutputInterface::clientMessage(ClientInfo &client, const QString &message, ClonkOutputInterface::MessageType type, const QTime &time) { Q_UNUSED(client); Q_UNUSED(message); Q_UNUSED(type); Q_UNUSED(time); return false; } -void ClonkOutputInterface::clientConnected(const ClientInfo &client) { Q_UNUSED(client); } +bool ClonkOutputInterface::clientConnected(const ClientInfo &client) { Q_UNUSED(client); return false; } -void ClonkOutputInterface::clientRemoved(const ClientInfo &client, const QString& reason) { Q_UNUSED(client); Q_UNUSED(reason); } +bool ClonkOutputInterface::clientRemoved(const ClientInfo &client, const QString& reason) { Q_UNUSED(client); Q_UNUSED(reason); return false; } -void ClonkOutputInterface::clientStateChanged(const ClientInfo &client, bool activated) { Q_UNUSED(client); Q_UNUSED(activated); } +bool ClonkOutputInterface::clientStateChanged(const ClientInfo &client, bool activated) { Q_UNUSED(client); Q_UNUSED(activated); return false; } -void ClonkOutputInterface::gameLoading() {} +bool ClonkOutputInterface::gameLoading() { return false; } -void ClonkOutputInterface::gameStarted() {} +bool ClonkOutputInterface::gameStarted() { return false; } -void ClonkOutputInterface::masterserverError(const QString &msg) { Q_UNUSED(msg); } +bool ClonkOutputInterface::masterserverError(const QString& msg) +{ Q_UNUSED(msg); return false; } ClonkControlInterface::~ClonkControlInterface() {} @@ -63,7 +64,10 @@ void ClonkParser::removeTarget(ClonkOutputInterface *target) #define dispatch(x) for(auto target : targets)\ {\ - target->x;\ + if(target->x)\ + {\ + break;\ + }\ } void ClonkParser::raw(const QString &msg) { dispatch(raw(msg)) } diff --git a/src/ClonkInterface.hpp b/src/ClonkInterface.hpp index a6961f3..86f7fc3 100644 --- a/src/ClonkInterface.hpp +++ b/src/ClonkInterface.hpp @@ -36,27 +36,27 @@ public: enum MessageType { Message, Action, Sound }; - virtual void raw(const QString& msg); - virtual void rawTimed(const QString& msg, const QTime& time); + virtual bool raw(const QString& msg); + virtual bool rawTimed(const QString& msg, const QTime& time); - virtual void lobbyCountdown(unsigned int seconds); - virtual void lobbyCountdownAborted(); + virtual bool lobbyCountdown(unsigned int seconds); + virtual bool lobbyCountdownAborted(); - virtual void playerRemoved(const QString& name); - virtual void playerJoined(const ClientInfo& client, const QString& name); + virtual bool playerRemoved(const QString& name); + virtual bool playerJoined(const ClientInfo& client, const QString& name); - virtual void watchdog(const QString& id); + virtual bool watchdog(const QString& id); - virtual void clientMessage(ClientInfo& client, const QString& message, MessageType type, const QTime& time); + virtual bool clientMessage(ClientInfo& client, const QString& message, MessageType type, const QTime& time); - virtual void clientConnected(const ClientInfo& client); - virtual void clientRemoved(const ClientInfo& client, const QString& reason); - virtual void clientStateChanged(const ClientInfo& client, bool activated); + virtual bool clientConnected(const ClientInfo& client); + virtual bool clientRemoved(const ClientInfo& client, const QString& reason); + virtual bool clientStateChanged(const ClientInfo& client, bool activated); - virtual void gameLoading(); - virtual void gameStarted(); + virtual bool gameLoading(); + virtual bool gameStarted(); - virtual void masterserverError(const QString& msg); + virtual bool masterserverError(const QString& msg); }; class ClonkParser { diff --git a/src/crsm.cpp b/src/crsm.cpp index f596edb..6adc72f 100644 --- a/src/crsm.cpp +++ b/src/crsm.cpp @@ -222,26 +222,29 @@ QString CRSM::findClientByName(ClientInfo &info, const QString &name) } } -void CRSM::lobbyCountdown(unsigned int seconds) +bool CRSM::lobbyCountdown(unsigned int seconds) { Session.CountDown = (int)seconds; + return false; } -void CRSM::lobbyCountdownAborted() +bool CRSM::lobbyCountdownAborted() { Session.CountDown = -1; + return false; } -void CRSM::watchdog(const QString& id) +bool CRSM::watchdog(const QString& id) { if(id == watchDogString) { watchDogString.clear(); watchDogTimer.start(Config.Clonk.Server.Watchdog.Interval * 1000); } + return false; } -void CRSM::clientMessage(ClientInfo& client, const QString& message, ClonkOutputInterface::MessageType type, const QTime& time) +bool CRSM::clientMessage(ClientInfo& client, const QString& message, ClonkOutputInterface::MessageType type, const QTime& time) { bool isMeMessage = (type == Action); if(type == Sound) @@ -270,7 +273,7 @@ void CRSM::clientMessage(ClientInfo& client, const QString& message, ClonkOutput } else if(type == Sound) { - return; + return false; } else if(!isMeMessage) { @@ -281,7 +284,7 @@ void CRSM::clientMessage(ClientInfo& client, const QString& message, ClonkOutput { respond(client, "Unbekannter Befehl: \"" + command + "\"!\n"); } - + return true; } else if(Session.IRC.UseIngameChat) { @@ -293,9 +296,10 @@ void CRSM::clientMessage(ClientInfo& client, const QString& message, ClonkOutput sendIrcMessage("[Clonk] " + client.nick + " " + message, Config.IRC.IngameChannel, true, false); } } + return false; } -void CRSM::clientConnected(const ClientInfo& client) +bool CRSM::clientConnected(const ClientInfo& client) { QTimer *timer = new QTimer; connect(timer, SIGNAL(timeout()), &greetMapper, SLOT(map())); @@ -310,9 +314,10 @@ void CRSM::clientConnected(const ClientInfo& client) { control.abortCountdown(); } + return false; } -void CRSM::clientRemoved(const ClientInfo& client, const QString& reason) +bool CRSM::clientRemoved(const ClientInfo& client, const QString& reason) { control.serverMessage(client.nick + " ist ein L34V0R!"); @@ -340,14 +345,16 @@ void CRSM::clientRemoved(const ClientInfo& client, const QString& reason) { control.setCountdown(Config.Clonk.Server.EmptyTimer); } + return false; } -void CRSM::gameLoading() +bool CRSM::gameLoading() { setSessionState(CRSMSession::Loading); + return false; } -void CRSM::gameStarted() +bool CRSM::gameStarted() { Stats.AddScenarioStart(Session.Scenario.wishClient, scenarioFileName(Session.Scenario.name)); if(!Session.League) @@ -356,9 +363,10 @@ void CRSM::gameStarted() } setSessionState(CRSMSession::Running); watchdog(); + return false; } -void CRSM::masterserverError(const QString& msg) +bool CRSM::masterserverError(const QString& msg) { userlist.clear(); if(autoHost && !hostingIsErrorDeactivated) @@ -369,9 +377,10 @@ void CRSM::masterserverError(const QString& msg) autoHost = false; static const QString gameRegisterFailMessage = "Aufgrund eines Problems beim Registrieren des Spiels am Masterserver (%1) wird Hosting temporär (für 5 Minuten) deaktiviert.\n"; announceInfo(gameRegisterFailMessage.arg(msg)); + return false; } -void CRSM::raw(const QString &line) +bool CRSM::raw(const QString &line) { if(Config.IRC.Use) { @@ -382,17 +391,20 @@ void CRSM::raw(const QString &line) } } out(line + "\n"); + return false; } -void CRSM::rawTimed(const QString &line, const QTime &time) +bool CRSM::rawTimed(const QString &line, const QTime &time) { Q_UNUSED(time); Log.clonkLog(line); + return false; } -void CRSM::playerRemoved(const QString& name) +bool CRSM::playerRemoved(const QString& name) { Q_UNUSED(name); + return false; } void CRSM::readServerOutput() diff --git a/src/crsm.hpp b/src/crsm.hpp index abae69a..61f3cca 100644 --- a/src/crsm.hpp +++ b/src/crsm.hpp @@ -112,18 +112,19 @@ public: void start(); bool isOk(); - void lobbyCountdown(unsigned int seconds); - void lobbyCountdownAborted(); - void watchdog(const QString &id); - void clientMessage(ClientInfo &client, const QString &message, ClonkOutputInterface::MessageType type, const QTime& time); - void clientConnected(const ClientInfo &client); - void clientRemoved(const ClientInfo &client, const QString& reason); - void gameLoading(); - void gameStarted(); - void masterserverError(const QString &msg); - void raw(const QString& line); - void rawTimed(const QString& line, const QTime& time); - void playerRemoved(const QString &name); + bool lobbyCountdown(unsigned int seconds); + bool lobbyCountdownAborted(); + bool watchdog(const QString &id); + bool clientMessage(ClientInfo &client, const QString &message, ClonkOutputInterface::MessageType type, const QTime& time); + bool clientConnected(const ClientInfo &client); + bool clientRemoved(const ClientInfo &client, const QString& reason); + bool gameLoading(); + bool gameStarted(); + bool masterserverError(const QString &msg); + bool raw(const QString& line); + bool rawTimed(const QString& line, const QTime& time); + bool playerRemoved(const QString &name); + signals: private slots: |
