]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_services_account.cpp
Implement feature in bug #395 reported by stealth, and tidy up a bit
[user/henk/code/inspircd.git] / src / modules / m_services_account.cpp
index 9e73ba26bc1300d5eac8af85931b03f13bcdade3..cff0d7698f236165e4f5543cd3566cdc0c39136f 100644 (file)
  * ---------------------------------------------------
  */
 
+#include "inspircd.h"
 #include "users.h"
 #include "channels.h"
 #include "modules.h"
 #include "hashcomp.h"
-#include "inspircd.h"
 
 /* $ModDesc: Povides support for ircu-style services accounts, including chmode +R, etc. */
 
@@ -116,7 +116,7 @@ class ModuleServicesAccount : public Module
        AChannel_M* m2;
        AUser_R* m3;
  public:
-       ModuleServicesAccount(InspIRCd* Me) : Module::Module(Me)
+       ModuleServicesAccount(InspIRCd* Me) : Module(Me)
        {
                
                m1 = new AChannel_R(ServerInstance);
@@ -159,7 +159,7 @@ class ModuleServicesAccount : public Module
                        
                        if ((c->IsModeSet('M')) && (!account))
                        {
-                               if ((ServerInstance->ULine(user->nick)) || (ServerInstance->ULine(user->server)) || (!strcmp(user->server,"")))
+                               if ((ServerInstance->ULine(user->nick)) || (ServerInstance->ULine(user->server)))
                                {
                                        // user is ulined, can speak regardless
                                        return 0;
@@ -225,7 +225,7 @@ class ModuleServicesAccount : public Module
        // this method is called. We should use the ProtoSendMetaData function after we've
        // corrected decided how the data should look, to send the metadata on its way if
        // it is ours.
-       virtual void OnSyncUserMetaData(userrec* user, Module* proto, void* opaque, const std::string &extname)
+       virtual void OnSyncUserMetaData(userrec* user, Module* proto, void* opaque, const std::string &extname, bool displayable)
        {
                // check if the linking module wants to know about OUR metadata
                if (extname == "accountname")
@@ -235,6 +235,9 @@ class ModuleServicesAccount : public Module
                        user->GetExt("accountname", account);
                        if (account)
                        {
+                               // remove any accidental leading/trailing spaces
+                               trim(*account);
+
                                // call this function in the linking module, let it format the data how it
                                // sees fit, and send it on its way. We dont need or want to know how.
                                proto->ProtoSendMetaData(opaque,TYPE_USER,user,extname,*account);
@@ -243,7 +246,7 @@ class ModuleServicesAccount : public Module
        }
 
        // when a user quits, tidy up their metadata
-       virtual void OnUserQuit(userrec* user, const std::string &message)
+       virtual void OnUserQuit(userrec* user, const std::string &message, const std::string &oper_message)
        {
                std::string* account;
                user->GetExt("accountname", account);
@@ -283,8 +286,9 @@ class ModuleServicesAccount : public Module
                if ((target_type == TYPE_USER) && (extname == "accountname"))
                {       
                        userrec* dest = (userrec*)target;
+                       
                        /* logging them out? */
-                       if (extdata == "")
+                       if (extdata.empty())
                        {
                                std::string* account;
                                dest->GetExt("accountname", account);
@@ -301,6 +305,8 @@ class ModuleServicesAccount : public Module
                                if (!dest->GetExt("accountname", text))
                                {
                                        text = new std::string(extdata);
+                                       // remove any accidental leading/trailing spaces
+                                       trim(*text);
                                        dest->Extend("accountname", text);
                                }
                        }
@@ -323,27 +329,4 @@ class ModuleServicesAccount : public Module
        }
 };
 
-
-class ModuleServicesAccountFactory : public ModuleFactory
-{
- public:
-       ModuleServicesAccountFactory()
-       {
-       }
-       
-       ~ModuleServicesAccountFactory()
-       {
-       }
-       
-       virtual Module * CreateModule(InspIRCd* Me)
-       {
-               return new ModuleServicesAccount(Me);
-       }
-       
-};
-
-
-extern "C" void * init_module( void )
-{
-       return new ModuleServicesAccountFactory;
-}
+MODULE_INIT(ModuleServicesAccount)