summaryrefslogtreecommitdiff
path: root/src/coremods
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/coremods
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/coremods')
-rw-r--r--src/coremods/core_user/cmd_away.cpp41
-rw-r--r--src/coremods/core_user/core_user.h4
2 files changed, 33 insertions, 12 deletions
diff --git a/src/coremods/core_user/cmd_away.cpp b/src/coremods/core_user/cmd_away.cpp
index 1b7baceba..50a586392 100644
--- a/src/coremods/core_user/cmd_away.cpp
+++ b/src/coremods/core_user/cmd_away.cpp
@@ -21,9 +21,18 @@
#include "inspircd.h"
#include "core_user.h"
+enum
+{
+ // From RFC 1459.
+ RPL_UNAWAY = 305,
+ RPL_NOWAWAY = 306
+};
+
CommandAway::CommandAway(Module* parent)
- : Command(parent, "AWAY", 0, 0)
+ : Command(parent, "AWAY", 0, 1)
+ , awayevprov(parent)
{
+ allow_empty_last_param = false;
syntax = "[<message>]";
}
@@ -31,29 +40,37 @@ CommandAway::CommandAway(Module* parent)
*/
CmdResult CommandAway::Handle(User* user, const Params& parameters)
{
+ LocalUser* luser = IS_LOCAL(user);
ModResult MOD_RESULT;
- if ((!parameters.empty()) && (!parameters[0].empty()))
+ if (!parameters.empty())
{
- FIRST_MOD_RESULT(OnSetAway, MOD_RESULT, (user, parameters[0]));
-
- if (MOD_RESULT == MOD_RES_DENY && IS_LOCAL(user))
- return CMD_FAILURE;
+ std::string message(parameters[0]);
+ if (luser)
+ {
+ FIRST_MOD_RESULT_CUSTOM(awayevprov, Away::EventListener, OnUserPreAway, MOD_RESULT, (luser, message));
+ if (MOD_RESULT == MOD_RES_DENY)
+ return CMD_FAILURE;
+ }
user->awaytime = ServerInstance->Time();
- user->awaymsg.assign(parameters[0], 0, ServerInstance->Config->Limits.MaxAway);
-
+ user->awaymsg.assign(message, 0, ServerInstance->Config->Limits.MaxAway);
user->WriteNumeric(RPL_NOWAWAY, "You have been marked as being away");
+ FOREACH_MOD_CUSTOM(awayevprov, Away::EventListener, OnUserAway, (user));
}
else
{
- FIRST_MOD_RESULT(OnSetAway, MOD_RESULT, (user, ""));
-
- if (MOD_RESULT == MOD_RES_DENY && IS_LOCAL(user))
- return CMD_FAILURE;
+ if (luser)
+ {
+ FIRST_MOD_RESULT_CUSTOM(awayevprov, Away::EventListener, OnUserPreBack, MOD_RESULT, (luser));
+ if (MOD_RESULT == MOD_RES_DENY)
+ return CMD_FAILURE;
+ }
+ user->awaytime = 0;
user->awaymsg.clear();
user->WriteNumeric(RPL_UNAWAY, "You are no longer marked as being away");
+ FOREACH_MOD_CUSTOM(awayevprov, Away::EventListener, OnUserBack, (user));
}
return CMD_SUCCESS;
diff --git a/src/coremods/core_user/core_user.h b/src/coremods/core_user/core_user.h
index f29d2e448..1365cd048 100644
--- a/src/coremods/core_user/core_user.h
+++ b/src/coremods/core_user/core_user.h
@@ -24,6 +24,7 @@
#include "inspircd.h"
#include "listmode.h"
+#include "modules/away.h"
class MessageWrapper
{
@@ -53,6 +54,9 @@ class MessageWrapper
*/
class CommandAway : public Command
{
+ private:
+ Away::EventProvider awayevprov;
+
public:
/** Constructor for away.
*/