CAH plugin ------ initial work/to be refactored, working through implementation bits
This commit is contained in:
parent
a4d9fa797c
commit
f20a325a1f
2
base.py
2
base.py
@ -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",
|
||||
|
@ -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()),
|
||||
@ -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
|
||||
@ -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)
|
||||
@ -232,6 +234,7 @@ class CAH(FastAPI):
|
||||
'errorText': f'Player {player} not found in {game}'
|
||||
}
|
||||
|
||||
|
||||
|
||||
def get_games(self):
|
||||
try:
|
||||
|
10
util.py
10
util.py
@ -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
|
||||
@ -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…
x
Reference in New Issue
Block a user