]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_uhnames.cpp
b0981d58d24d28816adc1f6700d0add8483bb63a
[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 "users.h"
15 #include "channels.h"
16 #include "modules.h"
17 #include "inspircd.h"
18
19 static const char* dummy = "ON";
20
21 /* $ModDesc: Provides aliases of commands. */
22
23 class ModuleUHNames : public Module
24 {
25         CUList nl;
26  public:
27         
28         ModuleUHNames(InspIRCd* Me)
29                 : Module::Module(Me)
30         {
31         }
32
33         void Implements(char* List)
34         {
35                 List[I_OnPreCommand] = List[I_OnUserList] = List[I_On005Numeric] = 1;
36         }
37
38         virtual ~ModuleUHNames()
39         {
40         }
41
42         virtual Version GetVersion()
43         {
44                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
45         }
46
47         virtual void On005Numeric(std::string &output)
48         {
49                 output.append(" UHNAMES");
50         }
51
52         Priority Prioritize()
53         {
54                 return (Priority)ServerInstance->PriorityBefore("m_namesx.so");
55         }
56
57         virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, bool validated, const std::string &original_line)
58         {
59                 irc::string c = command.c_str();
60                 /* We don't actually create a proper command handler class for PROTOCTL,
61                  * because other modules might want to have PROTOCTL hooks too.
62                  * Therefore, we just hook its as an unvalidated command therefore we
63                  * can capture it even if it doesnt exist! :-)
64                  */
65                 if (c == "PROTOCTL")
66                 {
67                         if ((pcnt) && (!strcasecmp(parameters[0],"UHNAMES")))
68                         {
69                                 user->Extend("UHNAMES",dummy);
70                                 return 1;
71                         }
72                 }
73                 return 0;
74         }
75
76         /* IMPORTANT: This must be prioritized above NAMESX! */
77         virtual int OnUserList(userrec* user, chanrec* Ptr, CUList* &ulist)
78         {
79                 if (user->GetExt("UHNAMES"))
80                 {
81                         if (!ulist)
82                                 ulist = Ptr->GetUsers();
83
84                         for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
85                                 i->second = i->first->GetFullHost();
86                 }
87                 return 0;               
88         }
89 };
90
91
92 class ModuleUHNamesFactory : public ModuleFactory
93 {
94  public:
95         ModuleUHNamesFactory()
96         {
97         }
98
99         ~ModuleUHNamesFactory()
100         {
101         }
102
103                 virtual Module * CreateModule(InspIRCd* Me)
104         {
105                 return new ModuleUHNames(Me);
106         }
107 };
108
109
110 extern "C" void * init_module( void )
111 {
112         return new ModuleUHNamesFactory;
113 }
114