Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/ruby
- require 'optparse'
- load '/home/sdtd/source/lib/telnet.rb'
- load './sdtdsay-class.rb'
- options = {}
- optparse = OptionParser.new do |opts|
- begin
- opts.banner = 'Usage: send-command.rb [options]'
- opts.on('-c <command>', '--command', String, 'The command to send i.e. "listplayers" or "listknownplayers"', '\'say "something to someone"\' or "admin add blotavious 0"') do |arg|
- options[:command] = arg.to_s
- end
- opts.on('-?', '--help', 'This help screen') do
- puts opts
- exit 0
- end
- options[:device] = "TELNET"
- opts.on('-D <device>', '--device', 'The device to use, can be one of "TELNET" or "STDOUT"') do |arg|
- options[:device] = arg.to_s
- end
- options[:quiet] = FALSE
- opts.on('-q', '--quiet', 'Suppress output') do
- options[:quiet] = TRUE
- end
- if ARGV.length < 1 then
- puts opts
- exit
- end
- opts.parse!
- rescue OptionParser::MissingArgument
- puts 'This option requires an argument'
- puts opts
- exit
- rescue OptionParser::InvalidArgument
- puts 'The argument supplied is invalid, i.e. a number instead of a string etc.'
- puts opts
- exit
- end
- end
- telnet = SDTDSay.new({ :device => options[:device],
- :password => 'yourpassword',
- :host => 'localhost',
- :port => 8081,
- :quiet => options[:quiet]})
- telnet.send(options[:command])
- telnet.close
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement