From 589a11f43ccb852d17122b2a8c194aecfb30ab6b Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 13 Jan 2024 16:43:16 -0500 Subject: [PATCH] Allow omission of player stats from total --- app/classes/models/servers.py | 1 + app/classes/shared/server.py | 1 + .../web/routes/api/servers/server/index.py | 2 ++ app/frontend/templates/panel/dashboard.html | 16 ++++++++++++---- app/frontend/templates/panel/server_config.html | 12 ++++++++++++ app/migrations/20231229_player_count.py | 16 ++++++++++++++++ app/translations/en_EN.json | 5 +++-- 7 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 app/migrations/20231229_player_count.py diff --git a/app/classes/models/servers.py b/app/classes/models/servers.py index a83fd0a2..00bc5002 100644 --- a/app/classes/models/servers.py +++ b/app/classes/models/servers.py @@ -42,6 +42,7 @@ class Servers(BaseModel): created_by = IntegerField(default=-100) shutdown_timeout = IntegerField(default=60) ignored_exits = CharField(default="0") + count_players = BooleanField(default=True) class Meta: table_name = "servers" diff --git a/app/classes/shared/server.py b/app/classes/shared/server.py index 8448f656..15544a26 100644 --- a/app/classes/shared/server.py +++ b/app/classes/shared/server.py @@ -1560,6 +1560,7 @@ class ServerInstance: "version": raw_ping_result.get("version"), "icon": raw_ping_result.get("icon"), "crashed": self.is_crashed, + "count_players": self.server_object.count_players, } ) diff --git a/app/classes/web/routes/api/servers/server/index.py b/app/classes/web/routes/api/servers/server/index.py index afe02a0b..06db3158 100644 --- a/app/classes/web/routes/api/servers/server/index.py +++ b/app/classes/web/routes/api/servers/server/index.py @@ -29,6 +29,7 @@ server_patch_schema = { "logs_delete_after": {"type": "integer", "minimum": 0}, "ignored_exits": {"type": "string"}, "show_status": {"type": "boolean"}, + "count_players": {"type": "boolean"}, }, "additionalProperties": False, "minProperties": 1, @@ -46,6 +47,7 @@ basic_server_patch_schema = { "shutdown_timeout": {"type": "integer"}, "logs_delete_after": {"type": "integer", "minimum": 0}, "ignored_exits": {"type": "string"}, + "count_players": {"type": "boolean"}, }, "additionalProperties": False, "minProperties": 1, diff --git a/app/frontend/templates/panel/dashboard.html b/app/frontend/templates/panel/dashboard.html index 88c9a821..eb4a51a9 100644 --- a/app/frontend/templates/panel/dashboard.html +++ b/app/frontend/templates/panel/dashboard.html @@ -315,7 +315,7 @@

- + {% end %} @@ -554,6 +554,9 @@ display: none; /* for Chrome, Safari, and Opera */ } + .gray { + color: gray !important; + } @@ -724,15 +727,20 @@ server_players.setAttribute('data-players', server.online); server_players.setAttribute('data-max', server.max); + server_players.setAttribute('data-count', server.count_players) let servers = Array.from(document.getElementsByClassName("server-player-totals")); let all_total_players = 0; let all_total_max_players = 0; servers.forEach(server => { try { - all_total_players += parseInt(server.getAttribute('data-players')); - all_total_max_players += parseInt(server.getAttribute('data-max')); - } catch { + console.log(`#server_desc_${server.getAttribute("data-serverId")}`) + $(`#server_desc_${server.getAttribute("data-serverId")}`).toggleClass("gray", server.getAttribute('data-count') === 'false') + if (server.getAttribute('data-count') === 'true'){ + all_total_players += parseInt(server.getAttribute('data-players')); + all_total_max_players += parseInt(server.getAttribute('data-max')); + } + } catch { console.log("Player totals are not of type int"); } }) diff --git a/app/frontend/templates/panel/server_config.html b/app/frontend/templates/panel/server_config.html index 46f7b4dc..6b29ea7c 100644 --- a/app/frontend/templates/panel/server_config.html +++ b/app/frontend/templates/panel/server_config.html @@ -188,6 +188,17 @@ {% end %} +
+
+ {% if data['server_stats']['server_id']['count_players'] %} + + + {% else %} + + + {% end %} +
+
{% if data['super_user'] %} @@ -559,6 +570,7 @@ formDataObject.show_status = $("#show_status").prop('checked'); formDataObject.crash_detection = $("#crash_detection").prop('checked'); formDataObject.auto_start = $("#auto_start").prop('checked'); + formDataObject.count_players = $("#count_players").prop('checked'); console.log(formDataObject); // Format the plain form data as JSON let formDataJsonString = JSON.stringify(formDataObject, replacer); diff --git a/app/migrations/20231229_player_count.py b/app/migrations/20231229_player_count.py new file mode 100644 index 00000000..0f7f1876 --- /dev/null +++ b/app/migrations/20231229_player_count.py @@ -0,0 +1,16 @@ +# Generated by database migrator +import peewee + + +def migrate(migrator, database, **kwargs): + migrator.add_columns("servers", count_players=peewee.BooleanField(default=True)) + """ + Write your migrations here. + """ + + +def rollback(migrator, database, **kwargs): + migrator.drop_columns("servers", ["count_players"]) + """ + Write your rollback migrations here. + """ diff --git a/app/translations/en_EN.json b/app/translations/en_EN.json index 4db8be71..a717c929 100644 --- a/app/translations/en_EN.json +++ b/app/translations/en_EN.json @@ -377,7 +377,8 @@ "timeoutExplain2": "command before it forces the process down.", "update": "Update Executable", "yesDelete": "Yes, delete", - "yesDeleteFiles": "Yes, delete files" + "yesDeleteFiles": "Yes, delete files", + "countPlayers": "Include server in total player count" }, "serverConfigHelp": { "desc": "Here is where you can change the configuration of your server", @@ -665,4 +666,4 @@ "webhook_body": "Webhook Body", "webhooks": "Webhooks" } -} +} \ No newline at end of file