diff --git a/gpsp/error.go b/gpsp/error.go index 0410e42..fc06450 100644 --- a/gpsp/error.go +++ b/gpsp/error.go @@ -6,11 +6,15 @@ import ( "wwfc/logging" ) -func replyError(moduleName string, connIndex uint64, err gpcm.GPError) { - logging.Error(moduleName, "Reply error:", err.ErrorString) - msg := err.GetMessage() - common.SendPacket(ServerName, connIndex, []byte(msg)) - if err.Fatal { - common.CloseConnection(ServerName, connIndex) +func replyError(moduleName string, connIndex uint64, gpErr gpcm.GPError) { + logging.Error(moduleName, "Reply error:", gpErr.ErrorString) + err := common.SendPacket(ServerName, connIndex, []byte(gpErr.GetMessage())) + if gpErr.Fatal || err != nil { + if err != nil { + logging.Error(moduleName, "Failed to send error message:", err) + } + if err := common.CloseConnection(ServerName, connIndex); err != nil { + logging.Error(moduleName, "Failed to close connection:", err) + } } } diff --git a/gpsp/main.go b/gpsp/main.go index 03de34a..896a5b4 100644 --- a/gpsp/main.go +++ b/gpsp/main.go @@ -45,13 +45,16 @@ func HandlePacket(index uint64, data []byte) { replyError(moduleName, index, gpcm.ErrParse) case "ka": - common.SendPacket(ServerName, index, []byte(`\ka\\final\`)) + err = common.SendPacket(ServerName, index, []byte(`\ka\\final\`)) case "otherslist": - common.SendPacket(ServerName, index, []byte(handleOthersList(command))) + err = common.SendPacket(ServerName, index, []byte(handleOthersList(command))) case "search": - common.SendPacket(ServerName, index, []byte(handleSearch(command))) + err = common.SendPacket(ServerName, index, []byte(handleSearch(command))) } } + if err != nil { + logging.Error(moduleName, "Failed to send packet:", err) + } }