Class: RMuh::ServerStats::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/rmuh/serverstats/base.rb

Overview

This is the Base server stats class. It wraps GamespyQuery::Socket and adds a simpler interface for the usage of querying the server.

The required parameter within the Hash is ‘:host’. Optional params are: port and cache

  • port: the GamespyQuery port of the server (usually game port)

  • cache: whether the data will cache on request, or pull new data each

    stats request
    

Direct Known Subclasses

Advanced

Constant Summary collapse

DEFAULT_PORT =
2_302

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Base

Returns a new instance of Base.



23
24
25
26
27
28
# File 'lib/rmuh/serverstats/base.rb', line 23

def initialize(opts = {})
  fail ArgumentError, 'arg 1 must be a Hash' unless opts.is_a?(Hash)
  self.class.validate_opts(opts)
  opts_to_instance(opts)
  @gsq = GamespyQuery::Socket.new("#{@host}:#{@port}")
end

Instance Method Details

#statsObject



30
31
32
# File 'lib/rmuh/serverstats/base.rb', line 30

def stats
  remote_stats
end

#update_cacheObject



34
35
36
# File 'lib/rmuh/serverstats/base.rb', line 34

def update_cache
  @serverstats = sync if @cache
end