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 * ---------------------------------------------------
23 #include "helperfuncs.h"
25 /* $ModDesc: Provides the SWHOIS command which allows setting of arbitary WHOIS lines */
29 class cmd_swhois : public command_t
32 cmd_swhois () : command_t("SWHOIS",'o',2)
34 this->source = "m_swhois.so";
37 void Handle (char **parameters, int pcnt, userrec *user)
39 userrec* dest = Srv->FindNick(std::string(parameters[0]));
42 std::string line = "";
43 for (int i = 1; i < pcnt; i++)
47 line = line + std::string(parameters[i]);
49 char* field = dest->GetExt("swhois");
52 std::string* text = (std::string*)field;
53 dest->Shrink("swhois");
56 std::string* text = new std::string(line);
57 dest->Extend("swhois",(char*)text);
62 class ModuleSWhois : public Module
64 cmd_swhois* mycommand;
66 ModuleSWhois(Server* Me)
70 mycommand = new cmd_swhois();
71 Srv->AddCommand(mycommand);
74 void Implements(char* List)
76 List[I_OnWhois] = List[I_OnSyncUserMetaData] = List[I_OnUserQuit] = List[I_OnCleanup] = 1;
79 // :kenny.chatspike.net 320 Brain Azhrarn :is getting paid to play games.
80 virtual void OnWhois(userrec* source, userrec* dest)
82 char* desc = dest->GetExt("swhois");
85 std::string* swhois = (std::string*)desc;
86 WriteServ(source->fd,"320 %s %s :%s",source->nick,dest->nick,swhois->c_str());
90 // Whenever the linking module wants to send out data, but doesnt know what the data
91 // represents (e.g. it is metadata, added to a userrec or chanrec by a module) then
92 // this method is called. We should use the ProtoSendMetaData function after we've
93 // corrected decided how the data should look, to send the metadata on its way if
95 virtual void OnSyncUserMetaData(userrec* user, Module* proto, void* opaque, std::string extname)
97 // check if the linking module wants to know about OUR metadata
98 if (extname == "swhois")
100 // check if this user has an swhois field to send
101 char* field = user->GetExt("swhois");
104 // get our extdata out with a cast
105 std::string* swhois = (std::string*)field;
106 // call this function in the linking module, let it format the data how it
107 // sees fit, and send it on its way. We dont need or want to know how.
108 proto->ProtoSendMetaData(opaque,TYPE_USER,user,extname,*swhois);
113 // when a user quits, tidy up their metadata
114 virtual void OnUserQuit(userrec* user, std::string message)
116 char* field = user->GetExt("swhois");
119 std::string* swhois = (std::string*)field;
120 user->Shrink("swhois");
125 // if the module is unloaded, tidy up all our dangling metadata
126 virtual void OnCleanup(int target_type, void* item)
128 if (target_type == TYPE_USER)
130 userrec* user = (userrec*)item;
131 char* field = user->GetExt("swhois");
134 std::string* swhois = (std::string*)field;
135 user->Shrink("swhois");
141 // Whenever the linking module receives metadata from another server and doesnt know what
142 // to do with it (of course, hence the 'meta') it calls this method, and it is up to each
143 // module in turn to figure out if this metadata key belongs to them, and what they want
145 // In our case we're only sending a single string around, so we just construct a std::string.
146 // Some modules will probably get much more complex and format more detailed structs and classes
147 // in a textual way for sending over the link.
148 virtual void OnDecodeMetaData(int target_type, void* target, std::string extname, std::string extdata)
150 // check if its our metadata key, and its associated with a user
151 if ((target_type == TYPE_USER) && (extname == "swhois"))
153 userrec* dest = (userrec*)target;
154 // if they dont already have an swhois field, accept the remote server's
155 if (!dest->GetExt("swhois"))
157 std::string* text = new std::string(extdata);
158 dest->Extend("swhois",(char*)text);
163 virtual ~ModuleSWhois()
167 virtual Version GetVersion()
169 return Version(1,0,0,0,VF_VENDOR);
174 class ModuleSWhoisFactory : public ModuleFactory
177 ModuleSWhoisFactory()
181 ~ModuleSWhoisFactory()
185 virtual Module * CreateModule(Server* Me)
187 return new ModuleSWhois(Me);
193 extern "C" void * init_module( void )
195 return new ModuleSWhoisFactory;