]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_customtitle.cpp
Remove InspIRCd* parameters and fields
[user/henk/code/inspircd.git] / src / modules / m_customtitle.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/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 /* $ModDesc: Provides the TITLE command which allows setting of CUSTOM WHOIS TITLE line */
17
18 /** Handle /TITLE
19  */
20 class CommandTitle : public Command
21 {
22  public:
23         StringExtItem ctitle;
24         CommandTitle(Module* Creator) : Command(Creator,"TITLE", 2),
25                 ctitle("ctitle", Creator)
26         {
27                 syntax = "<user> <password>";
28                 TRANSLATE3(TR_NICK, TR_TEXT, TR_END);
29         }
30
31         bool OneOfMatches(const char* host, const char* ip, const char* hostlist)
32         {
33                 std::stringstream hl(hostlist);
34                 std::string xhost;
35                 while (hl >> xhost)
36                 {
37                         if (InspIRCd::Match(host, xhost, ascii_case_insensitive_map) || InspIRCd::MatchCIDR(ip, xhost, ascii_case_insensitive_map))
38                         {
39                                 return true;
40                         }
41                 }
42                 return false;
43         }
44
45         CmdResult Handle(const std::vector<std::string> &parameters, User* user)
46         {
47                 char TheHost[MAXBUF];
48                 char TheIP[MAXBUF];
49
50                 snprintf(TheHost,MAXBUF,"%s@%s",user->ident.c_str(), user->host.c_str());
51                 snprintf(TheIP, MAXBUF,"%s@%s",user->ident.c_str(), user->GetIPString());
52
53                 ConfigReader Conf;
54                 for (int i=0; i<Conf.Enumerate("title"); i++)
55                 {
56                         std::string name = Conf.ReadValue("title", "name", "", i);
57                         std::string pass = Conf.ReadValue("title", "password", "", i);
58                         std::string hash = Conf.ReadValue("title", "hash", "", i);
59                         std::string host = Conf.ReadValue("title", "host", "*@*", i);
60                         std::string title = Conf.ReadValue("title", "title", "", i);
61                         std::string vhost = Conf.ReadValue("title", "vhost", "", i);
62
63                         if (!strcmp(name.c_str(),parameters[0].c_str()) && !ServerInstance->PassCompare(user, pass.c_str(), parameters[1].c_str(), hash.c_str()) && OneOfMatches(TheHost,TheIP,host.c_str()) && !title.empty())
64                         {
65                                 ctitle.set(user, title);
66
67                                 ServerInstance->PI->SendMetaData(user, "ctitle", title);
68
69                                 if (!vhost.empty())
70                                         user->ChangeDisplayedHost(vhost.c_str());
71
72                                 user->WriteServ("NOTICE %s :Custom title set to '%s'",user->nick.c_str(), title.c_str());
73
74                                 return CMD_SUCCESS;
75                         }
76                 }
77
78                 user->WriteServ("NOTICE %s :Invalid title credentials",user->nick.c_str());
79                 return CMD_SUCCESS;
80         }
81
82 };
83
84 class ModuleCustomTitle : public Module
85 {
86         CommandTitle cmd;
87
88  public:
89         ModuleCustomTitle() : cmd(this)
90         {
91                 ServerInstance->AddCommand(&cmd);
92                 Extensible::Register(&cmd.ctitle);
93                 ServerInstance->Modules->Attach(I_OnWhoisLine, this);
94         }
95
96         // :kenny.chatspike.net 320 Brain Azhrarn :is getting paid to play games.
97         ModResult OnWhoisLine(User* user, User* dest, int &numeric, std::string &text)
98         {
99                 /* We use this and not OnWhois because this triggers for remote, too */
100                 if (numeric == 312)
101                 {
102                         /* Insert our numeric before 312 */
103                         const std::string* ctitle = cmd.ctitle.get(dest);
104                         if (ctitle)
105                         {
106                                 ServerInstance->SendWhoisLine(user, dest, 320, "%s %s :%s",user->nick.c_str(), dest->nick.c_str(), ctitle->c_str());
107                         }
108                 }
109                 /* Don't block anything */
110                 return MOD_RES_PASSTHRU;
111         }
112
113         ~ModuleCustomTitle()
114         {
115         }
116
117         Version GetVersion()
118         {
119                 return Version("Custom Title for users", VF_COMMON | VF_VENDOR);
120         }
121 };
122
123 MODULE_INIT(ModuleCustomTitle)