Skip to content

Usage Examples Ruby

edmundask edited this page Nov 23, 2011 · 2 revisions

Querying game servers Querying a GoldSrc game server listening on IP 192.168.0.114 and port 27016

server_ip = IPAddr.new("192.168.0.114")
server = GoldSrcServer.new(server_ip, 27016)
server.init
puts server.players

Querying master servers Querying the GoldSrc master server and getting a random GoldSrc server

master = MasterServer.new(*MasterServer::GOLDSRC_MASTER_SERVER)
servers = master.servers
random_server = servers[rand(servers.length)]
server = GoldSrcServer.new(*random_server)

Controlling game servers using RCON Executing the command status on a local Source server and displaying the output

server_ip = IPAddr.new('127.0.0.1')
server = SourceServer.new(server_ip)
begin
  server.rcon_auth('passw0rd')
  puts server.rcon_exec('status')
rescue RCONNoAuthException
  warn 'Could not authenticate with the game server.'
end

Getting information from the Steam Community Getting the Steam Community profile of Valve's Adrian Finol and his TF2 achievements

id = SteamId.new('demomenz')
stats = id.game_stats('tf2')
achievements = stats.achievements
Clone this wiki locally