1 /* modules/m_services.c
2 * Copyright (C) 2005 Lee Hardy <lee -at- leeh.co.uk>
3 * Copyright (C) 2005 ircd-ratbox development team
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * 1.Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 * 2.Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3.The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
21 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
29 * $Id: m_services.c 1907 2006-08-29 19:18:15Z jilles $
44 #include "s_newconf.h"
50 #include "sprintf_irc.h"
54 static int me_su(struct Client
*, struct Client
*, int, const char **);
55 static int me_login(struct Client
*, struct Client
*, int, const char **);
56 static int me_rsfnc(struct Client
*, struct Client
*, int, const char **);
57 static int me_nickdelay(struct Client
*, struct Client
*, int, const char **);
59 static void h_svc_server_introduced(hook_data_client
*);
60 static void h_svc_whois(hook_data_client
*);
61 static void h_svc_stats(hook_data_int
*);
63 struct Message su_msgtab
= {
64 "SU", 0, 0, 0, MFLG_SLOW
,
65 {mg_ignore
, mg_ignore
, mg_ignore
, mg_ignore
, {me_su
, 2}, mg_ignore
}
67 struct Message login_msgtab
= {
68 "LOGIN", 0, 0, 0, MFLG_SLOW
,
69 {mg_ignore
, mg_ignore
, mg_ignore
, mg_ignore
, {me_login
, 2}, mg_ignore
}
71 struct Message rsfnc_msgtab
= {
72 "RSFNC", 0, 0, 0, MFLG_SLOW
,
73 {mg_ignore
, mg_ignore
, mg_ignore
, mg_ignore
, {me_rsfnc
, 4}, mg_ignore
}
75 struct Message nickdelay_msgtab
= {
76 "NICKDELAY", 0, 0, 0, MFLG_SLOW
,
77 {mg_unreg
, mg_ignore
, mg_ignore
, mg_ignore
, {me_nickdelay
, 3}, mg_ignore
}
80 mapi_clist_av1 services_clist
[] = {
81 &su_msgtab
, &login_msgtab
, &rsfnc_msgtab
, &nickdelay_msgtab
, NULL
83 mapi_hfn_list_av1 services_hfnlist
[] = {
84 { "doing_stats", (hookfn
) h_svc_stats
},
85 { "doing_whois", (hookfn
) h_svc_whois
},
86 { "doing_whois_global", (hookfn
) h_svc_whois
},
87 { "server_introduced", (hookfn
) h_svc_server_introduced
},
91 DECLARE_MODULE_AV1(services
, NULL
, NULL
, services_clist
, NULL
, services_hfnlist
, "$Revision: 1907 $");
94 me_su(struct Client
*client_p
, struct Client
*source_p
,
95 int parc
, const char *parv
[])
97 struct Client
*target_p
;
99 if(!(source_p
->flags
& FLAGS_SERVICE
))
102 if((target_p
= find_client(parv
[1])) == NULL
)
108 if(EmptyString(parv
[2]))
109 target_p
->user
->suser
[0] = '\0';
111 strlcpy(target_p
->user
->suser
, parv
[2], sizeof(target_p
->user
->suser
));
113 invalidate_bancache_user(target_p
);
119 me_login(struct Client
*client_p
, struct Client
*source_p
,
120 int parc
, const char *parv
[])
122 if(!IsPerson(source_p
))
125 strlcpy(source_p
->user
->suser
, parv
[1], sizeof(source_p
->user
->suser
));
130 clean_nick(const char *nick
)
134 if(EmptyString(nick
) || *nick
== '-' || IsDigit(*nick
))
140 if(!IsNickChar(*nick
))
151 me_rsfnc(struct Client
*client_p
, struct Client
*source_p
,
152 int parc
, const char *parv
[])
154 struct Client
*target_p
;
155 struct Client
*exist_p
;
158 if(!(source_p
->flags
& FLAGS_SERVICE
))
161 if((target_p
= find_person(parv
[1])) == NULL
)
164 if(!MyClient(target_p
))
167 if(!clean_nick(parv
[2]))
170 curts
= atol(parv
[4]);
172 /* if tsinfo is different from what it was when services issued the
173 * RSFNC, then we ignore it. This can happen when a client changes
174 * nicknames before the RSFNC arrives.. --anfl
176 if(target_p
->tsinfo
!= curts
)
179 if((exist_p
= find_named_client(parv
[2])))
183 /* this would be one hell of a race condition to trigger
184 * this one given the tsinfo check above, but its here for
187 if(target_p
== exist_p
)
190 if(MyClient(exist_p
))
191 sendto_one(exist_p
, ":%s KILL %s :(Nickname regained by services)",
192 me
.name
, exist_p
->name
);
194 exist_p
->flags
|= FLAGS_KILLED
;
195 /* Do not send kills to servers for unknowns -- jilles */
196 if(IsClient(exist_p
))
197 kill_client_serv_butone(NULL
, exist_p
, "%s (Nickname regained by services)",
200 snprintf(buf
, sizeof(buf
), "Killed (%s (Nickname regained by services))",
202 exit_client(NULL
, exist_p
, &me
, buf
);
205 newts
= atol(parv
[3]);
207 /* timestamp is older than 15mins, ignore it */
208 if(newts
< (CurrentTime
- 900))
209 newts
= CurrentTime
- 900;
211 target_p
->tsinfo
= newts
;
213 monitor_signoff(target_p
);
215 invalidate_bancache_user(target_p
);
217 sendto_realops_snomask(SNO_NCHANGE
, L_ALL
,
218 "Nick change: From %s to %s [%s@%s]",
219 target_p
->name
, parv
[2], target_p
->username
,
222 sendto_common_channels_local(target_p
, ":%s!%s@%s NICK :%s",
223 target_p
->name
, target_p
->username
,
224 target_p
->host
, parv
[2]);
226 add_history(target_p
, 1);
227 sendto_server(NULL
, NULL
, CAP_TS6
, NOCAPS
, ":%s NICK %s :%ld",
228 use_id(target_p
), parv
[2], (long) target_p
->tsinfo
);
229 sendto_server(NULL
, NULL
, NOCAPS
, CAP_TS6
, ":%s NICK %s :%ld",
230 target_p
->name
, parv
[2], (long) target_p
->tsinfo
);
232 del_from_client_hash(target_p
->name
, target_p
);
233 strcpy(target_p
->name
, parv
[2]);
234 add_to_client_hash(target_p
->name
, target_p
);
236 monitor_signon(target_p
);
238 del_all_accepts(target_p
);
240 comm_note(target_p
->localClient
->fd
, "Nick: %s", target_p
->name
);
246 ** parv[0] = sender prefix
247 ** parv[1] = duration in seconds (0 to remove)
251 me_nickdelay(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
256 if(!(source_p
->flags
& FLAGS_SERVICE
))
259 duration
= atoi(parv
[1]);
262 nd
= irc_dictionary_retrieve(nd_dict
, parv
[2]);
268 if (duration
> 86400)
270 add_nd_entry(parv
[2]);
271 nd
= irc_dictionary_retrieve(nd_dict
, parv
[2]);
273 nd
->expire
= CurrentTime
+ duration
;
280 h_svc_server_introduced(hook_data_client
*hdata
)
284 DLINK_FOREACH(ptr
, service_list
.head
)
286 if(!irccmp((const char *) ptr
->data
, hdata
->target
->name
))
288 hdata
->target
->flags
|= FLAGS_SERVICE
;
295 h_svc_whois(hook_data_client
*data
)
297 char *p
= data
->target
->user
->suser
;
300 /* Try to strip off any leading digits as this may be used to
301 * store both an ID number and an account name in one field.
302 * If only digits are present, leave as is.
307 p
= data
->target
->user
->suser
;
309 sendto_one(data
->client
, form_str(RPL_WHOISLOGGEDIN
),
310 get_id(&me
, data
->client
),
311 get_id(data
->client
, data
->client
),
312 data
->target
->name
, p
);
317 h_svc_stats(hook_data_int
*data
)
319 char statchar
= (char) data
->arg2
;
322 if (statchar
== 'U' && IsOper(data
->client
))
324 DLINK_FOREACH(ptr
, service_list
.head
)
326 sendto_one_numeric(data
->client
, RPL_STATSULINE
,
327 form_str(RPL_STATSULINE
),
328 ptr
->data
, "*", "*", "s");