]>
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"
10 #include "../lib/version.h"
12 MODULE_VERSION(QVERSION
)
14 #define PROTECTTIME 60 /* How long you have to renick if you encroach.. */
16 void csp_handlenick(int hooknum
, void *arg
);
17 void csp_handlerename(int hooknum
, void *arg
);
18 void csp_freenick(int hooknum
, void *arg
);
19 void csp_timerfunc (void *arg
);
20 int csp_doclaimnick(void *source
, int cargc
, char **cargv
);
23 registerhook(HOOK_NICK_NEWNICK
, csp_handlenick
);
24 registerhook(HOOK_NICK_RENAME
, csp_handlerename
);
26 registerhook(HOOK_NICK_NEWNICK
, csp_freenick
);
27 registerhook(HOOK_NICK_ACCOUNT
, csp_freenick
);
29 chanservaddcommand("claimnick", QCMD_STAFF
, 0, csp_doclaimnick
, "Reclaims your nickname if it has been stolen.","");
36 deregisterhook(HOOK_NICK_NEWNICK
, csp_handlenick
);
37 deregisterhook(HOOK_NICK_RENAME
, csp_handlerename
);
39 deregisterhook(HOOK_NICK_NEWNICK
, csp_freenick
);
40 deregisterhook(HOOK_NICK_ACCOUNT
, csp_freenick
);
42 chanservremovecommand("claimnick", csp_doclaimnick
);
43 deleteallschedules(csp_timerfunc
);
45 /* Kill off all fakeusers too */
46 for (i
=0;i
<REGUSERHASHSIZE
;i
++)
47 for (rup
=regusernicktable
[i
];rup
;rup
=rup
->nextbyname
)
49 if (getnickbynick(rup
->username
) == rup
->fakeuser
) {
50 deregisterlocaluser(rup
->fakeuser
,NULL
);
56 void csp_handlerename(int hooknum
, void *arg
) {
57 void **harg
= (void **)arg
;
58 csp_handlenick(hooknum
, harg
[0]);
61 void csp_handlenick(int hooknum
, void *arg
) {
64 char userhostbuf
[USERLEN
+HOSTLEN
+2];
66 /* Check that it's a protected nick */
67 if (!(rup
=findreguserbynick(np
->nick
)) || !UIsProtect(rup
))
70 /* If we already had a timer running, this means someone renamed off and back.
71 * Clear the old timer.
74 deleteschedule(rup
->checkshd
, csp_timerfunc
, rup
);
78 /* If they're an oper, or the legal user of the nick, it's OK */
79 /* Also, don't warn them if they are a fakeuser */
80 if (getreguserfromnick(np
)==rup
) {
85 if (rup
->lastuserhost
) {
86 sprintf(userhostbuf
,"%s@%s",np
->ident
,np
->host
->name
->content
);
87 if (!ircd_strcmp(userhostbuf
, rup
->lastuserhost
->content
))
91 if (IsOper(np
) || homeserver(np
->numeric
)==mylongnum
)
94 /* OK, at this stage we've established that:
95 * - This is a protected nick
96 * - The person using it isn't authed as the correct user
100 chanservstdmessage(np
, QM_PROTECTEDNICK
, rup
->username
);
102 /* Schedule checkup */
103 rup
->checkshd
=scheduleoneshot(time(NULL
)+PROTECTTIME
, csp_timerfunc
, rup
);
106 void csp_freenick(int hooknum
, void *arg
) {
108 reguser
*rup
=getreguserfromnick(np
);
110 if (!rup
|| !UIsProtect(rup
))
114 deleteschedule(rup
->checkshd
, csp_timerfunc
, rup
);
120 /* Before killing, check the user is valid */
121 if (getnickbynick(rup
->username
) == rup
->fakeuser
) {
122 /* Free up the fakeuser */
123 deregisterlocaluser(rup
->fakeuser
, NULL
);
125 chanservstdmessage(np
, QM_NICKWASFAKED
, rup
->username
);
130 void csp_timerfunc (void *arg
) {
136 /* Check that we still have a user with this name and
137 * that they're not now opered or authed.. */
138 if (!(np
=getnickbynick(rup
->username
)) || IsOper(np
) || (getreguserfromnick(np
)==rup
))
141 /* KILL! KILL! KILL! */
142 killuser(chanservnick
, np
, "Protected nick.");
146 /* If it's been stolen too much, create a fake user.. */
147 if (rup
->stealcount
>= 3) {
148 rup
->fakeuser
=registerlocaluser(rup
->username
, "reserved", "nick", "Protected nick.", NULL
, UMODE_INV
, NULL
);
152 int csp_doclaimnick(void *source
, int cargc
, char **cargv
) {
154 reguser
*rup
=getreguserfromnick(sender
);
160 if (!UIsProtect(rup
)) {
161 chanservstdmessage(sender
, QM_NOTPROTECTED
,rup
->username
);
165 if (!(target
=getnickbynick(rup
->username
))) {
166 chanservstdmessage(sender
, QM_UNKNOWNUSER
, rup
->username
);
170 if (getreguserfromnick(target
)==rup
) {
171 chanservstdmessage(sender
, QM_SAMEAUTH
, target
->nick
, rup
->username
);
175 if (rup
->fakeuser
==target
) {
176 deregisterlocaluser(rup
->fakeuser
, NULL
);
180 killuser(chanservnick
, target
, "Protected nick.");
183 chanservstdmessage(sender
, QM_DONE
);