]>
jfr.im git - irc/quakenet/newserv.git/blob - chanserv/chanserv_protect.c
2 * Nick protection system for the chanserv
7 #include "../core/schedule.h"
8 #include "../localuser/localuser.h"
9 #include "../lib/irc_string.h"
11 #define PROTECTTIME 60 /* How long you have to renick if you encroach.. */
13 void csp_handlenick(int hooknum
, void *arg
);
14 void csp_freenick(int hooknum
, void *arg
);
15 void csp_timerfunc (void *arg
);
16 int csp_doclaimnick(void *source
, int cargc
, char **cargv
);
19 registerhook(HOOK_NICK_NEWNICK
, csp_handlenick
);
20 registerhook(HOOK_NICK_RENAME
, csp_handlenick
);
22 registerhook(HOOK_NICK_NEWNICK
, csp_freenick
);
23 registerhook(HOOK_NICK_ACCOUNT
, csp_freenick
);
25 chanservaddcommand("claimnick", QCMD_STAFF
, 0, csp_doclaimnick
, "Reclaims your nickname if it has been stolen.","");
32 deregisterhook(HOOK_NICK_NEWNICK
, csp_handlenick
);
33 deregisterhook(HOOK_NICK_RENAME
, csp_handlenick
);
35 deregisterhook(HOOK_NICK_NEWNICK
, csp_freenick
);
36 deregisterhook(HOOK_NICK_ACCOUNT
, csp_freenick
);
38 chanservremovecommand("claimnick", csp_doclaimnick
);
39 deleteallschedules(csp_timerfunc
);
41 /* Kill off all fakeusers too */
42 for (i
=0;i
<REGUSERHASHSIZE
;i
++)
43 for (rup
=regusernicktable
[i
];rup
;rup
=rup
->nextbyname
)
45 if (getnickbynick(rup
->username
) == rup
->fakeuser
) {
46 deregisterlocaluser(rup
->fakeuser
,NULL
);
52 void csp_handlenick(int hooknum
, void *arg
) {
55 char userhostbuf
[USERLEN
+HOSTLEN
+2];
57 /* Check that it's a protected nick */
58 if (!(rup
=findreguserbynick(np
->nick
)) || !UIsProtect(rup
))
61 /* If we already had a timer running, this means someone renamed off and back.
62 * Clear the old timer.
65 deleteschedule(rup
->checkshd
, csp_timerfunc
, rup
);
69 /* If they're an oper, or the legal user of the nick, it's OK */
70 /* Also, don't warn them if they are a fakeuser */
71 if (getreguserfromnick(np
)==rup
) {
76 if (rup
->lastuserhost
) {
77 sprintf(userhostbuf
,"%s@%s",np
->ident
,np
->host
->name
->content
);
78 if (!ircd_strcmp(userhostbuf
, rup
->lastuserhost
->content
))
82 if (IsOper(np
) || homeserver(np
->numeric
)==mylongnum
)
85 /* OK, at this stage we've established that:
86 * - This is a protected nick
87 * - The person using it isn't authed as the correct user
91 chanservstdmessage(np
, QM_PROTECTEDNICK
, rup
->username
);
93 /* Schedule checkup */
94 rup
->checkshd
=scheduleoneshot(time(NULL
)+PROTECTTIME
, csp_timerfunc
, rup
);
97 void csp_freenick(int hooknum
, void *arg
) {
99 reguser
*rup
=getreguserfromnick(np
);
101 if (!rup
|| !UIsProtect(rup
))
105 deleteschedule(rup
->checkshd
, csp_timerfunc
, rup
);
111 /* Before killing, check the user is valid */
112 if (getnickbynick(rup
->username
) == rup
->fakeuser
) {
113 /* Free up the fakeuser */
114 deregisterlocaluser(rup
->fakeuser
, NULL
);
116 chanservstdmessage(np
, QM_NICKWASFAKED
, rup
->username
);
121 void csp_timerfunc (void *arg
) {
127 /* Check that we still have a user with this name and
128 * that they're not now opered or authed.. */
129 if (!(np
=getnickbynick(rup
->username
)) || IsOper(np
) || (getreguserfromnick(np
)==rup
))
132 /* KILL! KILL! KILL! */
133 killuser(chanservnick
, np
, "Protected nick.");
137 /* If it's been stolen too much, create a fake user.. */
138 if (rup
->stealcount
>= 3) {
139 rup
->fakeuser
=registerlocaluser(rup
->username
, "reserved", "nick", "Protected nick.", NULL
, UMODE_INV
, NULL
);
143 int csp_doclaimnick(void *source
, int cargc
, char **cargv
) {
145 reguser
*rup
=getreguserfromnick(sender
);
151 if (!UIsProtect(rup
)) {
152 chanservstdmessage(sender
, QM_NOTPROTECTED
,rup
->username
);
156 if (!(target
=getnickbynick(rup
->username
))) {
157 chanservstdmessage(sender
, QM_UNKNOWNUSER
, rup
->username
);
161 if (getreguserfromnick(target
)==rup
) {
162 chanservstdmessage(sender
, QM_SAMEAUTH
, target
->nick
, rup
->username
);
166 if (rup
->fakeuser
==target
) {
167 deregisterlocaluser(rup
->fakeuser
, NULL
);
171 killuser(chanservnick
, target
, "Protected nick.");
174 chanservstdmessage(sender
, QM_DONE
);