Start building game.py and websockets.py
This commit is contained in:
parent
fb54388325
commit
ad70939783
0
HeliosBackend/__init__.py
Normal file
0
HeliosBackend/__init__.py
Normal file
4
HeliosBackend/game.py
Normal file
4
HeliosBackend/game.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
class Game:
|
||||||
|
def __init__(self):
|
||||||
|
self.characters = []
|
||||||
|
self.locations = {}
|
||||||
25
HeliosBackend/websockets.py
Normal file
25
HeliosBackend/websockets.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import asyncio
|
||||||
|
|
||||||
|
import websockets
|
||||||
|
|
||||||
|
class WebSocketConnection:
|
||||||
|
def __init__(self, websocket: websockets.ServerConnection):
|
||||||
|
self.websocket = websocket
|
||||||
|
|
||||||
|
|
||||||
|
class WebSocketServer:
|
||||||
|
def __init__(self, port):
|
||||||
|
self.port = port
|
||||||
|
|
||||||
|
self.connections: set[websockets.ServerConnection] = set()
|
||||||
|
|
||||||
|
async def handler(self, websocket: websockets.ServerConnection):
|
||||||
|
self.connections.add(websocket)
|
||||||
|
try:
|
||||||
|
pass # Do something with the websocket
|
||||||
|
finally:
|
||||||
|
self.connections.remove(websocket)
|
||||||
|
|
||||||
|
async def start(self):
|
||||||
|
async with websockets.serve(self.handler, "", self.port):
|
||||||
|
await asyncio.Future()
|
||||||
Loading…
x
Reference in New Issue
Block a user