mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-29 03:52:41 +02:00
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:
@@ -25,11 +25,11 @@ type ShopItem struct {
|
||||
RoadFatalis uint16 `db:"road_fatalis"`
|
||||
}
|
||||
|
||||
func writeShopItems(bf *byteframe.ByteFrame, items []ShopItem) {
|
||||
func writeShopItems(bf *byteframe.ByteFrame, items []ShopItem, mode _config.Mode) {
|
||||
bf.WriteUint16(uint16(len(items)))
|
||||
bf.WriteUint16(uint16(len(items)))
|
||||
for _, item := range items {
|
||||
if _config.ErupeConfig.RealClientMode >= _config.Z2 {
|
||||
if mode >= _config.Z2 {
|
||||
bf.WriteUint32(item.ID)
|
||||
}
|
||||
bf.WriteUint32(item.ItemID)
|
||||
@@ -37,19 +37,19 @@ func writeShopItems(bf *byteframe.ByteFrame, items []ShopItem) {
|
||||
bf.WriteUint16(item.Quantity)
|
||||
bf.WriteUint16(item.MinHR)
|
||||
bf.WriteUint16(item.MinSR)
|
||||
if _config.ErupeConfig.RealClientMode >= _config.Z2 {
|
||||
if mode >= _config.Z2 {
|
||||
bf.WriteUint16(item.MinGR)
|
||||
}
|
||||
bf.WriteUint8(0) // Unk
|
||||
bf.WriteUint8(item.StoreLevel)
|
||||
if _config.ErupeConfig.RealClientMode >= _config.Z2 {
|
||||
if mode >= _config.Z2 {
|
||||
bf.WriteUint16(item.MaxQuantity)
|
||||
bf.WriteUint16(item.UsedQuantity)
|
||||
}
|
||||
if _config.ErupeConfig.RealClientMode == _config.Z1 {
|
||||
if mode == _config.Z1 {
|
||||
bf.WriteUint8(uint8(item.RoadFloors))
|
||||
bf.WriteUint8(uint8(item.RoadFatalis))
|
||||
} else if _config.ErupeConfig.RealClientMode >= _config.Z2 {
|
||||
} else if mode >= _config.Z2 {
|
||||
bf.WriteUint16(item.RoadFloors)
|
||||
bf.WriteUint16(item.RoadFatalis)
|
||||
}
|
||||
@@ -90,7 +90,7 @@ func handleMsgMhfEnumerateShop(s *Session, p mhfpacket.MHFPacket) {
|
||||
switch pkt.ShopType {
|
||||
case 1: // Running gachas
|
||||
// Fundamentally, gacha works completely differently, just hide it for now.
|
||||
if _config.ErupeConfig.RealClientMode <= _config.G7 {
|
||||
if s.server.erupeConfig.RealClientMode <= _config.G7 {
|
||||
doAckBufSucceed(s, pkt.AckHandle, make([]byte, 4))
|
||||
return
|
||||
}
|
||||
@@ -123,7 +123,7 @@ func handleMsgMhfEnumerateShop(s *Session, p mhfpacket.MHFPacket) {
|
||||
ps.Uint8(bf, g.Name, true)
|
||||
ps.Uint8(bf, g.URLBanner, false)
|
||||
ps.Uint8(bf, g.URLFeature, false)
|
||||
if _config.ErupeConfig.RealClientMode >= _config.G10 {
|
||||
if s.server.erupeConfig.RealClientMode >= _config.G10 {
|
||||
bf.WriteBool(g.Wide)
|
||||
ps.Uint8(bf, g.URLThumbnail, false)
|
||||
}
|
||||
@@ -133,7 +133,7 @@ func handleMsgMhfEnumerateShop(s *Session, p mhfpacket.MHFPacket) {
|
||||
bf.WriteUint16(0)
|
||||
}
|
||||
bf.WriteUint8(g.GachaType)
|
||||
if _config.ErupeConfig.RealClientMode >= _config.G10 {
|
||||
if s.server.erupeConfig.RealClientMode >= _config.G10 {
|
||||
bf.WriteBool(g.Hidden)
|
||||
}
|
||||
}
|
||||
@@ -223,7 +223,7 @@ func handleMsgMhfEnumerateShop(s *Session, p mhfpacket.MHFPacket) {
|
||||
if len(items) > int(pkt.Limit) {
|
||||
items = items[:pkt.Limit]
|
||||
}
|
||||
writeShopItems(bf, items)
|
||||
writeShopItems(bf, items, s.server.erupeConfig.RealClientMode)
|
||||
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
|
||||
}
|
||||
}
|
||||
@@ -303,7 +303,7 @@ func handleMsgMhfGetFpointExchangeList(s *Session, p mhfpacket.MHFPacket) {
|
||||
exchanges = append(exchanges, exchange)
|
||||
}
|
||||
}
|
||||
if _config.ErupeConfig.RealClientMode <= _config.Z2 {
|
||||
if s.server.erupeConfig.RealClientMode <= _config.Z2 {
|
||||
bf.WriteUint8(uint8(len(exchanges)))
|
||||
bf.WriteUint8(uint8(buyables))
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user