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