Downloads containing jj2srvinfo.rb

Downloads
Name Author Game Mode Rating
jj2srvinfo 1.0 Cheeze Utility 7.8 Download file

File preview

#!/usr/bin/ruby

###################################################
###################### jj2srvinfo (1.0) ###########
#
# This script is meant to connect to a Jazz Jacktabbit 2 server and determine who
#  is online, and what level is currently being run.
#
###################################################
#
# Copyright (C) 2002 Linas Vaskys
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
##################################################

require 'socket'

$server = 1   # sets a default value to the server

def hextoascii(bar)
    num = bar.length - 1
    final = ""
    for a in 0..num
	temp = bar[a].hex
	final = final + temp.chr
    end
    return final
end

def retrieveinfo(ip,tsf)
   port = 10052
   t = TCPSocket.new(ip,port)

   if tsf
      foo = %w{09 0F 01 04 32 34 20 20 01}   # third byte is uncertain, so i just threw in a 01
   else
      foo = %w{09 0F 01 04 32 31 20 20 01}   # third byte is uncertain, so i just threw in a 01
   end
   sendvar = hextoascii(foo)
   t.send(sendvar,0)

   temp = t.recv(200)
   recvd = "#{recvd}#{temp}"

   bar = recvd.sub(recvd[0..4],'')
   level = bar[/.*\.j2l/]
   puts "\nLevel: #{level}"

   foo = %w{14 0E 01 54 01 00 00 00 00 54 65 73 74 00 00 00 00 00 00 00} # test
   temp= recvd[3..3]
   bar = hextoascii(foo)
   sendvar = bar.sub('T', temp)
   
   t.send(sendvar,0)

   recvd = ""
   temp = "hello"
   #while temp != ""                    # I'm not sure of a good way to make sure that it recieves all the data...for some reason a loop won't work; it'll just hang
      temp = t.recv(2048)    # but i think it's a good bet that 2k will be pleanty
      recvd = "#{recvd}#{temp}"
   #end
   
   foo = ['00']
   a = hextoascii(foo)
   users = []
   i = 0
   
   b = Regexp.escape(recvd.slice(0..9))
   bar = recvd.sub(b,'')
   foo = bar[/[^#{a}]*#{a}/]
   bar = bar.sub(Regexp.escape(foo),'')
   users[i] = foo
   
   
   while bar != ""
      i = i + 1
      b = Regexp.escape(bar.slice(0..6))
      bar = bar.sub(b,'')
      foo = bar[/[^#{a}]*#{a}/]
      bar = bar.sub(Regexp.escape(foo),'')
      if foo != "Test#{a}"
         users[i]  = foo
      end
   end
   
   puts "\nCurrently online:"
   puts users
   
   t.shutdown
end

def retrievelist(server)
   if server == 1
      host = 'jazz.logicware.com'
   elsif server == 2
      host = 'monolith.idlegames.com'
   end
   
   port = 10057
   ip = IPSocket.getaddress(host)
   t = TCPSocket.new(ip,port)

   temp = "hello"

   while temp != ""
      temp = t.recv(200)
      recvd = "#{recvd}#{temp}"
   end
   
   return recvd    
   t.shutdown
end

def chooselist
   isntdone = TRUE
   while isntdone
      puts "\nPlease choose a listserver: \n1. Logicware (jazz.logicware.com)"
      puts "2. Monolith's Box (monolith.idlegames.com) \n"
      print "> "
      a = gets.to_i
      if (a == 1) or (a == 2)
         return a
	 isntdone = FALSE
      else
         puts "That's an invalid request."
      end
   end
end

def parselist(list)
   foo = list.split('\n')
   count = foo.length
   bar = []
   a = 0
   for i in 0..(count - 1)
      temp = foo[i].split
      if temp[2] == "public"
         bar[a] = temp
         a = a + 1
      end
   end
   return bar
end

def displaylist(list)
   a = list.length
   notdone = TRUE
   while notdone
      puts "\nEnter Selection:"
      for i in 0..(a - 1)
         print "\n#{i + 1}. "
	 num = list[i].length
	 for f in 7..(num - 1)
            print "#{list[i][f]} "
	end
	print "#{list[i][6]} #{list[i][4]}"
      end
      print "\n> "
      b = gets.to_i
      if (b <= 0) or (b > a)
         puts "Invalid Entry"
      else
         c = b - 1
         temp = list[c][0].split(':')
	 foo = []
         foo[0] = temp[0]
	 if list[c][4] == "1.24"
	    foo[1] = TRUE
	 else
	    foo[1] = FALSE
	 end
         return foo   
	 notdone = FALSE
      end
   end
end

def ui
   notdone = TRUE
   while notdone
      puts "\nEnter Selection: \n1. Select a listserver \n2. Select a server"
      puts "3. Version/Licence information \n4. Quit"
      print "> "
      a = gets.to_i
      
      if a == 1
         $server = chooselist
      elsif a == 2
	 foobar = parselist(retrievelist($server))
	 ip = displaylist(foobar)
	 retrieveinfo(ip[0],ip[1])
      elsif a == 3
	 puts "\n"
         versinfo
      elsif a == 4
         puts "\nBye.\n"
	 notdone = FALSE
      else
         puts "You entered and invalid request.\n"
      end
   end
end
   
def versinfo  
   puts "jj2srvinfo version 1.0, Copyright (C) 2002 Linas Vaskys"
   puts "\njj2srvinfo comes with ABSOLUTELY NO WARRANTY. "
   puts "This is free software, and you are welcome"
   puts "to redistribute it under certain conditions."
   puts "\n"
end   

versinfo
ui
puts "\nPress Any key..."
gets