1 |
|
2 |
# Getops 2.3a |
3 |
|
4 |
# $Id: getops.tcl,v 1.12 2001/07/15 05:26:41 guppy Exp $ |
5 |
|
6 |
# This script is used for bots to request and give ops to each other. |
7 |
# For this to work, you'll need: |
8 |
|
9 |
# - Bots must be linked in a botnet |
10 |
# - Every bot that should be ops on your channels must load this script |
11 |
# - Add all bots you wanna op with this one using the .+bot nick address |
12 |
# command. The "nick" should be exactly the botnet-nick of the other bot |
13 |
# - Add the hostmasks that uniquely identify this bot on IRC |
14 |
# - Add a global or channel +o flag on all bots to be opped |
15 |
# - Do exactly the same on all other bots |
16 |
|
17 |
# The security of this relies on the fact that the bot which wants to have |
18 |
# ops must be 1) linked to the current botnet (which requires a password), |
19 |
# 2) have an entry with +o on the bot that he wants ops from and 3) must match |
20 |
# the hostmask that is stored on each bots userfile (so it is good to keep the |
21 |
# hostmasks up-to-date). |
22 |
|
23 |
# ----------------------------------------------------------------------------- |
24 |
|
25 |
# 2.3a by guppy <guppy@eggheads.org> |
26 |
# - fix for bind need |
27 |
|
28 |
# 2.3 by guppy <guppy@eggheads.org> |
29 |
# - minor cleanup to use some 1.6 tcl functions |
30 |
# - use bind need over need-op, need-invite, etc ... |
31 |
|
32 |
# 2.2g by poptix <poptix@poptix.net> |
33 |
# - Fabian's 2.2e broke the script, fixed. |
34 |
|
35 |
# 2.2f by Eule <eule@berlin.snafu.de> |
36 |
# - removed key work-around added in 2.2d as eggdrop now handles this |
37 |
# correctly. |
38 |
|
39 |
# 2.2e by Fabian <fknittel@gmx.de> |
40 |
# - added support for !channels (so-called ID-channels), using chandname2name |
41 |
# functions. This makes it eggdrop 1.5+ specific. |
42 |
|
43 |
# 2.2d by brainsick <brnsck@mail.earthlink.net> |
44 |
# - Undernet now handles keys differently. It no longer gives the key on a |
45 |
# join, but instead gives it on an op, but eggdrop doesn't check for this. |
46 |
# getops-2.2d should now handle this correctly. (This should be the final |
47 |
# fix to the key problems.) |
48 |
|
49 |
# 2.2c by Progfou (Jean Christophe ANDRE <progfou@rumiko.info.unicaen.fr>) |
50 |
# - changed "Requested" to "Requesting" as it was a little confusing |
51 |
# - corrected the "I am not on chan..." problem with key request |
52 |
# (thanks to Kram |FL| and Gael for reporting it) |
53 |
# - removed more unnecessary check |
54 |
|
55 |
# 2.2b by Progfou (Jean Christophe ANDRE <progfou@rumiko.info.unicaen.fr>) |
56 |
# - removed global +o in unknown bot test |
57 |
# - removed unnecessary checks due to previous unknown bot test |
58 |
|
59 |
# 2.2a by Progfou (Jean Christophe ANDRE <progfou@rumiko.info.unicaen.fr>) |
60 |
# - removed Polish language! |
61 |
|
62 |
# 2.2 by Cron (Arkadiusz Miskiewicz <misiek@zsz2.starachowice.pl>) |
63 |
# - works good (tested on eggdrop 1.3.11) |
64 |
# - asks from unknown (and bots without +bo) are ignored |
65 |
# - all messages in Polish language |
66 |
# - better response from script to users |
67 |
# - fixed several bugs |
68 |
|
69 |
# 2.1 by Ernst |
70 |
# - asks for ops right after joining the channel: no wait anymore |
71 |
# - sets "need-op/need-invite/etc" config right after joining dynamic channels |
72 |
# - fixed "You aren't +o" being replied when other bot isn't even on channel |
73 |
# - better response from bots, in case something went wrong |
74 |
# (for example if bot is not recognized (hostmask) when asking for ops) |
75 |
# - removed several no-more-used variables |
76 |
# - added the information and description above |
77 |
|
78 |
# 2.0.1 by beldin (1.3.x ONLY version) |
79 |
# - actually, iso needed to be modded for 1.3 :P, and validchan is builtin |
80 |
# and I'll tidy a couple of functions up to |
81 |
|
82 |
# 2.0 by DarkDruid |
83 |
# - It'll work with dynamic channels(dan is a dork for making it not..) |
84 |
# - It will also only ask one bot at a time for ops so there won't be any more |
85 |
# annoying mode floods, and it's more secure that way |
86 |
# - I also took that annoying wallop and resynch stuff out :P |
87 |
# - And I guess this will with with 1.3.x too |
88 |
|
89 |
# Previously by The_O, dtM. |
90 |
|
91 |
# Originial incarnation by poptix (poptix@poptix.net) |
92 |
|
93 |
# ----------------------------------------------------------------------------- |
94 |
|
95 |
# [0/1] do you want GetOps to notice when some unknown (unauthorized) bot |
96 |
# sends request to your bot |
97 |
set go_bot_unknown 1 |
98 |
|
99 |
# [0/1] do you want your bot to request to be unbanned if it becomes banned? |
100 |
set go_bot_unban 1 |
101 |
|
102 |
# [0/1] do you want GetOps to notice the channel if there are no ops? |
103 |
set go_cycle 0 |
104 |
|
105 |
# set this to the notice txt for the above (go_cycle) |
106 |
set go_cycle_msg "Please part the channel so the bots can cycle!" |
107 |
|
108 |
# ----------------------------------------------------------------------------- |
109 |
|
110 |
set bns "" |
111 |
proc gain_entrance {what chan} { |
112 |
global botnick botname go_bot_unban go_cycle go_cycle_msg bns |
113 |
switch -exact $what { |
114 |
"limit" { |
115 |
foreach bs [lbots] { |
116 |
putbot $bs "gop limit $chan $botnick" |
117 |
putlog "GetOps: Requesting limit raise from $bs on $chan." |
118 |
} |
119 |
} |
120 |
"invite" { |
121 |
foreach bs [lbots] { |
122 |
putbot $bs "gop invite $chan $botnick" |
123 |
putlog "GetOps: Requesting invite from $bs for $chan." |
124 |
} |
125 |
} |
126 |
"unban" { |
127 |
if {$go_bot_unban} { |
128 |
foreach bs [lbots] { |
129 |
putbot $bs "gop unban $chan $botname" |
130 |
putlog "GetOps: Requesting unban on $chan from $bs." |
131 |
} |
132 |
} |
133 |
} |
134 |
"key" { |
135 |
foreach bs [lbots] { |
136 |
putbot $bs "gop key $chan $botnick" |
137 |
putlog "GetOps: Requesting key on $chan from $bs." |
138 |
} |
139 |
} |
140 |
"op" { |
141 |
if {[hasops $chan]} { |
142 |
set bot [getbot $chan] |
143 |
if {$bot == ""} { |
144 |
set bns "" |
145 |
set bot [getbot $chan] |
146 |
} |
147 |
lappend bns "$bot" |
148 |
if {$bot != ""} { |
149 |
putbot $bot "gop op $chan $botnick" |
150 |
putlog "GetOps: Requesting ops from $bot on $chan" |
151 |
} |
152 |
} { |
153 |
if {$go_cycle} { |
154 |
putserv "NOTICE [chandname2name $chan] :$go_cycle_msg" |
155 |
} |
156 |
} |
157 |
} |
158 |
} |
159 |
} |
160 |
|
161 |
proc hasops {chan} { |
162 |
foreach user [chanlist $chan] { |
163 |
if {[isop $user $chan]} { |
164 |
return 1 |
165 |
} |
166 |
} |
167 |
return 0 |
168 |
} |
169 |
|
170 |
proc getbot {chan} { |
171 |
global bns |
172 |
foreach bn [bots] { |
173 |
if {[lsearch $bns $bn] < 0} { |
174 |
if {[matchattr $bn o|o $chan]} { |
175 |
set nick [hand2nick $bn $chan] |
176 |
if {[onchan $nick $chan] && [isop nick $chan]} { |
177 |
return $bn |
178 |
break |
179 |
} |
180 |
} |
181 |
} |
182 |
} |
183 |
} |
184 |
|
185 |
proc botnet_request {bot com args} { |
186 |
global go_bot_unban go_bot_unknown |
187 |
set args [lindex $args 0] |
188 |
set subcom [lindex $args 0] |
189 |
set chan [string tolower [lindex $args 1]] |
190 |
if {![validchan $chan]} { |
191 |
putbot $bot "gop_resp I don't monitor $chan." |
192 |
return 0 |
193 |
} |
194 |
# Please note, 'chandname2name' will cause an error if it is not a valid channel |
195 |
# Thus, we make sure $chan is a valid channel -before- using it. -poptix |
196 |
set idchan [chandname2name $chan] |
197 |
set nick [lindex $args 2] |
198 |
|
199 |
if {$subcom != "takekey" && ![botonchan $chan]} { |
200 |
putbot $bot "gop_resp I am not on $chan." |
201 |
return 0 |
202 |
} |
203 |
if {![matchattr $bot b]} { |
204 |
if { $go_bot_unknown == 1} { |
205 |
putlog "GetOps: Request ($subcom) from $bot - unknown bot (IGNORED)" |
206 |
} |
207 |
return 0 |
208 |
} |
209 |
|
210 |
switch -exact $subcom { |
211 |
"op" { |
212 |
if {![onchan $nick $chan]} { |
213 |
putbot $bot "gop_resp You are not on $chan for me." |
214 |
return 1 |
215 |
} |
216 |
set bothand [finduser $nick![getchanhost $nick $chan]] |
217 |
if {$bothand == "*"} { |
218 |
putlog "GetOps: $bot requested ops on $chan. Ident not recognized: $nick![getchanhost $nick $chan]." |
219 |
putbot $bot "gop_resp I don't recognize you on IRC (your ident: $nick![getchanhost $nick $chan])" |
220 |
return 1 |
221 |
} |
222 |
if {[string tolower $bothand] == [string tolower $nick]} { |
223 |
putlog "GetOps: $bot requested ops on $chan." |
224 |
} { |
225 |
putlog "GetOps: $bot requested ops as $nick on $chan." |
226 |
} |
227 |
if {[iso $nick $chan] && [matchattr $bothand b]} { |
228 |
if {[botisop $chan]} { |
229 |
if {![isop $nick $chan]} { |
230 |
putlog "GetOps: $nick asked for op on $chan." |
231 |
putbot $bot "gop_resp Opped $nick on $chan." |
232 |
pushmode $chan +o $nick |
233 |
} |
234 |
} { |
235 |
putbot $bot "gop_resp I am not +o on $chan." |
236 |
} |
237 |
} { |
238 |
putbot $bot "gop_resp You aren't +o in my userlist for $chan, sorry." |
239 |
} |
240 |
return 1 |
241 |
} |
242 |
"unban" { |
243 |
if {$go_bot_unban} { |
244 |
putlog "GetOps: $bot requested that I unban him on $chan." |
245 |
foreach ban [chanbans $chan] { |
246 |
if {[string compare $nick $ban]} { |
247 |
set bug_1 [lindex $ban 0] |
248 |
pushmode $chan -b $bug_1 |
249 |
} |
250 |
} |
251 |
return 1 |
252 |
} { |
253 |
putlog "GetOps: Refused request to unban $bot ($nick) on $chan." |
254 |
putbot $bot "gop_resp Sorry, not accepting unban requests." |
255 |
} |
256 |
} |
257 |
"invite" { |
258 |
putlog "GetOps: $bot asked for an invite to $chan." |
259 |
putserv "invite $nick $idchan" |
260 |
return 1 |
261 |
} |
262 |
"limit" { |
263 |
putlog "GetOps: $bot asked for a limit raise on $chan." |
264 |
pushmode $chan +l [expr [llength [chanlist $chan]] + 1] |
265 |
return 1 |
266 |
} |
267 |
"key" { |
268 |
putlog "GetOps: $bot requested the key on $chan." |
269 |
if {[string match *k* [lindex [getchanmode $chan] 0]]} { |
270 |
putbot $bot "gop takekey $chan [lindex [getchanmode $chan] 1]" |
271 |
} { |
272 |
putbot $bot "gop_resp There isn't a key on $chan!" |
273 |
} |
274 |
return 1 |
275 |
} |
276 |
"takekey" { |
277 |
putlog "GetOps: $bot gave me the key to $chan! ($nick)" |
278 |
foreach channel [string tolower [channels]] { |
279 |
if {$chan == $channel} { |
280 |
if {$idchan != ""} { |
281 |
putserv "JOIN $idchan $nick" |
282 |
} else { |
283 |
putserv "JOIN $channel $nick" |
284 |
} |
285 |
return 1 |
286 |
} |
287 |
} |
288 |
} |
289 |
default { |
290 |
putlog "GetOps: ALERT! $bot sent fake 'gop' message! ($subcom)" |
291 |
} |
292 |
} |
293 |
} |
294 |
|
295 |
proc gop_resp {bot com msg} { |
296 |
putlog "GetOps: MSG from $bot: $msg" |
297 |
return 1 |
298 |
} |
299 |
|
300 |
proc lbots {} { |
301 |
set unf "" |
302 |
foreach users [userlist b] { |
303 |
foreach bs [bots] { |
304 |
if {$users == $bs} { |
305 |
lappend unf $users |
306 |
} |
307 |
} |
308 |
} |
309 |
return $unf |
310 |
} |
311 |
|
312 |
# Returns list of bots in the botnet and +o in my userfile on that channel |
313 |
proc lobots { channel } { |
314 |
set unf "" |
315 |
foreach users [userlist b] { |
316 |
if {![matchattr $users o|o $channel]} { continue } |
317 |
foreach bs [bots] { |
318 |
if {$users == $bs} { lappend unf $users } |
319 |
} |
320 |
} |
321 |
return $unf |
322 |
} |
323 |
|
324 |
proc iso {nick chan} { |
325 |
return [matchattr [nick2hand $nick $chan] o|o $chan] |
326 |
} |
327 |
|
328 |
proc gop_need {chan type} { |
329 |
# Use bind need over setting need-op, need-invite, etc ... |
330 |
gain_entrance $type $chan |
331 |
} |
332 |
|
333 |
bind need - * gop_need |
334 |
bind bot - gop botnet_request |
335 |
bind bot - gop_resp gop_resp |
336 |
bind join - * gop_join |
337 |
|
338 |
proc requestop { chan } { |
339 |
global botnick |
340 |
set chan [string tolower $chan] |
341 |
foreach thisbot [lobots $chan] { |
342 |
# Send request to all, because the bot does not have the channel info yet |
343 |
putbot $thisbot "gop op $chan $botnick" |
344 |
lappend askedbot $thisbot |
345 |
} |
346 |
if {[info exist askedbot]} { |
347 |
regsub -all " " $askedbot ", " askedbot |
348 |
putlog "GetOps: Requested Ops from $askedbot on $chan." |
349 |
} { |
350 |
putlog "GetOps: No bots to ask for ops on $chan." |
351 |
} |
352 |
return 0 |
353 |
} |
354 |
|
355 |
proc gop_join { nick uhost hand chan } { |
356 |
if {[isbotnick $nick]} { |
357 |
utimer 3 "requestop $chan" |
358 |
} |
359 |
return 0 |
360 |
} |
361 |
|
362 |
set getops_loaded 1 |
363 |
|
364 |
putlog "GetOps v2.3a loaded." |