diff --git a/cmd/protbot/conn/conn.go b/cmd/protbot/conn/conn.go index b7ad33173..e247ae821 100644 --- a/cmd/protbot/conn/conn.go +++ b/cmd/protbot/conn/conn.go @@ -22,7 +22,7 @@ func DialWithInit(addr string) (*MHFConn, error) { // Sign and entrance servers expect 8 NULL bytes to initialize the connection. _, err = conn.Write(make([]byte, 8)) if err != nil { - conn.Close() + _ = conn.Close() return nil, fmt.Errorf("write init bytes to %s: %w", addr, err) } diff --git a/cmd/protbot/conn/crypt_conn_test.go b/cmd/protbot/conn/crypt_conn_test.go index cb03004db..3c598e919 100644 --- a/cmd/protbot/conn/crypt_conn_test.go +++ b/cmd/protbot/conn/crypt_conn_test.go @@ -11,8 +11,8 @@ import ( func TestCryptConnRoundTrip(t *testing.T) { // Create an in-process TCP pipe. server, client := net.Pipe() - defer server.Close() - defer client.Close() + defer func() { _ = server.Close() }() + defer func() { _ = client.Close() }() sender := NewCryptConn(client) receiver := NewCryptConn(server) @@ -86,8 +86,8 @@ func TestCryptPacketHeaderRoundTrip(t *testing.T) { // multiple sequential packets. func TestMultiPacketSequence(t *testing.T) { server, client := net.Pipe() - defer server.Close() - defer client.Close() + defer func() { _ = server.Close() }() + defer func() { _ = client.Close() }() sender := NewCryptConn(client) receiver := NewCryptConn(server) @@ -123,7 +123,7 @@ func TestDialWithInit(t *testing.T) { if err != nil { t.Fatal(err) } - defer listener.Close() + defer func() { _ = listener.Close() }() done := make(chan []byte, 1) go func() { @@ -131,7 +131,7 @@ func TestDialWithInit(t *testing.T) { if err != nil { return } - defer conn.Close() + defer func() { _ = conn.Close() }() buf := make([]byte, 8) _, _ = io.ReadFull(conn, buf) done <- buf @@ -141,7 +141,7 @@ func TestDialWithInit(t *testing.T) { if err != nil { t.Fatal(err) } - defer c.Close() + defer func() { _ = c.Close() }() initBytes := <-done for i, b := range initBytes { diff --git a/cmd/protbot/main.go b/cmd/protbot/main.go index 4b1e0f72b..5d658269b 100644 --- a/cmd/protbot/main.go +++ b/cmd/protbot/main.go @@ -41,7 +41,7 @@ func main() { os.Exit(1) } fmt.Println("[done] Login successful!") - result.Channel.Close() + _ = result.Channel.Close() case "lobby": result, err := scenario.Login(*signAddr, *user, *pass) @@ -51,11 +51,11 @@ func main() { } if err := scenario.EnterLobby(result.Channel); err != nil { fmt.Fprintf(os.Stderr, "enter lobby failed: %v\n", err) - result.Channel.Close() + _ = result.Channel.Close() os.Exit(1) } fmt.Println("[done] Lobby entry successful!") - result.Channel.Close() + _ = result.Channel.Close() case "session": result, err := scenario.Login(*signAddr, *user, *pass) @@ -66,17 +66,17 @@ func main() { charID := result.Sign.CharIDs[0] if _, err := scenario.SetupSession(result.Channel, charID); err != nil { fmt.Fprintf(os.Stderr, "session setup failed: %v\n", err) - result.Channel.Close() + _ = result.Channel.Close() os.Exit(1) } if err := scenario.EnterLobby(result.Channel); err != nil { fmt.Fprintf(os.Stderr, "enter lobby failed: %v\n", err) - result.Channel.Close() + _ = result.Channel.Close() os.Exit(1) } fmt.Println("[session] Connected. Press Ctrl+C to disconnect.") waitForSignal() - scenario.Logout(result.Channel) + _ = scenario.Logout(result.Channel) case "chat": result, err := scenario.Login(*signAddr, *user, *pass) @@ -87,12 +87,12 @@ func main() { charID := result.Sign.CharIDs[0] if _, err := scenario.SetupSession(result.Channel, charID); err != nil { fmt.Fprintf(os.Stderr, "session setup failed: %v\n", err) - result.Channel.Close() + _ = result.Channel.Close() os.Exit(1) } if err := scenario.EnterLobby(result.Channel); err != nil { fmt.Fprintf(os.Stderr, "enter lobby failed: %v\n", err) - result.Channel.Close() + _ = result.Channel.Close() os.Exit(1) } @@ -110,7 +110,7 @@ func main() { fmt.Println("[chat] Listening for chat messages. Press Ctrl+C to disconnect.") waitForSignal() - scenario.Logout(result.Channel) + _ = scenario.Logout(result.Channel) case "quests": result, err := scenario.Login(*signAddr, *user, *pass) @@ -121,23 +121,23 @@ func main() { charID := result.Sign.CharIDs[0] if _, err := scenario.SetupSession(result.Channel, charID); err != nil { fmt.Fprintf(os.Stderr, "session setup failed: %v\n", err) - result.Channel.Close() + _ = result.Channel.Close() os.Exit(1) } if err := scenario.EnterLobby(result.Channel); err != nil { fmt.Fprintf(os.Stderr, "enter lobby failed: %v\n", err) - result.Channel.Close() + _ = result.Channel.Close() os.Exit(1) } data, err := scenario.EnumerateQuests(result.Channel, 0, 0) if err != nil { fmt.Fprintf(os.Stderr, "enumerate quests failed: %v\n", err) - scenario.Logout(result.Channel) + _ = scenario.Logout(result.Channel) os.Exit(1) } fmt.Printf("[quests] Received %d bytes of quest data\n", len(data)) - scenario.Logout(result.Channel) + _ = scenario.Logout(result.Channel) default: fmt.Fprintf(os.Stderr, "unknown action: %s (supported: login, lobby, session, chat, quests)\n", *action) diff --git a/cmd/protbot/protocol/entrance.go b/cmd/protbot/protocol/entrance.go index d7c516a3f..1931a790e 100644 --- a/cmd/protbot/protocol/entrance.go +++ b/cmd/protbot/protocol/entrance.go @@ -24,7 +24,7 @@ func DoEntrance(addr string) ([]ServerEntry, error) { if err != nil { return nil, fmt.Errorf("entrance connect: %w", err) } - defer c.Close() + defer func() { _ = c.Close() }() // Send a minimal packet (the entrance server reads it, checks len > 5 for USR data). // An empty/short packet triggers only SV2 response. diff --git a/cmd/protbot/protocol/sign.go b/cmd/protbot/protocol/sign.go index 4f6670b6f..5ebd99b88 100644 --- a/cmd/protbot/protocol/sign.go +++ b/cmd/protbot/protocol/sign.go @@ -25,7 +25,7 @@ func DoSign(addr, username, password string) (*SignResult, error) { if err != nil { return nil, fmt.Errorf("sign connect: %w", err) } - defer c.Close() + defer func() { _ = c.Close() }() // Build DSGN request: "DSGN:041" + \x00 + SJIS(user) + \x00 + SJIS(pass) + \x00 + \x00 // The server reads: null-terminated request type, null-terminated user, null-terminated pass, null-terminated unk. diff --git a/cmd/protbot/scenario/login.go b/cmd/protbot/scenario/login.go index a90941ef0..12b620eb4 100644 --- a/cmd/protbot/scenario/login.go +++ b/cmd/protbot/scenario/login.go @@ -58,17 +58,17 @@ func Login(signAddr, username, password string) (*LoginResult, error) { loginPkt := protocol.BuildLoginPacket(ack, charID, sign.TokenID, sign.TokenString) fmt.Printf("[channel] Sending MSG_SYS_LOGIN (charID=%d, ackHandle=%d)...\n", charID, ack) if err := ch.SendPacket(loginPkt); err != nil { - ch.Close() + _ = ch.Close() return nil, fmt.Errorf("channel send login: %w", err) } resp, err := ch.WaitForAck(ack, 10*time.Second) if err != nil { - ch.Close() + _ = ch.Close() return nil, fmt.Errorf("channel login ack: %w", err) } if resp.ErrorCode != 0 { - ch.Close() + _ = ch.Close() return nil, fmt.Errorf("channel login failed: error code %d", resp.ErrorCode) } fmt.Printf("[channel] Login ACK received (error=%d, %d bytes data)\n", diff --git a/cmd/protbot/scenario/logout.go b/cmd/protbot/scenario/logout.go index 692c97dda..67ed42316 100644 --- a/cmd/protbot/scenario/logout.go +++ b/cmd/protbot/scenario/logout.go @@ -10,7 +10,7 @@ import ( func Logout(ch *protocol.ChannelConn) error { fmt.Println("[logout] Sending MSG_SYS_LOGOUT...") if err := ch.SendPacket(protocol.BuildLogoutPacket()); err != nil { - ch.Close() + _ = ch.Close() return fmt.Errorf("logout send: %w", err) } return ch.Close() diff --git a/server/channelserver/channel_isolation_test.go b/server/channelserver/channel_isolation_test.go index 158fca9a3..c1db3cc01 100644 --- a/server/channelserver/channel_isolation_test.go +++ b/server/channelserver/channel_isolation_test.go @@ -59,7 +59,7 @@ func TestChannelIsolation_ShutdownDoesNotAffectOthers(t *testing.T) { if err != nil { t.Fatalf("initial connection to %s failed: %v", addr, err) } - conn.Close() + _ = conn.Close() } // Shut down channel 1. @@ -84,7 +84,7 @@ func TestChannelIsolation_ShutdownDoesNotAffectOthers(t *testing.T) { if err != nil { t.Errorf("%s should still accept connections after channel 1 shutdown, got: %v", tc.name, err) } else { - conn.Close() + _ = conn.Close() } } } @@ -99,7 +99,7 @@ func TestChannelIsolation_ListenerCloseDoesNotAffectOthers(t *testing.T) { addr2 := listenerAddr(ch2) // Forcibly close channel 1's listener (simulating unexpected failure). - ch1.listener.Close() + _ = ch1.listener.Close() time.Sleep(50 * time.Millisecond) // Channel 2 must still work. @@ -107,7 +107,7 @@ func TestChannelIsolation_ListenerCloseDoesNotAffectOthers(t *testing.T) { if err != nil { t.Fatalf("channel 2 should still accept connections after channel 1 listener closed: %v", err) } - conn.Close() + _ = conn.Close() } // TestChannelIsolation_SessionPanicDoesNotAffectChannel verifies that a panic @@ -124,9 +124,9 @@ func TestChannelIsolation_SessionPanicDoesNotAffectChannel(t *testing.T) { // Send garbage data that will cause handlePacketGroup to hit the panic recovery. // The session's defer/recover should catch it without killing the channel. - conn1.Write([]byte{0xFF, 0xFF, 0xFF, 0xFF}) + _, _ = conn1.Write([]byte{0xFF, 0xFF, 0xFF, 0xFF}) time.Sleep(100 * time.Millisecond) - conn1.Close() + _ = conn1.Close() time.Sleep(100 * time.Millisecond) // The channel should still accept new connections after the panic. @@ -134,7 +134,7 @@ func TestChannelIsolation_SessionPanicDoesNotAffectChannel(t *testing.T) { if err != nil { t.Fatalf("channel should still accept connections after session panic: %v", err) } - conn2.Close() + _ = conn2.Close() } // TestChannelIsolation_CrossChannelRegistryAfterShutdown verifies that the