Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Better handling of connection closing and errors

  • Loading branch information...
commit bfa598292737a06fa52f8317928ff86250e6b9a2 1 parent b66c3a1
@dhotson authored
Showing with 11 additions and 6 deletions.
  1. +11 −6 deathmatch.rb
View
17 deathmatch.rb
@@ -409,11 +409,20 @@ def collide?(line)
player = $world.new_player
ws.onopen do
- EventMachine::PeriodicTimer.new(dt) do
+ t = EventMachine::PeriodicTimer.new(dt) do
ws.send $world.to_json(player)
end
- end
+ ws.onclose do
+ t.cancel
+ $world.remove_player(player)
+ end
+
+ ws.onerror do
+ t.cancel
+ $world.remove_player(player)
+ end
+ end
ws.onmessage do |msg|
if !player.dead
@@ -440,8 +449,4 @@ def collide?(line)
end
end
end
-
- ws.onclose do
- $world.remove_player(player)
- end
end
Please sign in to comment.
Something went wrong with that request. Please try again.