1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * Inspire is copyright (C) 2002-2005 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 void handle_swhois(char **parameters, int pcnt, userrec *user)
31 userrec* dest = Srv->FindNick(std::string(parameters[0]));
34 std::string line = "";
35 for (int i = 1; i < pcnt; i++)
39 line = line + std::string(parameters[i]);
41 char* field = dest->GetExt("swhois");
44 std::string* text = (std::string*)field;
45 dest->Shrink("swhois");
48 std::string* text = new std::string(line);
49 dest->Extend("swhois",(char*)text);
53 class ModuleSWhois : public Module
56 ModuleSWhois(Server* Me)
60 Srv->AddCommand("SWHOIS",handle_swhois,'o',2,"m_swhois.so");
63 // :kenny.chatspike.net 320 Brain Azhrarn :is getting paid to play games.
64 virtual void OnWhois(userrec* source, userrec* dest)
66 char* desc = dest->GetExt("swhois");
69 std::string* swhois = (std::string*)desc;
70 WriteServ(source->fd,"320 %s %s :%s",source->nick,dest->nick,swhois->c_str());
74 // Whenever the linking module wants to send out data, but doesnt know what the data
75 // represents (e.g. it is metadata, added to a userrec or chanrec by a module) then
76 // this method is called. We should use the ProtoSendMetaData function after we've
77 // corrected decided how the data should look, to send the metadata on its way if
79 virtual void OnSyncUserMetaData(userrec* user, Module* proto, void* opaque, std::string extname)
81 // check if the linking module wants to know about OUR metadata
82 if (extname == "swhois")
84 // check if this user has an swhois field to send
85 char* field = user->GetExt("swhois");
88 // get our extdata out with a cast
89 std::string* swhois = (std::string*)field;
90 // call this function in the linking module, let it format the data how it
91 // sees fit, and send it on its way. We dont need or want to know how.
92 proto->ProtoSendMetaData(opaque,TYPE_USER,user,extname,*swhois);
97 // when a user quits, tidy up their metadata
98 virtual void OnUserQuit(userrec* user, std::string message)
100 char* field = user->GetExt("swhois");
103 std::string* swhois = (std::string*)field;
104 user->Shrink("swhois");
109 // if the module is unloaded, tidy up all our dangling metadata
110 virtual void OnCleanup(int target_type, void* item)
112 if (target_type == TYPE_USER)
114 userrec* user = (userrec*)item;
115 char* field = user->GetExt("swhois");
118 std::string* swhois = (std::string*)field;
119 user->Shrink("swhois");
125 // Whenever the linking module receives metadata from another server and doesnt know what
126 // to do with it (of course, hence the 'meta') it calls this method, and it is up to each
127 // module in turn to figure out if this metadata key belongs to them, and what they want
129 // In our case we're only sending a single string around, so we just construct a std::string.
130 // Some modules will probably get much more complex and format more detailed structs and classes
131 // in a textual way for sending over the link.
132 virtual void OnDecodeMetaData(int target_type, void* target, std::string extname, std::string extdata)
134 // check if its our metadata key, and its associated with a user
135 if ((target_type == TYPE_USER) && (extname == "swhois"))
137 userrec* dest = (userrec*)target;
138 // if they dont already have an swhois field, accept the remote server's
139 if (!dest->GetExt("swhois"))
141 std::string* text = new std::string(extdata);
142 dest->Extend("swhois",(char*)text);
147 virtual ~ModuleSWhois()
151 virtual Version GetVersion()
153 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
156 virtual void OnUserConnect(userrec* user)
163 class ModuleSWhoisFactory : public ModuleFactory
166 ModuleSWhoisFactory()
170 ~ModuleSWhoisFactory()
174 virtual Module * CreateModule(Server* Me)
176 return new ModuleSWhois(Me);
182 extern "C" void * init_module( void )
184 return new ModuleSWhoisFactory;