mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-22 07:32:32 +01:00
refactor(config): rename package _config to config with cfg alias
The config package used `package _config` with a leading underscore, which is unconventional in Go. Rename to `package config` (matching the directory name) and use `cfg` as the standard import alias across all 93 importing files.
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"erupe-ce/config"
|
||||
cfg "erupe-ce/config"
|
||||
"erupe-ce/network"
|
||||
"github.com/jmoiron/sqlx"
|
||||
"go.uber.org/zap"
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
type Server struct {
|
||||
sync.Mutex
|
||||
logger *zap.Logger
|
||||
erupeConfig *_config.Config
|
||||
erupeConfig *cfg.Config
|
||||
db *sqlx.DB
|
||||
listener net.Listener
|
||||
isShuttingDown bool
|
||||
@@ -28,7 +28,7 @@ type Server struct {
|
||||
type Config struct {
|
||||
Logger *zap.Logger
|
||||
DB *sqlx.DB
|
||||
ErupeConfig *_config.Config
|
||||
ErupeConfig *cfg.Config
|
||||
}
|
||||
|
||||
// NewServer creates a new Server type.
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
_config "erupe-ce/config"
|
||||
cfg "erupe-ce/config"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
@@ -14,7 +14,7 @@ func TestNewServer(t *testing.T) {
|
||||
cfg := &Config{
|
||||
Logger: nil,
|
||||
DB: nil,
|
||||
ErupeConfig: &_config.Config{},
|
||||
ErupeConfig: &cfg.Config{},
|
||||
}
|
||||
|
||||
s := NewServer(cfg)
|
||||
@@ -67,7 +67,7 @@ func TestConfigFields(t *testing.T) {
|
||||
|
||||
func TestServerShutdownFlag(t *testing.T) {
|
||||
cfg := &Config{
|
||||
ErupeConfig: &_config.Config{},
|
||||
ErupeConfig: &cfg.Config{},
|
||||
}
|
||||
s := NewServer(cfg)
|
||||
|
||||
@@ -85,12 +85,12 @@ func TestServerShutdownFlag(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServerConfigStorage(t *testing.T) {
|
||||
erupeConfig := &_config.Config{
|
||||
erupeConfig := &cfg.Config{
|
||||
Host: "192.168.1.100",
|
||||
Entrance: _config.Entrance{
|
||||
Entrance: cfg.Entrance{
|
||||
Enabled: true,
|
||||
Port: 53310,
|
||||
Entries: []_config.EntranceServerInfo{
|
||||
Entries: []cfg.EntranceServerInfo{
|
||||
{
|
||||
Name: "Test Server",
|
||||
IP: "127.0.0.1",
|
||||
@@ -115,13 +115,13 @@ func TestServerConfigStorage(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServerEntranceEntries(t *testing.T) {
|
||||
entries := []_config.EntranceServerInfo{
|
||||
entries := []cfg.EntranceServerInfo{
|
||||
{
|
||||
Name: "World 1",
|
||||
IP: "10.0.0.1",
|
||||
Type: 1,
|
||||
Recommended: 1,
|
||||
Channels: []_config.EntranceChannelInfo{
|
||||
Channels: []cfg.EntranceChannelInfo{
|
||||
{Port: 54001, MaxPlayers: 100},
|
||||
{Port: 54002, MaxPlayers: 100},
|
||||
},
|
||||
@@ -131,14 +131,14 @@ func TestServerEntranceEntries(t *testing.T) {
|
||||
IP: "10.0.0.2",
|
||||
Type: 2,
|
||||
Recommended: 0,
|
||||
Channels: []_config.EntranceChannelInfo{
|
||||
Channels: []cfg.EntranceChannelInfo{
|
||||
{Port: 54003, MaxPlayers: 50},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
erupeConfig := &_config.Config{
|
||||
Entrance: _config.Entrance{
|
||||
erupeConfig := &cfg.Config{
|
||||
Entrance: cfg.Entrance{
|
||||
Enabled: true,
|
||||
Port: 53310,
|
||||
Entries: entries,
|
||||
@@ -274,7 +274,7 @@ func TestCalcSum32LargeInput(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServerMutexLocking(t *testing.T) {
|
||||
cfg := &Config{ErupeConfig: &_config.Config{}}
|
||||
cfg := &Config{ErupeConfig: &cfg.Config{}}
|
||||
s := NewServer(cfg)
|
||||
|
||||
s.Lock()
|
||||
@@ -292,8 +292,8 @@ func TestServerMutexLocking(t *testing.T) {
|
||||
|
||||
func TestServerStartAndShutdown(t *testing.T) {
|
||||
logger := zap.NewNop()
|
||||
erupeConfig := &_config.Config{
|
||||
Entrance: _config.Entrance{
|
||||
erupeConfig := &cfg.Config{
|
||||
Entrance: cfg.Entrance{
|
||||
Enabled: true,
|
||||
Port: 0,
|
||||
},
|
||||
@@ -331,8 +331,8 @@ func TestServerStartAndShutdown(t *testing.T) {
|
||||
|
||||
func TestServerStartWithInvalidPort(t *testing.T) {
|
||||
logger := zap.NewNop()
|
||||
erupeConfig := &_config.Config{
|
||||
Entrance: _config.Entrance{
|
||||
erupeConfig := &cfg.Config{
|
||||
Entrance: cfg.Entrance{
|
||||
Port: 1,
|
||||
},
|
||||
}
|
||||
@@ -352,8 +352,8 @@ func TestServerStartWithInvalidPort(t *testing.T) {
|
||||
|
||||
func TestServerListenerAddress(t *testing.T) {
|
||||
logger := zap.NewNop()
|
||||
erupeConfig := &_config.Config{
|
||||
Entrance: _config.Entrance{
|
||||
erupeConfig := &cfg.Config{
|
||||
Entrance: cfg.Entrance{
|
||||
Enabled: true,
|
||||
Port: 0,
|
||||
},
|
||||
@@ -388,8 +388,8 @@ func TestServerListenerAddress(t *testing.T) {
|
||||
|
||||
func TestServerAcceptClientsExitsOnShutdown(t *testing.T) {
|
||||
logger := zap.NewNop()
|
||||
erupeConfig := &_config.Config{
|
||||
Entrance: _config.Entrance{
|
||||
erupeConfig := &cfg.Config{
|
||||
Entrance: cfg.Entrance{
|
||||
Enabled: true,
|
||||
Port: 0,
|
||||
},
|
||||
@@ -421,8 +421,8 @@ func TestServerAcceptClientsExitsOnShutdown(t *testing.T) {
|
||||
|
||||
func TestServerHandleConnectionImmediateClose(t *testing.T) {
|
||||
logger := zap.NewNop()
|
||||
erupeConfig := &_config.Config{
|
||||
Entrance: _config.Entrance{
|
||||
erupeConfig := &cfg.Config{
|
||||
Entrance: cfg.Entrance{
|
||||
Enabled: true,
|
||||
Port: 0,
|
||||
},
|
||||
@@ -452,8 +452,8 @@ func TestServerHandleConnectionImmediateClose(t *testing.T) {
|
||||
|
||||
func TestServerHandleConnectionShortInit(t *testing.T) {
|
||||
logger := zap.NewNop()
|
||||
erupeConfig := &_config.Config{
|
||||
Entrance: _config.Entrance{
|
||||
erupeConfig := &cfg.Config{
|
||||
Entrance: cfg.Entrance{
|
||||
Enabled: true,
|
||||
Port: 0,
|
||||
},
|
||||
@@ -484,8 +484,8 @@ func TestServerHandleConnectionShortInit(t *testing.T) {
|
||||
|
||||
func TestServerMultipleConnections(t *testing.T) {
|
||||
logger := zap.NewNop()
|
||||
erupeConfig := &_config.Config{
|
||||
Entrance: _config.Entrance{
|
||||
erupeConfig := &cfg.Config{
|
||||
Entrance: cfg.Entrance{
|
||||
Enabled: true,
|
||||
Port: 0,
|
||||
},
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"erupe-ce/common/stringsupport"
|
||||
_config "erupe-ce/config"
|
||||
cfg "erupe-ce/config"
|
||||
"net"
|
||||
|
||||
"erupe-ce/common/byteframe"
|
||||
@@ -12,18 +12,18 @@ import (
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func encodeServerInfo(config *_config.Config, s *Server, local bool) []byte {
|
||||
func encodeServerInfo(config *cfg.Config, s *Server, local bool) []byte {
|
||||
serverInfos := config.Entrance.Entries
|
||||
bf := byteframe.NewByteFrame()
|
||||
|
||||
for serverIdx, si := range serverInfos {
|
||||
// Prevent MezFes Worlds displaying on Z1
|
||||
if config.RealClientMode <= _config.Z1 {
|
||||
if config.RealClientMode <= cfg.Z1 {
|
||||
if si.Type == 6 {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if config.RealClientMode <= _config.G6 {
|
||||
if config.RealClientMode <= cfg.G6 {
|
||||
if si.Type == 5 {
|
||||
continue
|
||||
}
|
||||
@@ -42,22 +42,22 @@ func encodeServerInfo(config *_config.Config, s *Server, local bool) []byte {
|
||||
bf.WriteUint16(uint16(len(si.Channels)))
|
||||
bf.WriteUint8(si.Type)
|
||||
bf.WriteUint8(uint8(((gametime.Adjusted().Unix() / 86400) + int64(serverIdx)) % 3))
|
||||
if s.erupeConfig.RealClientMode >= _config.G1 {
|
||||
if s.erupeConfig.RealClientMode >= cfg.G1 {
|
||||
bf.WriteUint8(si.Recommended)
|
||||
}
|
||||
|
||||
fullName := append(append(stringsupport.UTF8ToSJIS(si.Name), []byte{0x00}...), stringsupport.UTF8ToSJIS(si.Description)...)
|
||||
if s.erupeConfig.RealClientMode >= _config.G1 && s.erupeConfig.RealClientMode <= _config.G5 {
|
||||
if s.erupeConfig.RealClientMode >= cfg.G1 && s.erupeConfig.RealClientMode <= cfg.G5 {
|
||||
bf.WriteUint8(uint8(len(fullName)))
|
||||
bf.WriteBytes(fullName)
|
||||
} else {
|
||||
if s.erupeConfig.RealClientMode >= _config.G51 {
|
||||
if s.erupeConfig.RealClientMode >= cfg.G51 {
|
||||
bf.WriteUint8(0) // Ignored
|
||||
}
|
||||
bf.WriteBytes(stringsupport.PaddedString(string(fullName), 65, false))
|
||||
}
|
||||
|
||||
if s.erupeConfig.RealClientMode >= _config.GG {
|
||||
if s.erupeConfig.RealClientMode >= cfg.GG {
|
||||
bf.WriteUint32(si.AllowedClientFlags)
|
||||
}
|
||||
|
||||
@@ -119,11 +119,11 @@ func makeHeader(data []byte, respType string, entryCount uint16, key byte) []byt
|
||||
return bf.Data()
|
||||
}
|
||||
|
||||
func makeSv2Resp(config *_config.Config, s *Server, local bool) []byte {
|
||||
func makeSv2Resp(config *cfg.Config, s *Server, local bool) []byte {
|
||||
serverInfos := config.Entrance.Entries
|
||||
// Decrease by the number of MezFes Worlds
|
||||
var mf int
|
||||
if config.RealClientMode <= _config.Z1 {
|
||||
if config.RealClientMode <= cfg.Z1 {
|
||||
for _, si := range serverInfos {
|
||||
if si.Type == 6 {
|
||||
mf++
|
||||
@@ -132,7 +132,7 @@ func makeSv2Resp(config *_config.Config, s *Server, local bool) []byte {
|
||||
}
|
||||
// and Return Worlds
|
||||
var ret int
|
||||
if config.RealClientMode <= _config.G6 {
|
||||
if config.RealClientMode <= cfg.G6 {
|
||||
for _, si := range serverInfos {
|
||||
if si.Type == 5 {
|
||||
ret++
|
||||
@@ -146,7 +146,7 @@ func makeSv2Resp(config *_config.Config, s *Server, local bool) []byte {
|
||||
}
|
||||
|
||||
respType := "SV2"
|
||||
if config.RealClientMode <= _config.G32 {
|
||||
if config.RealClientMode <= cfg.G32 {
|
||||
respType = "SVR"
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
_config "erupe-ce/config"
|
||||
cfg "erupe-ce/config"
|
||||
)
|
||||
|
||||
// TestEncodeServerInfo_EmptyClanMemberLimits verifies the crash is FIXED when ClanMemberLimits is empty
|
||||
@@ -15,13 +15,13 @@ import (
|
||||
// From erupe.log.1:659922
|
||||
// After fix: Should handle empty array gracefully with default value (60)
|
||||
func TestEncodeServerInfo_EmptyClanMemberLimits(t *testing.T) {
|
||||
config := &_config.Config{
|
||||
RealClientMode: _config.Z1,
|
||||
config := &cfg.Config{
|
||||
RealClientMode: cfg.Z1,
|
||||
Host: "127.0.0.1",
|
||||
Entrance: _config.Entrance{
|
||||
Entrance: cfg.Entrance{
|
||||
Enabled: true,
|
||||
Port: 53310,
|
||||
Entries: []_config.EntranceServerInfo{
|
||||
Entries: []cfg.EntranceServerInfo{
|
||||
{
|
||||
Name: "TestServer",
|
||||
Description: "Test",
|
||||
@@ -29,7 +29,7 @@ func TestEncodeServerInfo_EmptyClanMemberLimits(t *testing.T) {
|
||||
Type: 0,
|
||||
Recommended: 0,
|
||||
AllowedClientFlags: 0xFFFFFFFF,
|
||||
Channels: []_config.EntranceChannelInfo{
|
||||
Channels: []cfg.EntranceChannelInfo{
|
||||
{
|
||||
Port: 54001,
|
||||
MaxPlayers: 100,
|
||||
@@ -38,7 +38,7 @@ func TestEncodeServerInfo_EmptyClanMemberLimits(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
GameplayOptions: _config.GameplayOptions{
|
||||
GameplayOptions: cfg.GameplayOptions{
|
||||
ClanMemberLimits: [][]uint8{}, // Empty array - should now use default (60) instead of panicking
|
||||
},
|
||||
}
|
||||
@@ -117,13 +117,13 @@ func TestClanMemberLimitsBoundsChecking(t *testing.T) {
|
||||
// Previously panicked: runtime error: index out of range [1]
|
||||
// After fix: Should handle missing column gracefully with default value (60)
|
||||
func TestEncodeServerInfo_MissingSecondColumnClanMemberLimits(t *testing.T) {
|
||||
config := &_config.Config{
|
||||
RealClientMode: _config.Z1,
|
||||
config := &cfg.Config{
|
||||
RealClientMode: cfg.Z1,
|
||||
Host: "127.0.0.1",
|
||||
Entrance: _config.Entrance{
|
||||
Entrance: cfg.Entrance{
|
||||
Enabled: true,
|
||||
Port: 53310,
|
||||
Entries: []_config.EntranceServerInfo{
|
||||
Entries: []cfg.EntranceServerInfo{
|
||||
{
|
||||
Name: "TestServer",
|
||||
Description: "Test",
|
||||
@@ -131,7 +131,7 @@ func TestEncodeServerInfo_MissingSecondColumnClanMemberLimits(t *testing.T) {
|
||||
Type: 0,
|
||||
Recommended: 0,
|
||||
AllowedClientFlags: 0xFFFFFFFF,
|
||||
Channels: []_config.EntranceChannelInfo{
|
||||
Channels: []cfg.EntranceChannelInfo{
|
||||
{
|
||||
Port: 54001,
|
||||
MaxPlayers: 100,
|
||||
@@ -140,7 +140,7 @@ func TestEncodeServerInfo_MissingSecondColumnClanMemberLimits(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
GameplayOptions: _config.GameplayOptions{
|
||||
GameplayOptions: cfg.GameplayOptions{
|
||||
ClanMemberLimits: [][]uint8{
|
||||
{1}, // Only 1 element, code used to panic accessing [1]
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user