refactor(channelserver): remove Channels fallbacks, use Registry as sole cross-channel API

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.
This commit is contained in:
Houmgaor
2026-02-22 16:16:44 +01:00
parent cd630a7a58
commit 53b5bb3b96
11 changed files with 113 additions and 252 deletions

View File

@@ -52,7 +52,7 @@ func (m *mockConn) WasClosed() bool {
// createTestServer creates a test server instance
func createTestServer() *Server {
logger, _ := zap.NewDevelopment()
return &Server{
s := &Server{
ID: 1,
logger: logger,
sessions: make(map[net.Conn]*Session),
@@ -71,6 +71,8 @@ func createTestServer() *Server {
support: make([]uint32, 30),
},
}
s.Registry = NewLocalChannelRegistry([]*Server{s})
return s
}
// createTestSessionForServer creates a session for a specific server
@@ -296,7 +298,7 @@ func TestBroadcastMHFAllSessions(t *testing.T) {
// TestFindSessionByCharID tests finding sessions by character ID
func TestFindSessionByCharID(t *testing.T) {
server := createTestServer()
server.Channels = []*Server{server} // Add itself as a channel
server.Registry = NewLocalChannelRegistry([]*Server{server})
// Create sessions with different char IDs
charIDs := []uint32{100, 200, 300}