Commit 5414c884 authored by ZettaScript's avatar ZettaScript
Browse files

Request handling

parent c5213a06
......@@ -36,9 +36,9 @@ Exemple :
## Sources
http://www.trm.creationmonetaire.info/TheorieRelativedelaMonnaie.pdf
http://geconomicus.glibre.org/rules.html
https://www.youtube.com/watch?v=GMvQxk6mXhU
http://www.trm.creationmonetaire.info/TheorieRelativedelaMonnaie.pdf
http://geconomicus.glibre.org/rules.html
https://www.youtube.com/watch?v=GMvQxk6mXhU
https://www.le-sou.org/2018/01/08/retour-experience-animation-jeu-geconomicus/
## Licence
......@@ -61,3 +61,7 @@ Copyright 2018 Pascal Engélibert
> along with Pygeconomicus-server. If not, see <https://www.gnu.org/licenses/>.
La GNU AGPL impose de publier les sources d'une instance publiquement accessible de ce logiciel, si celles-ci sont modifiées. Pour faciliter cela, le serveur pourra générer et fournir une archive de son propre code source au client si celui-ci en fait la requête.
## Contact
Contactez-moi via le site de ZettaScript : https://zettascript.org
......@@ -26,6 +26,6 @@ from utils import *
# Debt money
class MoneySystem():
name = "Monnaie dette"
name = "debt_money"
def __init__(self):
pass
......@@ -24,7 +24,7 @@ UDV = 1.0905 # UD Variation 109.05%/year is ~200%/8 years
# Free money
class MoneySystem():
name = "Monnaie libre"
name = "free_money"
def __init__(self, players, consts):
self.players = players
......
......@@ -60,10 +60,11 @@ class Player():
self.t_wallet = None
class Game():
def __init__(self, name, leader_name, leader_address, consts):
def __init__(self, name, public, leader_name, leader_address, consts):
# Consts
self.name = name
self.creationtime = time()
self.creation_time = time()
self.public = public
self.leader_name = leader_name
self.leader_address = leader_address
self.C = consts
......@@ -252,10 +253,37 @@ Options:\n\
p_data_expected = p_mod in "pPQ"# if data expected
p_resp = p_mod in "IPQS"# if response expected by client
resp_raw = b""# raw response
resp = None# response
resp_lng = ""# response language
if p_data_expected:
try:
p_data = json.loads(p_raw)
except json.JSONDecodeError:
print("Error: decoding JSON")
if p_lng == "json":
try:
p_data = json.loads(p_raw)
except json.JSONDecodeError:
print("Error: decoding JSON")
continue
if "query" in p_data:
resp = []
resp_lng = "json"
if "games" in p_data["query"]:
resp["games"] = []
for game in games:
if game.public:
resp["games"].append({"name":game.name, "creation_time":game.creation_time, "leader_name":game.leader_name, "n_players":len(game.players), "money_system":game.money_system.name})
if "server_info" in p_data["query"]:
resp["server_info"] = {"version":VERSION, "protocol_versions":PROTOCOL_VERSIONS}
else:
print("Error: unknown language '"+p_lng)
continue
if p_resp:
if resp_lng == "json":
resp_raw = json.dumps(resp).encode()
# TODO: send response 'resp_raw' to the client
Supports Markdown
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