]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_uhnames.cpp
Header update: 2007 -> 2008
[user/henk/code/inspircd.git] / src / modules / m_uhnames.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 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
33         virtual ~ModuleUHNames()
34         {
35         }
36
37         void OnSyncUserMetaData(User* user, Module* proto,void* opaque, const std::string &extname, bool displayable)
38         {
39                 if ((displayable) && (extname == "UHNAMES"))
40                         proto->ProtoSendMetaData(opaque, TYPE_USER, user, extname, "Enabled");
41         }
42
43         virtual Version GetVersion()
44         {
45                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
46         }
47
48         virtual void On005Numeric(std::string &output)
49         {
50                 output.append(" UHNAMES");
51         }
52
53         void Prioritize()
54         {
55                 Module* namesx = ServerInstance->Modules->Find("m_namesx.so");
56                 ServerInstance->Modules->SetPriority(this, I_OnUserList, PRIO_BEFORE, &namesx);
57         }
58
59         virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, User *user, bool validated, const std::string &original_line)
60         {
61                 irc::string c = command.c_str();
62                 /* We don't actually create a proper command handler class for PROTOCTL,
63                  * because other modules might want to have PROTOCTL hooks too.
64                  * Therefore, we just hook its as an unvalidated command therefore we
65                  * can capture it even if it doesnt exist! :-)
66                  */
67                 if (c == "PROTOCTL")
68                 {
69                         if ((pcnt) && (!strcasecmp(parameters[0],"UHNAMES")))
70                         {
71                                 user->Extend("UHNAMES",dummy);
72                                 return 1;
73                         }
74                 }
75                 return 0;
76         }
77
78         /* IMPORTANT: This must be prioritized above NAMESX! */
79         virtual int OnUserList(User* user, Channel* Ptr, CUList* &ulist)
80         {
81                 if (user->GetExt("UHNAMES"))
82                 {
83                         if (!ulist)
84                                 ulist = Ptr->GetUsers();
85
86                         for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
87                                 i->second = i->first->GetFullHost();
88                 }
89                 return 0;               
90         }
91 };
92
93 MODULE_INIT(ModuleUHNames)