SRCDS Steam group


Query a Server from Ruby
#1
I want to thank "Toast" from this originating thread => Query server with php

I took their code and ported it over to Ruby for anyone interested in using it with RoR.

I tried to grab all information possible to parse out the data being returned into a Struct object..

Querying a Server with Ruby
Code:
require "socket"
require "struct"

UDP_RECV_TIMEOUT = 3

Settings = Struct.new(:server_name, :map, :game_directory,
                                :game_description, :appID, :number_players,
                                :maximum_players, :number_bots, :dedicated,
                                :os, :password, :secure, :game_version)

def query(host, port = 27015)

host = host.to_s

sock = UDPSocket.open
sock.send("\377\377\377\377TSource Engine Query\0", 0,host,port)
resp = if select([sock], nil, nil, UDP_RECV_TIMEOUT)
  sock.recvfrom(65536)
end



data = resp[0].unpack('@6Z*Z*Z*Z*vcccaaccZ*')

server_info = Settings.new(data[0],data[1],data[2],data[3],data[4],data[5],
                              data[6],data[7],data[8],data[9],data[10],data[11],
                              data[12])

return server_info

end


To get the information, just pull the attributes from the struct.

e.g. Here is a sample of how to get player count
Code:
server = query("someserver.com")
puts "#{server.server_name} has #{server.number_players} / #{server.maximum_players} players"

My programming sucks, but feel free to take and improve Wink
Reply
#2
Looks cool!
Reply
#3
already have java, php, ruby version

call "Steam Condenser"

The Steam Condenser is a multi-language library for querying the Steam Community, Source and GoldSrc game servers as well as the Steam master servers. Currently it is implemented in Java, PHP and Ruby. C# and Objective-C implementations are currently in progress.

At the moment the library is able to query Source and GoldSrc servers and built objects respresenting the server (including basic information, players and rules) in all three languages. Additionally these objects can be used to send RCON request to the corresponding server. Additionally you're able to acquire information from the Steam Community like player stats and achievements.

The project is hosted on GitHub and was created by Koraktor


http://developer.valvesoftware.com/wiki/Steam_Condenser
Reply
#4
raydan Wrote:alreday have java, php, ruby version

call "Steam Condenser"

The Steam Condenser is a multi-language library for querying the Steam Community, Source and GoldSrc game servers as well as the Steam master servers. Currently it is implemented in Java, PHP and Ruby. C# and Objective-C implementations are currently in progress.

At the moment the library is able to query Source and GoldSrc servers and built objects respresenting the server (including basic information, players and rules) in all three languages. Additionally these objects can be used to send RCON request to the corresponding server. Additionally you're able to acquire information from the Steam Community like player stats and achievements.

The project is hosted on GitHub and was created by Koraktor


http://developer.valvesoftware.com/wiki/Steam_Condenser

Oh...Didn't know about that thanks for posting.
~ trewq
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)