Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Pascal Engélibert
pygeconomicus-server
Commits
cffc1dfd
Commit
cffc1dfd
authored
Oct 11, 2018
by
ZettaScript
Browse files
User management
parent
30606776
Changes
4
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
cffc1dfd
...
...
@@ -59,6 +59,9 @@ Les données JSON comprennent un champ "error".
51: Game management error: there is no game with this name
52: Game management error: miss admin password
53: Game management error: wrong admin password
54: Game management error: that player does not exist
55: Game management error: wrong player password
56: Game management error: miss player password
Exemple de paquet valide :
geco42/json/109
...
...
server.py
View file @
cffc1dfd
...
...
@@ -86,10 +86,19 @@ class Game():
# address is ("address", port)
def
addPlayer
(
self
,
name
,
address
,
psw
):
player
=
Player
(
name
,
address
,
psw
,
self
.
next_uid
)
self
.
next_uid
+=
1
self
.
players
.
append
(
player
)
self
.
players_index
[
self
.
next_uid
]
=
player
self
.
next_uid
+=
1
return
player
# Remove one player
def
removePlayer
(
self
,
uid
):
if
uid
in
self
.
players_index
:
player
=
self
.
players_index
.
pop
(
uid
)
self
.
players
.
remove
(
player
)
return
player
return
False
# Init one player
# pass reborn=False at beginning
# pass reborn=True when the player dies and reborns
...
...
@@ -444,6 +453,49 @@ Options:\n\
player
=
game
.
addPlayer
(
g_player_name
,
g_player_address
,
g_player_psw
)
resp
[
"new_player_done"
]
=
{
"player_name"
:
player
.
name
,
"player_uid"
:
player
.
uid
,
"player_address"
:
player
.
address
[
0
],
"player_port"
:
player
.
address
[
1
]}
if
"rm_player"
in
p_data
:
p_resp
=
True
if
not
"game_name"
in
p_data
:
sendErrorToClient
(
client
,
ERROR_MGAME_MISSGAMENAME
,
resp_lng
)
# Game management error: miss game name
continue
g_name
=
p_data
[
"game_name"
]
if
not
g_name
in
games_index
:
sendErrorToClient
(
client
,
ERROR_MGAME_NONAMED
,
resp_lng
)
# Game management error: there is no game with this name
continue
game
=
games_index
[
g_name
]
g
=
p_data
[
"rm_player"
]
g_player_uid
=
None
if
"player_uid"
in
g
:
g_player_uid
=
g
[
"player_uid"
]
if
not
g_player_uid
in
game
.
players_index
:
sendErrorToClient
(
client
,
ERROR_MGAME_PLAYERNOEXIST
,
resp_lng
)
# Game management error: that player does not exist
continue
if
"admin_psw"
in
g
:
g_admin_psw
=
g
[
"admin_psw"
]
if
g_admin_psw
!=
game
.
admin_psw
:
sendErrorToClient
(
client
,
ERROR_MGAME_WRONGADMINPSW
,
resp_lng
)
# Game management error: wrong admin password
continue
elif
"player_psw"
in
g
:
g_player_psw
=
g
[
"player_psw"
]
if
g_player_psw
!=
game
.
players_index
[
g_player_uid
].
psw
:
sendErrorToClient
(
client
,
ERROR_MGAME_WRONGPLAYERPSW
,
resp_lng
)
# Game management error: wrong player password
continue
else
:
sendErrorToClient
(
client
,
ERROR_MGAME_MISSPLAYERPSW
,
resp_lng
)
# Game management error: miss player password
continue
player
=
game
.
removePlayer
(
g_player_uid
)
resp
[
"rm_player_done"
]
=
{
"player_name"
:
player
.
name
,
"player_uid"
:
player
.
uid
,
"player_address"
:
player
.
address
[
0
],
"player_port"
:
player
.
address
[
1
]}
player
=
None
else
:
sendErrorToClient
(
client
,
ERROR_COM_LANGUAGE
,
resp_lng
)
# Communication error: unknown language
...
...
testclient.py
View file @
cffc1dfd
...
...
@@ -106,6 +106,13 @@ def newplayer(name="Test game", player_name="Little Beetle", player_address=ADDR
"""New player"""
return
sdata
({
"game_name"
:
name
,
"new_player"
:{
"player_name"
:
player_name
,
"player_address"
:
player_address
,
"player_port"
:
player_port
,
"player_psw"
:
player_psw
}},
True
)
def
removeplayer
(
name
=
"Test game"
,
player_uid
=
1
,
player_psw
=
""
,
admin_psw
=
None
):
"""Remove player"""
if
admin_psw
!=
None
:
return
sdata
({
"game_name"
:
name
,
"rm_player"
:{
"player_uid"
:
player_uid
,
"admin_psw"
:
admin_psw
,
"player_psw"
:
player_psw
}},
True
)
else
:
return
sdata
({
"game_name"
:
name
,
"rm_player"
:{
"player_uid"
:
player_uid
,
"player_psw"
:
player_psw
}},
True
)
def
h
():
"""Show help"""
help
(
"__main__"
)
...
...
utils.py
View file @
cffc1dfd
...
...
@@ -28,6 +28,9 @@ ERROR_MGAME_MISSGAMENAME = 50
ERROR_MGAME_NONAMED
=
51
ERROR_MGAME_MISSADMINPSW
=
52
ERROR_MGAME_WRONGADMINPSW
=
53
ERROR_MGAME_PLAYERNOEXIST
=
54
ERROR_MGAME_WRONGPLAYERPSW
=
55
ERROR_MGAME_MISSPLAYERPSW
=
56
# Server functions
...
...
Write
Preview
Supports
Markdown
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