fix(guild): add nil guards for alliance guild lookups (#171)

scanAllianceWithGuilds dereferences guild pointers returned by GetByID
without checking for nil. Since GetByID returns (nil, nil) when a guild
is missing, alliances referencing deleted guilds cause nil-pointer
panics. The panic is caught by session recovery but no ACK is sent,
softlocking the client.

Add nil checks in scanAllianceWithGuilds, handleMsgMhfOperateJoint,
handleMsgMhfInfoJoint, and handleMsgMhfInfoGuild so that missing
guilds or alliances produce proper error responses instead of panics.
This commit is contained in:
Houmgaor
2026-03-02 19:43:11 +01:00
parent 07a587213d
commit aee53534a2
4 changed files with 127 additions and 41 deletions

View File

@@ -438,3 +438,70 @@ func TestInfoJoint_NotFound(t *testing.T) {
t.Error("No response packet queued")
}
}
func TestInfoJoint_NilAlliance(t *testing.T) {
server := createMockServer()
// alliance is nil, no error — simulates deleted alliance
guildMock := &mockGuildRepo{}
server.guildRepo = guildMock
session := createMockSession(1, server)
pkt := &mhfpacket.MsgMhfInfoJoint{AckHandle: 100, AllianceID: 999}
handleMsgMhfInfoJoint(session, pkt)
select {
case <-session.sendPackets:
default:
t.Error("No response packet queued — would softlock the client")
}
}
func TestOperateJoint_NilGuild(t *testing.T) {
server := createMockServer()
// guild is nil — simulates deleted guild
guildMock := &mockGuildRepo{
alliance: &GuildAlliance{ID: 5, ParentGuildID: 10},
}
server.guildRepo = guildMock
session := createMockSession(1, server)
pkt := &mhfpacket.MsgMhfOperateJoint{
AckHandle: 100,
AllianceID: 5,
GuildID: 10,
Action: mhfpacket.OPERATE_JOINT_DISBAND,
}
handleMsgMhfOperateJoint(session, pkt)
select {
case <-session.sendPackets:
default:
t.Error("No response packet queued — would softlock the client")
}
}
func TestOperateJoint_NilAlliance(t *testing.T) {
server := createMockServer()
guildMock := &mockGuildRepo{}
guildMock.guild = &Guild{ID: 10}
guildMock.guild.LeaderCharID = 1
server.guildRepo = guildMock
session := createMockSession(1, server)
pkt := &mhfpacket.MsgMhfOperateJoint{
AckHandle: 100,
AllianceID: 999,
GuildID: 10,
Action: mhfpacket.OPERATE_JOINT_DISBAND,
}
handleMsgMhfOperateJoint(session, pkt)
select {
case <-session.sendPackets:
default:
t.Error("No response packet queued — would softlock the client")
}
}