From e39630564e1d62381393cc89a1861ba604803dd3 Mon Sep 17 00:00:00 2001 From: rockisch Date: Wed, 22 Nov 2023 00:01:04 -0300 Subject: [PATCH 1/2] Add dev proxy config --- config.json | 1 + config/config.go | 29 +++++++++++++++-------------- main.go | 12 ++++++++---- server/entranceserver/make_resp.go | 6 +++++- 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/config.json b/config.json index e3e2b7ea4..bfa9e04de 100644 --- a/config.json +++ b/config.json @@ -29,6 +29,7 @@ "MezFesAlt": false, "DisableTokenCheck": false, "QuestDebugTools": false, + "ProxyPort": 0, "EarthStatusOverride": 0, "EarthIDOverride": 0, "EarthMonsterOverride": 0, diff --git a/config/config.go b/config/config.go index ee0e6b377..c9a05d3d1 100644 --- a/config/config.go +++ b/config/config.go @@ -96,20 +96,21 @@ type Config struct { // DevModeOptions holds various debug/temporary options for use while developing Erupe. type DevModeOptions struct { - AutoCreateAccount bool // Automatically create accounts if they don't exist - CleanDB bool // Automatically wipes the DB on server reset. - MaxLauncherHR bool // Sets the HR returned in the launcher to HR7 so that you can join non-beginner worlds. - LogInboundMessages bool // Log all messages sent to the server - LogOutboundMessages bool // Log all messages sent to the clients - LogMessageData bool // Log all bytes transferred as a hexdump - MaxHexdumpLength int // Maximum number of bytes printed when logs are enabled - DivaEvent int // Diva Defense event status - FestaEvent int // Hunter's Festa event status - TournamentEvent int // VS Tournament event status - MezFesEvent bool // MezFes status - MezFesAlt bool // Swaps out Volpakkun for Tokotoko - DisableTokenCheck bool // Disables checking login token exists in the DB (security risk!) - QuestDebugTools bool // Enable various quest debug logs + AutoCreateAccount bool // Automatically create accounts if they don't exist + CleanDB bool // Automatically wipes the DB on server reset. + MaxLauncherHR bool // Sets the HR returned in the launcher to HR7 so that you can join non-beginner worlds. + LogInboundMessages bool // Log all messages sent to the server + LogOutboundMessages bool // Log all messages sent to the clients + LogMessageData bool // Log all bytes transferred as a hexdump + MaxHexdumpLength int // Maximum number of bytes printed when logs are enabled + DivaEvent int // Diva Defense event status + FestaEvent int // Hunter's Festa event status + TournamentEvent int // VS Tournament event status + MezFesEvent bool // MezFes status + MezFesAlt bool // Swaps out Volpakkun for Tokotoko + DisableTokenCheck bool // Disables checking login token exists in the DB (security risk!) + QuestDebugTools bool // Enable various quest debug logs + ProxyPort uint16 // Forces the game connect to a channel server proxy EarthStatusOverride int32 EarthIDOverride int32 EarthMonsterOverride int32 diff --git a/main.go b/main.go index 2a538b094..724fe3f44 100644 --- a/main.go +++ b/main.go @@ -22,11 +22,13 @@ import ( ) // Temporary DB auto clean on startup for quick development & testing. -func cleanDB(db *sqlx.DB) { +func cleanDB(db *sqlx.DB, config *_config.Config) { _ = db.MustExec("DELETE FROM guild_characters") _ = db.MustExec("DELETE FROM guilds") _ = db.MustExec("DELETE FROM characters") - _ = db.MustExec("DELETE FROM sign_sessions") + if !config.DevMode || config.DevModeOptions.ProxyPort == 0 { + _ = db.MustExec("DELETE FROM sign_sessions") + } _ = db.MustExec("DELETE FROM users") } @@ -124,14 +126,16 @@ func main() { logger.Info("Database: Started successfully") // Clear stale data - _ = db.MustExec("DELETE FROM sign_sessions") + if !config.DevMode || config.DevModeOptions.ProxyPort == 0 { + _ = db.MustExec("DELETE FROM sign_sessions") + } _ = db.MustExec("DELETE FROM servers") _ = db.MustExec(`UPDATE guild_characters SET treasure_hunt=NULL`) // Clean the DB if the option is on. if config.DevMode && config.DevModeOptions.CleanDB { logger.Info("Database: Started clearing...") - cleanDB(db) + cleanDB(db, config) logger.Info("Database: Finished clearing") } diff --git a/server/entranceserver/make_resp.go b/server/entranceserver/make_resp.go index eaa023c5b..5ace5a427 100644 --- a/server/entranceserver/make_resp.go +++ b/server/entranceserver/make_resp.go @@ -69,7 +69,11 @@ func encodeServerInfo(config *_config.Config, s *Server, local bool) []byte { for channelIdx, ci := range si.Channels { sid = (4096 + serverIdx*256) + (16 + channelIdx) - bf.WriteUint16(ci.Port) + if _config.ErupeConfig.DevMode && _config.ErupeConfig.DevModeOptions.ProxyPort != 0 { + bf.WriteUint16(_config.ErupeConfig.DevModeOptions.ProxyPort) + } else { + bf.WriteUint16(ci.Port) + } bf.WriteUint16(16 + uint16(channelIdx)) bf.WriteUint16(ci.MaxPlayers) var currentPlayers uint16 From a2f488e5e3f6805a30cd0cf5e5649630c9441f7f Mon Sep 17 00:00:00 2001 From: wish Date: Sun, 26 Nov 2023 20:50:08 +1100 Subject: [PATCH 2/2] move ProxyPort config out of DevMode --- config.json | 2 +- config/config.go | 32 +++++++++++++++--------------- main.go | 2 +- server/entranceserver/make_resp.go | 4 ++-- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/config.json b/config.json index bfa9e04de..d6c233470 100644 --- a/config.json +++ b/config.json @@ -13,6 +13,7 @@ "DeleteOnSaveCorruption": false, "ClientMode": "ZZ", "QuestCacheExpiry": 300, + "ProxyPort": 0, "DevMode": true, "DevModeOptions": { "AutoCreateAccount": true, @@ -29,7 +30,6 @@ "MezFesAlt": false, "DisableTokenCheck": false, "QuestDebugTools": false, - "ProxyPort": 0, "EarthStatusOverride": 0, "EarthIDOverride": 0, "EarthMonsterOverride": 0, diff --git a/config/config.go b/config/config.go index c9a05d3d1..5bcea5659 100644 --- a/config/config.go +++ b/config/config.go @@ -79,7 +79,8 @@ type Config struct { DeleteOnSaveCorruption bool // Attempts to save corrupted data will flag the save for deletion ClientMode string RealClientMode Mode - QuestCacheExpiry int // Number of seconds to keep quest data cached + QuestCacheExpiry int // Number of seconds to keep quest data cached + ProxyPort uint16 // Forces the game to connect to a channel server proxy DevMode bool DevModeOptions DevModeOptions @@ -96,21 +97,20 @@ type Config struct { // DevModeOptions holds various debug/temporary options for use while developing Erupe. type DevModeOptions struct { - AutoCreateAccount bool // Automatically create accounts if they don't exist - CleanDB bool // Automatically wipes the DB on server reset. - MaxLauncherHR bool // Sets the HR returned in the launcher to HR7 so that you can join non-beginner worlds. - LogInboundMessages bool // Log all messages sent to the server - LogOutboundMessages bool // Log all messages sent to the clients - LogMessageData bool // Log all bytes transferred as a hexdump - MaxHexdumpLength int // Maximum number of bytes printed when logs are enabled - DivaEvent int // Diva Defense event status - FestaEvent int // Hunter's Festa event status - TournamentEvent int // VS Tournament event status - MezFesEvent bool // MezFes status - MezFesAlt bool // Swaps out Volpakkun for Tokotoko - DisableTokenCheck bool // Disables checking login token exists in the DB (security risk!) - QuestDebugTools bool // Enable various quest debug logs - ProxyPort uint16 // Forces the game connect to a channel server proxy + AutoCreateAccount bool // Automatically create accounts if they don't exist + CleanDB bool // Automatically wipes the DB on server reset. + MaxLauncherHR bool // Sets the HR returned in the launcher to HR7 so that you can join non-beginner worlds. + LogInboundMessages bool // Log all messages sent to the server + LogOutboundMessages bool // Log all messages sent to the clients + LogMessageData bool // Log all bytes transferred as a hexdump + MaxHexdumpLength int // Maximum number of bytes printed when logs are enabled + DivaEvent int // Diva Defense event status + FestaEvent int // Hunter's Festa event status + TournamentEvent int // VS Tournament event status + MezFesEvent bool // MezFes status + MezFesAlt bool // Swaps out Volpakkun for Tokotoko + DisableTokenCheck bool // Disables checking login token exists in the DB (security risk!) + QuestDebugTools bool // Enable various quest debug logs EarthStatusOverride int32 EarthIDOverride int32 EarthMonsterOverride int32 diff --git a/main.go b/main.go index 724fe3f44..1413392cf 100644 --- a/main.go +++ b/main.go @@ -26,7 +26,7 @@ func cleanDB(db *sqlx.DB, config *_config.Config) { _ = db.MustExec("DELETE FROM guild_characters") _ = db.MustExec("DELETE FROM guilds") _ = db.MustExec("DELETE FROM characters") - if !config.DevMode || config.DevModeOptions.ProxyPort == 0 { + if config.ProxyPort == 0 { _ = db.MustExec("DELETE FROM sign_sessions") } _ = db.MustExec("DELETE FROM users") diff --git a/server/entranceserver/make_resp.go b/server/entranceserver/make_resp.go index 5ace5a427..4b478fa24 100644 --- a/server/entranceserver/make_resp.go +++ b/server/entranceserver/make_resp.go @@ -69,8 +69,8 @@ func encodeServerInfo(config *_config.Config, s *Server, local bool) []byte { for channelIdx, ci := range si.Channels { sid = (4096 + serverIdx*256) + (16 + channelIdx) - if _config.ErupeConfig.DevMode && _config.ErupeConfig.DevModeOptions.ProxyPort != 0 { - bf.WriteUint16(_config.ErupeConfig.DevModeOptions.ProxyPort) + if _config.ErupeConfig.DevMode && _config.ErupeConfig.ProxyPort != 0 { + bf.WriteUint16(_config.ErupeConfig.ProxyPort) } else { bf.WriteUint16(ci.Port) }