1 |
/* |
2 |
* ircbinds.c -- part of botnetop.mod |
3 |
* |
4 |
* $Id$ |
5 |
*/ |
6 |
/* |
7 |
* Copyright (C) 2000, 2001, 2002 Teemu Hjelt <temex@iki.fi> |
8 |
* |
9 |
* This program is free software; you can redistribute it and/or |
10 |
* modify it under the terms of the GNU General Public License |
11 |
* as published by the Free Software Foundation; either version 2 |
12 |
* of the License, or (at your option) any later version. |
13 |
* |
14 |
* This program is distributed in the hope that it will be useful, |
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 |
* GNU General Public License for more details. |
18 |
* |
19 |
* You should have received a copy of the GNU General Public License |
20 |
* along with this program; if not, write to the Free Software |
21 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
22 |
*/ |
23 |
|
24 |
static int bnop_jointmr(char *nick, char *uhost, char *hand, char *chname) |
25 |
{ |
26 |
struct chanset_t *chan = NULL; |
27 |
struct delay_t *d = NULL; |
28 |
struct userrec *u = NULL; |
29 |
|
30 |
if (!(chan = findchan_by_dname(chname))) |
31 |
return 0; |
32 |
if (rfc_casecmp(nick, botname)) { |
33 |
/* Somebody joined the channel - Check if it's a bot and suggest ops. */ |
34 |
if (!(u = get_user_by_handle(userlist, hand))) |
35 |
return 0; |
36 |
if (!matchattr(u, "b|-", chan->dname) || !matchattr(u, "o|o", chan->dname) || matchattr(u, "d|d", chan->dname)) |
37 |
return 0; |
38 |
if (check_request_status(hand, chan->dname)) |
39 |
return 0; |
40 |
if (!bop_delay || lowbots(chan)) |
41 |
bnop_askbot(hand, chan->dname); |
42 |
else { |
43 |
if (!(d = find_delay(chan->dname, hand))) { |
44 |
if (!(d = add_delay(chan->dname, hand))) |
45 |
return 0; |
46 |
} |
47 |
d->reqtime = now + (random() % bop_delay) + 5; |
48 |
strncpyz(d->handle, hand, strlen(hand) + 1); |
49 |
} |
50 |
} else |
51 |
/* We joined the channel - Request ops from all linked bots. */ |
52 |
bnop_reqop(chan->dname, "op"); |
53 |
|
54 |
return 0; |
55 |
} |
56 |
|
57 |
static int bnop_modeop(char *nick, char *uhost, char *hand, char *chname, char *mode, char *victim) |
58 |
{ |
59 |
int i, bufsize; |
60 |
char s[UHOSTLEN], *buf = NULL; |
61 |
struct chanset_t *chan = NULL; |
62 |
struct userrec *u = NULL; |
63 |
struct delay_t *d = NULL; |
64 |
memberlist *m = NULL; |
65 |
|
66 |
if (bop_modeop) { |
67 |
if (!(chan = findchan_by_dname(chname))) |
68 |
return 0; |
69 |
if (!rfc_casecmp(victim, botname)) { |
70 |
/* We got opped - Suggest ops for all the deopped bots on the channel. */ |
71 |
for (m = chan->channel.member; m && m->nick[0]; m = m->next) { |
72 |
egg_snprintf(s, sizeof s, "%s!%s", m->nick, m->userhost); |
73 |
if ((u == get_user_by_host(s)) && !chan_hasop(m)) { |
74 |
if (!matchattr(u, "b|-", chan->dname) || !matchattr(u, "o|o", chan->dname) || matchattr(u, "d|d", chan->dname)) |
75 |
continue; |
76 |
if (check_request_status(u->handle, chan->dname)) |
77 |
continue; |
78 |
if (!bop_delay || lowbots(chan)) |
79 |
bnop_askbot(u->handle, chan->dname); |
80 |
else { |
81 |
if (!(d = find_delay(chan->dname, u->handle))) { |
82 |
if (!(d = add_delay(chan->dname, u->handle))) |
83 |
continue; |
84 |
} |
85 |
d->reqtime = now + (random() % bop_delay) + 5; |
86 |
strncpyz(d->handle, u->handle, strlen(u->handle) + 1); |
87 |
} |
88 |
} |
89 |
} |
90 |
} else if (!isop(botname, chan) && rfc_casecmp(nick, botname)) { |
91 |
/* Some other got opped - Ask for ops if it was a bot. */ |
92 |
if (!(m = ismember(chan, victim))) |
93 |
return 0; |
94 |
egg_snprintf(s, sizeof s, "%s!%s", m->nick, m->userhost); |
95 |
if (!(u = get_user_by_host(s))) |
96 |
return 0; |
97 |
if (matchattr(u, "b|-", chan->dname) && matchattr(u, "o|o", chan->dname) && ((i = nextbot(u->handle)) >= 0)) { |
98 |
bufsize = strlen(chan->dname) + 7 + 1; |
99 |
buf = (char *) nmalloc(bufsize); |
100 |
if (buf == NULL) |
101 |
return 0; |
102 |
egg_snprintf(buf, bufsize, "reqops %s", chan->dname); |
103 |
botnet_send_zapf(i, botnetnick, u->handle, buf); |
104 |
nfree(buf); |
105 |
} |
106 |
} |
107 |
} |
108 |
|
109 |
return 0; |
110 |
} |
111 |
|
112 |
static int bnop_modedeop(char *nick, char *uhost, char *hand, char *chname, char *mode, char *victim) |
113 |
{ |
114 |
char s[UHOSTLEN]; |
115 |
struct chanset_t *chan = NULL; |
116 |
struct userrec *u = NULL; |
117 |
struct delay_t *d = NULL; |
118 |
memberlist *m = NULL; |
119 |
|
120 |
if (bop_modedeop) { |
121 |
if (!(chan = findchan_by_dname(chname))) |
122 |
return 0; |
123 |
if (!rfc_casecmp(victim, botname)) |
124 |
/* We got deopped - Ask for ops from all linked bots. */ |
125 |
bnop_reqop(chan->dname, "op"); |
126 |
else if (rfc_casecmp(nick, botname)) { |
127 |
/* Some other got deopped and the deopper wasn't us - Check if it was a bot and suggest ops. */ |
128 |
if (!(m = ismember(chan, victim))) |
129 |
return 0; |
130 |
egg_snprintf(s, sizeof s, "%s!%s", m->nick, m->userhost); |
131 |
if (!(u = get_user_by_host(s))) |
132 |
return 0; |
133 |
if (!matchattr(u, "b|-", chan->dname) || !matchattr(u, "o|o", chan->dname) || matchattr(u, "d|d", chan->dname)) |
134 |
return 0; |
135 |
if (check_request_status(u->handle, chan->dname)) |
136 |
return 0; |
137 |
if (!bop_delay || lowbots(chan)) |
138 |
bnop_askbot(u->handle, chan->dname); |
139 |
else { |
140 |
if (!(d = find_delay(chan->dname, u->handle))) { |
141 |
if (!(d = add_delay(chan->dname, u->handle))) |
142 |
return 0; |
143 |
} |
144 |
d->reqtime = now + (random() % bop_delay) + 5; |
145 |
strncpyz(d->handle, u->handle, strlen(u->handle) + 1); |
146 |
} |
147 |
} |
148 |
} |
149 |
|
150 |
return 0; |
151 |
} |
152 |
|
153 |
static int bnop_userhost(char *from, char *msg) |
154 |
{ |
155 |
char *ptr = NULL, *reply = NULL, fromnick[NICKLEN], s[UHOSTLEN]; |
156 |
struct who_t *w = NULL; |
157 |
struct chanset_t *chan = NULL; |
158 |
|
159 |
ptr = (char *) nmalloc(strlen(msg) + 1); |
160 |
if (ptr == NULL) |
161 |
return 0; |
162 |
reply = ptr; |
163 |
strncpyz(reply, msg, strlen(msg) + 1); |
164 |
newsplit(&reply); |
165 |
reply = newsplit(&reply); |
166 |
splitc(fromnick, reply + 1, '='); |
167 |
splitc(fromnick, fromnick, '*'); |
168 |
if ((w = find_who(fromnick))) { |
169 |
if (!(chan = findchan_by_dname(w->chan))) |
170 |
return 0; |
171 |
strncpyz(s, strchr("~+-^=", reply[2]) ? reply + 3 : reply + 2, sizeof s); |
172 |
if (!egg_strcasecmp(w->uhost, s)) { |
173 |
dprintf(DP_SERVER, "INVITE %s %s\n", fromnick, chan->dname); |
174 |
if (bop_log >= 1) { |
175 |
if (egg_strcasecmp(fromnick, w->handle)) { |
176 |
putlog(LOG_MISC, "*", "botnetop.mod: " BOTNETOP_INVITED2, w->handle, fromnick, chan->dname); |
177 |
} else { |
178 |
putlog(LOG_MISC, "*", "botnetop.mod: " BOTNETOP_INVITED, w->handle, chan->dname); |
179 |
} |
180 |
} |
181 |
} |
182 |
del_who(w); |
183 |
} |
184 |
nfree(ptr); |
185 |
|
186 |
return 0; |
187 |
} |
188 |
|
189 |
static cmd_t botnetop_mode[] = |
190 |
{ |
191 |
{"% +o", "", (Function) bnop_modeop, "bop_modeop"}, |
192 |
{"% -o", "", (Function) bnop_modedeop, "bop_modedeop"}, |
193 |
{0, 0, 0, 0} |
194 |
}; |
195 |
|
196 |
static cmd_t botnetop_join[] = |
197 |
{ |
198 |
{"*", "", (Function) bnop_jointmr, "bop_jointmr"}, |
199 |
{0, 0, 0, 0} |
200 |
}; |
201 |
|
202 |
static cmd_t botnetop_raw[] = |
203 |
{ |
204 |
{"302", "", (Function) bnop_userhost, "bop_userhost"}, |
205 |
{0, 0, 0, 0} |
206 |
}; |