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