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
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.CRITICAL)
|
||||||
|
|
||||||
app = FastAPI(title="codey.lol API",
|
app = FastAPI(title="codey.lol API",
|
||||||
version="0.1a",
|
version="0.1a",
|
||||||
|
@ -59,10 +59,10 @@ class CAH(FastAPI):
|
|||||||
for __game in self.games:
|
for __game in self.games:
|
||||||
if __game.id == game:
|
if __game.id == game:
|
||||||
_game = __game
|
_game = __game
|
||||||
print(f"Got game!!!\n{game}")
|
print(f"Got game!!!\n{_game}\nPlayers: {_game.players}")
|
||||||
for _player in _game.players:
|
for idx, _player in enumerate(_game.players):
|
||||||
if _player.get('id') == player:
|
if _player.get('handle') == player:
|
||||||
_game.players.pop(_player)
|
_game.players.pop(idx)
|
||||||
await self.connection_manager.broadcast({
|
await self.connection_manager.broadcast({
|
||||||
'event': 'player_left',
|
'event': 'player_left',
|
||||||
'ts': int(time.time()),
|
'ts': int(time.time()),
|
||||||
@ -101,7 +101,7 @@ class CAH(FastAPI):
|
|||||||
'event': 'player_joined',
|
'event': 'player_joined',
|
||||||
'ts': int(time.time()),
|
'ts': int(time.time()),
|
||||||
'data': {
|
'data': {
|
||||||
'player': player
|
'player': player.__dict__,
|
||||||
}
|
}
|
||||||
}) # Change to broadcast to current game members only
|
}) # Change to broadcast to current game members only
|
||||||
return joined_game
|
return joined_game
|
||||||
@ -134,6 +134,8 @@ class CAH(FastAPI):
|
|||||||
case 'handshake':
|
case 'handshake':
|
||||||
await self.cah_handshake(websocket,
|
await self.cah_handshake(websocket,
|
||||||
data)
|
data)
|
||||||
|
case 'refresh':
|
||||||
|
await self.connection_manager.send_client_and_game_lists(self, websocket)
|
||||||
case 'create_game':
|
case 'create_game':
|
||||||
await self.create_game(websocket,
|
await self.create_game(websocket,
|
||||||
data)
|
data)
|
||||||
@ -232,6 +234,7 @@ class CAH(FastAPI):
|
|||||||
'errorText': f'Player {player} not found in {game}'
|
'errorText': f'Player {player} not found in {game}'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_games(self):
|
def get_games(self):
|
||||||
try:
|
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.
|
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 "):
|
if not key or not key.startswith("Bearer "):
|
||||||
return False
|
return False
|
||||||
@ -33,20 +33,20 @@ class Utilities:
|
|||||||
key = key.split("Bearer ", maxsplit=1)[1].strip()
|
key = key.split("Bearer ", maxsplit=1)[1].strip()
|
||||||
|
|
||||||
if not key in self.constants.API_KEYS:
|
if not key in self.constants.API_KEYS:
|
||||||
print("Auth failed")
|
# print("Auth failed")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if req_type == 2:
|
if req_type == 2:
|
||||||
if not key.startswith("PRV-"):
|
if not key.startswith("PRV-"):
|
||||||
print("Auth failed - not a PRV key")
|
# print("Auth failed - not a PRV key")
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if path.lower().startswith("/xc/") and not key.startswith("XC-"):
|
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
|
return False
|
||||||
|
|
||||||
print("Auth succeeded")
|
# print("Auth succeeded")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user