Mise à jour effectuée, merci de nous signaler tout dysfonctionnement ! | Upgrade done, please let us know about any dysfunction!

Commit c5213a06 authored by ZettaScript's avatar ZettaScript
Browse files

Added argv commands...

parent b6237c4d
......@@ -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.addPlayer("Alice", ("127.0.0.1",8653))
game.addPlayer("Bob", ("127.0.0.1",8654))
game.addPlayer("Eve", ("127.0.0.1",8655))
# Démarrer une partie en monnaie libre
game.startGame(server.money_free)
......
......@@ -42,8 +42,6 @@ class MoneySystem():
# Init players
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):
......
......@@ -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.addPlayer("Alice",("127.0.0.1",8653))
g.addPlayer("Bob",("127.0.0.1",8654))
g.addPlayer("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 "IPQS"# if response expected by client
if p_data_expected:
try:
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment