Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pygeconomicus-server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pascal Engélibert
pygeconomicus-server
Commits
c5213a06
Commit
c5213a06
authored
Sep 23, 2018
by
ZettaScript
Browse files
Options
Downloads
Patches
Plain Diff
Added argv commands...
parent
b6237c4d
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
README.md
+3
-3
3 additions, 3 deletions
README.md
money_free.py
+0
-2
0 additions, 2 deletions
money_free.py
server.py
+47
-5
47 additions, 5 deletions
server.py
utils.py
+1
-1
1 addition, 1 deletion
utils.py
with
51 additions
and
11 deletions
README.md
+
3
−
3
View file @
c5213a06
...
...
@@ -19,9 +19,9 @@ Exemple :
game = server.Game("Partie de test", "Maître du jeu", ("127.0.0.1",8652), server.CONSTS.copy())
# Ajoutez autant de joueurs que vous voulez...
game.
players.append(server.
Player("Alice",("127.0.0.1",8653))
)
game.
players.append(server.
Player("Bob",("127.0.0.1",8654))
)
game.
players.append(server.
Player("Eve",("127.0.0.1",8655))
)
game.
add
Player("Alice",
("127.0.0.1",8653))
game.
add
Player("Bob",
("127.0.0.1",8654))
game.
add
Player("Eve",
("127.0.0.1",8655))
# Démarrer une partie en monnaie libre
game.startGame(server.money_free)
...
...
This diff is collapsed.
Click to expand it.
money_free.py
+
0
−
2
View file @
c5213a06
...
...
@@ -43,8 +43,6 @@ class MoneySystem():
for
player
in
self
.
players
:
self
.
initPlayer
(
player
,
False
)
self
.
low_value
=
self
.
C
[
"
N_VALUES
"
]
-
self
.
C
[
"
N_WVALUES
"
]
# New turn
def
newTurn
(
self
,
turn
):
if
turn
>
1
:
...
...
This diff is collapsed.
Click to expand it.
server.py
+
47
−
5
View file @
c5213a06
...
...
@@ -40,6 +40,7 @@ CONSTS = {
PATH_CONF
=
"
server.ini
"
# config file relative path
RECBUF
=
1024
# reception buffer length
PROTOCOL_VERSIONS
=
[
b
"
geco0
"
]
# supported protocol versions
VERSION
=
"
0.0.0
"
HOST
=
socket
.
gethostname
()
# server host name
PORT
=
8651
# server port
...
...
@@ -74,6 +75,13 @@ class Game():
self
.
endturn
=
None
# end turn timestamp
self
.
values
=
[
None
]
*
self
.
C
[
"
N_VALUES
"
]
# values order (the last is the waiting value)
# Add one player
# address is ("address", port)
def
addPlayer
(
self
,
name
,
address
):
player
=
Player
(
name
,
address
)
self
.
players
.
append
(
player
)
return
player
# Init one player
# pass reborn=False at beginning
# pass reborn=True when the player dies and reborns
...
...
@@ -135,9 +143,9 @@ class Game():
# Test routine
def
test
():
g
=
Game
(
"
lipsum
"
,
"
Yoda
"
,(
"
127.0.0.1
"
,
8652
),
CONSTS
.
copy
())
g
.
players
.
append
(
Player
(
"
Alice
"
,(
"
127.0.0.1
"
,
8653
))
)
g
.
players
.
append
(
Player
(
"
Bob
"
,(
"
127.0.0.1
"
,
8654
))
)
g
.
players
.
append
(
Player
(
"
Eve
"
,(
"
127.0.0.1
"
,
8655
))
)
g
.
add
Player
(
"
Alice
"
,(
"
127.0.0.1
"
,
8653
))
g
.
add
Player
(
"
Bob
"
,(
"
127.0.0.1
"
,
8654
))
g
.
add
Player
(
"
Eve
"
,(
"
127.0.0.1
"
,
8655
))
g
.
startGame
(
money_free
)
return
g
...
...
@@ -161,8 +169,42 @@ if __name__ == "__main__":
# Config
readConfig
()
if
"
--help
"
in
argv
:
print
(
"
pygeconomicus-server
"
+
VERSION
+
"
\n\
Copyright 2018 Pascal Engélibert (GNU AGPL v3+)
\n\
\n\
Options:
\n\
-h <hostname> Server hostname (default:
'"
+
HOST
+
"'
)
\n\
-p <port> Server port (default:
"
+
str
(
PORT
)
+
"
)
\n\
--help Show this message
\n\
--source Create source archive (publish modified source code to comply with GNU AGPL)
\n\
"
)
exit
()
if
"
--source
"
in
argv
:
import
tarfile
def
tarReset
(
tarinfo
):
tarinfo
.
uid
=
tarinfo
.
gid
=
0
tarinfo
.
uname
=
tarinfo
.
gname
=
"
root
"
return
tarinfo
tar
=
tarfile
.
open
(
"
sourcecode.tar.gz
"
,
"
w:gz
"
)
tar
.
add
(
"
server.py
"
,
filter
=
tarReset
)
tar
.
add
(
"
money_free.py
"
,
filter
=
tarReset
)
tar
.
add
(
"
money_debt.py
"
,
filter
=
tarReset
)
tar
.
add
(
"
utils.py
"
,
filter
=
tarReset
)
tar
.
add
(
"
README.md
"
,
filter
=
tarReset
)
tar
.
add
(
"
LICENSE
"
,
filter
=
tarReset
)
tar
.
close
()
print
(
"
Archive successfully created!
"
)
exit
()
HOST
=
getargv
(
argv
,
"
-h
"
,
HOST
)
POST
=
getargv
(
argv
,
"
-p
"
,
PORT
)
try
:
PORT
=
int
(
getargv
(
argv
,
"
-p
"
,
PORT
))
except
ValueError
:
print
(
"
Error: port must be an integer
"
)
exit
(
1
)
# Start server
...
...
@@ -209,7 +251,7 @@ if __name__ == "__main__":
p_mod
=
chr
(
paquet
[
seps
[
1
]
+
1
])
# mode
p_data_expected
=
p_mod
in
"
pPQ
"
# if data expected
p_resp
=
p_mod
in
"
IPQ
"
# if response expected by client
p_resp
=
p_mod
in
"
IPQ
S
"
# if response expected by client
if
p_data_expected
:
try
:
...
...
This diff is collapsed.
Click to expand it.
utils.py
+
1
−
1
View file @
c5213a06
...
...
@@ -21,7 +21,7 @@
def
getargv
(
argv
,
arg
,
default
=
""
):
if
arg
in
argv
and
len
(
argv
)
>
argv
.
index
(
arg
)
+
1
:
return
argv
[
argv
.
index
[
arg
]
+
1
]
return
argv
[
argv
.
index
(
arg
)
+
1
]
else
:
return
default
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment