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