Class: Grueserve::Application
- Inherits:
-
Object
- Object
- Grueserve::Application
- Includes:
- Debuggable
- Defined in:
- lib/grueserve/application.rb
Constant Summary
Constants included from Debuggable
Instance Attribute Summary collapse
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#delay ⇒ Object
Returns the value of attribute delay.
-
#map ⇒ Object
Returns the value of attribute map.
-
#map_path ⇒ Object
Returns the value of attribute map_path.
-
#port ⇒ Object
Returns the value of attribute port.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
- #go ⇒ Object
-
#initialize ⇒ Application
constructor
A new instance of Application.
- #start_server! ⇒ Object
Methods included from Debuggable
format, level, level=, #method_missing, output, #report, #report_for, #reset, #reset_for, source_part, #time
Constructor Details
#initialize ⇒ Application
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
#debug ⇒ Object
Returns the value of attribute debug.
27 28 29 |
# File 'lib/grueserve/application.rb', line 27 def debug @debug end |
#delay ⇒ Object
Returns the value of attribute delay.
27 28 29 |
# File 'lib/grueserve/application.rb', line 27 def delay @delay end |
#map ⇒ Object
Returns the value of attribute map.
27 28 29 |
# File 'lib/grueserve/application.rb', line 27 def map @map end |
#map_path ⇒ Object
Returns the value of attribute map_path.
27 28 29 |
# File 'lib/grueserve/application.rb', line 27 def map_path @map_path end |
#port ⇒ Object
Returns the value of attribute port.
27 28 29 |
# File 'lib/grueserve/application.rb', line 27 def port @port end |
#timeout ⇒ Object
Returns the value of attribute timeout.
27 28 29 |
# File 'lib/grueserve/application.rb', line 27 def timeout @timeout end |
Instance Method Details
#go ⇒ Object
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. do |o| o.set_summary_indent(' ') o. = "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 |