diff --git a/SatiAPI.py b/SatiAPI.py index 5d79813..7881709 100644 --- a/SatiAPI.py +++ b/SatiAPI.py @@ -16,7 +16,7 @@ urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) class SatiAPI: """A API wrapper for Satisfactory dedicated server""" __AUTHOR__ = 'anima' - __VERSION__ = '0.4.3' + __VERSION__ = '0.5.2' def __init__(self, host: str = None, port: int = 7777, token: str = None, conffile: str = 'conf.yml', logfile: str = 'SatiAPI.log', loglevel: int = 20) -> None: """create a wrapper for satisfactory dedicated server @@ -164,11 +164,9 @@ class SatiAPI: headers['Content-Type'] = 'application/json' if auth: if self.token is None: - print(self.token) self.get_token() if self.token is None: - print(self.token) headers['Authorization'] = f'Bearer {self.token}' else: self._log.error('no data to authencitate') @@ -180,7 +178,6 @@ class SatiAPI: if 'data' in json_response: return json_response else: - #or if 403 # if json_response['errorMessage'] == '': # self._log.debug(f'token expired') # self.get_token() @@ -193,6 +190,23 @@ class SatiAPI: self._log.debug(f'{response.request.body=}') return False + def _passwordless_login(self, privilegeLevel: str = 'InitialAdmin') -> bool: + """Attempts to perform a passwordless login to the Dedicated Server as a player. Passwordless login is possible if the Dedicated Server is not claimed, or if Client Protection Password is not set for the Dedicated Server. This function requires no Authentication. + + :param privilegeLevel: Minimum privilege level to attempt to acquire by logging in. See Privilege Level enum for possible values + :type privilegeLevel: string + :return: true if successfull + :rtype: bool + """ + data = dict() + data['MinimumPrivilegeLevel'] = privilegeLevel + + response = self.__query('PasswordlessLogin', data) + if response: + self.token = response['data']['authenticationToken'] + return True + else: + return response def get_token(self, password: str = None, privilegeLevel: str = 'Administrator') -> bool: """get token from satisfacory dedicated server, password is needed! @@ -231,7 +245,7 @@ class SatiAPI: response = self.__query('PasswordLogin', data) if response: - self.token = response['authenticationToken'] + self.token = response['data']['authenticationToken'] return True else: return response @@ -273,8 +287,6 @@ class SatiAPI: """ return self.__query('GetAdvancedGameSettings') - - ## todo @@ -303,6 +315,7 @@ if __name__ == "__main__": # print(sati.get_token()) # print(sati.token) # print(sati.get_status()) - print(sati.claim_server('SDGame01', 'Admin123!')) + print(sati._passwordless_login()) + # print(sati.claim_server('SDGame01', 'Admin123!')) # print(sati.get_status()) \ No newline at end of file