Commit 445209dd authored by Taddeüs Kroes's avatar Taddeüs Kroes

Added deflate extensions and some debug lines

parent f65df69b
...@@ -94,6 +94,7 @@ finish = (scores) -> ...@@ -94,6 +94,7 @@ finish = (scores) ->
ws = new WebSocket URL ws = new WebSocket URL
ws.send_msg = (mtype, args...) -> ws.send_msg = (mtype, args...) ->
console.debug '>', mtype, args
@send [mtype].concat(args).join ';' @send [mtype].concat(args).join ';'
ws.onopen = -> ws.onopen = ->
...@@ -113,8 +114,8 @@ ws.onerror = (e) -> ...@@ -113,8 +114,8 @@ ws.onerror = (e) ->
ws.onmessage = (msg) -> ws.onmessage = (msg) ->
[mtype, args...] = msg.data.split ';' [mtype, args...] = msg.data.split ';'
args = ((if s.match /^\d+$/ then parseInt s else s) for s in args) args = args.map (s) -> if s.match /^\d+$/ then parseInt s else s
console.debug 'msg:', mtype, args console.debug '<', mtype, args
switch mtype switch mtype
when 'newgame' when 'newgame'
......
...@@ -4,7 +4,7 @@ import logging ...@@ -4,7 +4,7 @@ import logging
import time import time
from hashlib import sha1 from hashlib import sha1
from wspy import AsyncServer, TextMessage from wspy import AsyncServer, TextMessage, DeflateFrame, WebkitDeflateFrame
from game import Board from game import Board
...@@ -12,7 +12,7 @@ class BadRequest(RuntimeError): ...@@ -12,7 +12,7 @@ class BadRequest(RuntimeError):
pass pass
def check(condition, error='invalid type or args'): def check(condition, error='invalid format'):
if not condition: if not condition:
raise BadRequest(error) raise BadRequest(error)
...@@ -78,9 +78,8 @@ class Session: ...@@ -78,9 +78,8 @@ class Session:
scores = scores.items() scores = scores.items()
scores.sort(key=lambda (player, score): score, reverse=True) scores.sort(key=lambda (player, score): score, reverse=True)
self.bcast('finish', *['%d:%d' % s for s in scores])
logging.info('finishing session %s' % self.sid)
self.state = STATE_FINISHED self.state = STATE_FINISHED
self.bcast('finish', *['%d:%d' % s for s in scores])
else: else:
index = (self.clients.index(self.turn) + 1) % len(self.clients) index = (self.clients.index(self.turn) + 1) % len(self.clients)
self.turn = self.clients[index] self.turn = self.clients[index]
...@@ -148,6 +147,9 @@ class GameServer(AsyncServer): ...@@ -148,6 +147,9 @@ class GameServer(AsyncServer):
check(client.session, 'no session associated with client') check(client.session, 'no session associated with client')
client.session.click_wall(client, x, y, direction) client.session.click_wall(client, x, y, direction)
if client.session.state == STATE_FINISHED:
logging.info('session %s finished' % client.session.sid)
else: else:
raise BadRequest('unknown message type') raise BadRequest('unknown message type')
...@@ -165,11 +167,9 @@ class GameServer(AsyncServer): ...@@ -165,11 +167,9 @@ class GameServer(AsyncServer):
del self.sessions[client.session.sid] del self.sessions[client.session.sid]
if __name__ == '__main__':
if len(sys.argv) < 2:
print >>sys.stderr, 'usage: % PORT' % sys.argv[0]
sys.exit(1)
port = int(sys.argv[1]) if __name__ == '__main__':
GameServer(('', port)).run() port = int(sys.argv[1]) if len(sys.argv) > 1 else 8099
#GameServer(('', port), loglevel=logging.DEBUG).run() GameServer(('localhost', port),
extensions=[DeflateFrame(), WebkitDeflateFrame()],
loglevel=logging.DEBUG).run()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment