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 * ---------------------------------------------------
24 /* $ModDesc: Provides the SWHOIS command which allows setting of arbitary WHOIS lines */
28 void handle_swhois(char **parameters, int pcnt, userrec *user)
30 userrec* dest = Srv->FindNick(std::string(parameters[0]));
33 std::string line = "";
34 for (int i = 1; i < pcnt - 1; i++)
38 line = line + std::string(parameters[i]);
40 char* field = dest->GetExt("swhois");
43 std::string* text = (std::string*)field;
44 dest->Shrink("swhois");
47 std::string* text = new std::string(line);
48 dest->Extend("swhois",(char*)text);
52 class ModuleSWhois : public Module
55 ModuleSWhois(Server* Me)
59 Srv->AddCommand("SWHOIS",handle_swhois,2,'o',"m_swhois.so");
62 // :kenny.chatspike.net 320 Brain Azhrarn :is getting paid to play games.
63 virtual void OnWhois(userrec* source, userrec* dest)
65 char* desc = dest->GetExt("swhois");
68 std::string* swhois = (std::string*)desc;
69 WriteServ("320 %s %s :%s",source->nick,dest->nick,desc->c_str());
73 // Whenever the linking module wants to send out data, but doesnt know what the data
74 // represents (e.g. it is metadata, added to a userrec or chanrec by a module) then
75 // this method is called. We should use the ProtoSendMetaData function after we've
76 // corrected decided how the data should look, to send the metadata on its way if
78 virtual void OnSyncUserMetaData(userrec* user, Module* proto, void* opaque, std::string extname)
80 // check if the linking module wants to know about OUR metadata
81 if (extname == "swhois")
83 // check if this user has an swhois field to send
84 char* field = dest->GetExt("swhois");
87 // get our extdata out with a cast
88 std::string* swhois = (std::string*)field;
89 // call this function in the linking module, let it format the data how it
90 // sees fit, and send it on its way. We dont need or want to know how.
91 proto->ProtoSendMetaData(opaque,TYPE_USER,user,extname,*swhois);
96 // Whenever the linking module receives metadata from another server and doesnt know what
97 // to do with it (of course, hence the 'meta') it calls this method, and it is up to each
98 // module in turn to figure out if this metadata key belongs to them, and what they want
100 // In our case we're only sending a single string around, so we just construct a std::string.
101 // Some modules will probably get much more complex and format more detailed structs and classes
102 // in a textual way for sending over the link.
103 virtual void OnDecodeMetaData(int target_type, void* target, std::string extname, std::string extdata)
105 // check if its our metadata key, and its associated with a user
106 if ((target_type == TYPE_USER) && (extname == "swhois"))
108 userrec* dest = (userrec*)target;
109 // if they dont already have an swhois field, accept the remote server's
110 if (!dest->GetExt("swhois"))
112 std::string* text = new std::string(extdata);
113 target->Extend("swhois",(char*)text);
118 virtual ~ModuleSWhois()
122 virtual Version GetVersion()
124 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
127 virtual void OnUserConnect(userrec* user)
134 class ModuleSWhoisFactory : public ModuleFactory
137 ModuleSWhoisFactory()
141 ~ModuleSWhoisFactory()
145 virtual Module * CreateModule(Server* Me)
147 return new ModuleSWhois(Me);
153 extern "C" void * init_module( void )
155 return new ModuleSWhoisFactory;