summaryrefslogtreecommitdiff
path: root/src/modules/m_spanningtree
diff options
context:
space:
mode:
authorPeter Powell <petpow@saberuk.com>2018-08-12 14:56:27 +0100
committerPeter Powell <petpow@saberuk.com>2018-08-12 15:01:45 +0100
commitba23c2b115ad3bf2632179d283165c1579332fd8 (patch)
tree992b199acb6e10e75ab18422147de1cf377a65b4 /src/modules/m_spanningtree
parentf8a9b6ba4ae0b4b3c7b2a408332230dd82eb4608 (diff)
Convert AWAY to use cross-module events and clean up slightly.
OnSetAway has been replaced with four events. OnUserPreAway and OnUserPreBack can be used to deny an away state change and/or change the away message of a local user. OnUserAway and OnUserBack allow modules to be notified that a user's away state has changed.
Diffstat (limited to 'src/modules/m_spanningtree')
-rw-r--r--src/modules/m_spanningtree/away.cpp16
-rw-r--r--src/modules/m_spanningtree/commands.h11
-rw-r--r--src/modules/m_spanningtree/main.cpp13
-rw-r--r--src/modules/m_spanningtree/main.h8
4 files changed, 29 insertions, 19 deletions
diff --git a/src/modules/m_spanningtree/away.cpp b/src/modules/m_spanningtree/away.cpp
index e65b3099b..282f52a35 100644
--- a/src/modules/m_spanningtree/away.cpp
+++ b/src/modules/m_spanningtree/away.cpp
@@ -27,19 +27,19 @@ CmdResult CommandAway::HandleRemote(::RemoteUser* u, Params& params)
{
if (!params.empty())
{
- FOREACH_MOD(OnSetAway, (u, params.back()));
-
if (params.size() > 1)
u->awaytime = ConvToInt(params[0]);
else
u->awaytime = ServerInstance->Time();
u->awaymsg = params.back();
+ FOREACH_MOD_CUSTOM(awayevprov, Away::EventListener, OnUserAway, (u));
}
else
{
- FOREACH_MOD(OnSetAway, (u, ""));
+ u->awaytime = 0;
u->awaymsg.clear();
+ FOREACH_MOD_CUSTOM(awayevprov, Away::EventListener, OnUserBack, (u));
}
return CMD_SUCCESS;
}
@@ -47,12 +47,6 @@ CmdResult CommandAway::HandleRemote(::RemoteUser* u, Params& params)
CommandAway::Builder::Builder(User* user)
: CmdBuilder(user, "AWAY")
{
- push_int(user->awaytime).push_last(user->awaymsg);
-}
-
-CommandAway::Builder::Builder(User* user, const std::string& msg)
- : CmdBuilder(user, "AWAY")
-{
- if (!msg.empty())
- push_int(ServerInstance->Time()).push_last(msg);
+ if (user->awaymsg.empty())
+ push_int(user->awaytime).push_last(user->awaymsg);
}
diff --git a/src/modules/m_spanningtree/commands.h b/src/modules/m_spanningtree/commands.h
index b98512578..434528e46 100644
--- a/src/modules/m_spanningtree/commands.h
+++ b/src/modules/m_spanningtree/commands.h
@@ -22,6 +22,7 @@
#include "servercommand.h"
#include "commandbuilder.h"
#include "remoteuser.h"
+#include "modules/away.h"
namespace SpanningTree
{
@@ -241,15 +242,21 @@ class CommandResync : public ServerOnlyServerCommand<CommandResync>
class SpanningTree::CommandAway : public UserOnlyServerCommand<SpanningTree::CommandAway>
{
+ private:
+ Away::EventProvider awayevprov;
+
public:
- CommandAway(Module* Creator) : UserOnlyServerCommand<SpanningTree::CommandAway>(Creator, "AWAY", 0, 2) { }
+ CommandAway(Module* Creator)
+ : UserOnlyServerCommand<SpanningTree::CommandAway>(Creator, "AWAY", 0, 2)
+ , awayevprov(Creator)
+ {
+ }
CmdResult HandleRemote(::RemoteUser* user, Params& parameters);
class Builder : public CmdBuilder
{
public:
Builder(User* user);
- Builder(User* user, const std::string& msg);
};
};
diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp
index c7e55c66c..3c9089115 100644
--- a/src/modules/m_spanningtree/main.cpp
+++ b/src/modules/m_spanningtree/main.cpp
@@ -37,7 +37,8 @@
#include "translate.h"
ModuleSpanningTree::ModuleSpanningTree()
- : Stats::EventListener(this)
+ : Away::EventListener(this)
+ , Stats::EventListener(this)
, rconnect(this)
, rsquit(this)
, map(this)
@@ -718,12 +719,16 @@ void ModuleSpanningTree::OnDelLine(User* user, XLine *x)
params.Broadcast();
}
-ModResult ModuleSpanningTree::OnSetAway(User* user, const std::string &awaymsg)
+void ModuleSpanningTree::OnUserAway(User* user)
{
if (IS_LOCAL(user))
- CommandAway::Builder(user, awaymsg).Broadcast();
+ CommandAway::Builder(user).Broadcast();
+}
- return MOD_RES_PASSTHRU;
+void ModuleSpanningTree::OnUserBack(User* user)
+{
+ if (IS_LOCAL(user))
+ CommandAway::Builder(user).Broadcast();
}
void ModuleSpanningTree::OnMode(User* source, User* u, Channel* c, const Modes::ChangeList& modes, ModeParser::ModeProcessFlag processflags, const std::string& output_mode)
diff --git a/src/modules/m_spanningtree/main.h b/src/modules/m_spanningtree/main.h
index 34b657720..4a65f1c37 100644
--- a/src/modules/m_spanningtree/main.h
+++ b/src/modules/m_spanningtree/main.h
@@ -53,7 +53,10 @@ class Autoconnect;
/** This is the main class for the spanningtree module
*/
-class ModuleSpanningTree : public Module, public Stats::EventListener
+class ModuleSpanningTree
+ : public Module
+ , public Away::EventListener
+ , public Stats::EventListener
{
/** Client to server commands, registered in the core
*/
@@ -164,7 +167,8 @@ class ModuleSpanningTree : public Module, public Stats::EventListener
void OnAddLine(User *u, XLine *x) CXX11_OVERRIDE;
void OnDelLine(User *u, XLine *x) CXX11_OVERRIDE;
ModResult OnStats(Stats::Context& stats) CXX11_OVERRIDE;
- ModResult OnSetAway(User* user, const std::string &awaymsg) CXX11_OVERRIDE;
+ void OnUserAway(User* user) CXX11_OVERRIDE;
+ void OnUserBack(User* user) CXX11_OVERRIDE;
void OnLoadModule(Module* mod) CXX11_OVERRIDE;
void OnUnloadModule(Module* mod) CXX11_OVERRIDE;
ModResult OnAcceptConnection(int newsock, ListenSocket* from, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server) CXX11_OVERRIDE;