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