Can't get enough SRCDS.com? Follow us on: Twitter | IRC | Steam


Post Reply 

Query a Server from Ruby

Author Message
terminalhit Offline
Newbie

Posts: 1
Joined: Sep 2009
Reputation: 0
Post: #1
Query a Server from Ruby
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
09-02-2009 11:31 PM
Find all posts by this user Quote this message in a reply
realchamp Offline
Bæver klubben

Posts: 6,128
Joined: May 2008
Reputation: 60
Post: #2
RE: Query a Server from Ruby
Looks cool!
09-02-2009 11:44 PM
Visit this user's website Find all posts by this user Quote this message in a reply
raydan Offline
Junior Member

Posts: 20
Joined: Aug 2007
Reputation: 1
Post: #3
RE: Query a Server from Ruby
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
(This post was last modified: 09-03-2009 11:09 PM by raydan.)
09-03-2009 02:46 PM
Find all posts by this user Quote this message in a reply
Goilio Offline
THE Cool Moderator

Posts: 909
Joined: Feb 2008
Reputation: 9
Post: #4
RE: Query a Server from Ruby
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.

Footprint Gaming
Do not PM me for help

Code:
while true; do echo -n "Goilio "; done
09-03-2009 02:52 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply 


Forum Jump: