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 * ---------------------------------------------------
19 /* $ModDesc: Provides the SWHOIS command which allows setting of arbitary WHOIS lines */
23 class cmd_swhois : public command_t
27 cmd_swhois (InspIRCd* Instance) : command_t(Instance,"SWHOIS",'o',2)
29 this->source = "m_swhois.so";
30 syntax = "<nick> <swhois>";
33 CmdResult Handle(const char** parameters, int pcnt, userrec* user)
35 userrec* dest = ServerInstance->FindNick(parameters[0]);
39 for(int i = 1; i < pcnt; i++)
44 line.append(parameters[i]);
48 dest->GetExt("swhois", text);
52 // We already had it set...
54 if (!ServerInstance->ULine(user->server))
55 // Ulines set SWHOISes silently
56 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());
58 dest->Shrink("swhois");
61 else if(!ServerInstance->ULine(user->server))
63 // Ulines set SWHOISes silently
64 ServerInstance->WriteOpers("*** %s used SWHOIS to set %s's extra whois to '%s'", user->nick, dest->nick, line.c_str());
67 text = new std::string(line);
68 dest->Extend("swhois", text);
77 class ModuleSWhois : public Module
79 cmd_swhois* mycommand;
84 ModuleSWhois(InspIRCd* Me) : Module::Module(Me)
87 Conf = new ConfigReader(ServerInstance);
88 mycommand = new cmd_swhois(ServerInstance);
89 ServerInstance->AddCommand(mycommand);
92 void OnRehash(const std::string ¶meter)
95 Conf = new ConfigReader(ServerInstance);
98 void Implements(char* List)
100 List[I_OnWhois] = List[I_OnSyncUserMetaData] = List[I_OnUserQuit] = List[I_OnCleanup] = List[I_OnRehash] = List[I_OnPostCommand] = 1;
103 // :kenny.chatspike.net 320 Brain Azhrarn :is getting paid to play games.
104 virtual void OnWhois(userrec* source, userrec* dest)
107 dest->GetExt("swhois", swhois);
110 ServerInstance->SendWhoisLine(source, dest, 320, "%s %s :%s",source->nick,dest->nick,swhois->c_str());
114 // Whenever the linking module wants to send out data, but doesnt know what the data
115 // represents (e.g. it is metadata, added to a userrec or chanrec by a module) then
116 // this method is called. We should use the ProtoSendMetaData function after we've
117 // corrected decided how the data should look, to send the metadata on its way if
119 virtual void OnSyncUserMetaData(userrec* user, Module* proto, void* opaque, const std::string &extname)
121 ServerInstance->Log(DEBUG,"Sync user metadata type '%s'", extname.c_str());
122 // check if the linking module wants to know about OUR metadata
123 if (extname == "swhois")
125 // check if this user has an swhois field to send
127 user->GetExt("swhois", swhois);
130 // call this function in the linking module, let it format the data how it
131 // sees fit, and send it on its way. We dont need or want to know how.
132 proto->ProtoSendMetaData(opaque,TYPE_USER,user,extname,*swhois);
136 ServerInstance->Log(DEBUG,"User has a null swhois string!");
141 // when a user quits, tidy up their metadata
142 virtual void OnUserQuit(userrec* user, const std::string &message)
145 user->GetExt("swhois", swhois);
148 user->Shrink("swhois");
153 // if the module is unloaded, tidy up all our dangling metadata
154 virtual void OnCleanup(int target_type, void* item)
156 if (target_type == TYPE_USER)
158 userrec* user = (userrec*)item;
160 user->GetExt("swhois", swhois);
163 user->Shrink("swhois");
169 // Whenever the linking module receives metadata from another server and doesnt know what
170 // to do with it (of course, hence the 'meta') it calls this method, and it is up to each
171 // module in turn to figure out if this metadata key belongs to them, and what they want
173 // In our case we're only sending a single string around, so we just construct a std::string.
174 // Some modules will probably get much more complex and format more detailed structs and classes
175 // in a textual way for sending over the link.
176 virtual void OnDecodeMetaData(int target_type, void* target, const std::string &extname, const std::string &extdata)
178 // check if its our metadata key, and its associated with a user
179 if ((target_type == TYPE_USER) && (extname == "swhois"))
181 ServerInstance->Log(DEBUG,"Extend with swhois");
182 userrec* dest = (userrec*)target;
183 // if they dont already have an swhois field, accept the remote server's
185 if (!dest->GetExt("swhois", text))
187 std::string* text = new std::string(extdata);
188 dest->Extend("swhois",text);
189 ServerInstance->Log(DEBUG,"extended: %s %s", dest->nick, dest->text.c_str());
194 virtual void OnPostCommand(const std::string &command, const char **params, int pcnt, userrec *user, CmdResult result, const std::string &original_line)
196 if ((command != "OPER") || (result != CMD_SUCCESS))
201 for (int i = 0; i < Conf->Enumerate("oper"); i++)
203 std::string name = Conf->ReadValue("oper", "name", i);
205 if (name == params[0])
207 swhois = Conf->ReadValue("oper", "swhois", i);
212 if (!swhois.length())
214 for (int i = 0; i < Conf->Enumerate("type"); i++)
216 std::string type = Conf->ReadValue("type", "name", i);
218 if (type == user->oper)
220 swhois = Conf->ReadValue("type", "swhois", i);
227 if (user->GetExt("swhois", old))
229 user->Shrink("swhois");
233 if (!swhois.length())
236 std::string *text = new std::string(swhois);
237 user->Extend("swhois", text);
240 virtual ~ModuleSWhois()
245 virtual Version GetVersion()
247 return Version(1,1,0,0,VF_VENDOR,API_VERSION);
252 class ModuleSWhoisFactory : public ModuleFactory
255 ModuleSWhoisFactory()
259 ~ModuleSWhoisFactory()
263 virtual Module * CreateModule(InspIRCd* Me)
265 return new ModuleSWhois(Me);
271 extern "C" void * init_module( void )
273 return new ModuleSWhoisFactory;