]>
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_freenick(int hooknum
, void *arg
);
18 void csp_timerfunc (void *arg
);
19 int csp_doclaimnick(void *source
, int cargc
, char **cargv
);
22 registerhook(HOOK_NICK_NEWNICK
, csp_handlenick
);
23 registerhook(HOOK_NICK_RENAME
, csp_handlenick
);
25 registerhook(HOOK_NICK_NEWNICK
, csp_freenick
);
26 registerhook(HOOK_NICK_ACCOUNT
, csp_freenick
);
28 chanservaddcommand("claimnick", QCMD_STAFF
, 0, csp_doclaimnick
, "Reclaims your nickname if it has been stolen.","");
35 deregisterhook(HOOK_NICK_NEWNICK
, csp_handlenick
);
36 deregisterhook(HOOK_NICK_RENAME
, csp_handlenick
);
38 deregisterhook(HOOK_NICK_NEWNICK
, csp_freenick
);
39 deregisterhook(HOOK_NICK_ACCOUNT
, csp_freenick
);
41 chanservremovecommand("claimnick", csp_doclaimnick
);
42 deleteallschedules(csp_timerfunc
);
44 /* Kill off all fakeusers too */
45 for (i
=0;i
<REGUSERHASHSIZE
;i
++)
46 for (rup
=regusernicktable
[i
];rup
;rup
=rup
->nextbyname
)
48 if (getnickbynick(rup
->username
) == rup
->fakeuser
) {
49 deregisterlocaluser(rup
->fakeuser
,NULL
);
55 void csp_handlenick(int hooknum
, void *arg
) {
58 char userhostbuf
[USERLEN
+HOSTLEN
+2];
60 /* Check that it's a protected nick */
61 if (!(rup
=findreguserbynick(np
->nick
)) || !UIsProtect(rup
))
64 /* If we already had a timer running, this means someone renamed off and back.
65 * Clear the old timer.
68 deleteschedule(rup
->checkshd
, csp_timerfunc
, rup
);
72 /* If they're an oper, or the legal user of the nick, it's OK */
73 /* Also, don't warn them if they are a fakeuser */
74 if (getreguserfromnick(np
)==rup
) {
79 if (rup
->lastuserhost
) {
80 sprintf(userhostbuf
,"%s@%s",np
->ident
,np
->host
->name
->content
);
81 if (!ircd_strcmp(userhostbuf
, rup
->lastuserhost
->content
))
85 if (IsOper(np
) || homeserver(np
->numeric
)==mylongnum
)
88 /* OK, at this stage we've established that:
89 * - This is a protected nick
90 * - The person using it isn't authed as the correct user
94 chanservstdmessage(np
, QM_PROTECTEDNICK
, rup
->username
);
96 /* Schedule checkup */
97 rup
->checkshd
=scheduleoneshot(time(NULL
)+PROTECTTIME
, csp_timerfunc
, rup
);
100 void csp_freenick(int hooknum
, void *arg
) {
102 reguser
*rup
=getreguserfromnick(np
);
104 if (!rup
|| !UIsProtect(rup
))
108 deleteschedule(rup
->checkshd
, csp_timerfunc
, rup
);
114 /* Before killing, check the user is valid */
115 if (getnickbynick(rup
->username
) == rup
->fakeuser
) {
116 /* Free up the fakeuser */
117 deregisterlocaluser(rup
->fakeuser
, NULL
);
119 chanservstdmessage(np
, QM_NICKWASFAKED
, rup
->username
);
124 void csp_timerfunc (void *arg
) {
130 /* Check that we still have a user with this name and
131 * that they're not now opered or authed.. */
132 if (!(np
=getnickbynick(rup
->username
)) || IsOper(np
) || (getreguserfromnick(np
)==rup
))
135 /* KILL! KILL! KILL! */
136 killuser(chanservnick
, np
, "Protected nick.");
140 /* If it's been stolen too much, create a fake user.. */
141 if (rup
->stealcount
>= 3) {
142 rup
->fakeuser
=registerlocaluser(rup
->username
, "reserved", "nick", "Protected nick.", NULL
, UMODE_INV
, NULL
);
146 int csp_doclaimnick(void *source
, int cargc
, char **cargv
) {
148 reguser
*rup
=getreguserfromnick(sender
);
154 if (!UIsProtect(rup
)) {
155 chanservstdmessage(sender
, QM_NOTPROTECTED
,rup
->username
);
159 if (!(target
=getnickbynick(rup
->username
))) {
160 chanservstdmessage(sender
, QM_UNKNOWNUSER
, rup
->username
);
164 if (getreguserfromnick(target
)==rup
) {
165 chanservstdmessage(sender
, QM_SAMEAUTH
, target
->nick
, rup
->username
);
169 if (rup
->fakeuser
==target
) {
170 deregisterlocaluser(rup
->fakeuser
, NULL
);
174 killuser(chanservnick
, target
, "Protected nick.");
177 chanservstdmessage(sender
, QM_DONE
);