Class: Grueserve::Application

Inherits:
Object
  • Object
show all
Includes:
Debuggable
Defined in:
lib/grueserve/application.rb

Constant Summary

Constants included from Debuggable

Debuggable::LEVELS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Debuggable

format, level, level=, #method_missing, output, #report, #report_for, #reset, #reset_for, source_part, #time

Constructor Details

#initializeApplication

Returns a new instance of Application.



29
30
31
32
33
34
35
# File 'lib/grueserve/application.rb', line 29

def initialize
  @map_path = Pathname.new(__FILE__).parent.parent.parent.join("example")
  @port = 25999
  @debug = Grueserve::Debuggable::LEVELS[Grueserve::Debuggable::LEVELS.size / 2]
  @delay = 0.1
  @timeout = 20.0
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Grueserve::Debuggable

Instance Attribute Details

#debugObject

Returns the value of attribute debug.



27
28
29
# File 'lib/grueserve/application.rb', line 27

def debug
  @debug
end

#delayObject

Returns the value of attribute delay.



27
28
29
# File 'lib/grueserve/application.rb', line 27

def delay
  @delay
end

#mapObject

Returns the value of attribute map.



27
28
29
# File 'lib/grueserve/application.rb', line 27

def map
  @map
end

#map_pathObject

Returns the value of attribute map_path.



27
28
29
# File 'lib/grueserve/application.rb', line 27

def map_path
  @map_path
end

#portObject

Returns the value of attribute port.



27
28
29
# File 'lib/grueserve/application.rb', line 27

def port
  @port
end

#timeoutObject

Returns the value of attribute timeout.



27
28
29
# File 'lib/grueserve/application.rb', line 27

def timeout
  @timeout
end

Instance Method Details

#goObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/grueserve/application.rb', line 37

def go
  ARGV.options do |o|
    o.set_summary_indent('   ')
    o.banner = "Usage: #{$0} [OPTIONS]"
    o.define_head "Serves gruesome games."
    o.separator ""
    o.on("-p", "--port=PORT", Integer, :REQUIRED, "TCP port to listen on, defaults to #{@port}.") do |@port| end
    o.on("-D", "--delay=DELAY", Float, "The delay constant to use when prioritizing connected players against connecting players. Defaults to #{@delay}.") do |@delay| end
    o.on("-t", "--timeout=TIMEOUT", Float, "The timeout for broken and disconnected clients. Defaults to #{@timeout}.") do |@timeout| end
    o.on("-m", "--map=MAP", String, "Directory where the map to serve can be found, defaults to #{@map_path}.") do |m|
      @map_path = Pathname.new(m, self)
    end
    o.on("-d", "--debug=LEVEL", String, "Debug level to use, choose from '#{Grueserve::Debuggable::LEVELS.join(", ")}', defaults to #{@debug}.") do |d| 
      @debug = d.to_sym
    end
    o.separator ""
    o.on_tail("-h", "--help", "Show this help message.") do
      puts o
      exit
    end
    o.parse!
    start_server!
  end
end

#start_server!Object



62
63
64
65
66
67
68
# File 'lib/grueserve/application.rb', line 62

def start_server!
  Debuggable.level = @debug
  log_info("Starting Grueserve::Server serving map #{@map} on port #{@port} with debug level #{@debug}")
  @map = Grueserve::Map.new(@map_path, self)
  @server = Grueserve::Server.new(:port => @port, :application => self)
  @server.start!
end