1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
20 #include "helperfuncs.h"
23 /* $ModDesc: Provides the SWHOIS command which allows setting of arbitary WHOIS lines */
27 class cmd_swhois : public command_t
31 cmd_swhois (InspIRCd* Instance) : command_t(Instance,"SWHOIS",'o',2)
33 this->source = "m_swhois.so";
34 syntax = "<nick> <swhois>";
37 void Handle(const char** parameters, int pcnt, userrec* user)
39 userrec* dest = ServerInstance->FindNick(parameters[0]);
43 for(int i = 1; i < pcnt; i++)
48 line.append(parameters[i]);
52 dest->GetExt("swhois", text);
56 // We already had it set...
58 if (!ServerInstance->ULine(user->server))
59 // Ulines set SWHOISes silently
60 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());
62 dest->Shrink("swhois");
65 else if(!ServerInstance->ULine(user->server))
67 // Ulines set SWHOISes silently
68 ServerInstance->WriteOpers("*** %s used SWHOIS to set %s's extra whois to '%s'", user->nick, dest->nick, line.c_str());
71 text = new std::string(line);
72 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_OnOper] = 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 source->WriteServ("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 // check if the linking module wants to know about OUR metadata
122 if (extname == "swhois")
124 // check if this user has an swhois field to send
126 user->GetExt("swhois", swhois);
129 // call this function in the linking module, let it format the data how it
130 // sees fit, and send it on its way. We dont need or want to know how.
131 proto->ProtoSendMetaData(opaque,TYPE_USER,user,extname,*swhois);
136 // when a user quits, tidy up their metadata
137 virtual void OnUserQuit(userrec* user, const std::string &message)
140 user->GetExt("swhois", swhois);
143 user->Shrink("swhois");
148 // if the module is unloaded, tidy up all our dangling metadata
149 virtual void OnCleanup(int target_type, void* item)
151 if (target_type == TYPE_USER)
153 userrec* user = (userrec*)item;
155 user->GetExt("swhois", swhois);
158 user->Shrink("swhois");
164 // Whenever the linking module receives metadata from another server and doesnt know what
165 // to do with it (of course, hence the 'meta') it calls this method, and it is up to each
166 // module in turn to figure out if this metadata key belongs to them, and what they want
168 // In our case we're only sending a single string around, so we just construct a std::string.
169 // Some modules will probably get much more complex and format more detailed structs and classes
170 // in a textual way for sending over the link.
171 virtual void OnDecodeMetaData(int target_type, void* target, const std::string &extname, const std::string &extdata)
173 // check if its our metadata key, and its associated with a user
174 if ((target_type == TYPE_USER) && (extname == "swhois"))
176 userrec* dest = (userrec*)target;
177 // if they dont already have an swhois field, accept the remote server's
179 if (!dest->GetExt("swhois", text))
181 std::string* text = new std::string(extdata);
182 dest->Extend("swhois",text);
187 virtual void OnOper(userrec* user, const std::string &opertype)
189 for(int i =0; i < Conf->Enumerate("type"); i++)
191 std::string type = Conf->ReadValue("type", "name", i);
193 if(strcmp(type.c_str(), user->oper) == 0)
195 std::string swhois = Conf->ReadValue("type", "swhois", i);
200 if(user->GetExt("swhois", old))
202 user->Shrink("swhois");
206 std::string* text = new std::string(swhois);
207 user->Extend("swhois", text);
215 virtual ~ModuleSWhois()
220 virtual Version GetVersion()
222 return Version(1,0,0,0,VF_VENDOR);
227 class ModuleSWhoisFactory : public ModuleFactory
230 ModuleSWhoisFactory()
234 ~ModuleSWhoisFactory()
238 virtual Module * CreateModule(InspIRCd* Me)
240 return new ModuleSWhois(Me);
246 extern "C" void * init_module( void )
248 return new ModuleSWhoisFactory;