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
357a4209
Unverified
Commit
357a4209
authored
Apr 14, 2020
by
PLN (Algolia)
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: Send other players waiting
parent
52760898
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
11 deletions
+32
-11
lobby.py
server/game/lobby.py
+29
-9
message.py
server/game/message.py
+2
-1
ws.py
server/ws.py
+1
-1
No files found.
server/game/lobby.py
View file @
357a4209
...
...
@@ -5,8 +5,9 @@ from pydantic.main import BaseModel
from
socketio
import
AsyncServer
from
server.game.manager
import
ClientManager
from
server.game.message
import
MessageToPlayer
from
server.game.message
import
MessageToPlayer
,
MessageFromPlayer
from
server.model.game
import
Game
from
server.model.known
import
CARRE_ACE
from
server.model.players
import
Player
,
Announce
...
...
@@ -35,9 +36,9 @@ class LobbyManager(ClientManager):
def
players_ready
(
self
):
return
[
self
.
lobby
[
k
]
for
k
,
m
in
self
.
metadata
.
items
()
if
m
.
ready
]
async
def
add_player
(
self
,
player
:
Player
,
is_ready
:
bool
=
False
)
->
str
:
async
def
new_player
(
self
,
player
:
Player
,
sid
:
str
)
->
str
:
self
.
lobby
[
player
.
name
]
=
player
self
.
metadata
[
player
.
name
]
=
Metadata
(
ready
=
is_ready
)
self
.
metadata
[
player
.
name
]
=
Metadata
(
sid
=
sid
)
print
(
f
"Added {player} to a lobby with {len(self.lobby)} players."
)
return
f
"Bienvenu, {player}! Il y a {len(self.lobby)} joueurs en ligne."
...
...
@@ -64,18 +65,37 @@ class LobbyManager(ClientManager):
def
handle_message
(
self
,
sid
,
data
):
sender
:
Optional
[
Player
]
=
None
sanitized
=
str
(
data
)
message
=
None
extras
=
None
print
(
f
"Lobby| Received message from {sid}: {data}."
)
for
player
in
self
.
players
:
if
player
.
name
in
sanitize
d
:
sender
=
player
for
name
,
metadata
in
self
.
metadata
.
items
()
:
if
metadata
.
sid
==
si
d
:
sender
=
self
.
lobby
[
name
]
if
sender
:
print
(
f
"Lobby| Found sender: {sender.name}"
)
message
=
MessageToPlayer
.
Waiting
for
option
in
MessageFromPlayer
:
if
option
.
value
in
data
:
if
option
==
MessageFromPlayer
.
Waiting
:
self
.
metadata
[
sender
.
name
]
.
ready
=
False
extras
=
[
p
.
name
for
p
in
self
.
players
]
body
=
{
"message"
:
message
.
name
}
print
(
f
"MSG|Player ready {extras}"
)
elif
option
==
MessageFromPlayer
.
Ready
:
self
.
wants_to_play
(
player
=
sender
)
message
=
MessageToPlayer
.
Ready
extras
=
[
p
.
name
for
p
in
self
.
players_ready
]
elif
option
==
MessageFromPlayer
.
Bet
:
# FIXME vraie annonce, pas juste carre d'as lol
self
.
announces
(
player
=
sender
,
announce
=
Announce
(
bet
=
CARRE_ACE
))
# TODO: connect with current game, return appropriate message
elif
option
==
MessageFromPlayer
.
Menteur
:
self
.
announces
(
player
=
sender
,
announce
=
Announce
())
# TODO: connect with current game, return appropriate message
body
=
{
"message"
:
message
.
name
if
message
else
"none"
}
if
extras
:
body
[
"extras"
]
=
extras
return
json
.
dumps
(
body
)
server/game/message.py
View file @
357a4209
...
...
@@ -4,6 +4,7 @@ from enum import Enum
class
MessageToPlayer
(
Enum
):
Waiting
=
"WAITING_ROOM"
Ready
=
"READY_ROOM"
NewGame
=
"NEW_GAME"
GiveHand
=
"GIVE_HAND"
WaitTurn
=
"WAITING_TURN"
YourTurn
=
"YOUR_TURN"
...
...
@@ -15,7 +16,7 @@ class MessageToPlayer(Enum):
class
MessageFromPlayer
(
Enum
):
Wating
=
"WAITING"
Wa
i
ting
=
"WAITING"
Ready
=
"READY"
Bet
=
"BET"
Menteur
=
"MENTEUR"
server/ws.py
View file @
357a4209
...
...
@@ -28,7 +28,7 @@ class ClientPlayer(Player):
async
def
connect
(
sid
,
environ
):
print
(
"[WS] Connect "
,
sid
,
environ
)
player
=
ClientPlayer
(
lobby
)
reply
:
str
=
await
lobby
.
add_player
(
player
)
reply
:
str
=
await
lobby
.
new_player
(
player
,
sid
)
await
sio
.
emit
(
'messageChannel'
,
reply
,
room
=
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