Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kamertjekapen
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
kamertjekapen
Commits
445209dd
Commit
445209dd
authored
Dec 18, 2014
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added deflate extensions and some debug lines
parent
f65df69b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
13 deletions
+14
-13
game.coffee
game.coffee
+3
-2
server.py
server.py
+11
-11
No files found.
game.coffee
View file @
445209dd
...
@@ -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'
...
...
server.py
View file @
445209dd
...
@@ -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
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment