araeyn commited on
Commit
930de32
·
verified ·
1 Parent(s): c40a0b5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -0
app.py CHANGED
@@ -8,6 +8,7 @@ print("started")
8
  print("-------")
9
 
10
  json.dump({}, open("p.json", "w"))
 
11
 
12
  async def echo(websocket):
13
  timout = 2500
@@ -17,6 +18,7 @@ async def echo(websocket):
17
  if jm["token"] == None:
18
  await websocket.send(json.dumps({"type": "error", "data": "No token"}))
19
  p = json.load(open("p.json"))
 
20
  if jm["type"] == "login":
21
  if jm["token"] not in p.keys():
22
  p.update({jm["token"]: {"pos": {"x": 0,"y": 0, "vy": 0}}})
@@ -30,11 +32,22 @@ async def echo(websocket):
30
  p.update({jm["token"]: jm["data"]})
31
  json.dump(p, open("p.json", "w"))
32
  players = []
 
33
  for key, value in p.items():
34
  if key != jm["token"]:
35
  if time.time() * 1000 - value["time"] < timout:
36
  players.append({"pos": value["pos"], "name": value["name"], "color": value["color"]})
 
 
 
 
 
37
  await websocket.send(json.dumps({"type": "update", "data": {"players": players}}))
 
 
 
 
 
38
 
39
  async def main():
40
  async with serve(echo, "0.0.0.0", 7860):
 
8
  print("-------")
9
 
10
  json.dump({}, open("p.json", "w"))
11
+ json.dump({}, open("b.json", "w"))
12
 
13
  async def echo(websocket):
14
  timout = 2500
 
18
  if jm["token"] == None:
19
  await websocket.send(json.dumps({"type": "error", "data": "No token"}))
20
  p = json.load(open("p.json"))
21
+ b = json.load(open("p.json"))
22
  if jm["type"] == "login":
23
  if jm["token"] not in p.keys():
24
  p.update({jm["token"]: {"pos": {"x": 0,"y": 0, "vy": 0}}})
 
32
  p.update({jm["token"]: jm["data"]})
33
  json.dump(p, open("p.json", "w"))
34
  players = []
35
+ bullets = []
36
  for key, value in p.items():
37
  if key != jm["token"]:
38
  if time.time() * 1000 - value["time"] < timout:
39
  players.append({"pos": value["pos"], "name": value["name"], "color": value["color"]})
40
+ for key, value in b.items():
41
+ if key != jm["token"]:
42
+ if (time.time() - value["time"] / 1000) * 60 <= 420:
43
+ bullets.append(value)
44
+ await websocket.send(json.dumps({"type": "bullet", bullets}))
45
  await websocket.send(json.dumps({"type": "update", "data": {"players": players}}))
46
+ elif jm["type"] == "bullet":
47
+ if jm["token"] not in b.keys():
48
+ b.update({jm["token"]: []})
49
+ b[jm["token"]].append(jm["data"])
50
+ json.dump(b, open("b.json"))
51
 
52
  async def main():
53
  async with serve(echo, "0.0.0.0", 7860):