1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
20 /* $ModDesc: Povides support for ircu-style services accounts, including chmode +R, etc. */
22 /** Channel mode +R - unidentified users cannot join
24 class AChannel_R : public ModeHandler
27 AChannel_R(InspIRCd* Instance) : ModeHandler(Instance, 'R', 0, 0, false, MODETYPE_CHANNEL, false) { }
29 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
33 if (!channel->IsModeSet('R'))
35 channel->SetMode('R',true);
36 return MODEACTION_ALLOW;
41 if (channel->IsModeSet('R'))
43 channel->SetMode('R',false);
44 return MODEACTION_ALLOW;
48 return MODEACTION_DENY;
52 /** User mode +R - unidentified users cannot message
54 class AUser_R : public ModeHandler
57 AUser_R(InspIRCd* Instance) : ModeHandler(Instance, 'R', 0, 0, false, MODETYPE_USER, false) { }
59 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
63 if (!dest->IsModeSet('R'))
65 dest->SetMode('R',true);
66 return MODEACTION_ALLOW;
71 if (dest->IsModeSet('R'))
73 dest->SetMode('R',false);
74 return MODEACTION_ALLOW;
78 return MODEACTION_DENY;
82 /** Channel mode +M - unidentified users cannot message channel
84 class AChannel_M : public ModeHandler
87 AChannel_M(InspIRCd* Instance) : ModeHandler(Instance, 'M', 0, 0, false, MODETYPE_CHANNEL, false) { }
89 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
93 if (!channel->IsModeSet('M'))
95 channel->SetMode('M',true);
96 return MODEACTION_ALLOW;
101 if (channel->IsModeSet('M'))
103 channel->SetMode('M',false);
104 return MODEACTION_ALLOW;
108 return MODEACTION_DENY;
112 class ModuleServicesAccount : public Module
119 ModuleServicesAccount(InspIRCd* Me) : Module::Module(Me)
122 m1 = new AChannel_R(ServerInstance);
123 m2 = new AChannel_M(ServerInstance);
124 m3 = new AUser_R(ServerInstance);
125 ServerInstance->AddMode(m1, 'R');
126 ServerInstance->AddMode(m2, 'M');
127 ServerInstance->AddMode(m3, 'R');
130 /* <- :twisted.oscnet.org 330 w00t2 w00t2 w00t :is logged in as */
131 virtual void OnWhois(userrec* source, userrec* dest)
133 std::string *account;
134 dest->GetExt("accountname", account);
138 ServerInstance->SendWhoisLine(source, dest, 330, "%s %s %s :is logged in as", source->nick, dest->nick, account->c_str());
142 void Implements(char* List)
144 List[I_OnWhois] = List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = List[I_OnUserPreJoin] = 1;
145 List[I_OnSyncUserMetaData] = List[I_OnUserQuit] = List[I_OnCleanup] = List[I_OnDecodeMetaData] = 1;
148 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
150 std::string *account;
151 user->GetExt("accountname", account);
153 if (target_type == TYPE_CHANNEL)
155 chanrec* c = (chanrec*)dest;
157 if ((c->IsModeSet('M')) && (!account))
159 if ((ServerInstance->ULine(user->nick)) || (ServerInstance->ULine(user->server)) || (!strcmp(user->server,"")))
161 // user is ulined, can speak regardless
165 // user messaging a +M channel and is not registered
166 user->WriteServ("477 "+std::string(user->nick)+" "+std::string(c->name)+" :You need to be identified to a registered account to message this channel");
170 if (target_type == TYPE_USER)
172 userrec* u = (userrec*)dest;
174 if ((u->modes['R'-65]) && (!account))
176 if ((ServerInstance->ULine(user->nick)) || (ServerInstance->ULine(user->server)))
178 // user is ulined, can speak regardless
182 // user messaging a +R user and is not registered
183 user->WriteServ("477 "+std::string(user->nick)+" "+std::string(u->nick)+" :You need to be identified to a registered account to message this user");
190 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
192 return OnUserPreMessage(user, dest, target_type, text, status, exempt_list);
195 virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname, std::string &privs)
197 std::string *account;
198 user->GetExt("accountname", account);
202 if (chan->IsModeSet('R'))
206 if ((ServerInstance->ULine(user->nick)) || (ServerInstance->ULine(user->server)))
208 // user is ulined, won't be stopped from joining
211 // joining a +R channel and not identified
212 user->WriteServ("477 "+std::string(user->nick)+" "+std::string(chan->name)+" :You need to be identified to a registered account to join this channel");
220 // Whenever the linking module wants to send out data, but doesnt know what the data
221 // represents (e.g. it is metadata, added to a userrec or chanrec by a module) then
222 // this method is called. We should use the ProtoSendMetaData function after we've
223 // corrected decided how the data should look, to send the metadata on its way if
225 virtual void OnSyncUserMetaData(userrec* user, Module* proto, void* opaque, const std::string &extname)
227 // check if the linking module wants to know about OUR metadata
228 if (extname == "accountname")
230 // check if this user has an swhois field to send
231 std::string* account;
232 user->GetExt("accountname", account);
235 // call this function in the linking module, let it format the data how it
236 // sees fit, and send it on its way. We dont need or want to know how.
237 proto->ProtoSendMetaData(opaque,TYPE_USER,user,extname,*account);
242 // when a user quits, tidy up their metadata
243 virtual void OnUserQuit(userrec* user, const std::string &message)
245 std::string* account;
246 user->GetExt("accountname", account);
249 user->Shrink("accountname");
254 // if the module is unloaded, tidy up all our dangling metadata
255 virtual void OnCleanup(int target_type, void* item)
257 if (target_type == TYPE_USER)
259 userrec* user = (userrec*)item;
260 std::string* account;
261 user->GetExt("accountname", account);
264 user->Shrink("accountname");
270 // Whenever the linking module receives metadata from another server and doesnt know what
271 // to do with it (of course, hence the 'meta') it calls this method, and it is up to each
272 // module in turn to figure out if this metadata key belongs to them, and what they want
274 // In our case we're only sending a single string around, so we just construct a std::string.
275 // Some modules will probably get much more complex and format more detailed structs and classes
276 // in a textual way for sending over the link.
277 virtual void OnDecodeMetaData(int target_type, void* target, const std::string &extname, const std::string &extdata)
279 // check if its our metadata key, and its associated with a user
280 if ((target_type == TYPE_USER) && (extname == "accountname"))
282 userrec* dest = (userrec*)target;
283 /* logging them out? */
286 std::string* account;
287 dest->GetExt("accountname", account);
290 dest->Shrink("accountname");
296 // if they dont already have an accountname field, accept the remote server's
298 if (!dest->GetExt("accountname", text))
300 text = new std::string(extdata);
301 dest->Extend("accountname", text);
307 virtual ~ModuleServicesAccount()
309 ServerInstance->Modes->DelMode(m1);
310 ServerInstance->Modes->DelMode(m2);
311 ServerInstance->Modes->DelMode(m3);
317 virtual Version GetVersion()
319 return Version(1,1,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
324 class ModuleServicesAccountFactory : public ModuleFactory
327 ModuleServicesAccountFactory()
331 ~ModuleServicesAccountFactory()
335 virtual Module * CreateModule(InspIRCd* Me)
337 return new ModuleServicesAccount(Me);
343 extern "C" void * init_module( void )
345 return new ModuleServicesAccountFactory;