diff --git a/cloudflare_manager.py b/cloudflare_manager.py index 15db001..f6fb852 100644 --- a/cloudflare_manager.py +++ b/cloudflare_manager.py @@ -14,14 +14,14 @@ client = Cloudflare( ) -def add_cloudflare_dns(subdomain: str, port: str) -> SRVRecord: +def add_cloudflare_dns(subdomain: str, port: int) -> SRVRecord: record: Literal["SRV"] = "SRV" data: SRVRecordData = { 'weight': 5, 'port': int(port), 'priority': 5, 'target': "servii.fr", - port: int(port), + port: port, zone_id: zone_id, } return client.dns.records.create( diff --git a/file_manager.py b/file_manager.py index 9907918..bd5a8b8 100644 --- a/file_manager.py +++ b/file_manager.py @@ -62,7 +62,7 @@ def update_server_property(file_path, property_name, new_value): file.writelines(content) -def log_error(error_type: str, error_message: str): +async def log_error(error_type: str, error_message: str): logging.basicConfig(filename='logs.txt', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s', datefmt='%Y-%m-%d %H:%M:%S') diff --git a/firebase_manager.py b/firebase_manager.py index 1e0e31b..e8bcddd 100644 --- a/firebase_manager.py +++ b/firebase_manager.py @@ -118,8 +118,7 @@ def set_firestore(user_id: str, data: dict) -> bool: return False -def create_server(user_id: str, server_name: str, version: str, port: str, framework: str = "paper"): - port: int = int(port) +def create_server(user_id: str, server_name: str, version: str, port: int, framework: str = "paper"): servers_ref = firestore_database.collection('users').document(user_id).collection('servers') server_doc_ref = servers_ref.document(server_name) server_doc_ref.set( diff --git a/generic_executor.py b/generic_executor.py index 14e40b0..8952ad5 100644 --- a/generic_executor.py +++ b/generic_executor.py @@ -55,6 +55,7 @@ def fetch_servers(user: UserRecord) -> tuple[HTTPStatus, Union[str, list]]: try: connected_players = mc_manager.get_online_players(server_info.get('port', 25565)) except Exception as e: + file_manager.log_error(type(e).__name__, str(e)) connected_players = 0 server_info['onlinePlayers'] = connected_players servers_data.append(server_info) @@ -225,7 +226,7 @@ def update_properties(user: UserRecord, name: str, props: list[tuple[str, str]]) if status != HTTPStatus.OK: errors.append(message) if len(errors) > 0: - return HTTPStatus.IM_A_TEAPOT, errors + return HTTPStatus.IM_A_TEAPOT, str(errors) return HTTPStatus.OK, f"Successfully updated server '{name}'." diff --git a/requirements.txt b/requirements.txt index 6bd199a..e4ef2cc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,9 @@ Flask_Cors==4.0.1 google-api-core==2.19.0 PyJWT==2.8.0 gunicorn==20.1.0 -cloudflare==3.0.1 \ No newline at end of file +cloudflare==3.0.1 +Flask-Cors~=4.0.1 +mcipc~=2.4.2 +firebase-admin~=6.5.0 +protobuf~=4.25.3 +typing_extensions~=4.9.0 \ No newline at end of file diff --git a/unit_test.py b/unit_test.py index 85ae074..555da96 100644 --- a/unit_test.py +++ b/unit_test.py @@ -1,22 +1,13 @@ import firebase_manager -from mcipc.query import Client def ban_user(user_id: str): try: firebase_manager.auth.update_user(user_id, disabled=False) - print("Banned : "+user_id) + print("Banned : " + user_id) except Exception as e: - print("Error banning user "+user_id, "|", str(e), type(e).__name__) - - -def get_online_players(port) -> int: - with Client('127.0.0.1', port) as client: - stats: mcipc.query.proto.FullStats = client.stats(full=True) - stats: int = stats.num_players - return stats + print("Error banning user " + user_id, "|", str(e), type(e).__name__) if __name__ == '__main__': - #ban_user("MpkbDMOO8PQddQgB5VgBQdTMWF53") - get_online_players(25565) + ban_user("MpkbDMOO8PQddQgB5VgBQdTMWF53")