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) ->
ws = new WebSocket URL
ws.send_msg = (mtype, args...) ->
console.debug '>', mtype, args
@send [mtype].concat(args).join ';'
ws.onopen = ->
......@@ -113,8 +114,8 @@ ws.onerror = (e) ->
ws.onmessage = (msg) ->
[mtype, args...] = msg.data.split ';'
args = ((if s.match /^\d+$/ then parseInt s else s) for s in args)
console.debug 'msg:', mtype, args
args = args.map (s) -> if s.match /^\d+$/ then parseInt s else s
console.debug '<', mtype, args
switch mtype
when 'newgame'
......
......@@ -4,7 +4,7 @@ import logging
import time
from hashlib import sha1
from wspy import AsyncServer, TextMessage
from wspy import AsyncServer, TextMessage, DeflateFrame, WebkitDeflateFrame
from game import Board
......@@ -12,7 +12,7 @@ class BadRequest(RuntimeError):
pass
def check(condition, error='invalid type or args'):
def check(condition, error='invalid format'):
if not condition:
raise BadRequest(error)
......@@ -78,9 +78,8 @@ class Session:
scores = scores.items()
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.bcast('finish', *['%d:%d' % s for s in scores])
else:
index = (self.clients.index(self.turn) + 1) % len(self.clients)
self.turn = self.clients[index]
......@@ -148,6 +147,9 @@ class GameServer(AsyncServer):
check(client.session, 'no session associated with client')
client.session.click_wall(client, x, y, direction)
if client.session.state == STATE_FINISHED:
logging.info('session %s finished' % client.session.sid)
else:
raise BadRequest('unknown message type')
......@@ -165,11 +167,9 @@ class GameServer(AsyncServer):
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])
GameServer(('', port)).run()
#GameServer(('', port), loglevel=logging.DEBUG).run()
if __name__ == '__main__':
port = int(sys.argv[1]) if len(sys.argv) > 1 else 8099
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