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 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 // :kenny.chatspike.net 320 Brain Azhrarn :is getting paid to play games.
75 virtual void OnWhois(userrec* source, userrec* dest)
77 char* desc = dest->GetExt("swhois");
80 std::string* swhois = (std::string*)desc;
81 WriteServ(source->fd,"320 %s %s :%s",source->nick,dest->nick,swhois->c_str());
85 // Whenever the linking module wants to send out data, but doesnt know what the data
86 // represents (e.g. it is metadata, added to a userrec or chanrec by a module) then
87 // this method is called. We should use the ProtoSendMetaData function after we've
88 // corrected decided how the data should look, to send the metadata on its way if
90 virtual void OnSyncUserMetaData(userrec* user, Module* proto, void* opaque, std::string extname)
92 // check if the linking module wants to know about OUR metadata
93 if (extname == "swhois")
95 // check if this user has an swhois field to send
96 char* field = user->GetExt("swhois");
99 // get our extdata out with a cast
100 std::string* swhois = (std::string*)field;
101 // call this function in the linking module, let it format the data how it
102 // sees fit, and send it on its way. We dont need or want to know how.
103 proto->ProtoSendMetaData(opaque,TYPE_USER,user,extname,*swhois);
108 // when a user quits, tidy up their metadata
109 virtual void OnUserQuit(userrec* user, std::string message)
111 char* field = user->GetExt("swhois");
114 std::string* swhois = (std::string*)field;
115 user->Shrink("swhois");
120 // if the module is unloaded, tidy up all our dangling metadata
121 virtual void OnCleanup(int target_type, void* item)
123 if (target_type == TYPE_USER)
125 userrec* user = (userrec*)item;
126 char* field = user->GetExt("swhois");
129 std::string* swhois = (std::string*)field;
130 user->Shrink("swhois");
136 // Whenever the linking module receives metadata from another server and doesnt know what
137 // to do with it (of course, hence the 'meta') it calls this method, and it is up to each
138 // module in turn to figure out if this metadata key belongs to them, and what they want
140 // In our case we're only sending a single string around, so we just construct a std::string.
141 // Some modules will probably get much more complex and format more detailed structs and classes
142 // in a textual way for sending over the link.
143 virtual void OnDecodeMetaData(int target_type, void* target, std::string extname, std::string extdata)
145 // check if its our metadata key, and its associated with a user
146 if ((target_type == TYPE_USER) && (extname == "swhois"))
148 userrec* dest = (userrec*)target;
149 // if they dont already have an swhois field, accept the remote server's
150 if (!dest->GetExt("swhois"))
152 std::string* text = new std::string(extdata);
153 dest->Extend("swhois",(char*)text);
158 virtual ~ModuleSWhois()
162 virtual Version GetVersion()
164 return Version(1,0,0,0,VF_VENDOR);
167 virtual void OnUserConnect(userrec* user)
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;