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