1 |
sup |
1.9 |
/* |
2 |
sup |
1.3 |
* ircbinds.c -- part of botnetop.mod |
3 |
sup |
1.9 |
* |
4 |
|
|
* $Id$ |
5 |
sup |
1.3 |
*/ |
6 |
|
|
/* |
7 |
sup |
1.9 |
* Copyright (C) 2000, 2001, 2002 Teemu Hjelt <temex@iki.fi> |
8 |
guppy |
1.1 |
* |
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 |
sup |
1.9 |
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 |
guppy |
1.1 |
static int bnop_modeop(char *nick, char *uhost, char *hand, char *chname, char *mode, char *victim) |
58 |
|
|
{ |
59 |
sup |
1.9 |
int i, bufsize; |
60 |
|
|
char s[UHOSTLEN], *buf = NULL; |
61 |
guppy |
1.1 |
struct chanset_t *chan = NULL; |
62 |
sup |
1.9 |
struct userrec *u = NULL; |
63 |
|
|
struct delay_t *d = NULL; |
64 |
|
|
memberlist *m = NULL; |
65 |
guppy |
1.1 |
|
66 |
sup |
1.9 |
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 |
sup |
1.5 |
egg_snprintf(s, sizeof s, "%s!%s", m->nick, m->userhost); |
95 |
sup |
1.9 |
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 |
guppy |
1.1 |
} |
106 |
|
|
} |
107 |
|
|
} |
108 |
sup |
1.9 |
|
109 |
guppy |
1.1 |
return 0; |
110 |
|
|
} |
111 |
|
|
|
112 |
sup |
1.9 |
static int bnop_modedeop(char *nick, char *uhost, char *hand, char *chname, char *mode, char *victim) |
113 |
guppy |
1.1 |
{ |
114 |
sup |
1.9 |
char s[UHOSTLEN]; |
115 |
guppy |
1.1 |
struct chanset_t *chan = NULL; |
116 |
sup |
1.9 |
struct userrec *u = NULL; |
117 |
sup |
1.4 |
struct delay_t *d = NULL; |
118 |
sup |
1.9 |
memberlist *m = NULL; |
119 |
guppy |
1.1 |
|
120 |
sup |
1.9 |
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 |
sup |
1.7 |
d->reqtime = now + (random() % bop_delay) + 5; |
145 |
sup |
1.9 |
strncpyz(d->handle, u->handle, strlen(u->handle) + 1); |
146 |
|
|
} |
147 |
sup |
1.4 |
} |
148 |
guppy |
1.1 |
} |
149 |
sup |
1.9 |
|
150 |
sup |
1.5 |
return 0; |
151 |
|
|
} |
152 |
sup |
1.9 |
|
153 |
sup |
1.5 |
static int bnop_userhost(char *from, char *msg) |
154 |
|
|
{ |
155 |
sup |
1.9 |
char *ptr = NULL, *reply = NULL, fromnick[NICKLEN], s[UHOSTLEN]; |
156 |
sup |
1.5 |
struct who_t *w = NULL; |
157 |
|
|
struct chanset_t *chan = NULL; |
158 |
|
|
|
159 |
sup |
1.6 |
ptr = (char *) nmalloc(strlen(msg) + 1); |
160 |
sup |
1.9 |
if (ptr == NULL) |
161 |
sup |
1.6 |
return 0; |
162 |
|
|
reply = ptr; |
163 |
sup |
1.9 |
strncpyz(reply, msg, strlen(msg) + 1); |
164 |
sup |
1.6 |
newsplit(&reply); |
165 |
|
|
reply = newsplit(&reply); |
166 |
sup |
1.5 |
splitc(fromnick, reply + 1, '='); |
167 |
sup |
1.6 |
splitc(fromnick, fromnick, '*'); |
168 |
sup |
1.9 |
if ((w = find_who(fromnick))) { |
169 |
|
|
if (!(chan = findchan_by_dname(w->chan))) |
170 |
|
|
return 0; |
171 |
sup |
1.7 |
strncpyz(s, strchr("~+-^=", reply[2]) ? reply + 3 : reply + 2, sizeof s); |
172 |
sup |
1.5 |
if (!egg_strcasecmp(w->uhost, s)) { |
173 |
|
|
dprintf(DP_SERVER, "INVITE %s %s\n", fromnick, chan->dname); |
174 |
|
|
if (bop_log >= 1) { |
175 |
sup |
1.9 |
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 |
sup |
1.5 |
} |
181 |
|
|
} |
182 |
|
|
del_who(w); |
183 |
|
|
} |
184 |
sup |
1.6 |
nfree(ptr); |
185 |
sup |
1.9 |
|
186 |
sup |
1.5 |
return 0; |
187 |
guppy |
1.1 |
} |
188 |
|
|
|
189 |
|
|
static cmd_t botnetop_mode[] = |
190 |
|
|
{ |
191 |
sup |
1.9 |
{"% +o", "", (Function) bnop_modeop, "bop_modeop"}, |
192 |
|
|
{"% -o", "", (Function) bnop_modedeop, "bop_modedeop"}, |
193 |
|
|
{0, 0, 0, 0} |
194 |
guppy |
1.1 |
}; |
195 |
|
|
|
196 |
|
|
static cmd_t botnetop_join[] = |
197 |
|
|
{ |
198 |
sup |
1.9 |
{"*", "", (Function) bnop_jointmr, "bop_jointmr"}, |
199 |
|
|
{0, 0, 0, 0} |
200 |
guppy |
1.1 |
}; |
201 |
sup |
1.3 |
|
202 |
sup |
1.5 |
static cmd_t botnetop_raw[] = |
203 |
|
|
{ |
204 |
sup |
1.9 |
{"302", "", (Function) bnop_userhost, "bop_userhost"}, |
205 |
|
|
{0, 0, 0, 0} |
206 |
sup |
1.5 |
}; |