diff --git a/api_sender.html b/api_sender.html
index a4cd19a..85a46ea 100644
--- a/api_sender.html
+++ b/api_sender.html
@@ -100,7 +100,7 @@ document.addEventListener('DOMContentLoaded', () => {
});
function sendRequest(endpoint, payload) {
- return fetch(`https://176.165.62.226:3000/${endpoint}`, {
+ return fetch(`http://localhost:3000/${endpoint}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
diff --git a/firebase_manager.py b/firebase_manager.py
index 284ce77..3305c96 100644
--- a/firebase_manager.py
+++ b/firebase_manager.py
@@ -134,6 +134,12 @@ def delete_user(user_id: str):
user_ref.delete()
+def update_server_running_state(user_id: str, server_name: str, state: bool):
+ user_ref = firestore_database.collection('users').document(user_id).collection('servers').document(server_name)
+ if user_ref.get().get('running') != state:
+ user_ref.update({'running': state})
+
+
def log_exception_to_firestore(exception: Exception = None, user_id: str = None, data: dict = None):
new_id: str = datetime.now().strftime('%Y-%m-%d %H:%M:%S %Z%z')
log_entry = {
diff --git a/generic_executor.py b/generic_executor.py
index 40199ef..10ccd85 100644
--- a/generic_executor.py
+++ b/generic_executor.py
@@ -137,6 +137,10 @@ def server_run(user: UserRecord, name: str) -> tuple[HTTPStatus, str or None]:
if server_id is None:
return HTTPStatus.OK, f"You cannot run multiples instances at this time."
mc_manager.servers[server_id]['port'] = int(port)
+ try:
+ firebase_manager.update_server_running_state(user_id, name, True)
+ except Exception as e:
+ return HTTPStatus.INTERNAL_SERVER_ERROR, f"Error updating server {name}'s running state in database. {type(e).__name__}{str(e)}."
return HTTPStatus.ACCEPTED, f"Successfully started server {name}."
except Exception as e:
print(f"Error when running server: {e}")
@@ -145,8 +149,13 @@ def server_run(user: UserRecord, name: str) -> tuple[HTTPStatus, str or None]:
def server_stop(user: UserRecord, name: str) -> tuple[HTTPStatus, str or None]:
port = None
+ user_id = user.uid
try:
port = firebase_manager.get_server_port(user.uid)
+ try:
+ firebase_manager.update_server_running_state(user_id, name, False)
+ except Exception:
+ pass
if port is None:
return HTTPStatus.NOT_FOUND, f"Server {name} not found in firestore."
exists: bool = mc_manager.stop_server(port)