summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/m_ircv3.cpp40
-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
-rw-r--r--src/modules/m_watch.cpp20
6 files changed, 66 insertions, 42 deletions
diff --git a/src/modules/m_ircv3.cpp b/src/modules/m_ircv3.cpp
index bbf3d7bc4..92e8a0881 100644
--- a/src/modules/m_ircv3.cpp
+++ b/src/modules/m_ircv3.cpp
@@ -18,10 +18,14 @@
#include "inspircd.h"
#include "modules/account.h"
+#include "modules/away.h"
#include "modules/cap.h"
#include "modules/ircv3.h"
-class ModuleIRCv3 : public Module, public AccountEventListener
+class ModuleIRCv3
+ : public Module
+ , public AccountEventListener
+ , public Away::EventListener
{
Cap::Capability cap_accountnotify;
Cap::Capability cap_awaynotify;
@@ -32,9 +36,10 @@ class ModuleIRCv3 : public Module, public AccountEventListener
public:
ModuleIRCv3()
: AccountEventListener(this)
- , cap_accountnotify(this, "account-notify"),
- cap_awaynotify(this, "away-notify"),
- cap_extendedjoin(this, "extended-join")
+ , Away::EventListener(this)
+ , cap_accountnotify(this, "account-notify")
+ , cap_awaynotify(this, "away-notify")
+ , cap_extendedjoin(this, "extended-join")
{
}
@@ -133,19 +138,24 @@ class ModuleIRCv3 : public Module, public AccountEventListener
}
}
- ModResult OnSetAway(User* user, const std::string &awaymsg) CXX11_OVERRIDE
+ void OnUserAway(User* user) CXX11_OVERRIDE
{
- if (cap_awaynotify.IsActive())
- {
- // Going away: n!u@h AWAY :reason
- // Back from away: n!u@h AWAY
- std::string line = ":" + user->GetFullHost() + " AWAY";
- if (!awaymsg.empty())
- line += " :" + awaymsg;
+ if (!cap_awaynotify.IsActive())
+ return;
- IRCv3::WriteNeighborsWithCap(user, line, cap_awaynotify);
- }
- return MOD_RES_PASSTHRU;
+ // Going away: n!u@h AWAY :reason
+ const std::string line = ":" + user->GetFullHost() + " AWAY :" + user->awaymsg;
+ IRCv3::WriteNeighborsWithCap(user, line, cap_awaynotify);
+ }
+
+ void OnUserBack(User* user) CXX11_OVERRIDE
+ {
+ if (!cap_awaynotify.IsActive())
+ return;
+
+ // Back from away: n!u@h AWAY
+ const std::string line = ":" + user->GetFullHost() + " AWAY";
+ IRCv3::WriteNeighborsWithCap(user, line, cap_awaynotify);
}
void OnPostJoin(Membership *memb) CXX11_OVERRIDE
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;
diff --git a/src/modules/m_watch.cpp b/src/modules/m_watch.cpp
index 82cdcb6f8..8b84132b2 100644
--- a/src/modules/m_watch.cpp
+++ b/src/modules/m_watch.cpp
@@ -18,6 +18,7 @@
#include "inspircd.h"
+#include "modules/away.h"
#define INSPIRCD_MONITOR_MANAGER_ONLY
#include "m_monitor.cpp"
@@ -179,7 +180,9 @@ class CommandWatch : public SplitCommand
}
};
-class ModuleWatch : public Module
+class ModuleWatch
+ : public Module
+ , public Away::EventListener
{
IRCv3::Monitor::Manager manager;
CommandWatch cmd;
@@ -211,7 +214,8 @@ class ModuleWatch : public Module
public:
ModuleWatch()
- : manager(this, "watch")
+ : Away::EventListener(this)
+ , manager(this, "watch")
, cmd(this, manager)
{
}
@@ -245,14 +249,14 @@ class ModuleWatch : public Module
Offline(user, user->nick);
}
- ModResult OnSetAway(User* user, const std::string& awaymsg) CXX11_OVERRIDE
+ void OnUserAway(User* user) CXX11_OVERRIDE
{
- if (awaymsg.empty())
- SendAlert(user, user->nick, RPL_NOTAWAY, "is no longer away", ServerInstance->Time());
- else
- SendAlert(user, user->nick, RPL_GONEAWAY, awaymsg.c_str(), user->awaytime);
+ SendAlert(user, user->nick, RPL_GONEAWAY, user->awaymsg.c_str(), user->awaytime);
+ }
- return MOD_RES_PASSTHRU;
+ void OnUserBack(User* user) CXX11_OVERRIDE
+ {
+ SendAlert(user, user->nick, RPL_NOTAWAY, "is no longer away", ServerInstance->Time());
}
void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE