Spaces:
Runtime error
Runtime error
Update app.py
Browse files2 unmodified lines34567897 unmodified lines171819202122232 unmodified lines262728293031322 unmodified linesfrom websockets.server import serveimport timeprint("started")json.dump({}, open("p.json", "w"))7 unmodified linesp = json.load(open("p.json"))if jm["type"] == "login":if jm["token"] not in p.keys():p.update({jm["token"]: {"pos": {"x": 0,"y": 0, "vy": 0}}})json.dump(p, open("p.json", "w"))await websocket.send(json.dumps({"type": "init", "data": p[jm["token"]]}))elif jm["type"] == "update":2 unmodified linesplayers = []for key, value in p.items():if key != jm["token"] and time.time() * 1000 - value["time"] < 1000:players.append({"pos": value["pos"], "name": value["name"]})await websocket.send(json.dumps({"type": "update", "data": {"players": players}}))async def main():2 unmodified lines345678910117 unmodified lines192021222324252 unmodified lines282930313233342 unmodified linesfrom websockets.server import serveimport timeprint("-------")print("started")print("-------")json.dump({}, open("p.json", "w"))7 unmodified linesp = json.load(open("p.json"))if jm["type"] == "login":if jm["token"] not in p.keys():p.update({jm["token"]: {"pos": {"x": 0,"y": 0, "vy": 0}}, "time": time.time() * 1000})json.dump(p, open("p.json", "w"))await websocket.send(json.dumps({"type": "init", "data": p[jm["token"]]}))elif jm["type"] == "update":2 unmodified linesplayers = []for key, value in p.items():if key != jm["token"] and time.time() * 1000 - value["time"] < 1000:players.append({"pos": value["pos"], "name": value["name"], "color": value["color"]})await websocket.send(json.dumps({"type": "update", "data": {"players": players}}))async def main():
app.py+4-2