1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
17 /* $ModDesc: Provides the TITLE command which allows setting of CUSTOM WHOIS TITLE line */
21 class cmd_title : public command_t
25 cmd_title (InspIRCd* Instance) : command_t(Instance,"TITLE",0,2)
27 this->source = "m_customtitle.so";
28 syntax = "<user> <password>";
29 TRANSLATE3(TR_NICK, TR_TEXT, TR_END);
32 bool OneOfMatches(const char* host, const char* ip, const char* hostlist)
34 std::stringstream hl(hostlist);
38 if (match(host,xhost.c_str()) || match(ip,xhost.c_str(),true))
46 CmdResult Handle(const char** parameters, int pcnt, userrec* user)
54 snprintf(TheHost,MAXBUF,"%s@%s",user->ident,user->host);
55 snprintf(TheIP, MAXBUF,"%s@%s",user->ident,user->GetIPString());
57 ConfigReader Conf(ServerInstance);
58 for (int i=0; i<Conf.Enumerate("title"); i++)
60 std::string name = Conf.ReadValue("title", "name", "", i);
61 std::string pass = Conf.ReadValue("title", "password", "", i);
62 std::string host = Conf.ReadValue("title", "host", "*@*", i);
63 std::string title = Conf.ReadValue("title", "title", "", i);
64 std::string vhost = Conf.ReadValue("title", "vhost", "", i);
66 if (!strcmp(name.c_str(),parameters[0]) && !strcmp(pass.c_str(),parameters[1]) && OneOfMatches(TheHost,TheIP,host.c_str()) && !title.empty())
69 user->GetExt("ctitle", text);
73 user->Shrink("ctitle");
77 text = new std::string(title);
78 user->Extend("ctitle", text);
80 std::deque<std::string>* metadata = new std::deque<std::string>;
81 metadata->push_back(user->nick);
82 metadata->push_back("ctitle"); // The metadata id
83 metadata->push_back(*text); // The value to send
84 Event event((char*)metadata,(Module*)this,"send_metadata");
85 event.Send(ServerInstance);
89 user->ChangeDisplayedHost(vhost.c_str());
91 if (!ServerInstance->ULine(user->server))
92 // Ulines set TITLEs silently
93 ServerInstance->WriteOpers("*** %s used TITLE to set custom title '%s'",user->nick,title.c_str());
95 user->WriteServ("NOTICE %s :Custom title set to '%s'",user->nick, title.c_str());
101 if (!ServerInstance->ULine(user->server))
102 // Ulines also fail TITLEs silently
103 ServerInstance->WriteOpers("*** Failed TITLE attempt by %s!%s@%s using login '%s'",user->nick,user->ident,user->host,parameters[0]);
105 user->WriteServ("NOTICE %s :Invalid title credentials",user->nick);
111 class ModuleCustomTitle : public Module
113 cmd_title* mycommand;
116 ModuleCustomTitle(InspIRCd* Me) : Module(Me)
119 mycommand = new cmd_title(ServerInstance);
120 ServerInstance->AddCommand(mycommand);
123 void Implements(char* List)
125 List[I_OnDecodeMetaData] = List[I_OnWhoisLine] = List[I_OnSyncUserMetaData] = List[I_OnUserQuit] = List[I_OnCleanup] = 1;
128 // :kenny.chatspike.net 320 Brain Azhrarn :is getting paid to play games.
129 int OnWhoisLine(userrec* user, userrec* dest, int &numeric, std::string &text)
131 /* We use this and not OnWhois because this triggers for remote, too */
134 /* Insert our numeric before 312 */
136 dest->GetExt("ctitle", ctitle);
139 ServerInstance->SendWhoisLine(user, dest, 320, "%s %s :%s",user->nick,dest->nick,ctitle->c_str());
142 /* Dont block anything */
146 // Whenever the linking module wants to send out data, but doesnt know what the data
147 // represents (e.g. it is metadata, added to a userrec or chanrec by a module) then
148 // this method is called. We should use the ProtoSendMetaData function after we've
149 // corrected decided how the data should look, to send the metadata on its way if
151 virtual void OnSyncUserMetaData(userrec* user, Module* proto, void* opaque, const std::string &extname, bool displayable)
153 // check if the linking module wants to know about OUR metadata
154 if (extname == "ctitle")
156 // check if this user has an ctitle field to send
158 user->GetExt("ctitle", ctitle);
161 // call this function in the linking module, let it format the data how it
162 // sees fit, and send it on its way. We dont need or want to know how.
163 proto->ProtoSendMetaData(opaque,TYPE_USER,user,extname,*ctitle);
168 // when a user quits, tidy up their metadata
169 virtual void OnUserQuit(userrec* user, const std::string &message, const std::string &oper_message)
172 user->GetExt("ctitle", ctitle);
175 user->Shrink("ctitle");
180 // if the module is unloaded, tidy up all our dangling metadata
181 virtual void OnCleanup(int target_type, void* item)
183 if (target_type == TYPE_USER)
185 userrec* user = (userrec*)item;
187 user->GetExt("ctitle", ctitle);
190 user->Shrink("ctitle");
196 // Whenever the linking module receives metadata from another server and doesnt know what
197 // to do with it (of course, hence the 'meta') it calls this method, and it is up to each
198 // module in turn to figure out if this metadata key belongs to them, and what they want
200 // In our case we're only sending a single string around, so we just construct a std::string.
201 // Some modules will probably get much more complex and format more detailed structs and classes
202 // in a textual way for sending over the link.
203 virtual void OnDecodeMetaData(int target_type, void* target, const std::string &extname, const std::string &extdata)
205 // check if its our metadata key, and its associated with a user
206 if ((target_type == TYPE_USER) && (extname == "ctitle"))
208 userrec* dest = (userrec*)target;
209 // if they dont already have an ctitle field, accept the remote server's
211 if (!dest->GetExt("ctitle", text))
213 std::string* text = new std::string(extdata);
214 dest->Extend("ctitle",text);
219 virtual ~ModuleCustomTitle()
223 virtual Version GetVersion()
225 return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
229 MODULE_INIT(ModuleCustomTitle)