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 * ---------------------------------------------------
16 /* $ModDesc: Provides the SWHOIS command which allows setting of arbitary WHOIS lines */
20 class cmd_swhois : public command_t
24 cmd_swhois (InspIRCd* Instance) : command_t(Instance,"SWHOIS",'o',2)
26 this->source = "m_swhois.so";
27 syntax = "<nick> <swhois>";
30 CmdResult Handle(const char** parameters, int pcnt, userrec* user)
32 userrec* dest = ServerInstance->FindNick(parameters[0]);
36 user->WriteServ("401 %s %s :No such nick/channel", user->nick, parameters[0]);
42 user->WriteServ("NOTICE %s :*** SWHOIS: Whois line must be specified", user->nick);
47 for (int i = 1; i < pcnt; i++)
52 line.append(parameters[i]);
56 dest->GetExt("swhois", text);
60 // We already had it set...
62 if (!ServerInstance->ULine(user->server))
63 // Ulines set SWHOISes silently
64 ServerInstance->WriteOpers("*** %s used SWHOIS to set %s's extra whois from '%s' to '%s'", user->nick, dest->nick, text->c_str(), line.c_str());
66 dest->Shrink("swhois");
69 else if (!ServerInstance->ULine(user->server))
71 // Ulines set SWHOISes silently
72 ServerInstance->WriteOpers("*** %s used SWHOIS to set %s's extra whois to '%s'", user->nick, dest->nick, line.c_str());
75 text = new std::string(line);
76 dest->Extend("swhois", text);
78 /* Bug #376 - feature request -
79 * To cut down on the amount of commands services etc have to recognise, this only sends METADATA across the network now
80 * not an actual SWHOIS command. Any SWHOIS command sent from services will be automatically translated to METADATA by this.
81 * Sorry w00t i know this was your fix, but i got bored and wanted to clear down the tracker :)
84 std::deque<std::string>* metadata = new std::deque<std::string>;
85 metadata->push_back(dest->nick);
86 metadata->push_back("swhois"); // The metadata id
87 metadata->push_back(*text); // The value to send
88 Event event((char*)metadata,(Module*)this,"send_metadata");
89 event.Send(ServerInstance);
97 class ModuleSWhois : public Module
99 cmd_swhois* mycommand;
104 ModuleSWhois(InspIRCd* Me) : Module(Me)
107 Conf = new ConfigReader(ServerInstance);
108 mycommand = new cmd_swhois(ServerInstance);
109 ServerInstance->AddCommand(mycommand);
112 void OnRehash(userrec* user, const std::string ¶meter)
115 Conf = new ConfigReader(ServerInstance);
118 void Implements(char* List)
120 List[I_OnDecodeMetaData] = List[I_OnWhoisLine] = List[I_OnSyncUserMetaData] = List[I_OnUserQuit] = List[I_OnCleanup] = List[I_OnRehash] = List[I_OnPostCommand] = 1;
123 // :kenny.chatspike.net 320 Brain Azhrarn :is getting paid to play games.
124 int OnWhoisLine(userrec* user, userrec* dest, int &numeric, std::string &text)
126 /* We use this and not OnWhois because this triggers for remote, too */
129 /* Insert our numeric before 312 */
131 dest->GetExt("swhois", swhois);
134 ServerInstance->SendWhoisLine(user, dest, 320, "%s %s :%s",user->nick,dest->nick,swhois->c_str());
137 /* Dont block anything */
141 // Whenever the linking module wants to send out data, but doesnt know what the data
142 // represents (e.g. it is metadata, added to a userrec or chanrec by a module) then
143 // this method is called. We should use the ProtoSendMetaData function after we've
144 // corrected decided how the data should look, to send the metadata on its way if
146 virtual void OnSyncUserMetaData(userrec* user, Module* proto, void* opaque, const std::string &extname, bool displayable)
148 // check if the linking module wants to know about OUR metadata
149 if (extname == "swhois")
151 // check if this user has an swhois field to send
153 user->GetExt("swhois", swhois);
156 // call this function in the linking module, let it format the data how it
157 // sees fit, and send it on its way. We dont need or want to know how.
158 proto->ProtoSendMetaData(opaque,TYPE_USER,user,extname,*swhois);
163 // when a user quits, tidy up their metadata
164 virtual void OnUserQuit(userrec* user, const std::string &message, const std::string &oper_message)
167 user->GetExt("swhois", swhois);
170 user->Shrink("swhois");
175 // if the module is unloaded, tidy up all our dangling metadata
176 virtual void OnCleanup(int target_type, void* item)
178 if (target_type == TYPE_USER)
180 userrec* user = (userrec*)item;
182 user->GetExt("swhois", swhois);
185 user->Shrink("swhois");
191 // Whenever the linking module receives metadata from another server and doesnt know what
192 // to do with it (of course, hence the 'meta') it calls this method, and it is up to each
193 // module in turn to figure out if this metadata key belongs to them, and what they want
195 // In our case we're only sending a single string around, so we just construct a std::string.
196 // Some modules will probably get much more complex and format more detailed structs and classes
197 // in a textual way for sending over the link.
198 virtual void OnDecodeMetaData(int target_type, void* target, const std::string &extname, const std::string &extdata)
200 // check if its our metadata key, and its associated with a user
201 if ((target_type == TYPE_USER) && (extname == "swhois"))
203 userrec* dest = (userrec*)target;
204 // if they dont already have an swhois field, accept the remote server's
206 if (!dest->GetExt("swhois", text))
208 std::string* text = new std::string(extdata);
209 dest->Extend("swhois",text);
214 virtual void OnPostCommand(const std::string &command, const char **params, int pcnt, userrec *user, CmdResult result, const std::string &original_line)
216 if ((command != "OPER") || (result != CMD_SUCCESS))
221 for (int i = 0; i < Conf->Enumerate("oper"); i++)
223 std::string name = Conf->ReadValue("oper", "name", i);
225 if (name == params[0])
227 swhois = Conf->ReadValue("oper", "swhois", i);
232 if (!swhois.length())
234 for (int i = 0; i < Conf->Enumerate("type"); i++)
236 std::string type = Conf->ReadValue("type", "name", i);
238 if (type == user->oper)
240 swhois = Conf->ReadValue("type", "swhois", i);
247 if (user->GetExt("swhois", old))
249 user->Shrink("swhois");
253 if (!swhois.length())
256 std::string *text = new std::string(swhois);
257 user->Extend("swhois", text);
258 std::deque<std::string>* metadata = new std::deque<std::string>;
259 metadata->push_back(user->nick);
260 metadata->push_back("swhois"); // The metadata id
261 metadata->push_back(*text); // The value to send
262 Event event((char*)metadata,(Module*)this,"send_metadata");
263 event.Send(ServerInstance);
267 virtual ~ModuleSWhois()
272 virtual Version GetVersion()
274 return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
278 MODULE_INIT(ModuleSWhois)