diff --git a/SatiAPI.py b/SatiAPI.py index a79bffe..f14a414 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.11.3' + __VERSION__ = '0.13.1' 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 @@ -394,12 +394,50 @@ class SatiAPI: return self.__query('HealthCheck', data) def get_sessions(self): + """Enumerates all save game files available on the Dedicated Server. Requires Admin privileges. Function does not require any additional parameters. + + :return: List of sessions available on the Dedicated Server + :rtype: dict + """ return self.__query('EnumerateSessions', auth=True) - # def create_new_game(self, sessionname, startlocation) -> bool: - # data = dict() - # data['NewGameData'] - # pass + def create_new_game(self, sessionname: str = None, startLocation: str | int = None) -> bool: + """Creates a new session on the Dedicated Server, and immediately loads it. HTTPS API becomes temporarily unavailable when map loading is in progress | Function does not return any data on success. + + :param sessionname: name of session / world + :type sessionname: string + :param startLocation: selected starting location int or full name (1 = Grass Fields, 2 = Rocky Desert, 3 = Northern Forest, 4 = Dune Destert) + :type startLocation: str | int + :return: true if new session successfull created + :rtype: bool + """ + if not isinstance(sessionname, str): + self._log.error('can not create new game because session name is invalid') + return False + + match startLocation: + case 1 | '1' | 'Grass Fields': + startLocation = 'Grass Fields' + case 2 | '2' | 'Rocky Desert': + startLocation = 'Rocky Desert' + case 3 | '3' | 'Northern Forest': + startLocation = 'Northern Forest' + case 4 | '4' | 'Dune Desert': + startLocation = 'Dune Desert' # not working ... + case _: + startLocation = '' + + self._log.debug(f'matched {startLocation=}') + + data = dict() + data['NewGameData'] = dict() + data['NewGameData']['SessionName'] = sessionname + data['NewGameData']['MapName'] = '' + data['NewGameData']['StartingLocation'] = startLocation + + # TODO: add advanced start options + response = self.__query('CreateNewGame', data, True) + return response def get_server_options(self) -> dict: """Retrieves currently applied server options and server options that are still pending application (because of needing session or server restart) Does not require input parameters. @@ -426,7 +464,6 @@ class SatiAPI: #ApplyServerOptions #ApplyAdvancedGameSettings - #CreateNewGame #SaveGame #LoadGame #DownloadSaveGame @@ -434,11 +471,13 @@ class SatiAPI: #DeleteSaveFile #DeleteSaveSession - #EnumerateSessions if __name__ == "__main__": sati = SatiAPI(loglevel=10) # print('Verbundene Spieler: ', sati.get_status()['serverGameState']['numConnectedPlayers']) print(sati.get_status()) - print(sati.get_sessions()) \ No newline at end of file + print() + print(sati.get_sessions()) + print() + print(sati.create_new_game('MyWorld', 2)) \ No newline at end of file