Skip to content

Commit

Permalink
Merge branch 'master' of git@github.com:dansimpson/em-websocket-server
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Fowler committed Dec 15, 2009
2 parents 67fb2cd + 81366a5 commit 91f78de
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions examples/tictactoe/tictactoe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,16 @@ class TickTackToeServer < WebSocketServer
attr_accessor :game_id, :key, :status_key

def on_connect
puts "C"
@status_key = $status.subscribe do |c|
send_user_count c
end
$status.increment
end

def on_disconnect
puts "DC"
if $games.key?(game_id)
$games.delete(game_id)
end
$status.decrement
$status.unsubscribe @status_key
$status.decrement
delete_game!
end

def on_receive data
Expand Down Expand Up @@ -165,6 +161,12 @@ def on_receive data
end
end

def delete_game!
if $games.key?(game_id)
$games.delete(game_id)
end
end

def game
$games[game_id]
end
Expand All @@ -174,6 +176,7 @@ def turn!
end

def game_over!
delete_game!
send_command "game_over"
end

Expand Down

0 comments on commit 91f78de

Please sign in to comment.