-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathxmpp4me.lic
373 lines (354 loc) · 9.48 KB
/
xmpp4me.lic
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
=begin
Not wanting to answer questions about this script.
=end
if script.vars[1]
if (script.vars[1] == 'local-account') and script.vars[2]
CharSettings['local-account'] = script.vars[2]
elsif (script.vars[1] == 'local-password') and script.vars[2]
CharSettings['local-password'] = script.vars[2]
elsif (script.vars[1] == 'remote-account') and script.vars[2]
CharSettings['remote-account'] = script.vars[2]
else
echo "You're doing it wrong."
end
exit
end
unless local_account = CharSettings['local-account']
echo "You're doing it wrong."
exit
end
unless local_password = CharSettings['local-password']
echo "You're doing it wrong."
exit
end
unless remote_account = CharSettings['remote-account']
echo "You're doing it wrong."
exit
end
require 'xmpp4r'
hide_me
client = Jabber::Client.new(Jabber::JID::new(local_account))
client.connect
client.auth(local_password)
client.send(Jabber::Presence.new.set_type(:available))
client.on_exception {
begin
sleep 5
client.connect
client.auth(local_password)
client.send(Jabber::Presence.new.set_type(:available))
rescue
echo $!
respond $!.backtrace[0..1]
end
}
send_message = proc { |text|
msg = Jabber::Message::new(remote_account, text)
msg.type = :chat
client.send(msg)
}
$xmpp_echo = LimitedArray.new
echo_time = Time.now
echo_count = 0
echo_channels = Array.new
default_channel = nil
exec_string = "
before_dying { kill_script(#{script.name.inspect}) if running?(#{script.name.inspect}) }
Thread.new { wait_while { running?(#{script.name.inspect}) }; Script.self.kill }
hide_me
script.want_script_output = true
loop { $xmpp_echo.push(get) }
"
start_exec_script(exec_string, flags={ :quiet => true })
Thread.new {
loop {
begin
wait_while { $xmpp_echo.empty? }
if echo_count > 0
output = Array.new
10.times {
if line = $xmpp_echo.shift
output.push (line)
echo_count -= 1
break unless echo_count > 0
else
break
end
}
output = output.join("\n")
send_message.call(output)
elsif (echo_time > Time.now)
output = Array.new
10.times {
if line = $xmpp_echo.shift
output.push (line)
else
break
end
}
output = output.join("\n")
send_message.call(output)
elsif echo_channels.length > 0
output = Array.new
count = 0
while line = $xmpp_echo.shift
if line =~ /^\[(?:#{echo_channels.join('|')})\]/i
output.push(line)
count += 1
break if count >= 10
end
end
unless output.empty?
output = output.join("\n")
send_message.call(output)
end
else
$xmpp_echo.clear
end
sleep 0.25
rescue
puts $!
sleep 0.25
end
}
}
before_dying { Script.log "#{Time.now.strftime("%Y-%m-%d %I:%M%P")}: #{Char.name}: script ended" }
Script.log "#{Time.now.strftime("%Y-%m-%d %I:%M%P")}: #{Char.name}: script started"
if ARGV.include?('--reconnected') and (Time.now - $login_time) < 15
send_message.call('script started')
end
client.add_message_callback do |m|
if (m.type == :chat) and (m.from.to_s =~ /^#{remote_account}/)
if m.body =~ /^([0-9\.]+)?,,(.*)/
count = $1
cmd = $2
count ||= 1
if count == 0
echo_count = 0
echo_time = Time.now - 1
else
echo_count = [ echo_count, count.to_i ].max
end
unless cmd.empty?
if Alias.find(cmd)
Alias.run(cmd)
else
do_client(cmd)
end
end
elsif m.body =~ /^([0-9\.]+)?,(.*)/
seconds = $1
cmd = $2
seconds ||= 1
if seconds == 0
echo_count = 0
echo_time = Time.now - 1
else
echo_time = [ echo_time, (Time.now + seconds.to_f) ].max
end
unless cmd.empty?
if Alias.find(cmd)
Alias.run(cmd)
else
do_client(cmd)
end
end
elsif m.body =~ /^look/i
output = String.new
also_see = Array.new
GameObj.npcs.each { |npc|
if npc.status.nil?
also_see.push(npc.name)
else
also_see.push("#{npc.name} (#{npc.status})")
end
}
loot = GameObj.loot
unless loot.nil? or loot.empty?
also_see = (also_see + loot.collect { |obj| obj.name })
end
also_here = Array.new
GameObj.pcs.each { |pc|
if pc.status.nil?
also_here.push(pc.name)
else
also_here.push("#{pc.name} (#{pc.status})")
end
}
room = Room.current
output.concat "#{XMLData.room_title}#{' (' + room.id.to_s + ')' if room}\n"
# if also_see.empty?
# output.concat "#{XMLData.room_description}\n"
# else
# output.concat "#{XMLData.room_description} You also see #{also_see.join(', ')}.\n"
# end
unless also_see.empty?
output.concat "You notice #{also_see.join(', ')}.\n"
end
unless also_here.empty?
output.concat "Also here: #{also_here.join(', ')}\n"
end
output.concat "#{XMLData.room_exits_string}\n"
send_message.call(output)
elsif m.body =~ /^stats/i
output = "mana: #{mana}/#{maxmana}, health: #{health}/#{maxhealth}, spirit: #{spirit}/#{maxspirit}"
wounds = Array.new
scars = Array.new
XMLData.injuries.each_pair { |area,info|
if info['wound'] > 0
wounds.push "#{area}: #{info['wound']}"
end
if info['scar'] > 0
wounds.push "#{area}: #{info['scar']}"
end
}
unless wounds.empty?
output.concat "\nwounds:\n#{wounds.join(', ')}"
end
unless scars.empty?
output.concat "\nscars:\n#{scars.join(', ')}"
end
send_message.call(output)
elsif m.body =~ /^@([A-z\:]+) (.*)/
target = $1
msg = $2
LNet.send_message(h={'type'=>'private','to'=>target}, msg)
elsif m.body =~ /^tune ([A-z]+)/i
channel = $1.downcase
echo_channels.push(channel) unless echo_channels.include?(channel)
default_channel = channel if default_channel.nil?
# echo tuned/default channels
elsif m.body =~ /^untune ([A-z]+)/i
channel = $1.downcase
echo_channels.delete(channel)
# fixme
elsif m.body =~ /^([A-z]+)?\.([A-z].+)/i
channel = $1.downcase
msg = $2
if echo_channels.empty?
send_message.call("not tuned")
elsif channel
if channel_name = echo_channels.find { |c| c =~ /^#{channel}/ }
LNet.send_message(h={'type'=>'channel','channel'=>channel_name}, msg)
else
send_message.call("channels: #{echo_channels.join(', ')}")
end
else
if echo_channels.length == 1
LNet.send_message(h={'type'=>'channel','channel'=>echo_channels.first}, msg)
else
send_message.call("channels: #{echo_channels.join(', ')}")
end
end
elsif m.body =~ /^channels/i
if echo_channels.empty?
send_message.call("not tuned")
else
send_message.call("channels: #{echo_channels.join(', ')}")
end
elsif m.body =~ /^goals/i
link = nil
hook_proc = proc { |server_string|
if server_string =~ /<LaunchURL src="(\/gs4\/play\/cm\/loader.asp[^"]*)" \/>/
link = $1
DownstreamHook.remove('kill-goals')
nil
else
server_string
end
}
DownstreamHook.add('kill-goals', hook_proc)
put 'goals'
100.times {
sleep 0.05
break if link
}
if link
send_message.call("https://www.play.net#{link}")
end
end
end
end
Thread.new {
begin
loop {
wait_until { dead? }
send_message.call('dead')
Script.log "#{Time.now.strftime("%Y-%m-%d %I:%M%P")}: #{Char.name}: dead"
wait_while { dead? }
}
rescue
echo $!
puts $!.backtrace[0..1]
end
}
Thread.new {
begin
loop {
wait_while { percentmind > 0 }
send_message.call('empty mind')
Script.log "#{Time.now.strftime("%Y-%m-%d %I:%M%P")}: #{Char.name}: empty mind"
wait_until { percentmind > 50 }
}
rescue
echo $!
puts $!.backtrace[0..1]
end
}
Thread.new {
begin
after = XMLData.injuries.values.collect { |area| area['wound'] }.join('')
loop {
loop {
before = after.dup
sleep 1
after = XMLData.injuries.values.collect { |area| area['wound'] }.join('')
break if (after > before) and (after.include?('2') or after.include?('3')) and not (XMLData.room_title == '[Krag Slopes]' and XMLData.room_description == 'The shrieking wind races across the frozen ground and slams against the rugged wall which rises sharply to the south. To one side a sizeable stone chest lies on its side, firmly imbedded in the lava that spilled over it years ago.' and XMLData.room_exits_string == 'Obvious paths: north')
}
wounds = Array.new
scars = Array.new
XMLData.injuries.each_pair { |area,info|
if info['wound'] > 0
wounds.push "#{area}: #{info['wound']}"
end
if info['scar'] > 0
wounds.push "#{area}: #{info['scar']}"
end
}
output = String.new
unless wounds.empty?
output.concat "wounds:\n#{wounds.join(', ')}"
output.concat "\n" unless scars.empty?
end
unless scars.empty?
output.concat "scars:\n#{scars.join(', ')}"
end
send_message.call(output)
Script.log "#{Time.now.strftime("%Y-%m-%d %I:%M%P")}: #{Char.name}: wounded"
}
rescue
echo $!
puts $!.backtrace[0..1]
end
}
begin
script.want_downstream_xml = true
script.want_downstream = false
while (line = get)
if line =~ /^Announcement\: /
send_message.call(line.gsub(/<.*?>/, ''))
elsif line =~ /^(?:<stream id="thoughts">|<pushStream id="thoughts"\/>)\[Private\]\-[A-z\:]+\: ".*"/
unless line =~ /^(?:<stream id="thoughts">|<pushStream id="thoughts"\/>)\[Private\]\-GSF\:(?:Norlamin|Eschaton)\: ".*"/
send_message.call(line.gsub(/<.*?>/, ''))
end
elsif line =~ /^(?:<stream id="thoughts">|<pushStream id="thoughts"\/>)\[server\]\: "(?:no user named|be more specific)/
send_message.call(line.gsub(/<.*?>/, ''))
end
end
ensure
unless $_CLIENTBUFFER_.any? { |cmd| cmd =~ /^(?:\[.*?\])?(?:<c>)?(?:quit|exit)/i }
send_message.call('script ended') rescue()
end
client.close
end