class Process::Roulette::Croupier::Driver
The croupier is the person who runs a roulette table
Croupier
is started with a password (see WAIT state, below)
STATES
-
JOIN
-
accept connections
-
if a connection says :OK, they are added to player list
-
should include a desired username
-
if username is already taken, reject connection
-
if accepted, server sends :OK
-
-
if a connection gives password, they are added to controller list
-
all connections must send a :PING at least every 1000ms or be discarded
-
when controller says :EXIT, advance to FINISH
-
when controller says :GO, state advances to START and no further connections are accepted (listening socket is closed)
-
-
START
-
sends :GO to all players
-
players reply with name/pid of process they will kill
-
players must next respond with :OK after killing the process
-
if player does not reply within 1000ms they are flagged “DEAD”
-
if all players are flagged “DEAD”, advance to RESTART
-
when either all players have responded with :OK, or 1000ms have elapsed, advance to START
-
-
RESTART
-
send 'DONE' to controllers
-
send final score info to controllers
-
cleanup
-
advance to JOIN
-
-
FINISH
-
notify all players and controllers that server is ending
-
cleanup
-
exit
-
Attributes
Public Class Methods
# File lib/process/roulette/croupier/driver.rb, line 47 def initialize(port, password) @port = port @password = password @players = [] @controllers = [] end
Public Instance Methods
# File lib/process/roulette/croupier/driver.rb, line 64 def broadcast_update(message) payload = "UPDATE:#{message}" @controllers.each { |s| s.send_packet(payload) } end
# File lib/process/roulette/croupier/driver.rb, line 55 def reap! @players.delete_if(&:dead?) @controllers.delete_if(&:dead?) end
# File lib/process/roulette/croupier/driver.rb, line 69 def run next_state = Croupier::JoinHandler next_state = next_state.new(self).run while next_state end
# File lib/process/roulette/croupier/driver.rb, line 60 def sockets @players + @controllers end