Hack Forums
[Ruby] Socket/TS3 Serverquery application problems - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Coders Lounge (https://hackforums.net/forumdisplay.php?fid=5)
+---- Thread: [Ruby] Socket/TS3 Serverquery application problems (/showthread.php?tid=2176325)



[Ruby] Socket/TS3 Serverquery application problems - Nerv - Feb 3, 2012

So I'm working on a Teamspeak 3 serverquery client

What I want it to do is login as the server on the provided port and then skip to the last line of
Code
server.gets
To see the servers response to login.

The code I have so far is

Code
#!/usr/bin/ruby

require 'socket'

host = ARGV.shift
port = ARGV.shift
id = ARGV.shift
queryport = ARGV.shift || 10011

if !id
    abort "Usage: #{$0} [host] [port] [id] [queryport]\n"
    end

server = TCPSocket.open(host,queryport)

if !server
    abort("Cant connect to server on queryport #{queryport}\n")
    end

    puts "Enter Nickname to use"
    nick = gets
    nick = nick.chop
    if nick =~ /\s/
        nick.sub!(/\s/, '\s')
        end
    if nick.length < 3 || nick.length > 30
        abort("Nickname must be 3 or more characters and less than 30 characters.")
        end

puts "Connected to Server\n\n"

server.puts "use port=#{port}"
server.puts "clientupdate client_nickname=#{nick}"
server.puts "clientlist"

while bot = server.gets
    while bot !~ /clid/i
        next
        end
        
    puts bot
    end

server.close

Which returns

Code
$ ruby sp2.rb 1.1.1.1 9193 143

Enter Nickname to use
Nerv
Connected to Server

Which just idles until i CTRL+C.

If anyone could help it would be much appreciated.

I'm a perl coder mainly but I'm moving over to ruby as it seems more powerful and the syntax is just a lot nicer to look at.


😉