]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_uhnames.cpp
Convert all to new Attach() system. The Implements() method needs removing from all...
[user/henk/code/inspircd.git] / src / modules / m_uhnames.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15
16 static const char* dummy = "ON";
17
18 /* $ModDesc: Provides aliases of commands. */
19
20 class ModuleUHNames : public Module
21 {
22         CUList nl;
23  public:
24         
25         ModuleUHNames(InspIRCd* Me)
26                 : Module(Me)
27         {
28                 Implementation eventlist[] = { I_OnSyncUserMetaData, I_OnPreCommand, I_OnUserList, I_On005Numeric };
29                 ServerInstance->Modules->Attach(eventlist, this, 4);
30         }
31
32         void Implements(char* List)
33         {
34                 List[I_OnSyncUserMetaData] = List[I_OnPreCommand] = List[I_OnUserList] = List[I_On005Numeric] = 1;
35         }
36
37         virtual ~ModuleUHNames()
38         {
39         }
40
41         void OnSyncUserMetaData(User* user, Module* proto,void* opaque, const std::string &extname, bool displayable)
42         {
43                 if ((displayable) && (extname == "UHNAMES"))
44                         proto->ProtoSendMetaData(opaque, TYPE_USER, user, extname, "Enabled");
45         }
46
47         virtual Version GetVersion()
48         {
49                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
50         }
51
52         virtual void On005Numeric(std::string &output)
53         {
54                 output.append(" UHNAMES");
55         }
56
57         void Prioritize()
58         {
59                 Module* namesx = ServerInstance->Modules->Find("m_namesx.so");
60                 ServerInstance->Modules->SetPriority(this, I_OnUserList, PRIO_BEFORE, &namesx);
61         }
62
63         virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, User *user, bool validated, const std::string &original_line)
64         {
65                 irc::string c = command.c_str();
66                 /* We don't actually create a proper command handler class for PROTOCTL,
67                  * because other modules might want to have PROTOCTL hooks too.
68                  * Therefore, we just hook its as an unvalidated command therefore we
69                  * can capture it even if it doesnt exist! :-)
70                  */
71                 if (c == "PROTOCTL")
72                 {
73                         if ((pcnt) && (!strcasecmp(parameters[0],"UHNAMES")))
74                         {
75                                 user->Extend("UHNAMES",dummy);
76                                 return 1;
77                         }
78                 }
79                 return 0;
80         }
81
82         /* IMPORTANT: This must be prioritized above NAMESX! */
83         virtual int OnUserList(User* user, Channel* Ptr, CUList* &ulist)
84         {
85                 if (user->GetExt("UHNAMES"))
86                 {
87                         if (!ulist)
88                                 ulist = Ptr->GetUsers();
89
90                         for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
91                                 i->second = i->first->GetFullHost();
92                 }
93                 return 0;               
94         }
95 };
96
97 MODULE_INIT(ModuleUHNames)