Class: SRSGame::SRServer

Inherits:
GServer
  • Object
show all
Defined in:
lib/srs_game.rb

Constant Summary collapse

DEFAULT_PORT =

♫ 54-46 was my number ♫ ##

54_46
MAX_CONNECTIONS =
4

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mod, port = DEFAULT_PORT, host = DEFAULT_HOST, max_connections = MAX_CONNECTIONS) ⇒ SRServer

Returns a new instance of SRServer.



402
403
404
405
# File 'lib/srs_game.rb', line 402

def initialize(mod, port=DEFAULT_PORT, host=DEFAULT_HOST, max_connections=MAX_CONNECTIONS)
  @mod = mod
  super(port, host, max_connections, $stderr, true, true)
end

Instance Attribute Details

#modObject (readonly)

Returns the value of attribute mod.



400
401
402
# File 'lib/srs_game.rb', line 400

def mod
  @mod
end

Class Method Details

.play(*args) ⇒ Object



421
422
423
424
425
426
427
# File 'lib/srs_game.rb', line 421

def self.play(*args)
  server = new(*args)
  server.audit = true
  server.start
  trap(:INT) { server.stop }
  server.join
end

Instance Method Details

#serve(io) ⇒ Object



407
408
409
410
411
412
413
414
415
416
417
418
419
# File 'lib/srs_game.rb', line 407

def serve(io)
  game = Game.new(@mod, direct: false)

  begin
    loop do
      io.print game.prompt
      input = io.readline
      io.puts game.send(input) unless input.blank?
    end
  rescue DONE_WITH_SRS_GAME
    io.puts "\nHave a nice day!"
  end
end