Loading base.py +1 −1 Original line number Diff line number Diff line Loading @@ -9,7 +9,7 @@ from fastapi.security import APIKeyHeader, APIKeyQuery from fastapi.middleware.cors import CORSMiddleware logger = logging.getLogger() logger.setLevel(logging.DEBUG) logger.setLevel(logging.CRITICAL) app = FastAPI(title="codey.lol API", version="0.1a", Loading endpoints/cah.py +8 −5 Original line number Diff line number Diff line Loading @@ -59,10 +59,10 @@ class CAH(FastAPI): for __game in self.games: if __game.id == game: _game = __game print(f"Got game!!!\n{game}") for _player in _game.players: if _player.get('id') == player: _game.players.pop(_player) print(f"Got game!!!\n{_game}\nPlayers: {_game.players}") for idx, _player in enumerate(_game.players): if _player.get('handle') == player: _game.players.pop(idx) await self.connection_manager.broadcast({ 'event': 'player_left', 'ts': int(time.time()), Loading Loading @@ -101,7 +101,7 @@ class CAH(FastAPI): 'event': 'player_joined', 'ts': int(time.time()), 'data': { 'player': player 'player': player.__dict__, } }) # Change to broadcast to current game members only return joined_game Loading Loading @@ -134,6 +134,8 @@ class CAH(FastAPI): case 'handshake': await self.cah_handshake(websocket, data) case 'refresh': await self.connection_manager.send_client_and_game_lists(self, websocket) case 'create_game': await self.create_game(websocket, data) Loading Loading @@ -233,6 +235,7 @@ class CAH(FastAPI): } def get_games(self): try: _games: list = [] Loading util.py +5 −5 Original line number Diff line number Diff line Loading @@ -25,7 +25,7 @@ class Utilities: Accepts path as an argument to allow fine tuning access for each API key, not currently in use. """ print(f"Testing with path: {path}, key: {key}") # print(f"Testing with path: {path}, key: {key}") if not key or not key.startswith("Bearer "): return False Loading @@ -33,20 +33,20 @@ class Utilities: key = key.split("Bearer ", maxsplit=1)[1].strip() if not key in self.constants.API_KEYS: print("Auth failed") # print("Auth failed") return False if req_type == 2: if not key.startswith("PRV-"): print("Auth failed - not a PRV key") # print("Auth failed - not a PRV key") return False else: return True if path.lower().startswith("/xc/") and not key.startswith("XC-"): print("Auth failed - not an XC Key") # print("Auth failed - not an XC Key") return False print("Auth succeeded") # print("Auth succeeded") return True Loading
base.py +1 −1 Original line number Diff line number Diff line Loading @@ -9,7 +9,7 @@ from fastapi.security import APIKeyHeader, APIKeyQuery from fastapi.middleware.cors import CORSMiddleware logger = logging.getLogger() logger.setLevel(logging.DEBUG) logger.setLevel(logging.CRITICAL) app = FastAPI(title="codey.lol API", version="0.1a", Loading
endpoints/cah.py +8 −5 Original line number Diff line number Diff line Loading @@ -59,10 +59,10 @@ class CAH(FastAPI): for __game in self.games: if __game.id == game: _game = __game print(f"Got game!!!\n{game}") for _player in _game.players: if _player.get('id') == player: _game.players.pop(_player) print(f"Got game!!!\n{_game}\nPlayers: {_game.players}") for idx, _player in enumerate(_game.players): if _player.get('handle') == player: _game.players.pop(idx) await self.connection_manager.broadcast({ 'event': 'player_left', 'ts': int(time.time()), Loading Loading @@ -101,7 +101,7 @@ class CAH(FastAPI): 'event': 'player_joined', 'ts': int(time.time()), 'data': { 'player': player 'player': player.__dict__, } }) # Change to broadcast to current game members only return joined_game Loading Loading @@ -134,6 +134,8 @@ class CAH(FastAPI): case 'handshake': await self.cah_handshake(websocket, data) case 'refresh': await self.connection_manager.send_client_and_game_lists(self, websocket) case 'create_game': await self.create_game(websocket, data) Loading Loading @@ -233,6 +235,7 @@ class CAH(FastAPI): } def get_games(self): try: _games: list = [] Loading
util.py +5 −5 Original line number Diff line number Diff line Loading @@ -25,7 +25,7 @@ class Utilities: Accepts path as an argument to allow fine tuning access for each API key, not currently in use. """ print(f"Testing with path: {path}, key: {key}") # print(f"Testing with path: {path}, key: {key}") if not key or not key.startswith("Bearer "): return False Loading @@ -33,20 +33,20 @@ class Utilities: key = key.split("Bearer ", maxsplit=1)[1].strip() if not key in self.constants.API_KEYS: print("Auth failed") # print("Auth failed") return False if req_type == 2: if not key.startswith("PRV-"): print("Auth failed - not a PRV key") # print("Auth failed - not a PRV key") return False else: return True if path.lower().startswith("/xc/") and not key.startswith("XC-"): print("Auth failed - not an XC Key") # print("Auth failed - not an XC Key") return False print("Auth succeeded") # print("Auth succeeded") return True