]>
Commit | Line | Data |
---|---|---|
c86edd1d Q |
1 | /* localuser.c */ |
2 | ||
3 | #include "../nick/nick.h" | |
4 | #include "../lib/base64.h" | |
526e7c1d | 5 | #include "../lib/sstring.h" |
c86edd1d Q |
6 | #include "../irc/irc.h" |
7 | #include "../irc/irc_config.h" | |
8 | #include "../core/hooks.h" | |
9 | #include "../core/error.h" | |
87698d77 | 10 | #include "../lib/version.h" |
c86edd1d Q |
11 | #include "localuser.h" |
12 | ||
13 | #include <string.h> | |
14 | #include <stdarg.h> | |
15 | #include <stdio.h> | |
9cc363f1 | 16 | #include <inttypes.h> |
c86edd1d | 17 | |
70b0a4e5 | 18 | MODULE_VERSION(""); |
87698d77 | 19 | |
c86edd1d Q |
20 | int currentlocalunum; |
21 | UserMessageHandler umhandlers[MAXLOCALUSER+1]; | |
22 | ||
526e7c1d P |
23 | typedef struct pendingkill { |
24 | nick *source, *target; | |
25 | sstring *reason; | |
26 | struct pendingkill *next; | |
27 | } pendingkill; | |
28 | ||
29 | pendingkill *pendingkilllist; | |
30 | ||
c86edd1d | 31 | void checklocalkill(int hooknum, void *nick); |
526e7c1d P |
32 | void clearpendingkills(int hooknum, void *arg); |
33 | void checkpendingkills(int hooknum, void *arg); | |
34 | void _killuser(nick *source, nick *target, char *reason); | |
c86edd1d Q |
35 | |
36 | void _init() { | |
37 | int i; | |
38 | ||
39 | for (i=0;i<=MAXLOCALUSER;i++) { | |
40 | umhandlers[i]=NULL; | |
41 | } | |
42 | currentlocalunum=1; | |
526e7c1d | 43 | pendingkilllist=NULL; |
c86edd1d | 44 | registerhook(HOOK_IRC_SENDBURSTNICKS,&sendnickburst); |
acd438c7 | 45 | registerhook(HOOK_NICK_KILL,&checklocalkill); |
ff99b5c0 | 46 | registerhook(HOOK_NICK_LOSTNICK,&checkpendingkills); /* CHECK ME -> should this hook KILL or LOSTNICK or BOTH */ |
526e7c1d | 47 | registerhook(HOOK_CORE_ENDOFHOOKSQUEUE,&clearpendingkills); |
c86edd1d Q |
48 | registerserverhandler("P",&handleprivatemsgcmd,2); |
49 | registerserverhandler("O",&handleprivatenoticecmd, 2); | |
50 | } | |
51 | ||
df3bf970 CP |
52 | void _fini() { |
53 | pendingkill *pk; | |
54 | ||
55 | for (pk=pendingkilllist;pk;pk=pendingkilllist) { | |
56 | pendingkilllist = pk->next; | |
57 | freesstring(pk->reason); | |
58 | free(pk); | |
59 | } | |
65f2c6a3 | 60 | |
61 | deregisterhook(HOOK_IRC_SENDBURSTNICKS,&sendnickburst); | |
62 | deregisterhook(HOOK_NICK_KILL,&checklocalkill); | |
63 | deregisterhook(HOOK_NICK_LOSTNICK,&checkpendingkills); /* CHECK ME -> should this hook KILL or LOSTNICK or BOTH */ | |
64 | deregisterhook(HOOK_CORE_ENDOFHOOKSQUEUE,&clearpendingkills); | |
646b8161 | 65 | |
66 | deregisterserverhandler("P",&handleprivatemsgcmd); | |
67 | deregisterserverhandler("O",&handleprivatenoticecmd); | |
df3bf970 CP |
68 | } |
69 | ||
c86edd1d | 70 | /* |
c4ffdb9b | 71 | * registerlocaluserflags: |
c86edd1d Q |
72 | * This function creates a local user, and broadcasts it's existence to the net (if connected). |
73 | */ | |
74 | ||
c4ffdb9b | 75 | nick *registerlocaluserflags(char *nickname, char *ident, char *host, char *realname, char *authname, unsigned long authid, flag_t accountflags, flag_t umodes, UserMessageHandler handler) { |
c86edd1d Q |
76 | int i; |
77 | nick *newuser,*np; | |
526e7c1d P |
78 | struct irc_in_addr ipaddress; |
79 | ||
c86edd1d | 80 | i=0; |
95ee3dac | 81 | currentlocalunum=(currentlocalunum+1)%262142; |
c86edd1d Q |
82 | while (servernicks[numerictolong(mynumeric->content,2)][currentlocalunum&MAXLOCALUSER]!=NULL) { |
83 | /* Numeric 262143 on our server is used for "nouser" by the channels module, so cannot be allocated */ | |
84 | currentlocalunum=(currentlocalunum+1)%262142; | |
85 | if (++i>MAXLOCALUSER) { | |
86 | return NULL; | |
87 | } | |
88 | } | |
89 | ||
90 | /* This code is very similar to stuff in nick.c... */ | |
91 | newuser=newnick(); | |
92 | newuser->numeric=(numerictolong(mynumeric->content,2)<<18)|(currentlocalunum); | |
93 | strncpy(newuser->nick,nickname,NICKLEN); | |
94 | newuser->nick[NICKLEN]='\0'; | |
95 | strncpy(newuser->ident,ident,USERLEN); | |
96 | newuser->ident[USERLEN]='\0'; | |
97 | newuser->host=findorcreatehost(host); | |
98 | newuser->realname=findorcreaterealname(realname); | |
99 | newuser->nextbyhost=newuser->host->nicks; | |
100 | newuser->host->nicks=newuser; | |
101 | newuser->nextbyrealname=newuser->realname->nicks; | |
102 | newuser->realname->nicks=newuser; | |
103 | newuser->umodes=umodes; | |
3294b10b | 104 | |
526e7c1d | 105 | memset(&ipaddress, 0, sizeof(ipaddress)); |
c426783d | 106 | ((unsigned short *)(ipaddress.in6_16))[5] = 65535; |
4f077f54 P |
107 | ((unsigned short *)(ipaddress.in6_16))[6] = 127; |
108 | ((unsigned char *)(ipaddress.in6_16))[14] = 1; | |
109 | ((unsigned char *)(ipaddress.in6_16))[15] = (currentlocalunum%253)+1; | |
526e7c1d P |
110 | |
111 | newuser->ipnode = refnode(iptree, &ipaddress, PATRICIA_MAXBITS); | |
96644df6 | 112 | node_increment_usercount(newuser->ipnode); |
c426783d | 113 | |
c86edd1d Q |
114 | newuser->timestamp=getnettime(); |
115 | newuser->shident=NULL; | |
116 | newuser->sethost=NULL; | |
5144ddc4 | 117 | newuser->away=NULL; |
c86edd1d Q |
118 | newuser->marker=0; |
119 | memset(newuser->exts, 0, MAXNICKEXTS * sizeof(void *)); | |
120 | ||
f00ee067 CP |
121 | if (IsOper(newuser)) { |
122 | newuser->opername = getsstring("-", ACCOUNTLEN); | |
123 | } else { | |
124 | newuser->opername = NULL; | |
125 | } | |
3294b10b CP |
126 | |
127 | newuser->accountts=0; | |
128 | newuser->auth=NULL; | |
3404a8f0 | 129 | newuser->authname=NULLAUTHNAME; |
c86edd1d | 130 | if (IsAccount(newuser)) { |
47657339 C |
131 | newuser->accountts=newuser->timestamp; |
132 | if (authid) { | |
3294b10b CP |
133 | newuser->auth=findorcreateauthname(authid, authname); |
134 | newuser->authname=newuser->auth->name; | |
47657339 C |
135 | newuser->auth->usercount++; |
136 | newuser->nextbyauthname=newuser->auth->nicks; | |
137 | newuser->auth->nicks=newuser; | |
0b0fb773 | 138 | newuser->auth->flags=accountflags; |
47657339 | 139 | } else { |
3294b10b CP |
140 | /* |
141 | this is done for three reasons: | |
142 | 1: so I don't have to change 500 pieces of code | |
143 | 2: so services can be authed with special reserved ids | |
144 | 3: saves space over the old authname per user method | |
145 | */ | |
146 | newuser->authname=malloc(strlen(authname) + 1); | |
147 | strcpy(newuser->authname,authname); | |
47657339 | 148 | } |
c86edd1d | 149 | } |
3294b10b | 150 | |
c86edd1d Q |
151 | if (connected) { |
152 | /* Check for nick collision */ | |
153 | if ((np=getnickbynick(nickname))!=NULL) { | |
154 | /* Make sure we will win the collision */ | |
155 | newuser->timestamp=(np->timestamp-1); | |
156 | killuser(NULL, np, "Nick collision"); | |
157 | } | |
158 | sendnickmsg(newuser); | |
159 | } | |
160 | ||
161 | if (handler!=NULL) { | |
162 | umhandlers[(currentlocalunum&MAXLOCALUSER)]=handler; | |
163 | } | |
164 | ||
165 | *(gethandlebynumeric(newuser->numeric))=newuser; | |
166 | addnicktohash(newuser); | |
167 | triggerhook(HOOK_NICK_NEWNICK,newuser); | |
168 | ||
169 | return newuser; | |
170 | } | |
171 | ||
172 | /* | |
173 | * renamelocaluser: | |
174 | * This function changes the name of a given local user | |
175 | */ | |
176 | ||
177 | int renamelocaluser(nick *np, char *newnick) { | |
178 | nick *np2; | |
526e7c1d | 179 | char ipbuf[25]; |
c86edd1d | 180 | time_t timestamp=getnettime(); |
2fdef282 CP |
181 | void *harg[2]; |
182 | char oldnick[NICKLEN+1]; | |
183 | ||
c86edd1d Q |
184 | if (!np) |
185 | return -1; | |
186 | ||
187 | if (strlen(newnick) > NICKLEN) | |
188 | return -1; | |
189 | ||
190 | if (homeserver(np->numeric)!=mylongnum) | |
191 | return -1; | |
192 | ||
2fdef282 CP |
193 | strncpy(oldnick,np->nick,NICKLEN); |
194 | oldnick[NICKLEN]='\0'; | |
195 | harg[0]=(void *)np; | |
196 | harg[1]=(void *)oldnick; | |
197 | ||
c86edd1d Q |
198 | if ((np2=getnickbynick(newnick))) { |
199 | if (np2==np) { | |
200 | /* Case only name change */ | |
201 | strncpy(np->nick,newnick,NICKLEN); | |
202 | np->nick[NICKLEN]='\0'; | |
58a4da4a | 203 | irc_send("%s N %s %jd",iptobase64(ipbuf, &(np->p_ipaddr), sizeof(ipbuf), 1),np->nick,(intmax_t)np->timestamp); |
2fdef282 | 204 | triggerhook(HOOK_NICK_RENAME,harg); |
c86edd1d Q |
205 | return 0; |
206 | } else { | |
207 | /* Kill other user and drop through */ | |
208 | timestamp=np2->timestamp-1; | |
209 | killuser(NULL, np2, "Nick collision"); | |
210 | } | |
211 | } | |
212 | ||
213 | np->timestamp=timestamp; | |
214 | removenickfromhash(np); | |
215 | strncpy(np->nick,newnick,NICKLEN); | |
216 | np->nick[NICKLEN]='\0'; | |
217 | addnicktohash(np); | |
58a4da4a | 218 | irc_send("%s N %s %jd",longtonumeric(np->numeric,5),np->nick,(intmax_t)np->timestamp); |
2fdef282 | 219 | triggerhook(HOOK_NICK_RENAME,harg); |
c86edd1d Q |
220 | |
221 | return 0; | |
222 | } | |
223 | ||
224 | /* | |
225 | * deregisterlocaluser: | |
226 | * This function removes the given local user from the network | |
227 | */ | |
228 | ||
229 | int deregisterlocaluser(nick *np, char *reason) { | |
c86edd1d | 230 | long numeric; |
73ab573f | 231 | char reasonstr[512]; |
232 | void *harg[2]; | |
c86edd1d Q |
233 | |
234 | if (np==NULL || (homeserver(np->numeric)!=mylongnum)) { | |
235 | /* Non-existent user, or user not on this server */ | |
236 | return -1; | |
237 | } | |
238 | ||
239 | if (reason==NULL || *reason=='\0') { | |
73ab573f | 240 | sprintf(reasonstr,"Quit"); |
241 | } else { | |
242 | snprintf(reasonstr,510,"Quit: %s",reason); | |
c86edd1d Q |
243 | } |
244 | ||
73ab573f | 245 | harg[0]=np; |
246 | harg[1]=reasonstr; | |
247 | ||
248 | triggerhook(HOOK_NICK_QUIT, harg); | |
249 | ||
c86edd1d Q |
250 | numeric=np->numeric; |
251 | umhandlers[np->numeric&MAXLOCALUSER]=NULL; | |
252 | deletenick(np); | |
253 | if (connected) { | |
73ab573f | 254 | irc_send("%s Q :%s",longtonumeric(numeric,5),reasonstr); |
c86edd1d Q |
255 | } |
256 | ||
257 | return 0; | |
258 | } | |
259 | ||
c5f1f827 CP |
260 | /* |
261 | * hooklocaluserhandler: | |
262 | * This function adds a new handler to the hook chain for a local user | |
263 | * THIS RELIES ON MODULES BEING UNLOADED IN THE CORRECT ORDER. | |
264 | */ | |
265 | UserMessageHandler hooklocaluserhandler(nick *np, UserMessageHandler newhandler) { | |
266 | UserMessageHandler oldhandler = NULL; | |
267 | if (np==NULL || (homeserver(np->numeric)!=mylongnum)) { | |
268 | /* Non-existent user, or user not on this server */ | |
269 | return NULL; | |
270 | } | |
271 | oldhandler = umhandlers[np->numeric&MAXLOCALUSER]; | |
272 | umhandlers[np->numeric&MAXLOCALUSER]=newhandler; | |
273 | return oldhandler; | |
274 | } | |
275 | ||
c86edd1d Q |
276 | /* |
277 | * sendnickmsg: | |
278 | * Sends details of a given local nick to the network. | |
279 | */ | |
280 | ||
281 | void sendnickmsg(nick *np) { | |
282 | char numericbuf[6]; | |
843184e3 CP |
283 | char ipbuf[25], operbuf[ACCOUNTLEN + 5]; |
284 | char accountbuf[100]; | |
c86edd1d Q |
285 | |
286 | strncpy(numericbuf,longtonumeric(np->numeric,5),5); | |
287 | numericbuf[5]='\0'; | |
843184e3 CP |
288 | |
289 | if(IsOper(np) && (serverlist[myhub].flags & SMODE_OPERNAME)) { | |
290 | snprintf(operbuf,sizeof(operbuf)," %s",np->opername?np->opername->content:"-"); | |
291 | } else { | |
292 | operbuf[0] = '\0'; | |
293 | } | |
294 | ||
3294b10b | 295 | accountbuf[0]='\0'; |
47657339 | 296 | if (IsAccount(np)) { |
0b0fb773 CP |
297 | if (np->auth) { |
298 | if(np->auth->flags) { | |
9cc363f1 | 299 | snprintf(accountbuf,sizeof(accountbuf)," %s:%ld:%lu:%"PRIu64,np->authname,np->accountts,np->auth->userid,np->auth->flags); |
0b0fb773 | 300 | } else { |
843184e3 | 301 | snprintf(accountbuf,sizeof(accountbuf)," %s:%ld:%lu",np->authname,np->accountts,np->auth->userid); |
0b0fb773 | 302 | } |
3294b10b | 303 | } else if(np->authname) { |
c4ffdb9b | 304 | snprintf(accountbuf,sizeof(accountbuf)," %s:%ld:0",np->authname,np->accountts); |
47657339 | 305 | } |
47657339 | 306 | } |
843184e3 CP |
307 | |
308 | irc_send("%s N %s 1 %ld %s %s %s%s%s %s %s :%s", | |
309 | mynumeric->content,np->nick,np->timestamp,np->ident,np->host->name->content, | |
310 | printflags(np->umodes,umodeflags),operbuf,accountbuf,iptobase64(ipbuf,&(np->p_ipaddr), | |
311 | sizeof(ipbuf),1),numericbuf,np->realname->name->content); | |
c86edd1d Q |
312 | } |
313 | ||
314 | void sendnickburst(int hooknum, void *arg) { | |
315 | /* Send nick messages for all local users */ | |
316 | nick **nh; | |
317 | int i; | |
318 | ||
319 | nh=servernicks[numerictolong(mynumeric->content,2)]; | |
320 | for (i=0;i<=MAXLOCALUSER;i++) { | |
321 | if (nh[i]!=NULL) { | |
322 | sendnickmsg(nh[i]); | |
323 | } | |
324 | } | |
325 | } | |
326 | ||
327 | /* Check for a kill of a local user */ | |
acd438c7 CP |
328 | void checklocalkill(int hooknum, void *arg) { |
329 | void **args=arg; | |
330 | nick *target=args[0]; | |
331 | char *reason=args[1]; | |
c86edd1d | 332 | long numeric; |
acd438c7 CP |
333 | |
334 | void *myargs[1]; | |
335 | myargs[0]=reason; | |
336 | ||
c86edd1d Q |
337 | |
338 | numeric=((nick *)target)->numeric; | |
339 | ||
340 | if (homeserver(numeric)==mylongnum) { | |
341 | if (umhandlers[(numeric)&MAXLOCALUSER]!=NULL) { | |
acd438c7 | 342 | (umhandlers[(numeric)&MAXLOCALUSER])((nick *)target,LU_KILLED,myargs); |
c86edd1d Q |
343 | } |
344 | } | |
345 | } | |
346 | ||
347 | int handleprivatemsgcmd(void *source, int cargc, char **cargv) { | |
348 | return handlemessageornotice(source, cargc, cargv, 0); | |
349 | } | |
350 | ||
351 | int handleprivatenoticecmd(void *source, int cargc, char **cargv) { | |
352 | return handlemessageornotice(source, cargc, cargv, 1); | |
353 | } | |
354 | ||
355 | /* Handle privmsg or notice command addressed to user */ | |
356 | int handlemessageornotice(void *source, int cargc, char **cargv, int isnotice) { | |
357 | nick *sender; | |
358 | nick *target; | |
359 | char *ch; | |
360 | char targetnick[NICKLEN+1]; | |
361 | int foundat; | |
362 | void *nargs[2]; | |
363 | int i; | |
364 | ||
365 | /* Should have target and message */ | |
366 | if (cargc<2) { | |
367 | return CMD_OK; | |
368 | } | |
369 | ||
370 | if (cargv[0][0]=='#' || cargv[0][0]=='+') { | |
371 | /* Channel message/notice */ | |
372 | return CMD_OK; | |
373 | } | |
374 | ||
375 | if ((sender=getnickbynumericstr((char *)source))==NULL) { | |
376 | Error("localuser",ERR_WARNING,"PRIVMSG from non existant user %s",(char *)source); | |
377 | return CMD_OK; | |
378 | } | |
379 | ||
380 | /* Check for a "secure" message (foo@bar) */ | |
381 | foundat=0; | |
382 | for (i=0,ch=cargv[0];(i<=NICKLEN) && (*ch);i++,ch++) { | |
383 | if (*ch=='@') { | |
384 | targetnick[i]='\0'; | |
385 | foundat=1; | |
386 | break; | |
387 | } else { | |
388 | targetnick[i]=*ch; | |
389 | } | |
390 | } | |
391 | ||
392 | if (!foundat) { /* Didn't find an @ sign, assume it's a numeric */ | |
393 | if ((target=getnickbynumericstr(cargv[0]))==NULL) { | |
394 | Error("localuser",ERR_DEBUG,"Couldn't find target for %s",cargv[0]); | |
395 | return CMD_OK; | |
396 | } | |
397 | } else { /* Did find @, do a lookup by nick */ | |
398 | if ((target=getnickbynick(targetnick))==NULL) { | |
399 | Error("localuser",ERR_DEBUG,"Couldn't find target for %s",cargv[0]); | |
bc81aa36 | 400 | irc_send(":%s 401 %s %s :No such nick",myserver->content,sender->nick,cargv[0]); |
c86edd1d Q |
401 | return CMD_OK; |
402 | } | |
403 | } | |
404 | ||
405 | if (homeserver(target->numeric)!=mylongnum) { | |
406 | Error("localuser",ERR_WARNING,"Got message/notice for someone not on my server"); | |
bc81aa36 C |
407 | irc_send(":%s 401 %s %s :No such nick",myserver->content,sender->nick,cargv[0]); |
408 | return CMD_OK; | |
409 | } | |
410 | ||
411 | if (foundat && !IsService(target)) { | |
412 | Error("localuser",ERR_DEBUG,"Received secure message for %s, but user is not a service",cargv[0]); | |
413 | irc_send(":%s 401 %s %s :No such nick",myserver->content,sender->nick,cargv[0]); | |
c86edd1d Q |
414 | return CMD_OK; |
415 | } | |
416 | ||
417 | if (umhandlers[(target->numeric)&MAXLOCALUSER]==NULL) { | |
418 | /* No handler anyhow.. */ | |
419 | return CMD_OK; | |
420 | } | |
421 | ||
422 | /* Dispatch the message. */ | |
423 | nargs[0]=(void *)sender; | |
424 | nargs[1]=(void *)cargv[1]; | |
425 | (umhandlers[(target->numeric)&MAXLOCALUSER])(target,isnotice?LU_PRIVNOTICE:(foundat?LU_SECUREMSG:LU_PRIVMSG),nargs); | |
426 | ||
427 | return CMD_OK; | |
428 | } | |
429 | ||
430 | /* Send message to user */ | |
431 | void sendmessagetouser(nick *source, nick *target, char *format, ... ) { | |
432 | char buf[BUFSIZE]; | |
433 | char senderstr[6]; | |
434 | va_list va; | |
435 | ||
436 | longtonumeric2(source->numeric,5,senderstr); | |
437 | ||
438 | va_start(va,format); | |
439 | /* 10 bytes of numeric, 5 bytes of fixed format + terminator = 17 bytes */ | |
440 | /* So max sendable message is 495 bytes. Of course, a client won't be able | |
441 | * to receive this.. */ | |
442 | ||
443 | vsnprintf(buf,BUFSIZE-17,format,va); | |
444 | va_end(va); | |
445 | ||
446 | if (homeserver(target->numeric)!=mylongnum) | |
447 | irc_send("%s P %s :%s",senderstr,longtonumeric(target->numeric,5),buf); | |
448 | } | |
449 | ||
450 | /* Send messageto server, we don't check, but noones going to want to put a server pointer in anyway... */ | |
451 | void sendsecuremessagetouser(nick *source, nick *target, char *servername, char *format, ... ) { | |
452 | char buf[BUFSIZE]; | |
453 | char senderstr[6]; | |
454 | va_list va; | |
455 | ||
456 | longtonumeric2(source->numeric,5,senderstr); | |
457 | ||
458 | va_start(va,format); | |
459 | /* 10 bytes of numeric, 5 bytes of fixed format + terminator = 17 bytes */ | |
460 | /* So max sendable message is 495 bytes. Of course, a client won't be able | |
461 | * to receive this.. */ | |
462 | ||
463 | vsnprintf(buf,BUFSIZE-17,format,va); | |
464 | va_end(va); | |
465 | ||
466 | if (homeserver(target->numeric)!=mylongnum) | |
467 | irc_send("%s P %s@%s :%s",senderstr,target->nick,servername,buf); | |
468 | } | |
469 | ||
470 | /* Send notice to user */ | |
471 | void sendnoticetouser(nick *source, nick *target, char *format, ... ) { | |
472 | char buf[BUFSIZE]; | |
473 | char senderstr[6]; | |
474 | va_list va; | |
475 | ||
476 | longtonumeric2(source->numeric,5,senderstr); | |
477 | ||
478 | va_start(va,format); | |
479 | /* 10 bytes of numeric, 5 bytes of fixed format + terminator = 17 bytes */ | |
480 | /* So max sendable message is 495 bytes. Of course, a client won't be able | |
481 | * to receive this.. */ | |
482 | ||
483 | vsnprintf(buf,BUFSIZE-17,format,va); | |
484 | va_end(va); | |
485 | ||
486 | if (homeserver(target->numeric)!=mylongnum) | |
487 | irc_send("%s O %s :%s",senderstr,longtonumeric(target->numeric,5),buf); | |
488 | } | |
489 | ||
490 | /* Kill user */ | |
491 | void killuser(nick *source, nick *target, char *format, ... ) { | |
492 | char buf[BUFSIZE]; | |
526e7c1d P |
493 | va_list va; |
494 | pendingkill *pk; | |
495 | ||
496 | va_start(va, format); | |
497 | vsnprintf(buf, BUFSIZE-17, format, va); | |
498 | va_end (va); | |
499 | ||
500 | if (hookqueuelength) { | |
501 | for (pk = pendingkilllist; pk; pk = pk->next) | |
502 | if (pk->target == target) | |
503 | return; | |
504 | ||
a77bd764 | 505 | Error("localuser", ERR_DEBUG, "Adding pending kill for %s", target->nick); |
526e7c1d P |
506 | pk = (pendingkill *)malloc(sizeof(pendingkill)); |
507 | pk->source = source; | |
508 | pk->target = target; | |
509 | pk->reason = getsstring(buf, BUFSIZE); | |
510 | pk->next = pendingkilllist; | |
511 | pendingkilllist = pk; | |
512 | } else { | |
513 | _killuser(source, target, buf); | |
514 | } | |
515 | } | |
516 | ||
ab2c2b20 CP |
517 | void sethostuser(nick *target, char *ident, char *host) { |
518 | irc_send("%s SH %s %s %s", mynumeric->content, longtonumeric(target->numeric, 5), ident, host); | |
519 | } | |
520 | ||
526e7c1d | 521 | void _killuser(nick *source, nick *target, char *reason) { |
c86edd1d | 522 | char senderstr[6]; |
616eddc9 | 523 | char sourcestring[HOSTLEN+NICKLEN+3]; |
d7edba33 | 524 | char reasonstr[512]; |
525 | void *args[2]; | |
c86edd1d Q |
526 | |
527 | if (!source) { | |
528 | /* If we have a null nick, use the server.. */ | |
529 | strcpy(senderstr, mynumeric->content); | |
530 | strcpy(sourcestring, myserver->content); | |
531 | } else { | |
532 | strcpy(senderstr, longtonumeric(source->numeric,5)); | |
533 | sprintf(sourcestring,"%s!%s",source->host->name->content, source->nick); | |
534 | } | |
535 | ||
d7edba33 | 536 | snprintf(reasonstr,512,"%s (%s)",sourcestring,reason); |
537 | reasonstr[511]='\0'; | |
538 | ||
539 | irc_send("%s D %s :%s",senderstr,longtonumeric(target->numeric,5),reasonstr); | |
540 | ||
541 | args[0]=target; | |
542 | args[1]=reasonstr; | |
543 | triggerhook(HOOK_NICK_KILL, args); | |
544 | ||
c86edd1d Q |
545 | deletenick(target); |
546 | } | |
547 | ||
526e7c1d P |
548 | void clearpendingkills(int hooknum, void *arg) { |
549 | pendingkill *pk; | |
550 | ||
551 | pk = pendingkilllist; | |
552 | while (pk) { | |
553 | pendingkilllist = pk->next; | |
554 | ||
555 | if (pk->target) { | |
a77bd764 | 556 | Error("localuser", ERR_DEBUG, "Processing pending kill for %s", pk->target->nick); |
526e7c1d P |
557 | _killuser(pk->source, pk->target, pk->reason->content); |
558 | } | |
559 | ||
560 | freesstring(pk->reason); | |
561 | free(pk); | |
562 | pk = pendingkilllist; | |
563 | } | |
564 | } | |
565 | ||
566 | void checkpendingkills(int hooknum, void *arg) { | |
567 | nick *np = (nick *)arg; | |
568 | pendingkill *pk; | |
569 | ||
570 | for (pk=pendingkilllist; pk; pk = pk->next) { | |
571 | if (pk->source == np) { | |
572 | Error("localuser", ERR_INFO, "Pending kill source %s got deleted, NULL'ing source for pending kill", np->nick); | |
573 | pk->source = NULL; | |
574 | } | |
575 | if (pk->target == np) { | |
576 | Error("localuser", ERR_INFO, "Pending kill target %s got deleted, NULL'ing target for pending kill", np->nick); | |
577 | pk->target = NULL; | |
578 | } | |
579 | } | |
580 | } | |
581 | ||
3294b10b | 582 | void sendaccountmessage(nick *np) { |
94dc9910 | 583 | if (connected && IsAccount(np)) { |
3294b10b CP |
584 | if (np->auth) { |
585 | if (np->auth->flags) { | |
9cc363f1 | 586 | irc_send("%s AC %s %s %ld %lu %"PRIu64,mynumeric->content, longtonumeric(np->numeric,5), np->authname, np->accountts, np->auth->userid, np->auth->flags); |
3294b10b CP |
587 | } else { |
588 | irc_send("%s AC %s %s %ld %lu",mynumeric->content, longtonumeric(np->numeric,5), np->authname, np->accountts, np->auth->userid); | |
589 | } | |
590 | } else { | |
591 | irc_send("%s AC %s %s %ld 0",mynumeric->content, longtonumeric(np->numeric,5), np->authname, np->accountts); | |
592 | } | |
593 | } | |
594 | } | |
595 | ||
596 | /* Auth user, don't use to set flags after authing */ | |
92acf9ae | 597 | void localusersetaccount(nick *np, char *accname, unsigned long accid, u_int64_t accountflags, time_t authTS) { |
c86edd1d Q |
598 | if (IsAccount(np)) { |
599 | Error("localuser",ERR_WARNING,"Tried to set account on user %s already authed", np->nick); | |
600 | return; | |
601 | } | |
602 | ||
603 | SetAccount(np); | |
b17a30ed | 604 | np->accountts=authTS?authTS:getnettime(); |
47657339 C |
605 | |
606 | if (accid) { | |
5a335041 | 607 | np->auth=findorcreateauthname(accid, accname); |
47657339 | 608 | np->auth->usercount++; |
3294b10b | 609 | np->authname=np->auth->name; |
47657339 C |
610 | np->nextbyauthname=np->auth->nicks; |
611 | np->auth->nicks=np; | |
0b0fb773 | 612 | np->auth->flags=accountflags; |
47657339 C |
613 | } else { |
614 | np->auth=NULL; | |
3294b10b CP |
615 | np->authname=malloc(strlen(accname) + 1); |
616 | strcpy(np->authname,accname); | |
47657339 | 617 | } |
c86edd1d | 618 | |
3294b10b | 619 | sendaccountmessage(np); |
c86edd1d Q |
620 | |
621 | triggerhook(HOOK_NICK_ACCOUNT, np); | |
622 | } | |
623 | ||
eac66732 CP |
624 | void localusersetumodes(nick *np, flag_t newmodes) { |
625 | if (connected) { | |
626 | irc_send("%s M %s %s", longtonumeric(np->numeric,5), np->nick, printflagdiff(np->umodes, newmodes, umodeflags)); | |
627 | } | |
628 | ||
629 | np->umodes = newmodes; | |
630 | } | |
3294b10b | 631 | |
92acf9ae | 632 | void localusersetaccountflags(authname *anp, u_int64_t accountflags) { |
3294b10b CP |
633 | void *arg[2]; |
634 | nick *np; | |
92acf9ae | 635 | u_int64_t oldflags = anp->flags; |
3294b10b | 636 | |
92acf9ae CP |
637 | arg[0] = anp; |
638 | arg[1] = &oldflags; | |
3294b10b CP |
639 | anp->flags = accountflags; |
640 | ||
94dc9910 | 641 | for(np=anp->nicks;np;np=np->nextbyauthname) |
3294b10b CP |
642 | sendaccountmessage(np); |
643 | ||
92acf9ae | 644 | triggerhook(HOOK_AUTH_FLAGSUPDATED, arg); |
3294b10b | 645 | } |