From dc874877d729498225dbc74c5cb5898db2ac1bf4 Mon Sep 17 00:00:00 2001 From: Eclipse Date: Sun, 4 Sep 2022 01:16:15 -0400 Subject: [PATCH 1/4] Added world_name and land columns to the servers table to provide easier identification for external and internal applications utilizing the database --- main.go | 6 +++++- patch-schema/servers_info.sql | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 patch-schema/servers_info.sql diff --git a/main.go b/main.go index b9dc62538..b222e0ec9 100644 --- a/main.go +++ b/main.go @@ -14,6 +14,7 @@ import ( "erupe-ce/server/entranceserver" "erupe-ce/server/launcherserver" "erupe-ce/server/signserver" + "github.com/jmoiron/sqlx" _ "github.com/lib/pq" "go.uber.org/zap" @@ -173,6 +174,8 @@ func main() { ci := 0 count := 1 for _, ee := range erupeConfig.Entrance.Entries { + cn := 1 + for _, ce := range ee.Channels { sid := (4096 + si*256) + (16 + ci) c := *channelserver.NewServer(&channelserver.Config{ @@ -192,12 +195,13 @@ func main() { if err != nil { preventClose(fmt.Sprintf("Failed to start channel server: %s", err.Error())) } else { - channelQuery += fmt.Sprintf("INSERT INTO servers (server_id, season, current_players) VALUES (%d, %d, 0);", sid, si%3) + channelQuery += fmt.Sprintf("INSERT INTO servers (server_id, season, current_players, world_name, land) VALUES (%d, %d, 0, '%s', %d);", sid, si%3, ee.Name, cn) channels = append(channels, &c) logger.Info(fmt.Sprintf("Started channel server %d on port %d", count, ce.Port)) ci++ count++ } + cn++ } ci = 0 si++ diff --git a/patch-schema/servers_info.sql b/patch-schema/servers_info.sql new file mode 100644 index 000000000..6c24a035e --- /dev/null +++ b/patch-schema/servers_info.sql @@ -0,0 +1,10 @@ +--adds world_name and land columns + +CREATE TABLE IF NOT EXISTS public.servers +( + server_id integer NOT NULL, + season integer NOT NULL, + current_players integer NOT NULL, + world_name text COLLATE pg_catalog."default", + land integer +) \ No newline at end of file From 3ba56abfa8d98affe139ddf87f84df7e08816fba Mon Sep 17 00:00:00 2001 From: Eclipse Date: Sun, 4 Sep 2022 01:48:38 -0400 Subject: [PATCH 2/4] Forgot to add alter lines if table already exists --- patch-schema/servers_info.sql | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/patch-schema/servers_info.sql b/patch-schema/servers_info.sql index 6c24a035e..b01672f89 100644 --- a/patch-schema/servers_info.sql +++ b/patch-schema/servers_info.sql @@ -7,4 +7,11 @@ CREATE TABLE IF NOT EXISTS public.servers current_players integer NOT NULL, world_name text COLLATE pg_catalog."default", land integer -) \ No newline at end of file +) + + +ALTER TABLE IF EXISTS public.servers + ADD COLUMN land integer; + +ALTER TABLE IF EXISTS public.servers + ADD COLUMN world_name text COLLATE pg_catalog."default"; \ No newline at end of file From 3c096fa8d7040408973beba44480bcd7433bc925 Mon Sep 17 00:00:00 2001 From: Eclipse Date: Sun, 4 Sep 2022 02:10:46 -0400 Subject: [PATCH 3/4] proper formating --- patch-schema/servers_info.sql | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/patch-schema/servers_info.sql b/patch-schema/servers_info.sql index b01672f89..c514b8e12 100644 --- a/patch-schema/servers_info.sql +++ b/patch-schema/servers_info.sql @@ -1,4 +1,5 @@ --adds world_name and land columns +BEGIN; CREATE TABLE IF NOT EXISTS public.servers ( @@ -14,4 +15,6 @@ ALTER TABLE IF EXISTS public.servers ADD COLUMN land integer; ALTER TABLE IF EXISTS public.servers - ADD COLUMN world_name text COLLATE pg_catalog."default"; \ No newline at end of file + ADD COLUMN world_name text COLLATE pg_catalog."default"; + +END; \ No newline at end of file From e0176ca774454a77eca9a1dde86b3f0703a0bd85 Mon Sep 17 00:00:00 2001 From: wish Date: Sun, 4 Sep 2022 16:40:06 +1000 Subject: [PATCH 4/4] indexing changes and add world description --- main.go | 7 ++----- patch-schema/servers_info.sql | 13 ++++++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index b222e0ec9..a9c796f29 100644 --- a/main.go +++ b/main.go @@ -174,9 +174,7 @@ func main() { ci := 0 count := 1 for _, ee := range erupeConfig.Entrance.Entries { - cn := 1 - - for _, ce := range ee.Channels { + for i, ce := range ee.Channels { sid := (4096 + si*256) + (16 + ci) c := *channelserver.NewServer(&channelserver.Config{ ID: uint16(sid), @@ -195,13 +193,12 @@ func main() { if err != nil { preventClose(fmt.Sprintf("Failed to start channel server: %s", err.Error())) } else { - channelQuery += fmt.Sprintf("INSERT INTO servers (server_id, season, current_players, world_name, land) VALUES (%d, %d, 0, '%s', %d);", sid, si%3, ee.Name, cn) + channelQuery += fmt.Sprintf(`INSERT INTO servers (server_id, season, current_players, world_name, world_description, land) VALUES (%d, %d, 0, '%s', '%s', %d);`, sid, si%3, ee.Name, ee.Description, i+1) channels = append(channels, &c) logger.Info(fmt.Sprintf("Started channel server %d on port %d", count, ce.Port)) ci++ count++ } - cn++ } ci = 0 si++ diff --git a/patch-schema/servers_info.sql b/patch-schema/servers_info.sql index c514b8e12..06389b6ed 100644 --- a/patch-schema/servers_info.sql +++ b/patch-schema/servers_info.sql @@ -7,14 +7,17 @@ CREATE TABLE IF NOT EXISTS public.servers season integer NOT NULL, current_players integer NOT NULL, world_name text COLLATE pg_catalog."default", + world_description text, land integer -) +); +ALTER TABLE public.servers + ADD COLUMN IF NOT EXISTS land integer; -ALTER TABLE IF EXISTS public.servers - ADD COLUMN land integer; +ALTER TABLE public.servers + ADD COLUMN IF NOT EXISTS world_name text COLLATE pg_catalog."default"; -ALTER TABLE IF EXISTS public.servers - ADD COLUMN world_name text COLLATE pg_catalog."default"; +ALTER TABLE public.servers + ADD COLUMN IF NOT EXISTS world_description text; END; \ No newline at end of file