satisfactory-api-client 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- satisfactory_api_client-0.1.1/LICENSE +21 -0
- satisfactory_api_client-0.1.1/PKG-INFO +189 -0
- satisfactory_api_client-0.1.1/README.md +175 -0
- satisfactory_api_client-0.1.1/examples/__init__.py +0 -0
- satisfactory_api_client-0.1.1/pyproject.toml +3 -0
- satisfactory_api_client-0.1.1/satisfactory_api_client/__init__.py +3 -0
- satisfactory_api_client-0.1.1/satisfactory_api_client/api_client.py +546 -0
- satisfactory_api_client-0.1.1/satisfactory_api_client/config.py +0 -0
- satisfactory_api_client-0.1.1/satisfactory_api_client/data/__init__.py +0 -0
- satisfactory_api_client-0.1.1/satisfactory_api_client/data/advanced_game_settings.py +12 -0
- satisfactory_api_client-0.1.1/satisfactory_api_client/data/minimum_privilege_level.py +9 -0
- satisfactory_api_client-0.1.1/satisfactory_api_client/data/new_game_save.py +31 -0
- satisfactory_api_client-0.1.1/satisfactory_api_client/data/response.py +7 -0
- satisfactory_api_client-0.1.1/satisfactory_api_client/exceptions.py +7 -0
- satisfactory_api_client-0.1.1/satisfactory_api_client/models.py +0 -0
- satisfactory_api_client-0.1.1/satisfactory_api_client/utils.py +3 -0
- satisfactory_api_client-0.1.1/satisfactory_api_client.egg-info/PKG-INFO +189 -0
- satisfactory_api_client-0.1.1/satisfactory_api_client.egg-info/SOURCES.txt +24 -0
- satisfactory_api_client-0.1.1/satisfactory_api_client.egg-info/dependency_links.txt +1 -0
- satisfactory_api_client-0.1.1/satisfactory_api_client.egg-info/requires.txt +3 -0
- satisfactory_api_client-0.1.1/satisfactory_api_client.egg-info/top_level.txt +3 -0
- satisfactory_api_client-0.1.1/setup.cfg +4 -0
- satisfactory_api_client-0.1.1/setup.py +20 -0
- satisfactory_api_client-0.1.1/tests/__init__.py +0 -0
- satisfactory_api_client-0.1.1/tests/test_api_client.py +18 -0
- satisfactory_api_client-0.1.1/tests/test_api_functions.py +17 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Programmer-Timmy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: satisfactory_api_client
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: A Python Package for interacting with the Satisfactory Dedicated Server API
|
|
5
|
+
Home-page: https://github.com/Programmer-Timmy/satisfactory-dedicated-server-api-SDK
|
|
6
|
+
Author: Programmer-Timmy
|
|
7
|
+
License: MIT
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.6
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
|
|
15
|
+
# Satisfactory Dedicated Server API Client
|
|
16
|
+
|
|
17
|
+
This Python package provides a client for interacting with the Satisfactory Dedicated Server API. The client allows for managing various aspects of the server, including querying server state, logging in, adjusting game settings, handling save files, and issuing administrative commands.
|
|
18
|
+
|
|
19
|
+
## Features
|
|
20
|
+
|
|
21
|
+
- Perform health checks on the server
|
|
22
|
+
- Log in with or without a password to obtain an authentication token
|
|
23
|
+
- Query and modify server state and options
|
|
24
|
+
- Manage advanced game settings
|
|
25
|
+
- Create, load, save, and delete game sessions
|
|
26
|
+
- Set client and admin passwords
|
|
27
|
+
- Run server commands and shut down the server
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
To install this package, use:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install satisfactory-api-client
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Requirements
|
|
38
|
+
|
|
39
|
+
- Python 3.8+
|
|
40
|
+
- `requests` library
|
|
41
|
+
|
|
42
|
+
## Usage
|
|
43
|
+
|
|
44
|
+
### Initializing the Client
|
|
45
|
+
|
|
46
|
+
The `SatisfactoryAPI` class is the main entry point for interacting with the server API.
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from satisfactory_api_client import SatisfactoryAPI
|
|
50
|
+
|
|
51
|
+
# Initialize the API client
|
|
52
|
+
api = SatisfactoryAPI(host='your-server-ip', port=7777, auth_token='your-auth-token')
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Login
|
|
56
|
+
|
|
57
|
+
You can log in to the server using passwordless or password-based methods.
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from satisfactory_api_client.data import MinimumPrivilegeLevel
|
|
61
|
+
|
|
62
|
+
# Passwordless login
|
|
63
|
+
response = api.passwordless_login(MinimumPrivilegeLevel.ADMIN)
|
|
64
|
+
|
|
65
|
+
# Password login
|
|
66
|
+
response = api.password_login(MinimumPrivilegeLevel.ADMIN, password='your-admin-password')
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Health Check
|
|
70
|
+
|
|
71
|
+
To verify that the server is running and responsive, you can perform a health check:
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
response = api.health_check()
|
|
75
|
+
print(response.data)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Server Options
|
|
79
|
+
|
|
80
|
+
You can query the server's current options and apply new ones:
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
# Get server options
|
|
84
|
+
response = api.get_server_options()
|
|
85
|
+
print(response.data)
|
|
86
|
+
|
|
87
|
+
# Apply new server options
|
|
88
|
+
new_options = {"server_name": "New Server Name"}
|
|
89
|
+
response = api.apply_server_options(new_options)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Advanced Game Settings
|
|
93
|
+
|
|
94
|
+
Fetch and apply advanced game settings:
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from satisfactory_api_client.data import AdvancedGameSettings
|
|
98
|
+
|
|
99
|
+
# Get advanced game settings
|
|
100
|
+
response = api.get_advanced_game_settings()
|
|
101
|
+
print(response.data)
|
|
102
|
+
|
|
103
|
+
# Apply advanced game settings
|
|
104
|
+
new_settings = AdvancedGameSettings(your_custom_settings)
|
|
105
|
+
response = api.apply_advanced_game_settings(new_settings)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Managing Game Sessions
|
|
109
|
+
|
|
110
|
+
You can create, load, save, and delete game sessions.
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
from satisfactory_api_client.data import NewGameData
|
|
114
|
+
|
|
115
|
+
# Create a new game
|
|
116
|
+
new_game_data = NewGameData(save_name="MyNewGame", ...)
|
|
117
|
+
response = api.create_new_game(new_game_data)
|
|
118
|
+
|
|
119
|
+
# Load a saved game
|
|
120
|
+
response = api.load_game("MySaveGame")
|
|
121
|
+
|
|
122
|
+
# Save the current game
|
|
123
|
+
response = api.save_game("MySaveGame")
|
|
124
|
+
|
|
125
|
+
# Delete a save file
|
|
126
|
+
response = api.delete_save_file("MySaveGame")
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Running Commands and Managing the Server
|
|
130
|
+
|
|
131
|
+
You can run commands on the server or shut it down:
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
# Run a server command
|
|
135
|
+
response = api.run_command("SomeCommand")
|
|
136
|
+
|
|
137
|
+
# Shutdown the server
|
|
138
|
+
response = api.shutdown()
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Methods
|
|
142
|
+
|
|
143
|
+
### Authentication
|
|
144
|
+
|
|
145
|
+
- `passwordless_login(minimum_privilege_level: MinimumPrivilegeLevel)`: Log in without a password.
|
|
146
|
+
- `password_login(minimum_privilege_level: MinimumPrivilegeLevel, password: str)`: Log in using a password.
|
|
147
|
+
|
|
148
|
+
### Server Management
|
|
149
|
+
|
|
150
|
+
- `health_check(client_custom_data: str = '')`: Perform a health check on the server.
|
|
151
|
+
- `shutdown()`: Shut down the server.
|
|
152
|
+
|
|
153
|
+
### Game Management
|
|
154
|
+
|
|
155
|
+
- `create_new_game(game_data: NewGameData)`: Create a new game session.
|
|
156
|
+
- `load_game(save_name: str, enable_advanced_game_settings: bool = False)`: Load a saved game.
|
|
157
|
+
- `save_game(save_name: str)`: Save the current game session.
|
|
158
|
+
- `delete_save_file(save_name: str)`: Delete a saved game.
|
|
159
|
+
- `enumerate_sessions()`: List all available game sessions.
|
|
160
|
+
|
|
161
|
+
### Server Settings
|
|
162
|
+
|
|
163
|
+
- `get_server_options()`: Get current server settings.
|
|
164
|
+
- `apply_server_options(options: dict)`: Apply new server settings.
|
|
165
|
+
- `get_advanced_game_settings()`: Get advanced game settings.
|
|
166
|
+
- `apply_advanced_game_settings(settings: AdvancedGameSettings)`: Apply new advanced game settings.
|
|
167
|
+
|
|
168
|
+
### Commands
|
|
169
|
+
|
|
170
|
+
- `run_command(command: str)`: Run a server command.
|
|
171
|
+
|
|
172
|
+
## Error Handling
|
|
173
|
+
|
|
174
|
+
Errors returned by the API will raise an `APIError` exception, which contains the error message from the server.
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
try:
|
|
178
|
+
response = api.some_method()
|
|
179
|
+
except APIError as e:
|
|
180
|
+
print(f"Error: {e}")
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## Contributing
|
|
184
|
+
|
|
185
|
+
Contributions are welcome! If you find a bug or have a feature request, please create an issue on the GitHub repository.
|
|
186
|
+
|
|
187
|
+
## License
|
|
188
|
+
|
|
189
|
+
This project is licensed under the MIT License. See the LICENSE file for details.
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# Satisfactory Dedicated Server API Client
|
|
2
|
+
|
|
3
|
+
This Python package provides a client for interacting with the Satisfactory Dedicated Server API. The client allows for managing various aspects of the server, including querying server state, logging in, adjusting game settings, handling save files, and issuing administrative commands.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Perform health checks on the server
|
|
8
|
+
- Log in with or without a password to obtain an authentication token
|
|
9
|
+
- Query and modify server state and options
|
|
10
|
+
- Manage advanced game settings
|
|
11
|
+
- Create, load, save, and delete game sessions
|
|
12
|
+
- Set client and admin passwords
|
|
13
|
+
- Run server commands and shut down the server
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
To install this package, use:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install satisfactory-api-client
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Requirements
|
|
24
|
+
|
|
25
|
+
- Python 3.8+
|
|
26
|
+
- `requests` library
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
### Initializing the Client
|
|
31
|
+
|
|
32
|
+
The `SatisfactoryAPI` class is the main entry point for interacting with the server API.
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from satisfactory_api_client import SatisfactoryAPI
|
|
36
|
+
|
|
37
|
+
# Initialize the API client
|
|
38
|
+
api = SatisfactoryAPI(host='your-server-ip', port=7777, auth_token='your-auth-token')
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Login
|
|
42
|
+
|
|
43
|
+
You can log in to the server using passwordless or password-based methods.
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
from satisfactory_api_client.data import MinimumPrivilegeLevel
|
|
47
|
+
|
|
48
|
+
# Passwordless login
|
|
49
|
+
response = api.passwordless_login(MinimumPrivilegeLevel.ADMIN)
|
|
50
|
+
|
|
51
|
+
# Password login
|
|
52
|
+
response = api.password_login(MinimumPrivilegeLevel.ADMIN, password='your-admin-password')
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Health Check
|
|
56
|
+
|
|
57
|
+
To verify that the server is running and responsive, you can perform a health check:
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
response = api.health_check()
|
|
61
|
+
print(response.data)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Server Options
|
|
65
|
+
|
|
66
|
+
You can query the server's current options and apply new ones:
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
# Get server options
|
|
70
|
+
response = api.get_server_options()
|
|
71
|
+
print(response.data)
|
|
72
|
+
|
|
73
|
+
# Apply new server options
|
|
74
|
+
new_options = {"server_name": "New Server Name"}
|
|
75
|
+
response = api.apply_server_options(new_options)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Advanced Game Settings
|
|
79
|
+
|
|
80
|
+
Fetch and apply advanced game settings:
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from satisfactory_api_client.data import AdvancedGameSettings
|
|
84
|
+
|
|
85
|
+
# Get advanced game settings
|
|
86
|
+
response = api.get_advanced_game_settings()
|
|
87
|
+
print(response.data)
|
|
88
|
+
|
|
89
|
+
# Apply advanced game settings
|
|
90
|
+
new_settings = AdvancedGameSettings(your_custom_settings)
|
|
91
|
+
response = api.apply_advanced_game_settings(new_settings)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Managing Game Sessions
|
|
95
|
+
|
|
96
|
+
You can create, load, save, and delete game sessions.
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
from satisfactory_api_client.data import NewGameData
|
|
100
|
+
|
|
101
|
+
# Create a new game
|
|
102
|
+
new_game_data = NewGameData(save_name="MyNewGame", ...)
|
|
103
|
+
response = api.create_new_game(new_game_data)
|
|
104
|
+
|
|
105
|
+
# Load a saved game
|
|
106
|
+
response = api.load_game("MySaveGame")
|
|
107
|
+
|
|
108
|
+
# Save the current game
|
|
109
|
+
response = api.save_game("MySaveGame")
|
|
110
|
+
|
|
111
|
+
# Delete a save file
|
|
112
|
+
response = api.delete_save_file("MySaveGame")
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Running Commands and Managing the Server
|
|
116
|
+
|
|
117
|
+
You can run commands on the server or shut it down:
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
# Run a server command
|
|
121
|
+
response = api.run_command("SomeCommand")
|
|
122
|
+
|
|
123
|
+
# Shutdown the server
|
|
124
|
+
response = api.shutdown()
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Methods
|
|
128
|
+
|
|
129
|
+
### Authentication
|
|
130
|
+
|
|
131
|
+
- `passwordless_login(minimum_privilege_level: MinimumPrivilegeLevel)`: Log in without a password.
|
|
132
|
+
- `password_login(minimum_privilege_level: MinimumPrivilegeLevel, password: str)`: Log in using a password.
|
|
133
|
+
|
|
134
|
+
### Server Management
|
|
135
|
+
|
|
136
|
+
- `health_check(client_custom_data: str = '')`: Perform a health check on the server.
|
|
137
|
+
- `shutdown()`: Shut down the server.
|
|
138
|
+
|
|
139
|
+
### Game Management
|
|
140
|
+
|
|
141
|
+
- `create_new_game(game_data: NewGameData)`: Create a new game session.
|
|
142
|
+
- `load_game(save_name: str, enable_advanced_game_settings: bool = False)`: Load a saved game.
|
|
143
|
+
- `save_game(save_name: str)`: Save the current game session.
|
|
144
|
+
- `delete_save_file(save_name: str)`: Delete a saved game.
|
|
145
|
+
- `enumerate_sessions()`: List all available game sessions.
|
|
146
|
+
|
|
147
|
+
### Server Settings
|
|
148
|
+
|
|
149
|
+
- `get_server_options()`: Get current server settings.
|
|
150
|
+
- `apply_server_options(options: dict)`: Apply new server settings.
|
|
151
|
+
- `get_advanced_game_settings()`: Get advanced game settings.
|
|
152
|
+
- `apply_advanced_game_settings(settings: AdvancedGameSettings)`: Apply new advanced game settings.
|
|
153
|
+
|
|
154
|
+
### Commands
|
|
155
|
+
|
|
156
|
+
- `run_command(command: str)`: Run a server command.
|
|
157
|
+
|
|
158
|
+
## Error Handling
|
|
159
|
+
|
|
160
|
+
Errors returned by the API will raise an `APIError` exception, which contains the error message from the server.
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
try:
|
|
164
|
+
response = api.some_method()
|
|
165
|
+
except APIError as e:
|
|
166
|
+
print(f"Error: {e}")
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Contributing
|
|
170
|
+
|
|
171
|
+
Contributions are welcome! If you find a bug or have a feature request, please create an issue on the GitHub repository.
|
|
172
|
+
|
|
173
|
+
## License
|
|
174
|
+
|
|
175
|
+
This project is licensed under the MIT License. See the LICENSE file for details.
|
|
File without changes
|
|
@@ -0,0 +1,546 @@
|
|
|
1
|
+
from http.client import responses
|
|
2
|
+
|
|
3
|
+
import requests
|
|
4
|
+
|
|
5
|
+
from .data.advanced_game_settings import AdvancedGameSettings
|
|
6
|
+
from .data.minimum_privilege_level import MinimumPrivilegeLevel
|
|
7
|
+
from .data.new_game_save import NewGameData
|
|
8
|
+
from .data.response import Response
|
|
9
|
+
from .exceptions import APIError
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class SatisfactoryAPI:
|
|
13
|
+
""" A client for the Satisfactory Dedicated Server API """
|
|
14
|
+
|
|
15
|
+
def __init__(self, host: str, port: int = 7777, auth_token: str = None):
|
|
16
|
+
"""
|
|
17
|
+
Initialize the API client
|
|
18
|
+
|
|
19
|
+
Parameters
|
|
20
|
+
----------
|
|
21
|
+
host : str
|
|
22
|
+
The hostname or IP address of the server
|
|
23
|
+
port : int, optional
|
|
24
|
+
The port to connect to, by default 7777
|
|
25
|
+
auth_token : str, optional
|
|
26
|
+
The authentication token, by default None.
|
|
27
|
+
You can use the `password_login` or `passwordless_login` methods to request a token from the server.
|
|
28
|
+
|
|
29
|
+
Raises
|
|
30
|
+
------
|
|
31
|
+
APIError
|
|
32
|
+
If the authentication token is invalid
|
|
33
|
+
"""
|
|
34
|
+
self.host: str = host
|
|
35
|
+
self.port: int = port
|
|
36
|
+
self.auth_token: str | None = auth_token
|
|
37
|
+
|
|
38
|
+
if self.auth_token:
|
|
39
|
+
self.verify_authentication_token()
|
|
40
|
+
|
|
41
|
+
def _post(self, function, data=None, files=None):
|
|
42
|
+
"""
|
|
43
|
+
Post a request to the API
|
|
44
|
+
|
|
45
|
+
:param function: The function to call
|
|
46
|
+
:param data: The data to send
|
|
47
|
+
:param files: The files to send
|
|
48
|
+
:return: The response
|
|
49
|
+
:rtype: dict
|
|
50
|
+
|
|
51
|
+
:raises APIError: If the API returns an error
|
|
52
|
+
"""
|
|
53
|
+
url = f"https://{self.host}:{self.port}/api/v1"
|
|
54
|
+
headers = {'Content-Type': 'application/json'}
|
|
55
|
+
|
|
56
|
+
if self.auth_token:
|
|
57
|
+
headers['Authorization'] = f'Bearer {self.auth_token}'
|
|
58
|
+
|
|
59
|
+
payload = {'function': function, 'data': data} if data else {'function': function}
|
|
60
|
+
|
|
61
|
+
response = requests.post(url, json=payload, headers=headers, files=files, verify=False)
|
|
62
|
+
if response.status_code != 200 and response.status_code != 204:
|
|
63
|
+
raise APIError(f"API error: {response.text}")
|
|
64
|
+
|
|
65
|
+
if response.status_code == 204:
|
|
66
|
+
return {}
|
|
67
|
+
|
|
68
|
+
if response.json().get('errorCode'):
|
|
69
|
+
raise APIError(response.json().get('errorMessage'))
|
|
70
|
+
return response.json()
|
|
71
|
+
|
|
72
|
+
def _get(self, function, data=None):
|
|
73
|
+
"""
|
|
74
|
+
Get a request to the API
|
|
75
|
+
|
|
76
|
+
:param function: The function to call
|
|
77
|
+
:param data: The data to send
|
|
78
|
+
:return: The response
|
|
79
|
+
:rtype: dict
|
|
80
|
+
|
|
81
|
+
:raises APIError: If the API returns an error
|
|
82
|
+
"""
|
|
83
|
+
url = f"https://{self.host}:{self.port}/api/v1"
|
|
84
|
+
headers = {'Content-Type': 'application/json'}
|
|
85
|
+
|
|
86
|
+
if self.auth_token:
|
|
87
|
+
headers['Authorization'] = f'Bearer {self.auth_token}'
|
|
88
|
+
|
|
89
|
+
payload = {'function': function, 'data': data} if data else {'function': function}
|
|
90
|
+
|
|
91
|
+
response = requests.get(url, json=payload, headers=headers, verify=False)
|
|
92
|
+
if response.status_code != 200 and response.status_code != 204:
|
|
93
|
+
raise APIError(f"API error: {response.text}")
|
|
94
|
+
|
|
95
|
+
if response.status_code == 204:
|
|
96
|
+
return {}
|
|
97
|
+
|
|
98
|
+
if response.json().get('errorCode'):
|
|
99
|
+
raise APIError(response.json().get('errorMessage'))
|
|
100
|
+
return response.json()
|
|
101
|
+
|
|
102
|
+
def health_check(self, client_custom_data='') -> (
|
|
103
|
+
Response):
|
|
104
|
+
"""
|
|
105
|
+
Perform a health check on the server. This function is used to check if the server is running and if the API is.
|
|
106
|
+
|
|
107
|
+
Parameters
|
|
108
|
+
----------
|
|
109
|
+
client_custom_data : str
|
|
110
|
+
Custom data to send to the server. Defaults to an empty string.
|
|
111
|
+
|
|
112
|
+
Returns
|
|
113
|
+
-------
|
|
114
|
+
Response
|
|
115
|
+
A Response containing the data returned by the API.
|
|
116
|
+
|
|
117
|
+
Raises
|
|
118
|
+
------
|
|
119
|
+
APIError
|
|
120
|
+
If the API returns an error
|
|
121
|
+
"""
|
|
122
|
+
response = self._post('HealthCheck', {'ClientCustomData': client_custom_data})
|
|
123
|
+
return Response(success=True, data=response)
|
|
124
|
+
|
|
125
|
+
def verify_authentication_token(self) -> Response:
|
|
126
|
+
"""
|
|
127
|
+
Verify the authentication token
|
|
128
|
+
|
|
129
|
+
Returns
|
|
130
|
+
-------
|
|
131
|
+
Response
|
|
132
|
+
A Response containing the message 'Token is valid'.
|
|
133
|
+
|
|
134
|
+
Raises
|
|
135
|
+
------
|
|
136
|
+
APIError
|
|
137
|
+
If the API returns an error or if the token is invalid.
|
|
138
|
+
"""
|
|
139
|
+
self._post('VerifyAuthenticationToken')
|
|
140
|
+
return Response(success=True, data={'message': 'Token is valid'})
|
|
141
|
+
|
|
142
|
+
def passwordless_login(self, minimum_privilege_level: MinimumPrivilegeLevel) -> Response:
|
|
143
|
+
"""
|
|
144
|
+
Perform a passwordless login and store the authentication token.
|
|
145
|
+
|
|
146
|
+
Parameters
|
|
147
|
+
----------
|
|
148
|
+
minimum_privilege_level : MinimumPrivilegeLevel
|
|
149
|
+
The minimum privilege level required for the login.
|
|
150
|
+
|
|
151
|
+
Returns
|
|
152
|
+
-------
|
|
153
|
+
Response
|
|
154
|
+
A Response containing the message 'Successfully logged in, the token is now stored'.
|
|
155
|
+
|
|
156
|
+
Raises
|
|
157
|
+
------
|
|
158
|
+
APIError
|
|
159
|
+
If the API returns an error or if the login is unsuccessful
|
|
160
|
+
(e.g., incorrect password or insufficient privileges).
|
|
161
|
+
"""
|
|
162
|
+
response = self._post('PasswordlessLogin', {'MinimumPrivilegeLevel': minimum_privilege_level.value})
|
|
163
|
+
self.auth_token = response['data']['authenticationToken']
|
|
164
|
+
return Response(success=True, data=self.auth_token)
|
|
165
|
+
|
|
166
|
+
def password_login(self, minimum_privilege_level: MinimumPrivilegeLevel, password: str) -> Response:
|
|
167
|
+
"""
|
|
168
|
+
Perform a password login and store the authentication token.
|
|
169
|
+
|
|
170
|
+
Parameters
|
|
171
|
+
----------
|
|
172
|
+
minimum_privilege_level : MinimumPrivilegeLevel
|
|
173
|
+
The minimum privilege level required for the login.
|
|
174
|
+
password : str
|
|
175
|
+
The password associated with the account. Must not be empty.
|
|
176
|
+
|
|
177
|
+
Returns
|
|
178
|
+
-------
|
|
179
|
+
Response
|
|
180
|
+
A Response containing the message 'Successfully logged in, the token is now stored'.
|
|
181
|
+
|
|
182
|
+
Raises
|
|
183
|
+
------
|
|
184
|
+
APIError
|
|
185
|
+
If the API returns an error or if the login is unsuccessful
|
|
186
|
+
(e.g., incorrect password or insufficient privileges).
|
|
187
|
+
"""
|
|
188
|
+
response = self._post('PasswordLogin', {
|
|
189
|
+
'MinimumPrivilegeLevel': minimum_privilege_level.value,
|
|
190
|
+
'Password': password
|
|
191
|
+
})
|
|
192
|
+
self.auth_token = response['data']['authenticationToken']
|
|
193
|
+
return Response(success=True, data={'message': 'Successfully logged in, the token is now stored'})
|
|
194
|
+
|
|
195
|
+
def query_server_state(self):
|
|
196
|
+
"""
|
|
197
|
+
Query the server state
|
|
198
|
+
|
|
199
|
+
Returns
|
|
200
|
+
-------
|
|
201
|
+
Response
|
|
202
|
+
A Response containing the server state data.
|
|
203
|
+
|
|
204
|
+
Raises
|
|
205
|
+
------
|
|
206
|
+
APIError
|
|
207
|
+
If the API returns an error.
|
|
208
|
+
"""
|
|
209
|
+
response = self._post('QueryServerState')
|
|
210
|
+
return Response(success=True, data=response)
|
|
211
|
+
|
|
212
|
+
def get_server_options(self):
|
|
213
|
+
"""
|
|
214
|
+
Get the server options
|
|
215
|
+
|
|
216
|
+
Returns
|
|
217
|
+
-------
|
|
218
|
+
Response
|
|
219
|
+
A Response containing the server options data.
|
|
220
|
+
|
|
221
|
+
Raises
|
|
222
|
+
------
|
|
223
|
+
APIError
|
|
224
|
+
If the API returns an error.
|
|
225
|
+
"""
|
|
226
|
+
response = self._post('GetServerOptions')
|
|
227
|
+
return Response(success=True, data=response)
|
|
228
|
+
|
|
229
|
+
def get_advanced_game_settings(self) -> Response:
|
|
230
|
+
"""
|
|
231
|
+
Fetch advanced game settings.
|
|
232
|
+
|
|
233
|
+
Returns
|
|
234
|
+
-------
|
|
235
|
+
Response
|
|
236
|
+
A Response containing the advanced game settings.
|
|
237
|
+
"""
|
|
238
|
+
response = self._get('GetAdvancedGameSettings')
|
|
239
|
+
return Response(success=True, data=response['data'])
|
|
240
|
+
|
|
241
|
+
def apply_advanced_game_settings(self, settings: AdvancedGameSettings) -> Response:
|
|
242
|
+
"""
|
|
243
|
+
Apply advanced game settings.
|
|
244
|
+
|
|
245
|
+
Parameters
|
|
246
|
+
----------
|
|
247
|
+
settings : AdvancedGameSettings
|
|
248
|
+
The new advanced game settings to apply.
|
|
249
|
+
|
|
250
|
+
Returns
|
|
251
|
+
-------
|
|
252
|
+
Response
|
|
253
|
+
A Response indicating the success of the operation.
|
|
254
|
+
"""
|
|
255
|
+
response = self._post('ApplyAdvancedGameSettings', {
|
|
256
|
+
'AppliedAdvancedGameSettings': settings.__dict__ # Convert dataclass to dict
|
|
257
|
+
})
|
|
258
|
+
return Response(success=True, data=response['data'])
|
|
259
|
+
|
|
260
|
+
def claim_server(self, server_name: str, admin_password: str) -> Response:
|
|
261
|
+
"""
|
|
262
|
+
Claim the server.
|
|
263
|
+
|
|
264
|
+
Parameters
|
|
265
|
+
----------
|
|
266
|
+
server_name : str
|
|
267
|
+
The name of the server.
|
|
268
|
+
admin_password : str
|
|
269
|
+
The administrator password.
|
|
270
|
+
|
|
271
|
+
Returns
|
|
272
|
+
-------
|
|
273
|
+
Response
|
|
274
|
+
A Response containing the server claim result.
|
|
275
|
+
"""
|
|
276
|
+
response = self._post('ClaimServer', {
|
|
277
|
+
'ServerName': server_name,
|
|
278
|
+
'AdminPassword': admin_password
|
|
279
|
+
})
|
|
280
|
+
return Response(success=True, data=response['data'])
|
|
281
|
+
|
|
282
|
+
def rename_server(self, server_name: str) -> Response:
|
|
283
|
+
"""
|
|
284
|
+
Rename the server.
|
|
285
|
+
|
|
286
|
+
Parameters
|
|
287
|
+
----------
|
|
288
|
+
server_name : str
|
|
289
|
+
The new name for the server.
|
|
290
|
+
|
|
291
|
+
Returns
|
|
292
|
+
-------
|
|
293
|
+
Response
|
|
294
|
+
A Response indicating the success of the operation.
|
|
295
|
+
"""
|
|
296
|
+
response = self._post('RenameServer', {
|
|
297
|
+
'ServerName': server_name
|
|
298
|
+
})
|
|
299
|
+
return Response(success=True, data=response['data'])
|
|
300
|
+
|
|
301
|
+
def set_client_password(self, password: str) -> Response:
|
|
302
|
+
"""
|
|
303
|
+
Set the client password.
|
|
304
|
+
|
|
305
|
+
Parameters
|
|
306
|
+
----------
|
|
307
|
+
password : str
|
|
308
|
+
The new client password.
|
|
309
|
+
|
|
310
|
+
Returns
|
|
311
|
+
-------
|
|
312
|
+
Response
|
|
313
|
+
A Response indicating the success of the operation.
|
|
314
|
+
"""
|
|
315
|
+
response = self._post('SetClientPassword', {
|
|
316
|
+
'Password': password
|
|
317
|
+
})
|
|
318
|
+
return Response(success=True, data=response['data'])
|
|
319
|
+
|
|
320
|
+
def set_admin_password(self, password: str, auth_token: str) -> Response:
|
|
321
|
+
"""
|
|
322
|
+
Set the admin password.
|
|
323
|
+
|
|
324
|
+
Parameters
|
|
325
|
+
----------
|
|
326
|
+
password : str
|
|
327
|
+
The new admin password.
|
|
328
|
+
auth_token : str
|
|
329
|
+
The authentication token.
|
|
330
|
+
|
|
331
|
+
Returns
|
|
332
|
+
-------
|
|
333
|
+
Response
|
|
334
|
+
A Response indicating the success of the operation.
|
|
335
|
+
"""
|
|
336
|
+
response = self._post('SetAdminPassword', {
|
|
337
|
+
'Password': password,
|
|
338
|
+
'AuthenticationToken': auth_token
|
|
339
|
+
})
|
|
340
|
+
return Response(success=True, data=response['data'])
|
|
341
|
+
|
|
342
|
+
def set_auto_load_session_name(self, session_name: str) -> Response:
|
|
343
|
+
"""
|
|
344
|
+
Set the auto-load session name.
|
|
345
|
+
|
|
346
|
+
Parameters
|
|
347
|
+
----------
|
|
348
|
+
session_name : str
|
|
349
|
+
The session name to auto-load.
|
|
350
|
+
|
|
351
|
+
Returns
|
|
352
|
+
-------
|
|
353
|
+
Response
|
|
354
|
+
A Response indicating the success of the operation.
|
|
355
|
+
"""
|
|
356
|
+
response = self._post('SetAutoLoadSessionName', {
|
|
357
|
+
'SessionName': session_name
|
|
358
|
+
})
|
|
359
|
+
return Response(success=True, data=response['data'])
|
|
360
|
+
|
|
361
|
+
def run_command(self, command: str) -> Response:
|
|
362
|
+
"""
|
|
363
|
+
Run a server command.
|
|
364
|
+
|
|
365
|
+
Parameters
|
|
366
|
+
----------
|
|
367
|
+
command : str
|
|
368
|
+
The command to run.
|
|
369
|
+
|
|
370
|
+
Returns
|
|
371
|
+
-------
|
|
372
|
+
Response
|
|
373
|
+
A Response containing the result of the command.
|
|
374
|
+
"""
|
|
375
|
+
response = self._post('RunCommand', {
|
|
376
|
+
'Command': command
|
|
377
|
+
})
|
|
378
|
+
return Response(success=True, data=response['data'])
|
|
379
|
+
|
|
380
|
+
def shutdown(self) -> Response:
|
|
381
|
+
"""
|
|
382
|
+
Shut down the server.
|
|
383
|
+
|
|
384
|
+
Returns
|
|
385
|
+
-------
|
|
386
|
+
Response
|
|
387
|
+
A Response indicating the success of the operation.
|
|
388
|
+
"""
|
|
389
|
+
response = self._post('Shutdown')
|
|
390
|
+
return Response(success=True, data=response['data'])
|
|
391
|
+
|
|
392
|
+
def apply_server_options(self, options: dict) -> Response:
|
|
393
|
+
"""
|
|
394
|
+
Apply server options.
|
|
395
|
+
|
|
396
|
+
Parameters
|
|
397
|
+
----------
|
|
398
|
+
options : dict
|
|
399
|
+
The server options to apply.
|
|
400
|
+
|
|
401
|
+
Returns
|
|
402
|
+
-------
|
|
403
|
+
Response
|
|
404
|
+
A Response indicating the success of the operation.
|
|
405
|
+
"""
|
|
406
|
+
response = self._post('ApplyServerOptions', {
|
|
407
|
+
'UpdatedServerOptions': options
|
|
408
|
+
})
|
|
409
|
+
return Response(success=True, data=response['data'])
|
|
410
|
+
|
|
411
|
+
def create_new_game(self, game_data: NewGameData) -> Response:
|
|
412
|
+
"""
|
|
413
|
+
Create a new game.
|
|
414
|
+
|
|
415
|
+
Parameters
|
|
416
|
+
----------
|
|
417
|
+
game_data : NewGameData
|
|
418
|
+
The data for the new game.
|
|
419
|
+
|
|
420
|
+
Returns
|
|
421
|
+
-------
|
|
422
|
+
Response
|
|
423
|
+
A Response indicating the success of the operation.
|
|
424
|
+
"""
|
|
425
|
+
response = self._post('CreateNewGame', {
|
|
426
|
+
'NewGameData': game_data.__dict__ # Convert dataclass to dict
|
|
427
|
+
})
|
|
428
|
+
return Response(success=True, data=response['data'])
|
|
429
|
+
|
|
430
|
+
def save_game(self, save_name: str) -> Response:
|
|
431
|
+
"""
|
|
432
|
+
Save the game.
|
|
433
|
+
|
|
434
|
+
Parameters
|
|
435
|
+
----------
|
|
436
|
+
save_name : str
|
|
437
|
+
The name of the save file.
|
|
438
|
+
|
|
439
|
+
Returns
|
|
440
|
+
-------
|
|
441
|
+
Response
|
|
442
|
+
A Response indicating the success of the save operation.
|
|
443
|
+
"""
|
|
444
|
+
response = self._post('SaveGame', {
|
|
445
|
+
'SaveName': save_name
|
|
446
|
+
})
|
|
447
|
+
return Response(success=True, data=response['data'])
|
|
448
|
+
|
|
449
|
+
def delete_save_file(self, save_name: str) -> Response:
|
|
450
|
+
"""
|
|
451
|
+
Delete a save file.
|
|
452
|
+
|
|
453
|
+
Parameters
|
|
454
|
+
----------
|
|
455
|
+
save_name : str
|
|
456
|
+
The name of the save file to delete.
|
|
457
|
+
|
|
458
|
+
Returns
|
|
459
|
+
-------
|
|
460
|
+
Response
|
|
461
|
+
A Response indicating the success of the operation.
|
|
462
|
+
"""
|
|
463
|
+
response = self._post('DeleteSaveFile', {
|
|
464
|
+
'SaveName': save_name
|
|
465
|
+
})
|
|
466
|
+
return Response(success=True, data=response['data'])
|
|
467
|
+
|
|
468
|
+
def delete_save_session(self, session_name: str) -> Response:
|
|
469
|
+
"""
|
|
470
|
+
Delete a save session.
|
|
471
|
+
|
|
472
|
+
Parameters
|
|
473
|
+
----------
|
|
474
|
+
session_name : str
|
|
475
|
+
The name of the session to delete.
|
|
476
|
+
|
|
477
|
+
Returns
|
|
478
|
+
-------
|
|
479
|
+
Response
|
|
480
|
+
A Response indicating the success of the operation.
|
|
481
|
+
"""
|
|
482
|
+
response = self._post('DeleteSaveSession', {
|
|
483
|
+
'SessionName': session_name
|
|
484
|
+
})
|
|
485
|
+
return Response(success=True, data=response['data'])
|
|
486
|
+
|
|
487
|
+
def enumerate_sessions(self) -> Response:
|
|
488
|
+
"""
|
|
489
|
+
Enumerate available sessions.
|
|
490
|
+
|
|
491
|
+
Returns
|
|
492
|
+
-------
|
|
493
|
+
Response
|
|
494
|
+
A Response containing the available sessions.
|
|
495
|
+
"""
|
|
496
|
+
response = self._get('EnumerateSessions')
|
|
497
|
+
return Response(success=True, data=response['data'])
|
|
498
|
+
|
|
499
|
+
def load_game(self, save_name: str, enable_advanced_game_settings: bool = False) -> Response:
|
|
500
|
+
"""
|
|
501
|
+
Load a saved game.
|
|
502
|
+
|
|
503
|
+
Parameters
|
|
504
|
+
----------
|
|
505
|
+
save_name : str
|
|
506
|
+
The name of the save file to load.
|
|
507
|
+
enable_advanced_game_settings : bool, optional
|
|
508
|
+
Whether to enable advanced game settings (default is False).
|
|
509
|
+
|
|
510
|
+
Returns
|
|
511
|
+
-------
|
|
512
|
+
Response
|
|
513
|
+
A Response indicating the success of the load operation.
|
|
514
|
+
"""
|
|
515
|
+
response = self._post('LoadGame', {
|
|
516
|
+
'SaveName': save_name,
|
|
517
|
+
'EnableAdvancedGameSettings': enable_advanced_game_settings
|
|
518
|
+
})
|
|
519
|
+
return Response(success=True, data=response['data'])
|
|
520
|
+
|
|
521
|
+
def upload_save_game(self, save_name: str, load_save_game: bool = False,
|
|
522
|
+
enable_advanced_game_settings: bool = False) -> Response:
|
|
523
|
+
raise NotImplementedError('This method is not implemented yet')
|
|
524
|
+
|
|
525
|
+
def download_save_game(self, save_name: str) -> Response:
|
|
526
|
+
"""
|
|
527
|
+
Download a save game file.
|
|
528
|
+
|
|
529
|
+
Parameters
|
|
530
|
+
----------
|
|
531
|
+
save_name : str
|
|
532
|
+
The name of the save file to download.
|
|
533
|
+
|
|
534
|
+
Returns
|
|
535
|
+
-------
|
|
536
|
+
Response
|
|
537
|
+
A Response indicating the success of the download operation.
|
|
538
|
+
"""
|
|
539
|
+
response = self._get('DownloadSaveGame', {
|
|
540
|
+
'SaveName': save_name
|
|
541
|
+
})
|
|
542
|
+
return Response(success=True, data=response['data'])
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import dataclasses
|
|
2
|
+
@dataclasses.dataclass
|
|
3
|
+
class AdvancedGameSettings:
|
|
4
|
+
"""
|
|
5
|
+
Advanced game settings for a Satisfactory Dedicated Server
|
|
6
|
+
|
|
7
|
+
Attributes
|
|
8
|
+
----------
|
|
9
|
+
some_setting : str
|
|
10
|
+
A setting for the server
|
|
11
|
+
"""
|
|
12
|
+
some_setting: str # Replace with actual settings fields
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from typing import Optional
|
|
3
|
+
from .advanced_game_settings import AdvancedGameSettings
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@dataclass
|
|
7
|
+
class NewGameData:
|
|
8
|
+
"""
|
|
9
|
+
New game data for a Satisfactory Dedicated Server
|
|
10
|
+
|
|
11
|
+
Attributes
|
|
12
|
+
----------
|
|
13
|
+
SessionName : str
|
|
14
|
+
The name of the session
|
|
15
|
+
MapName : Optional[str]
|
|
16
|
+
The name of the map
|
|
17
|
+
StartingLocation : Optional[str]
|
|
18
|
+
The starting location of the session
|
|
19
|
+
SkipOnboarding : Optional[bool]
|
|
20
|
+
Whether to skip the onboarding process
|
|
21
|
+
AdvancedGameSettings : Optional[AdvancedGameSettings]
|
|
22
|
+
Advanced game settings for the server
|
|
23
|
+
CustomOptionsOnlyForModding : Optional[dict]
|
|
24
|
+
Custom options only for mod
|
|
25
|
+
"""
|
|
26
|
+
SessionName: str
|
|
27
|
+
MapName: Optional[str] = None
|
|
28
|
+
StartingLocation: Optional[str] = None
|
|
29
|
+
SkipOnboarding: Optional[bool] = None
|
|
30
|
+
AdvancedGameSettings: Optional[AdvancedGameSettings] = None
|
|
31
|
+
CustomOptionsOnlyForModding: Optional[dict] = None
|
|
File without changes
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: satisfactory-api-client
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: A Python Package for interacting with the Satisfactory Dedicated Server API
|
|
5
|
+
Home-page: https://github.com/Programmer-Timmy/satisfactory-dedicated-server-api-SDK
|
|
6
|
+
Author: Programmer-Timmy
|
|
7
|
+
License: MIT
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.6
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
|
|
15
|
+
# Satisfactory Dedicated Server API Client
|
|
16
|
+
|
|
17
|
+
This Python package provides a client for interacting with the Satisfactory Dedicated Server API. The client allows for managing various aspects of the server, including querying server state, logging in, adjusting game settings, handling save files, and issuing administrative commands.
|
|
18
|
+
|
|
19
|
+
## Features
|
|
20
|
+
|
|
21
|
+
- Perform health checks on the server
|
|
22
|
+
- Log in with or without a password to obtain an authentication token
|
|
23
|
+
- Query and modify server state and options
|
|
24
|
+
- Manage advanced game settings
|
|
25
|
+
- Create, load, save, and delete game sessions
|
|
26
|
+
- Set client and admin passwords
|
|
27
|
+
- Run server commands and shut down the server
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
To install this package, use:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install satisfactory-api-client
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Requirements
|
|
38
|
+
|
|
39
|
+
- Python 3.8+
|
|
40
|
+
- `requests` library
|
|
41
|
+
|
|
42
|
+
## Usage
|
|
43
|
+
|
|
44
|
+
### Initializing the Client
|
|
45
|
+
|
|
46
|
+
The `SatisfactoryAPI` class is the main entry point for interacting with the server API.
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from satisfactory_api_client import SatisfactoryAPI
|
|
50
|
+
|
|
51
|
+
# Initialize the API client
|
|
52
|
+
api = SatisfactoryAPI(host='your-server-ip', port=7777, auth_token='your-auth-token')
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Login
|
|
56
|
+
|
|
57
|
+
You can log in to the server using passwordless or password-based methods.
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from satisfactory_api_client.data import MinimumPrivilegeLevel
|
|
61
|
+
|
|
62
|
+
# Passwordless login
|
|
63
|
+
response = api.passwordless_login(MinimumPrivilegeLevel.ADMIN)
|
|
64
|
+
|
|
65
|
+
# Password login
|
|
66
|
+
response = api.password_login(MinimumPrivilegeLevel.ADMIN, password='your-admin-password')
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Health Check
|
|
70
|
+
|
|
71
|
+
To verify that the server is running and responsive, you can perform a health check:
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
response = api.health_check()
|
|
75
|
+
print(response.data)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Server Options
|
|
79
|
+
|
|
80
|
+
You can query the server's current options and apply new ones:
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
# Get server options
|
|
84
|
+
response = api.get_server_options()
|
|
85
|
+
print(response.data)
|
|
86
|
+
|
|
87
|
+
# Apply new server options
|
|
88
|
+
new_options = {"server_name": "New Server Name"}
|
|
89
|
+
response = api.apply_server_options(new_options)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Advanced Game Settings
|
|
93
|
+
|
|
94
|
+
Fetch and apply advanced game settings:
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from satisfactory_api_client.data import AdvancedGameSettings
|
|
98
|
+
|
|
99
|
+
# Get advanced game settings
|
|
100
|
+
response = api.get_advanced_game_settings()
|
|
101
|
+
print(response.data)
|
|
102
|
+
|
|
103
|
+
# Apply advanced game settings
|
|
104
|
+
new_settings = AdvancedGameSettings(your_custom_settings)
|
|
105
|
+
response = api.apply_advanced_game_settings(new_settings)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Managing Game Sessions
|
|
109
|
+
|
|
110
|
+
You can create, load, save, and delete game sessions.
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
from satisfactory_api_client.data import NewGameData
|
|
114
|
+
|
|
115
|
+
# Create a new game
|
|
116
|
+
new_game_data = NewGameData(save_name="MyNewGame", ...)
|
|
117
|
+
response = api.create_new_game(new_game_data)
|
|
118
|
+
|
|
119
|
+
# Load a saved game
|
|
120
|
+
response = api.load_game("MySaveGame")
|
|
121
|
+
|
|
122
|
+
# Save the current game
|
|
123
|
+
response = api.save_game("MySaveGame")
|
|
124
|
+
|
|
125
|
+
# Delete a save file
|
|
126
|
+
response = api.delete_save_file("MySaveGame")
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Running Commands and Managing the Server
|
|
130
|
+
|
|
131
|
+
You can run commands on the server or shut it down:
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
# Run a server command
|
|
135
|
+
response = api.run_command("SomeCommand")
|
|
136
|
+
|
|
137
|
+
# Shutdown the server
|
|
138
|
+
response = api.shutdown()
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Methods
|
|
142
|
+
|
|
143
|
+
### Authentication
|
|
144
|
+
|
|
145
|
+
- `passwordless_login(minimum_privilege_level: MinimumPrivilegeLevel)`: Log in without a password.
|
|
146
|
+
- `password_login(minimum_privilege_level: MinimumPrivilegeLevel, password: str)`: Log in using a password.
|
|
147
|
+
|
|
148
|
+
### Server Management
|
|
149
|
+
|
|
150
|
+
- `health_check(client_custom_data: str = '')`: Perform a health check on the server.
|
|
151
|
+
- `shutdown()`: Shut down the server.
|
|
152
|
+
|
|
153
|
+
### Game Management
|
|
154
|
+
|
|
155
|
+
- `create_new_game(game_data: NewGameData)`: Create a new game session.
|
|
156
|
+
- `load_game(save_name: str, enable_advanced_game_settings: bool = False)`: Load a saved game.
|
|
157
|
+
- `save_game(save_name: str)`: Save the current game session.
|
|
158
|
+
- `delete_save_file(save_name: str)`: Delete a saved game.
|
|
159
|
+
- `enumerate_sessions()`: List all available game sessions.
|
|
160
|
+
|
|
161
|
+
### Server Settings
|
|
162
|
+
|
|
163
|
+
- `get_server_options()`: Get current server settings.
|
|
164
|
+
- `apply_server_options(options: dict)`: Apply new server settings.
|
|
165
|
+
- `get_advanced_game_settings()`: Get advanced game settings.
|
|
166
|
+
- `apply_advanced_game_settings(settings: AdvancedGameSettings)`: Apply new advanced game settings.
|
|
167
|
+
|
|
168
|
+
### Commands
|
|
169
|
+
|
|
170
|
+
- `run_command(command: str)`: Run a server command.
|
|
171
|
+
|
|
172
|
+
## Error Handling
|
|
173
|
+
|
|
174
|
+
Errors returned by the API will raise an `APIError` exception, which contains the error message from the server.
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
try:
|
|
178
|
+
response = api.some_method()
|
|
179
|
+
except APIError as e:
|
|
180
|
+
print(f"Error: {e}")
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## Contributing
|
|
184
|
+
|
|
185
|
+
Contributions are welcome! If you find a bug or have a feature request, please create an issue on the GitHub repository.
|
|
186
|
+
|
|
187
|
+
## License
|
|
188
|
+
|
|
189
|
+
This project is licensed under the MIT License. See the LICENSE file for details.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
setup.py
|
|
5
|
+
examples/__init__.py
|
|
6
|
+
satisfactory_api_client/__init__.py
|
|
7
|
+
satisfactory_api_client/api_client.py
|
|
8
|
+
satisfactory_api_client/config.py
|
|
9
|
+
satisfactory_api_client/exceptions.py
|
|
10
|
+
satisfactory_api_client/models.py
|
|
11
|
+
satisfactory_api_client/utils.py
|
|
12
|
+
satisfactory_api_client.egg-info/PKG-INFO
|
|
13
|
+
satisfactory_api_client.egg-info/SOURCES.txt
|
|
14
|
+
satisfactory_api_client.egg-info/dependency_links.txt
|
|
15
|
+
satisfactory_api_client.egg-info/requires.txt
|
|
16
|
+
satisfactory_api_client.egg-info/top_level.txt
|
|
17
|
+
satisfactory_api_client/data/__init__.py
|
|
18
|
+
satisfactory_api_client/data/advanced_game_settings.py
|
|
19
|
+
satisfactory_api_client/data/minimum_privilege_level.py
|
|
20
|
+
satisfactory_api_client/data/new_game_save.py
|
|
21
|
+
satisfactory_api_client/data/response.py
|
|
22
|
+
tests/__init__.py
|
|
23
|
+
tests/test_api_client.py
|
|
24
|
+
tests/test_api_functions.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name='satisfactory_api_client',
|
|
5
|
+
version='0.1.1',
|
|
6
|
+
packages=find_packages(),
|
|
7
|
+
install_requires=[req.strip() for req in open('requirements.txt').readlines()],
|
|
8
|
+
description='A Python Package for interacting with the Satisfactory Dedicated Server API',
|
|
9
|
+
long_description=open('README.md').read(),
|
|
10
|
+
long_description_content_type='text/markdown',
|
|
11
|
+
url='https://github.com/Programmer-Timmy/satisfactory-dedicated-server-api-SDK', # Replace with your repo URL
|
|
12
|
+
author='Programmer-Timmy',
|
|
13
|
+
license='MIT',
|
|
14
|
+
classifiers=[
|
|
15
|
+
'Programming Language :: Python :: 3',
|
|
16
|
+
'License :: OSI Approved :: MIT License',
|
|
17
|
+
'Operating System :: OS Independent',
|
|
18
|
+
],
|
|
19
|
+
python_requires='>=3.6',
|
|
20
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from satisfactory_api_client.api_client import SatisfactoryAPI
|
|
3
|
+
class TestAPIClient(unittest.TestCase):
|
|
4
|
+
def test_initialization(self):
|
|
5
|
+
client = SatisfactoryAPI("localhost")
|
|
6
|
+
self.assertEqual(client.host, "localhost")
|
|
7
|
+
self.assertEqual(client.port, 7777)
|
|
8
|
+
|
|
9
|
+
def test_initialization_with_port(self):
|
|
10
|
+
client = SatisfactoryAPI("localhost", port=1234)
|
|
11
|
+
self.assertEqual(client.port, 1234)
|
|
12
|
+
|
|
13
|
+
def test_post(self):
|
|
14
|
+
pass
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
if __name__ == "__main__":
|
|
18
|
+
unittest.main()
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import unittest
|
|
3
|
+
|
|
4
|
+
class TestApiFunctions(unittest.TestCase):
|
|
5
|
+
def test_health_check(self):
|
|
6
|
+
pass
|
|
7
|
+
|
|
8
|
+
def test_passwordless_login(self):
|
|
9
|
+
pass
|
|
10
|
+
|
|
11
|
+
def test_password_login(self):
|
|
12
|
+
pass
|
|
13
|
+
def test_verify_authentication_token(self):
|
|
14
|
+
pass
|
|
15
|
+
|
|
16
|
+
if __name__ == "__main__":
|
|
17
|
+
unittest.main()
|