From 814092a9f08c2f71c166c23c948f5eceeb95e367 Mon Sep 17 00:00:00 2001 From: Corey Date: Tue, 7 May 2024 12:07:26 +0000 Subject: [PATCH] Add more recommended settings Also split expansions out into their own field. --- .devcontainer/devcontainer.json | 2 +- api/entrypoint.sh | 2 +- ...ations_server_settings_summary_and_more.py | 23 +++++++ api/v1/models/server.py | 62 +++++++++++++------ api/v1/serializers/server.py | 3 +- .../src/components/Server/ExpansionsBar.tsx | 16 ++--- .../components/Server/SettingsChipCloud.tsx | 2 +- client/src/components/ServerCard.tsx | 12 ++-- client/src/data/ServerData.tsx | 19 +++++- client/src/pages/Home.tsx | 49 ++++++--------- 10 files changed, 122 insertions(+), 68 deletions(-) create mode 100644 api/v1/migrations/0006_rename_customizations_server_settings_summary_and_more.py diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 23c2a9e..a0004f7 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -21,7 +21,7 @@ "ghcr.io/devcontainers/features/docker-outside-of-docker:latest": {} }, "mounts": [ - "source=vscode-extensions,target=/root/.vscode-server/extensions,type=volume", + "source=vscode-extensions,target=/root/.vscode-server/extensions,type=volume" ], "customizations": { "vscode": { diff --git a/api/entrypoint.sh b/api/entrypoint.sh index 008379a..aa0e68e 100755 --- a/api/entrypoint.sh +++ b/api/entrypoint.sh @@ -1,7 +1,7 @@ #!/bin/sh python manage.py collectstatic --noinput -python manage.py makemigrations +# python manage.py makemigrations python manage.py migrate exec "$@" diff --git a/api/v1/migrations/0006_rename_customizations_server_settings_summary_and_more.py b/api/v1/migrations/0006_rename_customizations_server_settings_summary_and_more.py new file mode 100644 index 0000000..e249688 --- /dev/null +++ b/api/v1/migrations/0006_rename_customizations_server_settings_summary_and_more.py @@ -0,0 +1,23 @@ +# Generated by Django 5.0.5 on 2024-05-07 11:42 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('v1', '0005_alter_server_url'), + ] + + operations = [ + migrations.RenameField( + model_name='server', + old_name='customizations', + new_name='settings_summary', + ), + migrations.AddField( + model_name='server', + name='expansions', + field=models.JSONField(editable=False, null=True), + ), + ] diff --git a/api/v1/models/server.py b/api/v1/models/server.py index 31b1186..005d1de 100644 --- a/api/v1/models/server.py +++ b/api/v1/models/server.py @@ -17,15 +17,31 @@ required_settings = [ ] recommended_settings = [ + "LOGIN.CLIENT_VER", "MAIN.ENABLE_TRUST_CASTING", + "MAIN.HOMEPOINT_TELEPORT", + "MAIN.ENABLE_SURVIVAL_GUIDE", "MAP.LEVEL_SYNC_ENABLE", - "LOGIN.RISE_OF_ZILART", - "LOGIN.CHAINS_OF_PROMATHIA", - "LOGIN.TREASURES_OF_AHT_URGHAN", - "LOGIN.WINGS_OF_THE_GODDESS", - "LOGIN.SEEKERS_OF_ADOULIN", + "MAIN.ENABLE_ROE", + "MAIN.ENABLE_FIELD_MANUALS", + "MAIN.ENABLE_GROUNDS_TOMES", ] +expansions_settings = { + "LOGIN.RISE_OF_ZILART": "rotz", + "LOGIN.CHAINS_OF_PROMATHIA": "cop", + "LOGIN.TREASURES_OF_AHT_URGHAN": "toau", + "LOGIN.WINGS_OF_THE_GODDESS": "wotg", + "LOGIN.SEEKERS_OF_ADOULIN": "soa", + "MAIN.ENABLE_ACP": "acp", + "MAIN.ENABLE_AMK": "amk", + "MAIN.ENABLE_ASA": "asa", + "MAIN.ENABLE_ABYSSEA": "abyssea", + "MAIN.ENABLE_VOIDWATCH": "voidwatch", + "MAIN.ENABLE_ROV": "rov", + "MAIN.ENABLE_TVR": "tvr", +} + class OptionalSchemeURLValidator(URLValidator): def __call__(self, value): @@ -51,8 +67,9 @@ class Server(models.Model): ) location = models.CharField(max_length=255, null=True, editable=False) max_level = models.IntegerField(null=True, editable=False) + expansions = models.JSONField(null=True, editable=False) settings = models.JSONField(null=True, editable=False) - customizations = models.JSONField(null=True, editable=False) + settings_summary = models.JSONField(null=True, editable=False) login_limit = models.IntegerField(null=True, editable=False) active_sessions = models.IntegerField(null=True, editable=False) created = models.DateTimeField(auto_now_add=True) @@ -119,30 +136,39 @@ class Server(models.Model): self.max_level = server_settings["MAIN.MAX_LEVEL"] self.login_limit = server_settings["LOGIN.LOGIN_LIMIT"] - # Check customizations with open("defaultLsbSettings.json", "r") as default_settings_file: default_settings = json.load(default_settings_file) - customizations = {} - customizations["LOGIN.CLIENT_VER"] = server_settings["LOGIN.CLIENT_VER"] + expansions = {} + for setting in expansions_settings: + expansions[expansions_settings[setting]] = ( + True if server_settings[setting] else False + ) + settings_summary = {} + for setting in recommended_settings: + if server_settings[setting]: + settings_summary[setting] = server_settings[setting] + # Check customizations for key, value in server_settings.items(): - if key not in required_settings and ( - key in recommended_settings - or key not in default_settings - or default_settings[key] != value + if ( + key not in required_settings + and key not in recommended_settings + and key not in expansions_settings + and (key not in default_settings or default_settings[key] != value) ): - customizations[key] = value + settings_summary[key] = value - self.customizations = customizations + self.expansions = expansions self.settings = server_settings + self.settings_summary = settings_summary # Request the active session count from API response = requests.get(f"http://{self.url}/api/sessions") response.raise_for_status() - session_count = response.text - if session_count.isdigit(): - self.active_sessions = int(session_count) + active_sessions = response.text + if active_sessions.isdigit(): + self.active_sessions = int(active_sessions) # Test other server ports (you can actually change all of these?) # ports_to_check = [ diff --git a/api/v1/serializers/server.py b/api/v1/serializers/server.py index 38385f0..671dd0b 100644 --- a/api/v1/serializers/server.py +++ b/api/v1/serializers/server.py @@ -11,7 +11,8 @@ class ServerSerializer(serializers.ModelSerializer): "url", "location", "max_level", - "customizations", + "expansions", + "settings_summary", "login_limit", "active_sessions", "updated", diff --git a/client/src/components/Server/ExpansionsBar.tsx b/client/src/components/Server/ExpansionsBar.tsx index 0087928..d8001a8 100644 --- a/client/src/components/Server/ExpansionsBar.tsx +++ b/client/src/components/Server/ExpansionsBar.tsx @@ -55,13 +55,15 @@ export default function ExpansionBar({ server }: ExpansionBarProps) { return ( {expansions} diff --git a/client/src/components/Server/SettingsChipCloud.tsx b/client/src/components/Server/SettingsChipCloud.tsx index 4dde241..9c19767 100644 --- a/client/src/components/Server/SettingsChipCloud.tsx +++ b/client/src/components/Server/SettingsChipCloud.tsx @@ -80,7 +80,7 @@ export default function SettingsChipCloud({ server }: SettingsChipCloudProps) { maxWidth: '100%', }} > - {Object.entries(server.customizations).map(renderSettingsChip)} + {Object.entries(server.settings_summary).map(renderSettingsChip)} ); } diff --git a/client/src/components/ServerCard.tsx b/client/src/components/ServerCard.tsx index 8bcaafa..f18d159 100644 --- a/client/src/components/ServerCard.tsx +++ b/client/src/components/ServerCard.tsx @@ -124,7 +124,7 @@ export default function ServerCard({ server, children }: ServerCardProps) { > - {server.customizations['LOGIN.MAINT_MODE'] === 1 ? ( + {server.settings_summary['LOGIN.MAINT_MODE'] === 1 ? ( {server.name} - {typeof server.customizations['API.WEBSITE'] === 'string' && - server.customizations['API.WEBSITE'] !== '' && ( + {typeof server.settings_summary['API.WEBSITE'] === 'string' && + server.settings_summary['API.WEBSITE'] !== '' && ( - {server.customizations['MAIN.SERVER_MESSAGE'] && ( + {server.settings_summary['MAIN.SERVER_MESSAGE'] && ( <> - {server.customizations['MAIN.SERVER_MESSAGE']} + {server.settings_summary['MAIN.SERVER_MESSAGE']} diff --git a/client/src/data/ServerData.tsx b/client/src/data/ServerData.tsx index 1283ed0..d98876c 100644 --- a/client/src/data/ServerData.tsx +++ b/client/src/data/ServerData.tsx @@ -16,8 +16,9 @@ export type ServerData = { url: string; location: string; max_level: number; + expansions: ServerSettings; settings?: ServerSettings; - customizations: ServerSettings; + settings_summary: ServerSettings; login_limit: number; active_sessions: number; updated: string; @@ -29,8 +30,22 @@ export const DemoServerData: ServerData = { url: 'github.com/LandSandBoat/server', location: 'NA', max_level: 99, + expansions: { + rotz: true, + cop: true, + toau: true, + wotg: true, + soa: true, + acp: true, + amk: true, + asa: true, + abyssea: true, + voidwatch: true, + rov: true, + tvr: true, + }, settings: LsbDefaults, - customizations: { + settings_summary: { 'API.WEBSITE': 'https://landsandboat.github.io/server/', 'MAIN.ENABLE_TRUST_CASTING': 1, 'MAP.LEVEL_SYNC_ENABLE': true, diff --git a/client/src/pages/Home.tsx b/client/src/pages/Home.tsx index 2ee90a9..b721926 100644 --- a/client/src/pages/Home.tsx +++ b/client/src/pages/Home.tsx @@ -29,10 +29,10 @@ export default function Home({ if ( searchState.trusts && - typeof server.customizations['MAIN.ENABLE_TRUST_CASTING'] === 'number' + typeof server.settings_summary['MAIN.ENABLE_TRUST_CASTING'] === 'number' ) { const serverTrusts = - server.customizations['MAIN.ENABLE_TRUST_CASTING'] === 1; + server.settings_summary['MAIN.ENABLE_TRUST_CASTING'] === 1; const searchEnabled = searchState.trusts.includes('enabled'); const searchDisabled = searchState.trusts.includes('disabled'); if (serverTrusts && searchDisabled && !searchEnabled) { @@ -45,9 +45,9 @@ export default function Home({ if ( searchState.levelSync && - typeof server.customizations['MAP.LEVEL_SYNC_ENABLE'] === 'boolean' + typeof server.settings_summary['MAP.LEVEL_SYNC_ENABLE'] === 'boolean' ) { - const serverLevelSync = server.customizations['MAP.LEVEL_SYNC_ENABLE']; + const serverLevelSync = server.settings_summary['MAP.LEVEL_SYNC_ENABLE']; const searchEnabled = searchState.levelSync.includes('enabled'); const searchDisabled = searchState.levelSync.includes('disabled'); if (serverLevelSync && searchDisabled && !searchEnabled) { @@ -59,45 +59,32 @@ export default function Home({ } if (searchState.expansions) { - const searchNoneEnabled = searchState.expansions.includes('none'); - const searchRotzEnabled = searchState.expansions.includes('rotz'); - const serverRotzEnabled = - server.customizations['LOGIN.RISE_OF_ZILART'] === true; - const searchCopEnabled = searchState.expansions.includes('cop'); - const serverCopEnabled = - server.customizations['LOGIN.CHAINS_OF_PROMATHIA'] === true; - const searchToauEnabled = searchState.expansions.includes('toau'); - const serverToauEnabled = - server.customizations['LOGIN.TREASURES_OF_AHT_URGHAN'] === true; - const searchWotgEnabled = searchState.expansions.includes('wotg'); - const serverWotgEnabled = - server.customizations['LOGIN.WINGS_OF_THE_GODDESS'] === true; - const searchSoaEnabled = searchState.expansions.includes('soa'); - const serverSoaEnabled = - server.customizations['LOGIN.SEEKERS_OF_ADOULIN'] === true; + if (!server.expansions) { + return false; + } if ( - searchNoneEnabled && - (serverRotzEnabled || - serverCopEnabled || - serverToauEnabled || - serverWotgEnabled || - serverSoaEnabled) + searchState.expansions.includes('none') && + (server.expansions.rotz || + server.expansions.cop || + server.expansions.toau || + server.expansions.wotg || + server.expansions.soa) ) { return false; } - if (searchRotzEnabled !== serverRotzEnabled) { + if (searchState.expansions.includes('rotz') && server.expansions.rotz) { return false; } - if (searchCopEnabled !== serverCopEnabled) { + if (searchState.expansions.includes('cop') && server.expansions.cop) { return false; } - if (searchToauEnabled !== serverToauEnabled) { + if (searchState.expansions.includes('toau') && server.expansions.toau) { return false; } - if (searchWotgEnabled !== serverWotgEnabled) { + if (searchState.expansions.includes('wotg') && server.expansions.wotg) { return false; } - if (searchSoaEnabled !== serverSoaEnabled) { + if (searchState.expansions.includes('soa') && server.expansions.soa) { return false; } }