mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-22 15:43:49 +01:00
main.go always sets both Channels and Registry together, making the Channels fallback paths dead code. This removes: - Server.Channels field from the Server struct - 3 if/else fallback blocks in handlers_session.go (replaced with Registry.FindChannelForStage, SearchSessions, SearchStages) - 1 if/else fallback block in handlers_guild_ops.go (replaced with Registry.NotifyMailToCharID) - 3 method fallbacks in sys_channel_server.go (WorldcastMHF, FindSessionByCharID, DisconnectUser now delegate directly) Updates anti-patterns.md #6 to "accepted design" — Session struct is appropriate for this game server's handler pattern, and cross-channel coupling is now fully routed through the ChannelRegistry interface.
71 lines
1.7 KiB
Go
71 lines
1.7 KiB
Go
package channelserver
|
|
|
|
import (
|
|
"net"
|
|
|
|
"erupe-ce/common/byteframe"
|
|
cfg "erupe-ce/config"
|
|
"erupe-ce/network"
|
|
"erupe-ce/network/clientctx"
|
|
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
// mockPacket implements mhfpacket.MHFPacket for testing.
|
|
// Imported from v9.2.x-stable.
|
|
type mockPacket struct {
|
|
opcode uint16
|
|
}
|
|
|
|
func (m *mockPacket) Opcode() network.PacketID {
|
|
return network.PacketID(m.opcode)
|
|
}
|
|
|
|
func (m *mockPacket) Build(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error {
|
|
if ctx == nil {
|
|
panic("clientContext is nil")
|
|
}
|
|
bf.WriteUint32(0x12345678)
|
|
return nil
|
|
}
|
|
|
|
func (m *mockPacket) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error {
|
|
return nil
|
|
}
|
|
|
|
// createMockServer creates a minimal Server for testing.
|
|
// Imported from v9.2.x-stable and adapted for main.
|
|
func createMockServer() *Server {
|
|
logger, _ := zap.NewDevelopment()
|
|
s := &Server{
|
|
logger: logger,
|
|
erupeConfig: &cfg.Config{},
|
|
// stages is a StageMap (zero value is ready to use)
|
|
sessions: make(map[net.Conn]*Session),
|
|
handlerTable: buildHandlerTable(),
|
|
raviente: &Raviente{
|
|
register: make([]uint32, 30),
|
|
state: make([]uint32, 30),
|
|
support: make([]uint32, 30),
|
|
},
|
|
}
|
|
s.i18n = getLangStrings(s)
|
|
s.Registry = NewLocalChannelRegistry([]*Server{s})
|
|
return s
|
|
}
|
|
|
|
// createMockSession creates a minimal Session for testing.
|
|
// Imported from v9.2.x-stable and adapted for main.
|
|
func createMockSession(charID uint32, server *Server) *Session {
|
|
logger, _ := zap.NewDevelopment()
|
|
return &Session{
|
|
charID: charID,
|
|
clientContext: &clientctx.ClientContext{},
|
|
sendPackets: make(chan packet, 20),
|
|
Name: "TestPlayer",
|
|
server: server,
|
|
logger: logger,
|
|
semaphoreID: make([]uint16, 2),
|
|
}
|
|
}
|