]>
jfr.im git - irc/quakenet/newserv.git/blob - chanserv/chanserv_protect.c
2 * Nick protection system for the chanserv
6 #include "../core/schedule.h"
7 #include "../localuser/localuser.h"
10 #define PROTECTTIME 60 /* How long you have to renick if you encroach.. */
12 void csp_handlenick(int hooknum
, void *arg
);
13 void csp_freenick(int hooknum
, void *arg
);
14 void csp_timerfunc (void *arg
);
15 int csp_doclaimnick(void *source
, int cargc
, char **cargv
);
18 registerhook(HOOK_NICK_NEWNICK
, csp_handlenick
);
19 registerhook(HOOK_NICK_RENAME
, csp_handlenick
);
21 registerhook(HOOK_NICK_NEWNICK
, csp_freenick
);
22 registerhook(HOOK_NICK_ACCOUNT
, csp_freenick
);
24 chanservaddcommand("claimnick", QCMD_HELPER
, 0, csp_doclaimnick
, "Reclaims your nickname if it has been stolen.","");
31 deregisterhook(HOOK_NICK_NEWNICK
, csp_handlenick
);
32 deregisterhook(HOOK_NICK_RENAME
, csp_handlenick
);
34 deregisterhook(HOOK_NICK_NEWNICK
, csp_freenick
);
35 deregisterhook(HOOK_NICK_ACCOUNT
, csp_freenick
);
37 chanservremovecommand("claimnick", csp_doclaimnick
);
38 deleteallschedules(csp_timerfunc
);
40 /* Kill off all fakeusers too */
41 for (i
=0;i
<REGUSERHASHSIZE
;i
++)
42 for (rup
=regusernicktable
[i
];rup
;rup
=rup
->nextbyname
)
44 if (getnickbynick(rup
->username
) == rup
->fakeuser
) {
45 deregisterlocaluser(rup
->fakeuser
,NULL
);
51 void csp_handlenick(int hooknum
, void *arg
) {
54 char userhostbuf
[USERLEN
+HOSTLEN
+2];
56 /* Check that it's a protected nick */
57 if (!(rup
=findreguserbynick(np
->nick
)) || !UIsProtect(rup
))
60 /* If we already had a timer running, this means someone renamed off and back.
61 * Clear the old timer.
64 deleteschedule(rup
->checkshd
, csp_timerfunc
, rup
);
68 /* If they're an oper, or the legal user of the nick, it's OK */
69 /* Also, don't warn them if they are a fakeuser */
70 if (getreguserfromnick(np
)==rup
) {
75 if (rup
->lastuserhost
) {
76 sprintf(userhostbuf
,"%s@%s",np
->ident
,np
->host
->name
->content
);
77 if (!ircd_strcmp(userhostbuf
, rup
->lastuserhost
->content
))
81 if (IsOper(np
) || homeserver(np
->numeric
)==mylongnum
)
84 /* OK, at this stage we've established that:
85 * - This is a protected nick
86 * - The person using it isn't authed as the correct user
90 chanservstdmessage(np
, QM_PROTECTEDNICK
, rup
->username
);
92 /* Schedule checkup */
93 rup
->checkshd
=scheduleoneshot(time(NULL
)+PROTECTTIME
, csp_timerfunc
, rup
);
96 void csp_freenick(int hooknum
, void *arg
) {
98 reguser
*rup
=getreguserfromnick(np
);
100 if (!rup
|| !UIsProtect(rup
))
104 deleteschedule(rup
->checkshd
, csp_timerfunc
, rup
);
110 /* Before killing, check the user is valid */
111 if (getnickbynick(rup
->username
) == rup
->fakeuser
) {
112 /* Free up the fakeuser */
113 deregisterlocaluser(rup
->fakeuser
, NULL
);
115 chanservstdmessage(np
, QM_NICKWASFAKED
, rup
->username
);
120 void csp_timerfunc (void *arg
) {
126 /* Check that we still have a user with this name and
127 * that they're not now opered or authed.. */
128 if (!(np
=getnickbynick(rup
->username
)) || IsOper(np
) || (getreguserfromnick(np
)==rup
))
131 /* KILL! KILL! KILL! */
132 killuser(chanservnick
, np
, "Protected nick.");
136 /* If it's been stolen too much, create a fake user.. */
137 if (rup
->stealcount
>= 3) {
138 rup
->fakeuser
=registerlocaluser(rup
->username
, "reserved", "nick", "Protected nick.", NULL
, UMODE_INV
, NULL
);
142 int csp_doclaimnick(void *source
, int cargc
, char **cargv
) {
144 reguser
*rup
=getreguserfromnick(sender
);
150 if (!UIsProtect(rup
)) {
151 chanservstdmessage(sender
, QM_NOTPROTECTED
,rup
->username
);
155 if (!(target
=getnickbynick(rup
->username
))) {
156 chanservstdmessage(sender
, QM_UNKNOWNUSER
, rup
->username
);
160 if (getreguserfromnick(target
)==rup
) {
161 chanservstdmessage(sender
, QM_SAMEAUTH
, target
->nick
, rup
->username
);
165 if (rup
->fakeuser
==target
) {
166 deregisterlocaluser(rup
->fakeuser
, NULL
);
170 killuser(chanservnick
, target
, "Protected nick.");
173 chanservstdmessage(sender
, QM_DONE
);