mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Merge branch 'dev' into tweak/stats-clients
This commit is contained in:
commit
1f842574c4
@ -1,13 +1,14 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
## --- [4.0.16] - 2022/10/09
|
## --- [4.0.16] - 2022/10/23
|
||||||
### New features
|
### New features
|
||||||
TBD
|
- Automatically set update url for (new) server creation ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/487))
|
||||||
### Bug fixes
|
### Bug fixes
|
||||||
- Fix conditional issue with zip imports/uploads ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/476))
|
- Fix conditional issue with zip imports/uploads ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/476))
|
||||||
- Fix API Schedule updates ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/478))
|
- Fix API Schedule updates ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/478))
|
||||||
- Add port constraint for all server creation & api ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/479))
|
- Add port constraint for all server creation & api ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/479))
|
||||||
- Clean up backup configs when deleting servers ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/480))
|
- Clean up backup configs when deleting servers ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/480))
|
||||||
- Add timeout to socket for servers with incorrect port selection ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/482))
|
- Add timeout to socket for servers with incorrect port selection ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/482))
|
||||||
|
- Fix server_stats db file when deleting server ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/486))
|
||||||
### Tweaks
|
### Tweaks
|
||||||
- Fix sidebar to not move when scrolling ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/481))
|
- Fix sidebar to not move when scrolling ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/481))
|
||||||
- Add the rest of CSS predefined colors to themes ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/477))
|
- Add the rest of CSS predefined colors to themes ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/477))
|
||||||
|
@ -120,6 +120,7 @@ class HelperServerStats:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def get_all_servers_stats(self):
|
def get_all_servers_stats(self):
|
||||||
|
self.database.connect(reuse_if_open=True)
|
||||||
servers = HelperServers.get_all_defined_servers()
|
servers = HelperServers.get_all_defined_servers()
|
||||||
server_data = []
|
server_data = []
|
||||||
try:
|
try:
|
||||||
@ -136,18 +137,23 @@ class HelperServerStats:
|
|||||||
logger.error(
|
logger.error(
|
||||||
f"Stats collection failed with error: {ex}. Was a server just created?"
|
f"Stats collection failed with error: {ex}. Was a server just created?"
|
||||||
)
|
)
|
||||||
|
self.database.close()
|
||||||
return server_data
|
return server_data
|
||||||
|
|
||||||
def get_history_stats(self, server_id, num_days):
|
def get_history_stats(self, server_id, num_days):
|
||||||
|
self.database.connect(reuse_if_open=True)
|
||||||
max_age = datetime.datetime.now() - timedelta(days=num_days)
|
max_age = datetime.datetime.now() - timedelta(days=num_days)
|
||||||
return (
|
server_stats = (
|
||||||
ServerStats.select()
|
ServerStats.select()
|
||||||
.where(ServerStats.created > max_age)
|
.where(ServerStats.created > max_age)
|
||||||
.where(ServerStats.server_id == server_id)
|
.where(ServerStats.server_id == server_id)
|
||||||
.execute(self.database)
|
.execute(self.database)
|
||||||
)
|
)
|
||||||
|
self.database.connect(reuse_if_open=True)
|
||||||
|
return server_stats
|
||||||
|
|
||||||
def insert_server_stats(self, server_stats):
|
def insert_server_stats(self, server_stats):
|
||||||
|
self.database.connect(reuse_if_open=True)
|
||||||
server_id = server_stats.get("id", 0)
|
server_id = server_stats.get("id", 0)
|
||||||
|
|
||||||
if server_id == 0:
|
if server_id == 0:
|
||||||
@ -176,13 +182,18 @@ class HelperServerStats:
|
|||||||
}
|
}
|
||||||
).execute(self.database)
|
).execute(self.database)
|
||||||
|
|
||||||
|
self.database.close()
|
||||||
|
|
||||||
def remove_old_stats(self, last_week):
|
def remove_old_stats(self, last_week):
|
||||||
|
self.database.connect(reuse_if_open=True)
|
||||||
# self.select_database(self.server_id)
|
# self.select_database(self.server_id)
|
||||||
ServerStats.delete().where(ServerStats.created < last_week).execute(
|
ServerStats.delete().where(ServerStats.created < last_week).execute(
|
||||||
self.database
|
self.database
|
||||||
)
|
)
|
||||||
|
self.database.close()
|
||||||
|
|
||||||
def get_latest_server_stats(self):
|
def get_latest_server_stats(self):
|
||||||
|
self.database.connect(reuse_if_open=True)
|
||||||
latest = (
|
latest = (
|
||||||
ServerStats.select()
|
ServerStats.select()
|
||||||
.where(ServerStats.server_id == self.server_id)
|
.where(ServerStats.server_id == self.server_id)
|
||||||
@ -190,12 +201,15 @@ class HelperServerStats:
|
|||||||
.limit(1)
|
.limit(1)
|
||||||
.get(self.database)
|
.get(self.database)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.database.close()
|
||||||
try:
|
try:
|
||||||
return DatabaseShortcuts.get_data_obj(latest)
|
return DatabaseShortcuts.get_data_obj(latest)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
def get_server_stats(self):
|
def get_server_stats(self):
|
||||||
|
self.database.connect(reuse_if_open=True)
|
||||||
stats = (
|
stats = (
|
||||||
ServerStats.select()
|
ServerStats.select()
|
||||||
.where(ServerStats.server_id == self.server_id)
|
.where(ServerStats.server_id == self.server_id)
|
||||||
@ -203,63 +217,70 @@ class HelperServerStats:
|
|||||||
.limit(1)
|
.limit(1)
|
||||||
.first(self.database)
|
.first(self.database)
|
||||||
)
|
)
|
||||||
|
self.database.close()
|
||||||
return DatabaseShortcuts.get_data_obj(stats)
|
return DatabaseShortcuts.get_data_obj(stats)
|
||||||
|
|
||||||
def server_id_exists(self):
|
def server_id_exists(self):
|
||||||
# self.select_database(self.server_id)
|
|
||||||
if not HelperServers.get_server_data_by_id(self.server_id):
|
if not HelperServers.get_server_data_by_id(self.server_id):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def sever_crashed(self):
|
def sever_crashed(self):
|
||||||
# self.select_database(self.server_id)
|
self.database.connect(reuse_if_open=True)
|
||||||
ServerStats.update(crashed=True).where(
|
ServerStats.update(crashed=True).where(
|
||||||
ServerStats.server_id == self.server_id
|
ServerStats.server_id == self.server_id
|
||||||
).execute(self.database)
|
).execute(self.database)
|
||||||
|
self.database.close()
|
||||||
|
|
||||||
def set_import(self):
|
def set_import(self):
|
||||||
# self.select_database(self.server_id)
|
self.database.connect(reuse_if_open=True)
|
||||||
ServerStats.update(importing=True).where(
|
ServerStats.update(importing=True).where(
|
||||||
ServerStats.server_id == self.server_id
|
ServerStats.server_id == self.server_id
|
||||||
).execute(self.database)
|
).execute(self.database)
|
||||||
|
self.database.close()
|
||||||
|
|
||||||
def finish_import(self):
|
def finish_import(self):
|
||||||
# self.select_database(self.server_id)
|
self.database.connect(reuse_if_open=True)
|
||||||
ServerStats.update(importing=False).where(
|
ServerStats.update(importing=False).where(
|
||||||
ServerStats.server_id == self.server_id
|
ServerStats.server_id == self.server_id
|
||||||
).execute(self.database)
|
).execute(self.database)
|
||||||
|
self.database.close()
|
||||||
|
|
||||||
def get_import_status(self):
|
def get_import_status(self):
|
||||||
# self.select_database(self.server_id)
|
self.database.connect(reuse_if_open=True)
|
||||||
import_status = (
|
import_status = (
|
||||||
ServerStats.select()
|
ServerStats.select()
|
||||||
.where(ServerStats.server_id == self.server_id)
|
.where(ServerStats.server_id == self.server_id)
|
||||||
.get(self.database)
|
.get(self.database)
|
||||||
)
|
)
|
||||||
|
self.database.close()
|
||||||
return import_status.importing
|
return import_status.importing
|
||||||
|
|
||||||
def server_crash_reset(self):
|
def server_crash_reset(self):
|
||||||
if self.server_id is None:
|
if self.server_id is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
# self.select_database(self.server_id)
|
self.database.connect(reuse_if_open=True)
|
||||||
ServerStats.update(crashed=False).where(
|
ServerStats.update(crashed=False).where(
|
||||||
ServerStats.server_id == self.server_id
|
ServerStats.server_id == self.server_id
|
||||||
).execute(self.database)
|
).execute(self.database)
|
||||||
|
self.database.close()
|
||||||
|
|
||||||
def is_crashed(self):
|
def is_crashed(self):
|
||||||
# self.select_database(self.server_id)
|
self.database.connect(reuse_if_open=True)
|
||||||
svr: ServerStats = (
|
svr: ServerStats = (
|
||||||
ServerStats.select()
|
ServerStats.select()
|
||||||
.where(ServerStats.server_id == self.server_id)
|
.where(ServerStats.server_id == self.server_id)
|
||||||
.get(self.database)
|
.get(self.database)
|
||||||
)
|
)
|
||||||
|
self.database.close()
|
||||||
return svr.crashed
|
return svr.crashed
|
||||||
|
|
||||||
def set_update(self, value):
|
def set_update(self, value):
|
||||||
if self.server_id is None:
|
if self.server_id is None:
|
||||||
return
|
return
|
||||||
# self.select_database(self.server_id)
|
|
||||||
|
self.database.connect(reuse_if_open=True)
|
||||||
try:
|
try:
|
||||||
# Checks if server even exists
|
# Checks if server even exists
|
||||||
ServerStats.select().where(ServerStats.server_id == self.server_id).execute(
|
ServerStats.select().where(ServerStats.server_id == self.server_id).execute(
|
||||||
@ -267,22 +288,26 @@ class HelperServerStats:
|
|||||||
)
|
)
|
||||||
except DoesNotExist as ex:
|
except DoesNotExist as ex:
|
||||||
logger.error(f"Database entry not found! {ex}")
|
logger.error(f"Database entry not found! {ex}")
|
||||||
|
self.database.close()
|
||||||
return
|
return
|
||||||
|
|
||||||
ServerStats.update(updating=value).where(
|
ServerStats.update(updating=value).where(
|
||||||
ServerStats.server_id == self.server_id
|
ServerStats.server_id == self.server_id
|
||||||
).execute(self.database)
|
).execute(self.database)
|
||||||
|
self.database.close()
|
||||||
|
|
||||||
def get_update_status(self):
|
def get_update_status(self):
|
||||||
# self.select_database(self.server_id)
|
self.database.connect(reuse_if_open=True)
|
||||||
update_status = (
|
update_status = (
|
||||||
ServerStats.select()
|
ServerStats.select()
|
||||||
.where(ServerStats.server_id == self.server_id)
|
.where(ServerStats.server_id == self.server_id)
|
||||||
.get(self.database)
|
.get(self.database)
|
||||||
)
|
)
|
||||||
|
self.database.close()
|
||||||
return update_status.updating
|
return update_status.updating
|
||||||
|
|
||||||
def set_first_run(self):
|
def set_first_run(self):
|
||||||
# self.select_database(self.server_id)
|
self.database.connect(reuse_if_open=True)
|
||||||
# Sets first run to false
|
# Sets first run to false
|
||||||
try:
|
try:
|
||||||
# Checks if server even exists
|
# Checks if server even exists
|
||||||
@ -291,22 +316,25 @@ class HelperServerStats:
|
|||||||
)
|
)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logger.error(f"Database entry not found! {ex}")
|
logger.error(f"Database entry not found! {ex}")
|
||||||
|
self.database.close()
|
||||||
return
|
return
|
||||||
ServerStats.update(first_run=False).where(
|
ServerStats.update(first_run=False).where(
|
||||||
ServerStats.server_id == self.server_id
|
ServerStats.server_id == self.server_id
|
||||||
).execute(self.database)
|
).execute(self.database)
|
||||||
|
self.database.close()
|
||||||
|
|
||||||
def get_first_run(self):
|
def get_first_run(self):
|
||||||
# self.select_database(self.server_id)
|
self.database.connect(reuse_if_open=True)
|
||||||
first_run = (
|
first_run = (
|
||||||
ServerStats.select()
|
ServerStats.select()
|
||||||
.where(ServerStats.server_id == self.server_id)
|
.where(ServerStats.server_id == self.server_id)
|
||||||
.get(self.database)
|
.get(self.database)
|
||||||
)
|
)
|
||||||
|
self.database.close()
|
||||||
return first_run.first_run
|
return first_run.first_run
|
||||||
|
|
||||||
def get_ttl_without_player(self):
|
def get_ttl_without_player(self):
|
||||||
# self.select_database(self.server_id)
|
self.database.connect(reuse_if_open=True)
|
||||||
last_stat = (
|
last_stat = (
|
||||||
ServerStats.select()
|
ServerStats.select()
|
||||||
.where(ServerStats.server_id == self.server_id)
|
.where(ServerStats.server_id == self.server_id)
|
||||||
@ -320,6 +348,7 @@ class HelperServerStats:
|
|||||||
.order_by(ServerStats.created.desc())
|
.order_by(ServerStats.created.desc())
|
||||||
.first(self.database)
|
.first(self.database)
|
||||||
)
|
)
|
||||||
|
self.database.close()
|
||||||
return last_stat.created - last_stat_with_player.created
|
return last_stat.created - last_stat_with_player.created
|
||||||
|
|
||||||
def can_stop_no_players(self, time_limit):
|
def can_stop_no_players(self, time_limit):
|
||||||
@ -327,7 +356,7 @@ class HelperServerStats:
|
|||||||
return (time_limit == -1) or (ttl_no_players > time_limit)
|
return (time_limit == -1) or (ttl_no_players > time_limit)
|
||||||
|
|
||||||
def set_waiting_start(self, value):
|
def set_waiting_start(self, value):
|
||||||
# self.select_database(self.server_id)
|
self.database.connect(reuse_if_open=True)
|
||||||
try:
|
try:
|
||||||
# Checks if server even exists
|
# Checks if server even exists
|
||||||
ServerStats.select().where(ServerStats.server_id == self.server_id).execute(
|
ServerStats.select().where(ServerStats.server_id == self.server_id).execute(
|
||||||
@ -335,15 +364,19 @@ class HelperServerStats:
|
|||||||
)
|
)
|
||||||
except DoesNotExist as ex:
|
except DoesNotExist as ex:
|
||||||
logger.error(f"Database entry not found! {ex}")
|
logger.error(f"Database entry not found! {ex}")
|
||||||
|
self.database.close()
|
||||||
return
|
return
|
||||||
ServerStats.update(waiting_start=value).where(
|
ServerStats.update(waiting_start=value).where(
|
||||||
ServerStats.server_id == self.server_id
|
ServerStats.server_id == self.server_id
|
||||||
).execute(self.database)
|
).execute(self.database)
|
||||||
|
self.database.close()
|
||||||
|
|
||||||
def get_waiting_start(self):
|
def get_waiting_start(self):
|
||||||
|
self.database.connect(reuse_if_open=True)
|
||||||
waiting_start = (
|
waiting_start = (
|
||||||
ServerStats.select()
|
ServerStats.select()
|
||||||
.where(ServerStats.server_id == self.server_id)
|
.where(ServerStats.server_id == self.server_id)
|
||||||
.get(self.database)
|
.get(self.database)
|
||||||
)
|
)
|
||||||
|
self.database.close()
|
||||||
return waiting_start.waiting_start
|
return waiting_start.waiting_start
|
||||||
|
@ -419,6 +419,15 @@ class Controller:
|
|||||||
data["create_type"] == "minecraft_java"
|
data["create_type"] == "minecraft_java"
|
||||||
and root_create_data["create_type"] == "download_jar"
|
and root_create_data["create_type"] == "download_jar"
|
||||||
):
|
):
|
||||||
|
# modded update urls from server jars will only update the installer
|
||||||
|
if create_data["category"] != "modded":
|
||||||
|
server_obj = self.servers.get_server_obj(new_server_id)
|
||||||
|
url = (
|
||||||
|
f"https://serverjars.com/api/fetchJar/{create_data['category']}"
|
||||||
|
f"/{create_data['type']}/{create_data['version']}"
|
||||||
|
)
|
||||||
|
server_obj.executable_update_url = url
|
||||||
|
self.servers.update_server(server_obj)
|
||||||
self.server_jars.download_jar(
|
self.server_jars.download_jar(
|
||||||
create_data["category"],
|
create_data["category"],
|
||||||
create_data["type"],
|
create_data["type"],
|
||||||
@ -502,7 +511,12 @@ class Controller:
|
|||||||
user_id,
|
user_id,
|
||||||
server_type="minecraft-java",
|
server_type="minecraft-java",
|
||||||
)
|
)
|
||||||
|
# modded update urls from server jars will only update the installer
|
||||||
|
if jar != "modded":
|
||||||
|
server_obj = self.servers.get_server_obj(new_id)
|
||||||
|
url = f"https://serverjars.com/api/fetchJar/{jar}/{server}/{version}"
|
||||||
|
server_obj.executable_update_url = url
|
||||||
|
self.servers.update_server(server_obj)
|
||||||
# download the jar
|
# download the jar
|
||||||
self.server_jars.download_jar(
|
self.server_jars.download_jar(
|
||||||
jar, server, version, os.path.join(server_dir, server_file), new_id
|
jar, server, version, os.path.join(server_dir, server_file), new_id
|
||||||
|
Loading…
Reference in New Issue
Block a user