mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-21 23:22:34 +01:00
style: check error returns flagged by errcheck linter
golangci-lint's errcheck rule requires explicit handling of error return values from Close, Write, and Logout calls. Use blank identifier assignment for cleanup paths where errors are intentionally discarded.
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user