From 665c2dd32fc7b5f9f5c912132064f9fce2e61e00 Mon Sep 17 00:00:00 2001 From: wish Date: Sat, 1 Oct 2022 00:10:00 +1000 Subject: [PATCH] handle alliance kicking --- network/mhfpacket/msg_mhf_operate_joint.go | 36 +++++++++---------- .../channelserver/handlers_guild_alliance.go | 20 +++++++++++ 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/network/mhfpacket/msg_mhf_operate_joint.go b/network/mhfpacket/msg_mhf_operate_joint.go index 9733a2278..1fa360d01 100644 --- a/network/mhfpacket/msg_mhf_operate_joint.go +++ b/network/mhfpacket/msg_mhf_operate_joint.go @@ -1,28 +1,28 @@ package mhfpacket import ( - "errors" + "errors" - "erupe-ce/network/clientctx" - "erupe-ce/network" "erupe-ce/common/byteframe" + "erupe-ce/network" + "erupe-ce/network/clientctx" ) type OperateJointAction uint8 const ( - OPERATE_JOINT_DISBAND = 0x01 - OPERATE_JOINT_LEAVE = 0x03 - OPERATE_JOINT_KICK = 0x09 + OPERATE_JOINT_DISBAND = 0x01 + OPERATE_JOINT_LEAVE = 0x03 + OPERATE_JOINT_KICK = 0x09 ) // MsgMhfOperateJoint represents the MSG_MHF_OPERATE_JOINT type MsgMhfOperateJoint struct { - AckHandle uint32 - AllianceID uint32 - GuildID uint32 - Action OperateJointAction - UnkData []byte + AckHandle uint32 + AllianceID uint32 + GuildID uint32 + Action OperateJointAction + UnkData *byteframe.ByteFrame } // Opcode returns the ID associated with this packet type. @@ -32,13 +32,13 @@ func (m *MsgMhfOperateJoint) Opcode() network.PacketID { // Parse parses the packet from binary func (m *MsgMhfOperateJoint) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error { - m.AckHandle = bf.ReadUint32() - m.AllianceID = bf.ReadUint32() - m.GuildID = bf.ReadUint32() - m.Action = OperateJointAction(bf.ReadUint8()) - m.UnkData = bf.DataFromCurrent() - bf.Seek(int64(len(bf.Data()) - 2), 0) - return nil + m.AckHandle = bf.ReadUint32() + m.AllianceID = bf.ReadUint32() + m.GuildID = bf.ReadUint32() + m.Action = OperateJointAction(bf.ReadUint8()) + m.UnkData = byteframe.NewByteFrameFromBytes(bf.DataFromCurrent()) + bf.Seek(int64(len(bf.Data())-2), 0) + return nil } // Build builds a binary packet from the current data. diff --git a/server/channelserver/handlers_guild_alliance.go b/server/channelserver/handlers_guild_alliance.go index 1d0960780..7e2a9a2ac 100644 --- a/server/channelserver/handlers_guild_alliance.go +++ b/server/channelserver/handlers_guild_alliance.go @@ -157,6 +157,26 @@ func handleMsgMhfOperateJoint(s *Session, p mhfpacket.MHFPacket) { ) doAckSimpleFail(s, pkt.AckHandle, make([]byte, 4)) } + case mhfpacket.OPERATE_JOINT_KICK: + if alliance.ParentGuild.LeaderCharID == s.charID { + _ = pkt.UnkData.ReadUint8() + kickedGuildID := pkt.UnkData.ReadUint32() + if kickedGuildID == alliance.SubGuild1ID && alliance.SubGuild2ID > 0 { + s.server.db.Exec(`UPDATE guild_alliances SET sub1_id = sub2_id, sub2_id = NULL WHERE id = $1`, alliance.ID) + } else if kickedGuildID == alliance.SubGuild1ID && alliance.SubGuild2ID == 0 { + s.server.db.Exec(`UPDATE guild_alliances SET sub1_id = NULL WHERE id = $1`, alliance.ID) + } else { + s.server.db.Exec(`UPDATE guild_alliances SET sub2_id = NULL WHERE id = $1`, alliance.ID) + } + doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4)) + } else { + s.logger.Warn( + "Non-owner of alliance attempted kick", + zap.Uint32("CharID", s.charID), + zap.Uint32("AllyID", alliance.ID), + ) + doAckSimpleFail(s, pkt.AckHandle, make([]byte, 4)) + } default: doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4)) panic(fmt.Sprintf("Unhandled operate joint action '%d'", pkt.Action))