refactor(config): eliminate ErupeConfig global variable

Replace the mutable global `_config.ErupeConfig` with dependency
injection across 79 files. Config is now threaded through existing
paths: `ClientContext.RealClientMode` for packet encoding, `s.server.
erupeConfig` for channel handlers, and explicit parameters for utility
functions. This removes hidden coupling, enables test parallelism
without global save/restore, and prevents low-level packages from
reaching up to the config layer.

Key changes:
- Enrich ClientContext with RealClientMode for packet files
- Add mode parameter to CryptConn, mhfitem, mhfcourse functions
- Convert handlers_commands init() to lazy sync.Once initialization
- Delete global var, init(), and helper functions from config.go
- Update all tests to pass config explicitly
This commit is contained in:
Houmgaor
2026-02-20 17:07:42 +01:00
parent 8c7e95ce18
commit 5f3c843082
79 changed files with 509 additions and 723 deletions

View File

@@ -5,6 +5,7 @@ import (
"testing"
"erupe-ce/common/byteframe"
_config "erupe-ce/config"
"erupe-ce/network"
"erupe-ce/network/clientctx"
)
@@ -63,7 +64,7 @@ func TestMsgSysPingRoundTrip(t *testing.T) {
AckHandle: 0x12345678,
}
ctx := &clientctx.ClientContext{}
ctx := &clientctx.ClientContext{RealClientMode: _config.ZZ}
// Build
bf := byteframe.NewByteFrame()
@@ -105,7 +106,7 @@ func TestMsgSysTimeRoundTrip(t *testing.T) {
Timestamp: tt.timestamp,
}
ctx := &clientctx.ClientContext{}
ctx := &clientctx.ClientContext{RealClientMode: _config.ZZ}
// Build
bf := byteframe.NewByteFrame()
@@ -239,7 +240,7 @@ func TestParserInterface(t *testing.T) {
bf.WriteUint32(123)
_, _ = bf.Seek(0, io.SeekStart)
err := p.Parse(bf, &clientctx.ClientContext{})
err := p.Parse(bf, &clientctx.ClientContext{RealClientMode: _config.ZZ})
if err != nil {
t.Errorf("Parse() error = %v", err)
}
@@ -250,7 +251,7 @@ func TestBuilderInterface(t *testing.T) {
var b Builder = &MsgSysPing{AckHandle: 456}
bf := byteframe.NewByteFrame()
err := b.Build(bf, &clientctx.ClientContext{})
err := b.Build(bf, &clientctx.ClientContext{RealClientMode: _config.ZZ})
if err != nil {
t.Errorf("Build() error = %v", err)
}
@@ -269,24 +270,21 @@ func TestOpcoderInterface(t *testing.T) {
}
}
func TestClientContextNilSafe(t *testing.T) {
// Some packets may need to handle nil ClientContext
func TestClientContextBuildSafe(t *testing.T) {
pkt := &MsgSysPing{AckHandle: 123}
bf := byteframe.NewByteFrame()
// This should not panic even with nil context (implementation dependent)
// Note: The actual behavior depends on implementation
err := pkt.Build(bf, nil)
ctx := &clientctx.ClientContext{RealClientMode: _config.ZZ}
err := pkt.Build(bf, ctx)
if err != nil {
// Error is acceptable if nil context is not supported
t.Logf("Build() with nil context returned error: %v", err)
t.Logf("Build() returned error: %v", err)
}
}
func TestMsgSysPingBuildFormat(t *testing.T) {
pkt := &MsgSysPing{AckHandle: 0x12345678}
bf := byteframe.NewByteFrame()
_ = pkt.Build(bf, &clientctx.ClientContext{})
_ = pkt.Build(bf, &clientctx.ClientContext{RealClientMode: _config.ZZ})
data := bf.Data()
if len(data) != 4 {
@@ -305,7 +303,7 @@ func TestMsgSysTimeBuildFormat(t *testing.T) {
Timestamp: 0xDEADBEEF,
}
bf := byteframe.NewByteFrame()
_ = pkt.Build(bf, &clientctx.ClientContext{})
_ = pkt.Build(bf, &clientctx.ClientContext{RealClientMode: _config.ZZ})
data := bf.Data()
if len(data) != 5 {
@@ -504,7 +502,7 @@ func TestMsgSysCreateStageParse(t *testing.T) {
_, _ = bf.Seek(0, io.SeekStart)
pkt := &MsgSysCreateStage{}
err := pkt.Parse(bf, &clientctx.ClientContext{})
err := pkt.Parse(bf, &clientctx.ClientContext{RealClientMode: _config.ZZ})
if err != nil {
t.Fatalf("Parse() error = %v", err)
}
@@ -556,7 +554,7 @@ func TestMsgSysEnterStageParse(t *testing.T) {
_, _ = bf.Seek(0, io.SeekStart)
pkt := &MsgSysEnterStage{}
err := pkt.Parse(bf, &clientctx.ClientContext{})
err := pkt.Parse(bf, &clientctx.ClientContext{RealClientMode: _config.ZZ})
if err != nil {
t.Fatalf("Parse() error = %v", err)
}
@@ -605,7 +603,7 @@ func TestMsgSysMoveStageParse(t *testing.T) {
_, _ = bf.Seek(0, io.SeekStart)
pkt := &MsgSysMoveStage{}
err := pkt.Parse(bf, &clientctx.ClientContext{})
err := pkt.Parse(bf, &clientctx.ClientContext{RealClientMode: _config.ZZ})
if err != nil {
t.Fatalf("Parse() error = %v", err)
}
@@ -651,7 +649,7 @@ func TestMsgSysLockStageParse(t *testing.T) {
_, _ = bf.Seek(0, io.SeekStart)
pkt := &MsgSysLockStage{}
err := pkt.Parse(bf, &clientctx.ClientContext{})
err := pkt.Parse(bf, &clientctx.ClientContext{RealClientMode: _config.ZZ})
if err != nil {
t.Fatalf("Parse() error = %v", err)
}
@@ -678,7 +676,7 @@ func TestMsgSysUnlockStageRoundTrip(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctx := &clientctx.ClientContext{}
ctx := &clientctx.ClientContext{RealClientMode: _config.ZZ}
// Build (returns NOT IMPLEMENTED)
original := &MsgSysUnlockStage{}
@@ -719,7 +717,7 @@ func TestMsgSysBackStageParse(t *testing.T) {
_, _ = bf.Seek(0, io.SeekStart)
pkt := &MsgSysBackStage{}
err := pkt.Parse(bf, &clientctx.ClientContext{})
err := pkt.Parse(bf, &clientctx.ClientContext{RealClientMode: _config.ZZ})
if err != nil {
t.Fatalf("Parse() error = %v", err)
}
@@ -749,7 +747,7 @@ func TestMsgSysLogoutParse(t *testing.T) {
_, _ = bf.Seek(0, io.SeekStart)
pkt := &MsgSysLogout{}
err := pkt.Parse(bf, &clientctx.ClientContext{})
err := pkt.Parse(bf, &clientctx.ClientContext{RealClientMode: _config.ZZ})
if err != nil {
t.Fatalf("Parse() error = %v", err)
}
@@ -803,7 +801,7 @@ func TestMsgSysLoginParse(t *testing.T) {
_, _ = bf.Seek(0, io.SeekStart)
pkt := &MsgSysLogin{}
err := pkt.Parse(bf, &clientctx.ClientContext{})
err := pkt.Parse(bf, &clientctx.ClientContext{RealClientMode: _config.ZZ})
if err != nil {
t.Fatalf("Parse() error = %v", err)
}