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
|
# File 'lib/vendor/xmpp4r/data/doc/xmpp4r/examples/advanced/fileserve.rb', line 283
def command(from, cmd, arg)
say = lambda { |text|
say(from, text)
}
socksconf = lambda { |stream|
stream.add_streamhost(@socksserver)
@proxies.each { |sh|
stream.add_streamhost(sh)
}
}
case cmd
when 'get'
arg.gsub!(/\//, '')
arg.gsub!(/^\.+/, '')
transfer = Download.new(@ft, from, "#{@directory}/#{arg}", say, socksconf)
@downloads += 1
@transfers_lock.synchronize {
@transfers.push(transfer)
}
when 'ls'
text = ""
Dir.foreach(@directory) { |file|
next if file =~ /^\./
path = "#{@directory}/#{file}"
text += "#{file} (#{human_readable File.size(path)})\n" if File.file?(path)
}
say.call(text.strip)
when 'stat'
@transfers_lock.synchronize {
text = "#{@transfers.size} transfers:\n"
@transfers.each { |t|
text += "#{t.filename} (#{t.peer}): #{(t.bytes * 100) / t.filesize}% (#{human_readable t.stats}/s)\n"
}
}
say.call(text.strip)
when 'help'
say.call "Download a file: get <filename>\nList directory contents: ls\nLook who is currently wasting bandwidth: stat\nUpload a file, simply send this file"
else
say.call "Unknown command: #{cmd}, try help"
end
end
|