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
c33c76b4
Unverified
Commit
c33c76b4
authored
May 03, 2020
by
PLN (Algolia)
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(lobby): sendall
parent
c7c10c0b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
5 deletions
+20
-5
lobby.py
server/game/lobby.py
+18
-5
message.py
server/game/message.py
+2
-0
No files found.
server/game/lobby.py
View file @
c33c76b4
import
asyncio
import
json
import
sys
from
sys
import
stderr
from
typing
import
List
,
Dict
,
Optional
...
...
@@ -47,6 +46,7 @@ class LobbyManager(ClientManager):
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
})
await
self
.
sendall
(
MessageToPlayer
.
NewPlayer
,
but
=
player
)
async
def
player_left
(
self
,
sid
:
str
)
->
None
:
""" Reports the disconnection of a player, both internally and to other players."""
...
...
@@ -57,9 +57,9 @@ class LobbyManager(ClientManager):
player
=
self
.
lobby
.
pop
(
name
)
self
.
players
.
remove
(
player
)
for
p
in
self
.
players
:
await
self
.
send
(
p
,
MessageToPlayer
.
Disconnected
,
extras
=
{
"justLeft"
:
name
})
self
.
metadata
.
pop
(
name
)
await
self
.
sendall
(
MessageToPlayer
.
Disconnected
,
extras
=
{
"justLeft"
:
name
})
return
print
(
f
"No player for sid {sid}..."
,
file
=
stderr
)
...
...
@@ -70,6 +70,8 @@ class LobbyManager(ClientManager):
self
.
metadata
[
player
.
name
]
.
ready
=
True
print
(
f
"Lobby | {player} wants to play!"
)
self
.
sendall
(
MessageToPlayer
.
PlayerReady
,
extras
=
{
"wantsToPlay"
:
player
.
name
},
but
=
player
)
ready
=
self
.
players_ready
return
ready
...
...
@@ -104,6 +106,7 @@ class LobbyManager(ClientManager):
games
=
len
(
self
.
games
)
msg
=
f
"Resetting! sorry for the {players} players / {games} games..."
print
(
msg
)
for
p
in
self
.
players
:
m
=
self
.
metadata
[
p
.
name
]
await
self
.
send
(
p
,
MessageToPlayer
.
Reset
)
...
...
@@ -114,6 +117,17 @@ class LobbyManager(ClientManager):
self
.
games
.
clear
()
return
msg
async
def
sendall
(
self
,
message
:
MessageToPlayer
,
extras
=
None
,
to
:
List
[
Player
]
=
None
,
but
:
Optional
[
Player
]
=
None
):
if
to
is
None
:
to
=
self
.
players
for
p
in
to
:
if
but
and
p
.
name
==
but
.
name
:
continue
self
.
send
(
p
,
message
,
extras
)
async
def
send
(
self
,
to
:
Player
,
message
:
MessageToPlayer
,
extras
=
None
)
->
None
:
sid
:
str
=
"?"
...
...
@@ -227,5 +241,4 @@ class LobbyManager(ClientManager):
await
self
.
send
(
player
,
MessageToPlayer
.
YourTurn
,
extras
)
extras
[
"waitingFor"
]
=
player
.
name
for
p
in
[
p
for
p
in
game
.
players
if
p
!=
player
]:
await
self
.
send
(
p
,
MessageToPlayer
.
Waiting
,
extras
)
await
self
.
sendall
(
MessageToPlayer
.
Waiting
,
extras
,
but
=
player
)
server/game/message.py
View file @
c33c76b4
...
...
@@ -8,6 +8,8 @@ class MessageToPlayer(Enum):
NewGame
=
"NEW_GAME"
GiveHand
=
"GIVE_HAND"
WaitTurn
=
"WAITING_TURN"
NewPlayer
=
"NEW_PLAYER"
PlayerReady
=
"PLAYER_READY"
YourTurn
=
"YOUR_TURN"
WrongAnnounce
=
"WRONG_ANNOUNCE"
Announce
=
"ANNOUNCE"
...
...
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