mirror of
https://github.com/hubHarmony/servii-backend.git
synced 2024-11-17 21:40:31 +00:00
[+] /FetchServers now also returns the amount of connected players
This commit is contained in:
parent
37dc160a12
commit
0747e02fce
@ -31,7 +31,7 @@ def set_subdomain(user: UserRecord, subdomain: str) -> tuple[HTTPStatus, str or
|
||||
try:
|
||||
record: SRVRecord = cloudflare_manager.add_cloudflare_dns(subdomain, port)
|
||||
record_id: str = record.id
|
||||
if record_id is None:
|
||||
if record_id == "":
|
||||
return HTTPStatus.BAD_REQUEST, "Failed to add record to cloudflare"
|
||||
firebase_manager.update_firestore(user_id, {'cloudflare_entry': str(record_id)})
|
||||
except Exception as e:
|
||||
@ -47,7 +47,16 @@ def fetch_servers(user: UserRecord) -> tuple[HTTPStatus, str or list]:
|
||||
server_ref = firebase_manager.firestore_database.collection('users').document(user_id).collection('servers')
|
||||
try:
|
||||
servers = list(server_ref.stream())
|
||||
servers_data = [doc.to_dict() for doc in servers]
|
||||
servers_data: list[dict[str, any]] = []
|
||||
for doc in servers:
|
||||
server_info = doc.to_dict()
|
||||
if server_info.get('running', False):
|
||||
try:
|
||||
connected_players = mc_manager.get_online_players(server_info.get('port', 25565))
|
||||
except Exception as e:
|
||||
connected_players = 0
|
||||
server_info['onlinePlayers'] = connected_players
|
||||
servers_data.append(server_info)
|
||||
if not servers_data:
|
||||
account_create(user)
|
||||
return HTTPStatus.OK, servers_data
|
||||
|
Loading…
Reference in New Issue
Block a user