PDA

View Full Version : GS4 AutoConnect



SpiffyJr
08-22-2010, 11:45 PM
The Goods

I've written a small utility to handle connecting to the game similar to the script that was posted earlier. Here's the rundown:


Can handle multiple characters easily
Can specify scripts to start when Lich fires up
Can turn off the front-end if you want to run without the Wizard or StormFront being visible
Loads data from an XML file that can be changed on the fly to add/edit/remove character information
Includes a taskbar icon so you don't clutter up your toolbar


This file is an EXECUTABLE and has the potential to carry a virus. Never run something unless you trust the person it came from. That said, I am trustworthy and it's just a simple ruby script I ran OCRA on so I could hide the source. If you have an issue with it being an exe then don't use it.

Source


require 'gtk2'
require 'rexml/document'
require 'win32ole'
include REXML

version = "0.2-08222010"

# Load settings from XML
$icon = nil
characters = nil
options = nil
raw_xml = nil
doc = nil

$stdout = File.new("autoconnect-output-#{Time.now.to_i}.txt", 'w')
$stdout.sync = true

$stderr = File.new("autoconnect-errors-#{Time.now.to_i}.txt", 'w')
$stderr.sync = true

load_xml_data = proc {
$stdout.puts 'Loading XML data from autoconnect.xml'
fh = File.open('autoconnect.xml', 'r')
doc = Document.new(fh.read)

options = Hash.new
XPath.each(doc, 'autoconnect/options') { |option|
for element in option.elements
options[$1] = $2 if element.to_s =~ /<(\w+)>(.*)<\/.*>/
end
}

characters = Hash.new
XPath.each(doc, 'autoconnect/characters/character') { |character|
name = character.elements['name'].to_s.gsub(/^<\w+>/,'').gsub(/<\/\w+>$/,'')
characters[name] ||= Hash.new

for element in character.elements
next if element.to_s =~ /name/i
characters[name][$1] = $2 if element.to_s =~ /<(\w+)>(.*)<\/.*>/
end
}

fh.close
}

load_xml_data.call

unless File.exists?("#{options['ruby_path']}")
$stderr.puts "error: unable to locate Ruby at #{options['ruby_path']}"
exit
end

unless File.exists?("#{options['lich_path']}")
$stderr.puts "error: unable to locate Lich at #{options['lich_path']}"
exit
end

wmi = WIN32OLE.connect("winmgmts://")

# GTK stuff ripped from Lich
begin
module Gtk
@@pending_blocks = Array.new

def Gtk.queue &block
@@pending_blocks.push(block)
end

def Gtk.do_queue
while block = @@pending_blocks.shift
begin
block.call
rescue
$stderr.puts "error in Gtk.queue: #{$!}"
$stderr.puts $!.backtrace
rescue SyntaxError
$stderr.puts "error in Gtk.queue: #{$!}"
$stderr.puts $!.backtrace
rescue SystemExit
nil
rescue SecurityError
$stderr.puts "error in Gtk.queue: #{$!}"
$stderr.puts $!.backtrace
rescue ThreadError
$stderr.puts "error in Gtk.queue: #{$!}"
$stderr.puts $!.backtrace
rescue SystemStackError
$stderr.puts "error in Gtk.queue: #{$!}"
$stderr.puts $!.backtrace
rescue Exception
$stderr.puts "error in Gtk.queue: #{$!}"
$stderr.puts $!.backtrace
rescue ScriptError
$stderr.puts "error in Gtk.queue: #{$!}"
$stderr.puts $!.backtrace
rescue LoadError
$stderr.puts "error in Gtk.queue: #{$!}"
$stderr.puts $!.backtrace
rescue NoMemoryError
$stderr.puts "error in Gtk.queue: #{$!}"
$stderr.puts $!.backtrace
rescue
$stderr.puts "error in Gtk.queue: #{$!}"
$stderr.puts $!.backtrace
end
end
end
end
HAVE_GTK = true
$stdout.puts "info: HAVE_GTK: true"
rescue LoadError
HAVE_GTK = false
$stdout.puts "warning: failed to load GTK bindings: #{$!}"
$stderr.puts "warning: failed to load GTK bindings: #{$!}"
rescue
HAVE_GTK = false
$stdout.puts "warning: failed to load GTK bindings: #{$!}"
$stderr.puts "warning: failed to load GTK bindings: #{$!}"
end

$stdout.puts 'GS4 AutoConnect started!'

Thread.new {
loop {
$stdout.puts "Character List (#{characters.size})"
characters.each_pair { |char, args| puts " #{char}" }

characters.each_pair { |char, char_opts|
if wmi.ExecQuery("SELECT * FROM win32_process WHERE CommandLine LIKE '%--login #{char}%'").count == 0
$stdout.puts "Starting #{char}..."

args = ''
args += ' --without-frontend' if char_opts['frontend'] == 'false'
args += ' --shattered' if char_opts['shattered'] == 'true'
args += " --start-scripts=#{char_opts['scripts']}" unless char_opts['scripts'].nil? or char_opts['scripts'].empty?

$stdout.puts "Passing arguments: #{args}"

if not defined?(Ocra)
#Thread.new { system("start /B \"GS4 AutoConnect\" \"#{options['ruby_path']}\" \"#{options['lich_path']}\" --login #{char} --shattered #{args}") }

cmd = "\"#{options['ruby_path']}\" \"#{options['lich_path']}\" --login #{char}#{args}"
$stdout.puts "Running via command: #{cmd}"
Thread.new { system(cmd) }

$stdout.puts "Delaying sign-on for #{options['sign_on_delay']} seconds"

start = Time.now.to_f
sleep options['sign_on_delay'].to_i
$stdout.puts "Sleep time: #{Time.now.to_f - start}"
end
end
}

$stdout.puts "Checking for reconnect in #{options['reconnect_delay']} seconds"

start = Time.now.to_f
loop {
break if (Time.now.to_f - start) > options['reconnect_delay'].to_i
sleep 1
}

load_xml_data.call
}
}

Gtk.queue {
window = Gtk::Window.new

$icon = Gtk::StatusIcon.new
$icon.stock = Gtk::Stock::CONNECT
$icon.tooltip = "GS4 AutoConnect"

about = Gtk::ImageMenuItem.new(Gtk::Stock::ABOUT)
about.signal_connect('activate') {
dialog = Gtk::AboutDialog.new
dialog.name = "GS4 AutoConnect"
dialog.comments = "by SpiffyJr (SpiffyJr@gmail.com)"
dialog.copyright = "(c) 2010 Kyle Spraggs"
dialog.version = "v#{version}"
dialog.website = "http://www.blitzaroo.com"
dialog.run
dialog.destroy
}

quit = Gtk::ImageMenuItem.new(Gtk::Stock::QUIT)
quit.signal_connect('activate') { $stdout.close; $stderr.close; Gtk.main_quit }

menu = Gtk::Menu.new
menu.append(about)
menu.append(Gtk::SeparatorMenuItem.new)
menu.append(quit)
menu.show_all

$icon.signal_connect('popup-menu') { |tray, button, time| menu.popup(nil, nil, button, time) }
}

Thread.current.priority = -10
GLib::Timeout.add(100) { Gtk.do_queue; true }

if not defined?(Ocra)
Gtk.main
end


Sample XML File



<autoconnect>
<options>
<lich_path>C:\Users\SpiffyJr\Documents\Simutronics\Lich\lich. rbw</lich_path>
<ruby_path>C:\Ruby\bin\rubyw.exe</ruby_path>
<reconnect_delay>60</reconnect_delay>
<sign_on_delay>5</sign_on_delay>
</options>
<characters>
<character>
<name>Pandin</name>
<scripts>sbounty</scripts>
<frontend>true</frontend>
<shattered>true</shattered>
</character>
</characters>
</autoconnect>


Installation
1. Copy the source above into a script called autoconnect.rbw.
2. Download the XML file and put it in the same directory as the executable (http://lichproject.org/download/autoconnect.xml)
3. Edit the XML file to your settings
4. Double-click on the autoconnect.rbw file.
5. ????
6. Profit!

BigWorm
08-22-2010, 11:57 PM
Why don't you want to share the source?

BriarFox
08-22-2010, 11:58 PM
This program is awesome.

SpiffyJr
08-22-2010, 11:58 PM
Why don't you want to share the source?

Cause I don' wanna!

SpiffyJr
08-22-2010, 11:59 PM
This program is awesome.

Thanks for being my beta testing whor... err, guy.

BriarFox
08-23-2010, 12:04 AM
Thanks for being my beta testing whor... err, guy.

Amusingly, the beta-testing purely involved me figuring out how not to fuck things up.

Donquix
08-23-2010, 12:12 AM
Amusingly, the beta-testing purely involved me figuring out how not to fuck things up.

Then you're bad.

Beta testing is all about figuring out how to fuck things up :)

BigWorm
08-23-2010, 12:14 AM
Cause I don' wanna!

/sadface

SpiffyJr
08-23-2010, 12:29 AM
/sadface

If you try really hard you can still find the source.

Jaimaltz
08-23-2010, 07:10 AM
If you try really hard you can still find the source.

No Marlu specific code that formats their hard drive?
No Marlu specific code that emails everyone they know informing them of their faggotry status?
No Marlu specific code that claims to do these just for funsies?

I was hoping for a hidden gem, and it's just all programmy!

/sadface

Deathravin
08-23-2010, 08:04 AM
at least

if character name =~ /list of marlu/ then exit

Buckwheet
08-23-2010, 12:50 PM
When I added citizendata to the xml file, it loads and gets the following message:

--- Exception: undefined method `include' for #<XMLParser:0x4c0f7ac>
citizendata:30:in `start_script'
--- Lich: citizendata has exited.

Any thoughts?

Liagala
08-23-2010, 04:24 PM
When I added citizendata to the xml file, it loads and gets the following message:

--- Exception: undefined method `include' for #<XMLParser:0x4c0f7ac>
citizendata:30:in `start_script'
--- Lich: citizendata has exited.

Any thoughts?
I don't use citizendata, so I'm not sure how it operates, but does it have any arguments in it (like go2 has an argument for the room # -- ;go2 228, for example)? If so, that might be messing things up.

Buckwheet
08-23-2010, 06:43 PM
Not that I am aware of. You just run citizendata and it goes to the shops and starts scanning.

SpiffyJr
08-23-2010, 07:28 PM
Not that I am aware of. You just run citizendata and it goes to the shops and starts scanning.

<scripts>citizendata</scripts> should work just fine. If it starts Gemstone and you get an error after it starts it's probably something with initialization. You could just add it to favorites if you want.

Buckwheet
08-23-2010, 07:33 PM
<scripts>citizendata</scripts> should work just fine. If it starts Gemstone and you get an error after it starts it's probably something with initialization. You could just add it to favorites if you want.

Yeah thats what I did in the end. But I am using a windows scheduled task to launch lich. I was hoping this program would alleviate some of the issues I have had with downloading too man .sal files at the same time if I listed off 8 characters.

Its still a really cool program.

SpiffyJr
08-23-2010, 08:46 PM
I don't see why having eight characters would be an issue. Just increase the sign on delay if you're having problems.

Drunken Durfin
08-23-2010, 09:34 PM
I'm assuming that this will work just dandy on the new Ubuntu box I just set up to be dedicated to GS?

SpiffyJr
08-24-2010, 08:47 AM
No, it's Windows only.