11"""Aternos Minecraft server"""
22
3- import enum
3+ import re
44import json
55
6+ import enum
7+
68from typing import Optional
79from typing import List , Dict , Any
810
911import requests
1012
11- from .atconnect import AJAX_URL
13+ from .atconnect import BASE_URL , AJAX_URL
1214from .atconnect import AternosConnect
1315from .atwss import AternosWss
1416
1820from .atfm import FileManager
1921from .atconf import AternosConfig
2022
23+ from .aterrors import AternosError
2124from .aterrors import ServerStartError
2225
2326
27+ status_re = re .compile (
28+ r'<script>\s*var lastStatus\s*?=\s*?(\{.+?\});?\s*<\/script>'
29+ )
30+
31+
2432class Edition (enum .IntEnum ):
2533
2634 """Server edition type enum (java, bedrock)"""
@@ -56,7 +64,7 @@ class AternosServer:
5664 def __init__ (
5765 self , servid : str ,
5866 atconn : AternosConnect ,
59- reqinfo : bool = True ) -> None :
67+ reqinfo : bool = False ) -> None :
6068 """Class for controlling your Aternos Minecraft server
6169
6270 Args:
@@ -69,17 +77,24 @@ def __init__(
6977
7078 self .servid = servid
7179 self .atconn = atconn
80+
7281 if reqinfo :
7382 self .fetch ()
7483
7584 def fetch (self ) -> None :
76- """Send a request to Aternos API to get all server info"""
85+ """Get all server info"""
7786
78- servreq = self .atserver_request (
79- f'{ AJAX_URL } /status.php' ,
80- 'GET' , sendtoken = True
87+ page = self .atserver_request (
88+ f'{ BASE_URL } /server' , 'GET'
8189 )
82- self ._info = json .loads (servreq .content )
90+ with open ('server.html' , 'wt' ) as f :
91+ f .write (page .text )
92+ match = status_re .search (page .text )
93+
94+ if match is None :
95+ raise AternosError ('Unable to parse lastStatus object' )
96+
97+ self ._info = json .loads (match [1 ])
8398
8499 def wss (self , autoconfirm : bool = False ) -> AternosWss :
85100 """Returns AternosWss instance for
0 commit comments