]>
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 Q |
180 | time_t timestamp=getnettime(); |
181 | ||
182 | if (!np) | |
183 | return -1; | |
184 | ||
185 | if (strlen(newnick) > NICKLEN) | |
186 | return -1; | |
187 | ||
188 | if (homeserver(np->numeric)!=mylongnum) | |
189 | return -1; | |
190 | ||
191 | if ((np2=getnickbynick(newnick))) { | |
192 | if (np2==np) { | |
193 | /* Case only name change */ | |
194 | strncpy(np->nick,newnick,NICKLEN); | |
195 | np->nick[NICKLEN]='\0'; | |
58a4da4a | 196 | irc_send("%s N %s %jd",iptobase64(ipbuf, &(np->p_ipaddr), sizeof(ipbuf), 1),np->nick,(intmax_t)np->timestamp); |
526e7c1d | 197 | triggerhook(HOOK_NICK_RENAME,np); |
c86edd1d Q |
198 | return 0; |
199 | } else { | |
200 | /* Kill other user and drop through */ | |
201 | timestamp=np2->timestamp-1; | |
202 | killuser(NULL, np2, "Nick collision"); | |
203 | } | |
204 | } | |
205 | ||
206 | np->timestamp=timestamp; | |
207 | removenickfromhash(np); | |
208 | strncpy(np->nick,newnick,NICKLEN); | |
209 | np->nick[NICKLEN]='\0'; | |
210 | addnicktohash(np); | |
58a4da4a | 211 | irc_send("%s N %s %jd",longtonumeric(np->numeric,5),np->nick,(intmax_t)np->timestamp); |
c86edd1d Q |
212 | triggerhook(HOOK_NICK_RENAME,np); |
213 | ||
214 | return 0; | |
215 | } | |
216 | ||
217 | /* | |
218 | * deregisterlocaluser: | |
219 | * This function removes the given local user from the network | |
220 | */ | |
221 | ||
222 | int deregisterlocaluser(nick *np, char *reason) { | |
c86edd1d | 223 | long numeric; |
73ab573f | 224 | char reasonstr[512]; |
225 | void *harg[2]; | |
c86edd1d Q |
226 | |
227 | if (np==NULL || (homeserver(np->numeric)!=mylongnum)) { | |
228 | /* Non-existent user, or user not on this server */ | |
229 | return -1; | |
230 | } | |
231 | ||
232 | if (reason==NULL || *reason=='\0') { | |
73ab573f | 233 | sprintf(reasonstr,"Quit"); |
234 | } else { | |
235 | snprintf(reasonstr,510,"Quit: %s",reason); | |
c86edd1d Q |
236 | } |
237 | ||
73ab573f | 238 | harg[0]=np; |
239 | harg[1]=reasonstr; | |
240 | ||
241 | triggerhook(HOOK_NICK_QUIT, harg); | |
242 | ||
c86edd1d Q |
243 | numeric=np->numeric; |
244 | umhandlers[np->numeric&MAXLOCALUSER]=NULL; | |
245 | deletenick(np); | |
246 | if (connected) { | |
73ab573f | 247 | irc_send("%s Q :%s",longtonumeric(numeric,5),reasonstr); |
c86edd1d Q |
248 | } |
249 | ||
250 | return 0; | |
251 | } | |
252 | ||
c5f1f827 CP |
253 | /* |
254 | * hooklocaluserhandler: | |
255 | * This function adds a new handler to the hook chain for a local user | |
256 | * THIS RELIES ON MODULES BEING UNLOADED IN THE CORRECT ORDER. | |
257 | */ | |
258 | UserMessageHandler hooklocaluserhandler(nick *np, UserMessageHandler newhandler) { | |
259 | UserMessageHandler oldhandler = NULL; | |
260 | if (np==NULL || (homeserver(np->numeric)!=mylongnum)) { | |
261 | /* Non-existent user, or user not on this server */ | |
262 | return NULL; | |
263 | } | |
264 | oldhandler = umhandlers[np->numeric&MAXLOCALUSER]; | |
265 | umhandlers[np->numeric&MAXLOCALUSER]=newhandler; | |
266 | return oldhandler; | |
267 | } | |
268 | ||
c86edd1d Q |
269 | /* |
270 | * sendnickmsg: | |
271 | * Sends details of a given local nick to the network. | |
272 | */ | |
273 | ||
274 | void sendnickmsg(nick *np) { | |
275 | char numericbuf[6]; | |
843184e3 CP |
276 | char ipbuf[25], operbuf[ACCOUNTLEN + 5]; |
277 | char accountbuf[100]; | |
c86edd1d Q |
278 | |
279 | strncpy(numericbuf,longtonumeric(np->numeric,5),5); | |
280 | numericbuf[5]='\0'; | |
843184e3 CP |
281 | |
282 | if(IsOper(np) && (serverlist[myhub].flags & SMODE_OPERNAME)) { | |
283 | snprintf(operbuf,sizeof(operbuf)," %s",np->opername?np->opername->content:"-"); | |
284 | } else { | |
285 | operbuf[0] = '\0'; | |
286 | } | |
287 | ||
3294b10b | 288 | accountbuf[0]='\0'; |
47657339 | 289 | if (IsAccount(np)) { |
0b0fb773 CP |
290 | if (np->auth) { |
291 | if(np->auth->flags) { | |
9cc363f1 | 292 | snprintf(accountbuf,sizeof(accountbuf)," %s:%ld:%lu:%"PRIu64,np->authname,np->accountts,np->auth->userid,np->auth->flags); |
0b0fb773 | 293 | } else { |
843184e3 | 294 | snprintf(accountbuf,sizeof(accountbuf)," %s:%ld:%lu",np->authname,np->accountts,np->auth->userid); |
0b0fb773 | 295 | } |
3294b10b | 296 | } else if(np->authname) { |
c4ffdb9b | 297 | snprintf(accountbuf,sizeof(accountbuf)," %s:%ld:0",np->authname,np->accountts); |
47657339 | 298 | } |
47657339 | 299 | } |
843184e3 CP |
300 | |
301 | irc_send("%s N %s 1 %ld %s %s %s%s%s %s %s :%s", | |
302 | mynumeric->content,np->nick,np->timestamp,np->ident,np->host->name->content, | |
303 | printflags(np->umodes,umodeflags),operbuf,accountbuf,iptobase64(ipbuf,&(np->p_ipaddr), | |
304 | sizeof(ipbuf),1),numericbuf,np->realname->name->content); | |
c86edd1d Q |
305 | } |
306 | ||
307 | void sendnickburst(int hooknum, void *arg) { | |
308 | /* Send nick messages for all local users */ | |
309 | nick **nh; | |
310 | int i; | |
311 | ||
312 | nh=servernicks[numerictolong(mynumeric->content,2)]; | |
313 | for (i=0;i<=MAXLOCALUSER;i++) { | |
314 | if (nh[i]!=NULL) { | |
315 | sendnickmsg(nh[i]); | |
316 | } | |
317 | } | |
318 | } | |
319 | ||
320 | /* Check for a kill of a local user */ | |
acd438c7 CP |
321 | void checklocalkill(int hooknum, void *arg) { |
322 | void **args=arg; | |
323 | nick *target=args[0]; | |
324 | char *reason=args[1]; | |
c86edd1d | 325 | long numeric; |
acd438c7 CP |
326 | |
327 | void *myargs[1]; | |
328 | myargs[0]=reason; | |
329 | ||
c86edd1d Q |
330 | |
331 | numeric=((nick *)target)->numeric; | |
332 | ||
333 | if (homeserver(numeric)==mylongnum) { | |
334 | if (umhandlers[(numeric)&MAXLOCALUSER]!=NULL) { | |
acd438c7 | 335 | (umhandlers[(numeric)&MAXLOCALUSER])((nick *)target,LU_KILLED,myargs); |
c86edd1d Q |
336 | } |
337 | } | |
338 | } | |
339 | ||
340 | int handleprivatemsgcmd(void *source, int cargc, char **cargv) { | |
341 | return handlemessageornotice(source, cargc, cargv, 0); | |
342 | } | |
343 | ||
344 | int handleprivatenoticecmd(void *source, int cargc, char **cargv) { | |
345 | return handlemessageornotice(source, cargc, cargv, 1); | |
346 | } | |
347 | ||
348 | /* Handle privmsg or notice command addressed to user */ | |
349 | int handlemessageornotice(void *source, int cargc, char **cargv, int isnotice) { | |
350 | nick *sender; | |
351 | nick *target; | |
352 | char *ch; | |
353 | char targetnick[NICKLEN+1]; | |
354 | int foundat; | |
355 | void *nargs[2]; | |
356 | int i; | |
357 | ||
358 | /* Should have target and message */ | |
359 | if (cargc<2) { | |
360 | return CMD_OK; | |
361 | } | |
362 | ||
363 | if (cargv[0][0]=='#' || cargv[0][0]=='+') { | |
364 | /* Channel message/notice */ | |
365 | return CMD_OK; | |
366 | } | |
367 | ||
368 | if ((sender=getnickbynumericstr((char *)source))==NULL) { | |
369 | Error("localuser",ERR_WARNING,"PRIVMSG from non existant user %s",(char *)source); | |
370 | return CMD_OK; | |
371 | } | |
372 | ||
373 | /* Check for a "secure" message (foo@bar) */ | |
374 | foundat=0; | |
375 | for (i=0,ch=cargv[0];(i<=NICKLEN) && (*ch);i++,ch++) { | |
376 | if (*ch=='@') { | |
377 | targetnick[i]='\0'; | |
378 | foundat=1; | |
379 | break; | |
380 | } else { | |
381 | targetnick[i]=*ch; | |
382 | } | |
383 | } | |
384 | ||
385 | if (!foundat) { /* Didn't find an @ sign, assume it's a numeric */ | |
386 | if ((target=getnickbynumericstr(cargv[0]))==NULL) { | |
387 | Error("localuser",ERR_DEBUG,"Couldn't find target for %s",cargv[0]); | |
388 | return CMD_OK; | |
389 | } | |
390 | } else { /* Did find @, do a lookup by nick */ | |
391 | if ((target=getnickbynick(targetnick))==NULL) { | |
392 | Error("localuser",ERR_DEBUG,"Couldn't find target for %s",cargv[0]); | |
bc81aa36 | 393 | irc_send(":%s 401 %s %s :No such nick",myserver->content,sender->nick,cargv[0]); |
c86edd1d Q |
394 | return CMD_OK; |
395 | } | |
396 | } | |
397 | ||
398 | if (homeserver(target->numeric)!=mylongnum) { | |
399 | Error("localuser",ERR_WARNING,"Got message/notice for someone not on my server"); | |
bc81aa36 C |
400 | irc_send(":%s 401 %s %s :No such nick",myserver->content,sender->nick,cargv[0]); |
401 | return CMD_OK; | |
402 | } | |
403 | ||
404 | if (foundat && !IsService(target)) { | |
405 | Error("localuser",ERR_DEBUG,"Received secure message for %s, but user is not a service",cargv[0]); | |
406 | irc_send(":%s 401 %s %s :No such nick",myserver->content,sender->nick,cargv[0]); | |
c86edd1d Q |
407 | return CMD_OK; |
408 | } | |
409 | ||
410 | if (umhandlers[(target->numeric)&MAXLOCALUSER]==NULL) { | |
411 | /* No handler anyhow.. */ | |
412 | return CMD_OK; | |
413 | } | |
414 | ||
415 | /* Dispatch the message. */ | |
416 | nargs[0]=(void *)sender; | |
417 | nargs[1]=(void *)cargv[1]; | |
418 | (umhandlers[(target->numeric)&MAXLOCALUSER])(target,isnotice?LU_PRIVNOTICE:(foundat?LU_SECUREMSG:LU_PRIVMSG),nargs); | |
419 | ||
420 | return CMD_OK; | |
421 | } | |
422 | ||
423 | /* Send message to user */ | |
424 | void sendmessagetouser(nick *source, nick *target, char *format, ... ) { | |
425 | char buf[BUFSIZE]; | |
426 | char senderstr[6]; | |
427 | va_list va; | |
428 | ||
429 | longtonumeric2(source->numeric,5,senderstr); | |
430 | ||
431 | va_start(va,format); | |
432 | /* 10 bytes of numeric, 5 bytes of fixed format + terminator = 17 bytes */ | |
433 | /* So max sendable message is 495 bytes. Of course, a client won't be able | |
434 | * to receive this.. */ | |
435 | ||
436 | vsnprintf(buf,BUFSIZE-17,format,va); | |
437 | va_end(va); | |
438 | ||
439 | if (homeserver(target->numeric)!=mylongnum) | |
440 | irc_send("%s P %s :%s",senderstr,longtonumeric(target->numeric,5),buf); | |
441 | } | |
442 | ||
443 | /* Send messageto server, we don't check, but noones going to want to put a server pointer in anyway... */ | |
444 | void sendsecuremessagetouser(nick *source, nick *target, char *servername, char *format, ... ) { | |
445 | char buf[BUFSIZE]; | |
446 | char senderstr[6]; | |
447 | va_list va; | |
448 | ||
449 | longtonumeric2(source->numeric,5,senderstr); | |
450 | ||
451 | va_start(va,format); | |
452 | /* 10 bytes of numeric, 5 bytes of fixed format + terminator = 17 bytes */ | |
453 | /* So max sendable message is 495 bytes. Of course, a client won't be able | |
454 | * to receive this.. */ | |
455 | ||
456 | vsnprintf(buf,BUFSIZE-17,format,va); | |
457 | va_end(va); | |
458 | ||
459 | if (homeserver(target->numeric)!=mylongnum) | |
460 | irc_send("%s P %s@%s :%s",senderstr,target->nick,servername,buf); | |
461 | } | |
462 | ||
463 | /* Send notice to user */ | |
464 | void sendnoticetouser(nick *source, nick *target, char *format, ... ) { | |
465 | char buf[BUFSIZE]; | |
466 | char senderstr[6]; | |
467 | va_list va; | |
468 | ||
469 | longtonumeric2(source->numeric,5,senderstr); | |
470 | ||
471 | va_start(va,format); | |
472 | /* 10 bytes of numeric, 5 bytes of fixed format + terminator = 17 bytes */ | |
473 | /* So max sendable message is 495 bytes. Of course, a client won't be able | |
474 | * to receive this.. */ | |
475 | ||
476 | vsnprintf(buf,BUFSIZE-17,format,va); | |
477 | va_end(va); | |
478 | ||
479 | if (homeserver(target->numeric)!=mylongnum) | |
480 | irc_send("%s O %s :%s",senderstr,longtonumeric(target->numeric,5),buf); | |
481 | } | |
482 | ||
483 | /* Kill user */ | |
484 | void killuser(nick *source, nick *target, char *format, ... ) { | |
485 | char buf[BUFSIZE]; | |
526e7c1d P |
486 | va_list va; |
487 | pendingkill *pk; | |
488 | ||
489 | va_start(va, format); | |
490 | vsnprintf(buf, BUFSIZE-17, format, va); | |
491 | va_end (va); | |
492 | ||
493 | if (hookqueuelength) { | |
494 | for (pk = pendingkilllist; pk; pk = pk->next) | |
495 | if (pk->target == target) | |
496 | return; | |
497 | ||
a77bd764 | 498 | Error("localuser", ERR_DEBUG, "Adding pending kill for %s", target->nick); |
526e7c1d P |
499 | pk = (pendingkill *)malloc(sizeof(pendingkill)); |
500 | pk->source = source; | |
501 | pk->target = target; | |
502 | pk->reason = getsstring(buf, BUFSIZE); | |
503 | pk->next = pendingkilllist; | |
504 | pendingkilllist = pk; | |
505 | } else { | |
506 | _killuser(source, target, buf); | |
507 | } | |
508 | } | |
509 | ||
ab2c2b20 CP |
510 | void sethostuser(nick *target, char *ident, char *host) { |
511 | irc_send("%s SH %s %s %s", mynumeric->content, longtonumeric(target->numeric, 5), ident, host); | |
512 | } | |
513 | ||
526e7c1d | 514 | void _killuser(nick *source, nick *target, char *reason) { |
c86edd1d | 515 | char senderstr[6]; |
616eddc9 | 516 | char sourcestring[HOSTLEN+NICKLEN+3]; |
d7edba33 | 517 | char reasonstr[512]; |
518 | void *args[2]; | |
c86edd1d Q |
519 | |
520 | if (!source) { | |
521 | /* If we have a null nick, use the server.. */ | |
522 | strcpy(senderstr, mynumeric->content); | |
523 | strcpy(sourcestring, myserver->content); | |
524 | } else { | |
525 | strcpy(senderstr, longtonumeric(source->numeric,5)); | |
526 | sprintf(sourcestring,"%s!%s",source->host->name->content, source->nick); | |
527 | } | |
528 | ||
d7edba33 | 529 | snprintf(reasonstr,512,"%s (%s)",sourcestring,reason); |
530 | reasonstr[511]='\0'; | |
531 | ||
532 | irc_send("%s D %s :%s",senderstr,longtonumeric(target->numeric,5),reasonstr); | |
533 | ||
534 | args[0]=target; | |
535 | args[1]=reasonstr; | |
536 | triggerhook(HOOK_NICK_KILL, args); | |
537 | ||
c86edd1d Q |
538 | deletenick(target); |
539 | } | |
540 | ||
526e7c1d P |
541 | void clearpendingkills(int hooknum, void *arg) { |
542 | pendingkill *pk; | |
543 | ||
544 | pk = pendingkilllist; | |
545 | while (pk) { | |
546 | pendingkilllist = pk->next; | |
547 | ||
548 | if (pk->target) { | |
a77bd764 | 549 | Error("localuser", ERR_DEBUG, "Processing pending kill for %s", pk->target->nick); |
526e7c1d P |
550 | _killuser(pk->source, pk->target, pk->reason->content); |
551 | } | |
552 | ||
553 | freesstring(pk->reason); | |
554 | free(pk); | |
555 | pk = pendingkilllist; | |
556 | } | |
557 | } | |
558 | ||
559 | void checkpendingkills(int hooknum, void *arg) { | |
560 | nick *np = (nick *)arg; | |
561 | pendingkill *pk; | |
562 | ||
563 | for (pk=pendingkilllist; pk; pk = pk->next) { | |
564 | if (pk->source == np) { | |
565 | Error("localuser", ERR_INFO, "Pending kill source %s got deleted, NULL'ing source for pending kill", np->nick); | |
566 | pk->source = NULL; | |
567 | } | |
568 | if (pk->target == np) { | |
569 | Error("localuser", ERR_INFO, "Pending kill target %s got deleted, NULL'ing target for pending kill", np->nick); | |
570 | pk->target = NULL; | |
571 | } | |
572 | } | |
573 | } | |
574 | ||
3294b10b | 575 | void sendaccountmessage(nick *np) { |
94dc9910 | 576 | if (connected && IsAccount(np)) { |
3294b10b CP |
577 | if (np->auth) { |
578 | if (np->auth->flags) { | |
9cc363f1 | 579 | 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 |
580 | } else { |
581 | irc_send("%s AC %s %s %ld %lu",mynumeric->content, longtonumeric(np->numeric,5), np->authname, np->accountts, np->auth->userid); | |
582 | } | |
583 | } else { | |
584 | irc_send("%s AC %s %s %ld 0",mynumeric->content, longtonumeric(np->numeric,5), np->authname, np->accountts); | |
585 | } | |
586 | } | |
587 | } | |
588 | ||
589 | /* Auth user, don't use to set flags after authing */ | |
92acf9ae | 590 | void localusersetaccount(nick *np, char *accname, unsigned long accid, u_int64_t accountflags, time_t authTS) { |
c86edd1d Q |
591 | if (IsAccount(np)) { |
592 | Error("localuser",ERR_WARNING,"Tried to set account on user %s already authed", np->nick); | |
593 | return; | |
594 | } | |
595 | ||
596 | SetAccount(np); | |
b17a30ed | 597 | np->accountts=authTS?authTS:getnettime(); |
47657339 C |
598 | |
599 | if (accid) { | |
5a335041 | 600 | np->auth=findorcreateauthname(accid, accname); |
47657339 | 601 | np->auth->usercount++; |
3294b10b | 602 | np->authname=np->auth->name; |
47657339 C |
603 | np->nextbyauthname=np->auth->nicks; |
604 | np->auth->nicks=np; | |
0b0fb773 | 605 | np->auth->flags=accountflags; |
47657339 C |
606 | } else { |
607 | np->auth=NULL; | |
3294b10b CP |
608 | np->authname=malloc(strlen(accname) + 1); |
609 | strcpy(np->authname,accname); | |
47657339 | 610 | } |
c86edd1d | 611 | |
3294b10b | 612 | sendaccountmessage(np); |
c86edd1d Q |
613 | |
614 | triggerhook(HOOK_NICK_ACCOUNT, np); | |
615 | } | |
616 | ||
eac66732 CP |
617 | void localusersetumodes(nick *np, flag_t newmodes) { |
618 | if (connected) { | |
619 | irc_send("%s M %s %s", longtonumeric(np->numeric,5), np->nick, printflagdiff(np->umodes, newmodes, umodeflags)); | |
620 | } | |
621 | ||
622 | np->umodes = newmodes; | |
623 | } | |
3294b10b | 624 | |
92acf9ae | 625 | void localusersetaccountflags(authname *anp, u_int64_t accountflags) { |
3294b10b CP |
626 | void *arg[2]; |
627 | nick *np; | |
92acf9ae | 628 | u_int64_t oldflags = anp->flags; |
3294b10b | 629 | |
92acf9ae CP |
630 | arg[0] = anp; |
631 | arg[1] = &oldflags; | |
3294b10b CP |
632 | anp->flags = accountflags; |
633 | ||
94dc9910 | 634 | for(np=anp->nicks;np;np=np->nextbyauthname) |
3294b10b CP |
635 | sendaccountmessage(np); |
636 | ||
92acf9ae | 637 | triggerhook(HOOK_AUTH_FLAGSUPDATED, arg); |
3294b10b | 638 | } |