mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-22 15:43:49 +01:00
refactor: replace panic calls with structured error handling
Replace ~25 panic() calls in non-fatal code paths with proper s.logger.Error + return patterns. Panics in handler code crashed goroutines (caught by defer/recover but still disruptive) instead of failing gracefully. Key changes: - SJISToUTF8 now returns (string, error); all 30+ callers updated - Handler DB/IO panics replaced with log + return/ack fail - Unhandled switch-case panics replaced with logger.Error - Sign server Accept() panic replaced with log + continue - Dead unreachable panic in guild_model.go removed - deltacomp patch error logs and returns partial data Panics intentionally kept: ByteFrame sentinel, unimplemented packet stubs, os.Exit in main.go.
This commit is contained in:
@@ -40,8 +40,8 @@ func (m *MsgBinChat) Parse(bf *byteframe.ByteFrame) error {
|
||||
m.Flags = bf.ReadUint16()
|
||||
_ = bf.ReadUint16() // lenSenderName
|
||||
_ = bf.ReadUint16() // lenMessage
|
||||
m.Message = stringsupport.SJISToUTF8(bf.ReadNullTerminatedBytes())
|
||||
m.SenderName = stringsupport.SJISToUTF8(bf.ReadNullTerminatedBytes())
|
||||
m.Message, _ = stringsupport.SJISToUTF8(bf.ReadNullTerminatedBytes())
|
||||
m.SenderName, _ = stringsupport.SJISToUTF8(bf.ReadNullTerminatedBytes())
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -30,9 +30,9 @@ func (m *MsgMhfApplyBbsArticle) Parse(bf *byteframe.ByteFrame, ctx *clientctx.Cl
|
||||
m.AckHandle = bf.ReadUint32()
|
||||
m.Unk0 = bf.ReadUint32()
|
||||
m.Unk1 = bf.ReadBytes(16)
|
||||
m.Name = stringsupport.SJISToUTF8(bfutil.UpToNull(bf.ReadBytes(32)))
|
||||
m.Title = stringsupport.SJISToUTF8(bfutil.UpToNull(bf.ReadBytes(128)))
|
||||
m.Description = stringsupport.SJISToUTF8(bfutil.UpToNull(bf.ReadBytes(256)))
|
||||
m.Name, _ = stringsupport.SJISToUTF8(bfutil.UpToNull(bf.ReadBytes(32)))
|
||||
m.Title, _ = stringsupport.SJISToUTF8(bfutil.UpToNull(bf.ReadBytes(128)))
|
||||
m.Description, _ = stringsupport.SJISToUTF8(bfutil.UpToNull(bf.ReadBytes(256)))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ func (m *MsgMhfCreateGuild) Parse(bf *byteframe.ByteFrame, ctx *clientctx.Client
|
||||
m.AckHandle = bf.ReadUint32()
|
||||
bf.ReadUint16() // Zeroed
|
||||
bf.ReadUint16() // Name length
|
||||
m.Name = stringsupport.SJISToUTF8(bf.ReadNullTerminatedBytes())
|
||||
m.Name, _ = stringsupport.SJISToUTF8(bf.ReadNullTerminatedBytes())
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ func (m *MsgMhfCreateJoint) Parse(bf *byteframe.ByteFrame, ctx *clientctx.Client
|
||||
m.GuildID = bf.ReadUint32()
|
||||
bf.ReadUint16() // Zeroed
|
||||
bf.ReadUint16() // Name length
|
||||
m.Name = stringsupport.SJISToUTF8(bf.ReadNullTerminatedBytes())
|
||||
m.Name, _ = stringsupport.SJISToUTF8(bf.ReadNullTerminatedBytes())
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ func (m *MsgMhfEnumerateHouse) Parse(bf *byteframe.ByteFrame, ctx *clientctx.Cli
|
||||
bf.ReadUint16() // Zeroed
|
||||
lenName := bf.ReadUint8()
|
||||
if lenName > 0 {
|
||||
m.Name = stringsupport.SJISToUTF8(bf.ReadNullTerminatedBytes())
|
||||
m.Name, _ = stringsupport.SJISToUTF8(bf.ReadNullTerminatedBytes())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ func (m *MsgMhfLoadHouse) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientCo
|
||||
m.CheckPass = bf.ReadBool()
|
||||
bf.ReadUint16() // Zeroed
|
||||
bf.ReadUint8() // Password length
|
||||
m.Password = stringsupport.SJISToUTF8(bf.ReadNullTerminatedBytes())
|
||||
m.Password, _ = stringsupport.SJISToUTF8(bf.ReadNullTerminatedBytes())
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ func (m *MsgMhfOperateWarehouse) Parse(bf *byteframe.ByteFrame, ctx *clientctx.C
|
||||
lenName := bf.ReadUint8()
|
||||
bf.ReadUint16() // Zeroed
|
||||
if lenName > 0 {
|
||||
m.Name = stringsupport.SJISToUTF8(bf.ReadNullTerminatedBytes())
|
||||
m.Name, _ = stringsupport.SJISToUTF8(bf.ReadNullTerminatedBytes())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -35,8 +35,8 @@ func (m *MsgMhfSendMail) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientCon
|
||||
bf.ReadUint16() // Zeroed
|
||||
m.Quantity = bf.ReadUint16()
|
||||
m.ItemID = bf.ReadUint16()
|
||||
m.Subject = stringsupport.SJISToUTF8(bf.ReadNullTerminatedBytes())
|
||||
m.Body = stringsupport.SJISToUTF8(bf.ReadNullTerminatedBytes())
|
||||
m.Subject, _ = stringsupport.SJISToUTF8(bf.ReadNullTerminatedBytes())
|
||||
m.Body, _ = stringsupport.SJISToUTF8(bf.ReadNullTerminatedBytes())
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -38,8 +38,8 @@ func (m *MsgMhfUpdateGuildMessageBoard) Parse(bf *byteframe.ByteFrame, ctx *clie
|
||||
m.StampID = bf.ReadUint32()
|
||||
m.TitleLength = bf.ReadUint32()
|
||||
m.BodyLength = bf.ReadUint32()
|
||||
m.Title = stringsupport.SJISToUTF8(bf.ReadBytes(uint(m.TitleLength)))
|
||||
m.Body = stringsupport.SJISToUTF8(bf.ReadBytes(uint(m.BodyLength)))
|
||||
m.Title, _ = stringsupport.SJISToUTF8(bf.ReadBytes(uint(m.TitleLength)))
|
||||
m.Body, _ = stringsupport.SJISToUTF8(bf.ReadBytes(uint(m.BodyLength)))
|
||||
case 1:
|
||||
m.PostID = bf.ReadUint32()
|
||||
case 2:
|
||||
@@ -47,8 +47,8 @@ func (m *MsgMhfUpdateGuildMessageBoard) Parse(bf *byteframe.ByteFrame, ctx *clie
|
||||
bf.ReadBytes(8)
|
||||
m.TitleLength = bf.ReadUint32()
|
||||
m.BodyLength = bf.ReadUint32()
|
||||
m.Title = stringsupport.SJISToUTF8(bf.ReadBytes(uint(m.TitleLength)))
|
||||
m.Body = stringsupport.SJISToUTF8(bf.ReadBytes(uint(m.BodyLength)))
|
||||
m.Title, _ = stringsupport.SJISToUTF8(bf.ReadBytes(uint(m.TitleLength)))
|
||||
m.Body, _ = stringsupport.SJISToUTF8(bf.ReadBytes(uint(m.BodyLength)))
|
||||
case 3:
|
||||
m.PostID = bf.ReadUint32()
|
||||
bf.ReadBytes(8)
|
||||
|
||||
@@ -30,7 +30,7 @@ func (m *MsgMhfUpdateHouse) Parse(bf *byteframe.ByteFrame, ctx *clientctx.Client
|
||||
bf.ReadUint8() // Zeroed
|
||||
bf.ReadUint8() // Zeroed
|
||||
bf.ReadUint8() // Password length
|
||||
m.Password = stringsupport.SJISToUTF8(bf.ReadNullTerminatedBytes())
|
||||
m.Password, _ = stringsupport.SJISToUTF8(bf.ReadNullTerminatedBytes())
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user