Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
Menteur
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PLN
Menteur
Commits
cf9cbaf9
Unverified
Commit
cf9cbaf9
authored
May 03, 2020
by
PLN (Algolia)
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: Right to disconnect
parent
98e612aa
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
21 additions
and
3 deletions
+21
-3
App.vue
client/src/App.vue
+1
-1
vuex-store.js
client/src/vuex-store.js
+1
-1
lobby.py
server/game/lobby.py
+16
-0
message.py
server/game/message.py
+1
-0
ws.py
server/ws.py
+2
-1
No files found.
client/src/App.vue
View file @
cf9cbaf9
...
...
@@ -87,7 +87,7 @@ export default {
},
currentCards
()
{
let
currentState
=
this
.
socketMessage
;
console
.
log
(
"curCards!
state now:"
,
currentState
);
console
.
log
(
"curCards!
Last message:"
,
JSON
.
stringify
(
currentState
)
);
if
(
currentState
[
"data"
])
{
if
(
currentState
[
"data"
][
"cards"
])
{
console
.
log
(
"Setting cards..."
);
...
...
client/src/vuex-store.js
View file @
cf9cbaf9
...
...
@@ -66,7 +66,7 @@ export const store = new Vuex.Store({
state
.
text
=
text
;
}
if
(
extras
)
{
console
.
log
(
"Extras: "
,
extras
)
console
.
log
(
"Extras: "
,
extras
)
;
let
name
=
extras
.
name
;
if
(
name
)
{
console
.
log
(
"Setting name:"
,
name
);
...
...
server/game/lobby.py
View file @
cf9cbaf9
import
asyncio
import
json
from
sys
import
stderr
from
typing
import
List
,
Dict
,
Optional
from
pydantic.main
import
BaseModel
...
...
@@ -39,12 +40,27 @@ class LobbyManager(ClientManager):
return
[
self
.
lobby
[
k
]
for
k
,
m
in
self
.
metadata
.
items
()
if
m
.
ready
]
async
def
new_player
(
self
,
player
:
Player
,
sid
:
str
)
->
None
:
""" Registers a new player. """
self
.
lobby
[
player
.
name
]
=
player
self
.
players
.
append
(
player
)
self
.
metadata
[
player
.
name
]
=
Metadata
(
sid
=
sid
)
print
(
f
"Added {player} to a lobby with {len(self.lobby)} players."
)
await
self
.
send
(
to
=
player
,
message
=
MessageToPlayer
.
Welcome
,
extras
=
{
"name"
:
player
.
name
})
async
def
player_left
(
self
,
sid
:
str
)
->
None
:
""" Reports the disconnection of a player, both internally and to other players."""
for
name
,
meta
in
self
.
metadata
.
items
():
if
meta
.
sid
==
sid
:
print
(
f
"Player {name} disconnected."
)
player
=
self
.
lobby
.
pop
(
name
)
self
.
players
.
remove
(
player
)
for
p
in
self
.
players
:
await
self
.
send
(
p
,
MessageToPlayer
.
Disconnected
,
extras
=
{
"justLeft"
:
name
})
return
print
(
f
"No player for sid {sid}..."
,
file
=
stderr
)
def
wants_to_play
(
self
,
player
:
Player
):
"""
Notes that a player wants to play, starting a game if others too.
...
...
server/game/message.py
View file @
cf9cbaf9
...
...
@@ -15,6 +15,7 @@ class MessageToPlayer(Enum):
WinnerIs
=
"WINNER_IS"
Lose
=
"LOSER"
Reset
=
"RESET"
Disconnected
=
"DISCONNECTED"
class
MessageFromPlayer
(
Enum
):
...
...
server/ws.py
View file @
cf9cbaf9
...
...
@@ -55,5 +55,6 @@ async def ping_server(sid, data):
@sio.event
def
disconnect
(
sid
):
async
def
disconnect
(
sid
):
print
(
'[WS] Disconnect '
,
sid
)
await
lobby
.
player_left
(
sid
)
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