summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7>2008-03-30 14:26:01 +0000
committerw00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7>2008-03-30 14:26:01 +0000
commite2f4bf3a135e6b23fea21b2628c2c830de29cdec (patch)
treef65396b2731efe96f631a6104912480139e1a797
parentd65f2c382531e2fd747f21f14b6b4d6c9659ca64 (diff)
Merge OnCancelAway and OnSetAway, add param awaymsg to OnSetAway (blank when cancelling), and change return type to int so modules can block away messages by returning nonzero.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@9223 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/modules.h18
-rw-r--r--src/commands/cmd_away.cpp15
-rw-r--r--src/modules.cpp3
-rw-r--r--src/modules/m_spanningtree/main.cpp29
-rw-r--r--src/modules/m_spanningtree/main.h3
5 files changed, 38 insertions, 30 deletions
diff --git a/include/modules.h b/include/modules.h
index 48d063455..ce6e3fa21 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -399,7 +399,7 @@ enum Implementation
I_OnCheckKey, I_OnCheckLimit, I_OnCheckBan, I_OnStats, I_OnChangeLocalUserHost, I_OnChangeLocalUserGecos, I_OnLocalTopicChange,
I_OnPostLocalTopicChange, I_OnEvent, I_OnRequest, I_OnGlobalOper, I_OnPostConnect, I_OnAddBan, I_OnDelBan,
I_OnRawSocketAccept, I_OnRawSocketClose, I_OnRawSocketWrite, I_OnRawSocketRead, I_OnChangeLocalUserGECOS, I_OnUserRegister,
- I_OnChannelPreDelete, I_OnChannelDelete, I_OnPostOper, I_OnSyncOtherMetaData, I_OnSetAway, I_OnCancelAway, I_OnUserList,
+ I_OnChannelPreDelete, I_OnChannelDelete, I_OnPostOper, I_OnSyncOtherMetaData, I_OnSetAway, I_OnUserList,
I_OnPostCommand, I_OnPostJoin, I_OnWhoisLine, I_OnBuildExemptList, I_OnRawSocketConnect, I_OnGarbageCollect, I_OnBufferFlushed,
I_OnText, I_OnReadConfig, I_OnDownloadFile, I_OnPassCompare, I_OnRunTestSuite, I_OnNamesListItem, I_OnNumeric, I_OnHookUserIO,
I_END
@@ -1299,17 +1299,15 @@ class CoreExport Module : public Extensible
*/
virtual int OnRawSocketRead(int fd, char* buffer, unsigned int count, int &readresult);
- /** Called whenever a user sets away.
- * This method has no parameter for the away message, as it is available in the
- * user record as User::awaymsg.
+ /** Called whenever a user sets away or returns from being away.
+ * The away message is available as a parameter, but should not be modified.
+ * At this stage, it has already been copied into the user record.
+ * If awaymsg is empty, the user is returning from away.
* @param user The user setting away
+ * @param awaymsg The away message of the user, or empty if returning from away
+ * @return nonzero if the away message should be blocked - should ONLY be nonzero for LOCAL users (IS_LOCAL) (no output is returned by core)
*/
- virtual void OnSetAway(User* user);
-
- /** Called when a user cancels their away state.
- * @param user The user returning from away
- */
- virtual void OnCancelAway(User* user);
+ virtual int OnSetAway(User* user, const std::string &awaymsg);
/** Called whenever a NAMES list is requested.
* You can produce the nameslist yourself, overriding the current list,
diff --git a/src/commands/cmd_away.cpp b/src/commands/cmd_away.cpp
index 2ca2df7db..c49813b52 100644
--- a/src/commands/cmd_away.cpp
+++ b/src/commands/cmd_away.cpp
@@ -23,17 +23,28 @@ extern "C" DllExport Command* init_command(InspIRCd* Instance)
*/
CmdResult CommandAway::Handle (const char* const* parameters, int pcnt, User *user)
{
+ int MOD_RESULT = 0;
+
if ((pcnt) && (*parameters[0]))
{
+ FOREACH_RESULT(I_OnSetAway, OnSetAway(user, parameters[0]));
+
+ if (MOD_RESULT != 0 && !IS_LOCAL(user))
+ return CMD_FAILURE;
+
strlcpy(user->awaymsg,parameters[0],MAXAWAY);
user->WriteNumeric(306, "%s :You have been marked as being away",user->nick);
- FOREACH_MOD(I_OnSetAway,OnSetAway(user));
}
else
{
+ FOREACH_RESULT(I_OnSetAway, OnSetAway(user, ""));
+
+ if (MOD_RESULT != 0 && !IS_LOCAL(user))
+ return CMD_FAILURE;
+
*user->awaymsg = 0;
user->WriteNumeric(305, "%s :You are no longer marked as being away",user->nick);
- FOREACH_MOD(I_OnCancelAway,OnCancelAway(user));
}
+
return CMD_SUCCESS;
}
diff --git a/src/modules.cpp b/src/modules.cpp
index 5ec74da7b..1081effa1 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -184,8 +184,7 @@ void Module::OnExpireLine(XLine*) { }
void Module::OnCleanup(int, void*) { }
int Module::OnChannelPreDelete(Channel*) { return 0; }
void Module::OnChannelDelete(Channel*) { }
-void Module::OnSetAway(User*) { }
-void Module::OnCancelAway(User*) { }
+void Module::OnSetAway(User*, const std::string &) { }
int Module::OnUserList(User*, Channel*, CUList*&) { return 0; }
int Module::OnWhoisLine(User*, User*, int&, std::string&) { return 0; }
void Module::OnBuildExemptList(MessageType, Channel*, User*, char, CUList&, const std::string&) { }
diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp
index b37edf583..84771901e 100644
--- a/src/modules/m_spanningtree/main.cpp
+++ b/src/modules/m_spanningtree/main.cpp
@@ -52,7 +52,7 @@ ModuleSpanningTree::ModuleSpanningTree(InspIRCd* Me)
I_OnUserJoin, I_OnChangeHost, I_OnChangeName, I_OnUserPart, I_OnPostConnect,
I_OnUserQuit, I_OnUserPostNick, I_OnUserKick, I_OnRemoteKill, I_OnRehash,
I_OnOper, I_OnAddLine, I_OnDelLine, I_ProtoSendMode, I_OnMode,
- I_OnStats, I_ProtoSendMetaData, I_OnEvent, I_OnSetAway, I_OnCancelAway, I_OnPostCommand
+ I_OnStats, I_ProtoSendMetaData, I_OnEvent, I_OnSetAway, I_OnPostCommand
};
ServerInstance->Modules->Attach(eventlist, this, 29);
@@ -817,24 +817,25 @@ void ModuleSpanningTree::OnMode(User* user, void* dest, int target_type, const s
}
}
-void ModuleSpanningTree::OnSetAway(User* user)
+int ModuleSpanningTree::OnSetAway(User* user, const std::string &awaymsg)
{
if (IS_LOCAL(user))
{
- std::deque<std::string> params;
- params.push_back(":"+std::string(user->awaymsg));
- Utils->DoOneToMany(user->uuid,"AWAY",params);
+ if (awaymsg.empty())
+ {
+ std::deque<std::string> params;
+ params.clear();
+ Utils->DoOneToMany(user->uuid,"AWAY",params);
+ }
+ else
+ {
+ std::deque<std::string> params;
+ params.push_back(":" + awaymsg);
+ Utils->DoOneToMany(user->uuid,"AWAY",params);
+ }
}
-}
-void ModuleSpanningTree::OnCancelAway(User* user)
-{
- if (IS_LOCAL(user))
- {
- std::deque<std::string> params;
- params.clear();
- Utils->DoOneToMany(user->uuid,"AWAY",params);
- }
+ return 0;
}
void ModuleSpanningTree::ProtoSendMode(void* opaque, int target_type, void* target, const std::string &modeline)
diff --git a/src/modules/m_spanningtree/main.h b/src/modules/m_spanningtree/main.h
index a3d249a51..cfdec9131 100644
--- a/src/modules/m_spanningtree/main.h
+++ b/src/modules/m_spanningtree/main.h
@@ -173,8 +173,7 @@ class ModuleSpanningTree : public Module
virtual void OnDelLine(User *u, XLine *x);
virtual void OnMode(User* user, void* dest, int target_type, const std::string &text);
virtual int OnStats(char statschar, User* user, string_list &results);
- virtual void OnSetAway(User* user);
- virtual void OnCancelAway(User* user);
+ virtual int OnSetAway(User* user, const std::string &awaymsg);
virtual void ProtoSendMode(void* opaque, int target_type, void* target, const std::string &modeline);
virtual void ProtoSendMetaData(void* opaque, int target_type, void* target, const std::string &extname, const std::string &extdata);
virtual void OnEvent(Event* event);