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