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
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
12 deletions
+33
-12
lobby.py
server/game/lobby.py
+30
-10
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
...
@@ -5,8 +5,9 @@ from pydantic.main import BaseModel
from
socketio
import
AsyncServer
from
socketio
import
AsyncServer
from
server.game.manager
import
ClientManager
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.game
import
Game
from
server.model.known
import
CARRE_ACE
from
server.model.players
import
Player
,
Announce
from
server.model.players
import
Player
,
Announce
...
@@ -35,9 +36,9 @@ class LobbyManager(ClientManager):
...
@@ -35,9 +36,9 @@ class LobbyManager(ClientManager):
def
players_ready
(
self
):
def
players_ready
(
self
):
return
[
self
.
lobby
[
k
]
for
k
,
m
in
self
.
metadata
.
items
()
if
m
.
ready
]
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
.
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."
)
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."
return
f
"Bienvenu, {player}! Il y a {len(self.lobby)} joueurs en ligne."
...
@@ -64,18 +65,37 @@ class LobbyManager(ClientManager):
...
@@ -64,18 +65,37 @@ class LobbyManager(ClientManager):
def
handle_message
(
self
,
sid
,
data
):
def
handle_message
(
self
,
sid
,
data
):
sender
:
Optional
[
Player
]
=
None
sender
:
Optional
[
Player
]
=
None
sanitized
=
str
(
data
)
message
=
None
extras
=
None
print
(
f
"Lobby| Received message from {sid}: {data}."
)
print
(
f
"Lobby| Received message from {sid}: {data}."
)
for
player
in
self
.
players
:
for
name
,
metadata
in
self
.
metadata
.
items
()
:
if
player
.
name
in
sanitize
d
:
if
metadata
.
sid
==
si
d
:
sender
=
player
sender
=
self
.
lobby
[
name
]
if
sender
:
if
sender
:
print
(
f
"Lobby| Found sender: {sender.name}"
)
print
(
f
"Lobby| Found sender: {sender.name}"
)
message
=
MessageToPlayer
.
Waiting
for
option
in
MessageFromPlayer
:
extras
=
[
p
.
name
for
p
in
self
.
players
]
if
option
.
value
in
data
:
body
=
{
"message"
:
message
.
name
}
if
option
==
MessageFromPlayer
.
Waiting
:
self
.
metadata
[
sender
.
name
]
.
ready
=
False
extras
=
[
p
.
name
for
p
in
self
.
players
]
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
:
if
extras
:
body
[
"extras"
]
=
extras
body
[
"extras"
]
=
extras
return
json
.
dumps
(
body
)
return
json
.
dumps
(
body
)
server/game/message.py
View file @
357a4209
...
@@ -4,6 +4,7 @@ from enum import Enum
...
@@ -4,6 +4,7 @@ from enum import Enum
class
MessageToPlayer
(
Enum
):
class
MessageToPlayer
(
Enum
):
Waiting
=
"WAITING_ROOM"
Waiting
=
"WAITING_ROOM"
Ready
=
"READY_ROOM"
Ready
=
"READY_ROOM"
NewGame
=
"NEW_GAME"
GiveHand
=
"GIVE_HAND"
GiveHand
=
"GIVE_HAND"
WaitTurn
=
"WAITING_TURN"
WaitTurn
=
"WAITING_TURN"
YourTurn
=
"YOUR_TURN"
YourTurn
=
"YOUR_TURN"
...
@@ -15,7 +16,7 @@ class MessageToPlayer(Enum):
...
@@ -15,7 +16,7 @@ class MessageToPlayer(Enum):
class
MessageFromPlayer
(
Enum
):
class
MessageFromPlayer
(
Enum
):
Wating
=
"WAITING"
Wa
i
ting
=
"WAITING"
Ready
=
"READY"
Ready
=
"READY"
Bet
=
"BET"
Bet
=
"BET"
Menteur
=
"MENTEUR"
Menteur
=
"MENTEUR"
server/ws.py
View file @
357a4209
...
@@ -28,7 +28,7 @@ class ClientPlayer(Player):
...
@@ -28,7 +28,7 @@ class ClientPlayer(Player):
async
def
connect
(
sid
,
environ
):
async
def
connect
(
sid
,
environ
):
print
(
"[WS] Connect "
,
sid
,
environ
)
print
(
"[WS] Connect "
,
sid
,
environ
)
player
=
ClientPlayer
(
lobby
)
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
)
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