[+] Type & dependencies fixes

This commit is contained in:
Charles Le Maux 2024-08-15 10:49:41 +02:00
parent ef2aa65173
commit 8ca465a0e4
6 changed files with 15 additions and 19 deletions

View File

@ -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(

View File

@ -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')

View File

@ -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(

View File

@ -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}'."

View File

@ -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
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

View File

@ -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")