mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-15 16:34:51 +01:00
Abracted away broadcast utils
This commit is contained in:
@@ -2,6 +2,7 @@ package channelserver
|
||||
|
||||
import (
|
||||
"erupe-ce/network/mhfpacket"
|
||||
"erupe-ce/utils/broadcast"
|
||||
"erupe-ce/utils/byteframe"
|
||||
"erupe-ce/utils/db"
|
||||
"erupe-ce/utils/gametime"
|
||||
@@ -18,31 +19,31 @@ func HandleMsgMhfPostGuildScout(s *Session, p mhfpacket.MHFPacket) {
|
||||
actorCharGuildData, err := GetCharacterGuildData(s, s.CharID)
|
||||
|
||||
if err != nil {
|
||||
DoAckBufFail(s, pkt.AckHandle, make([]byte, 4))
|
||||
broadcast.DoAckBufFail(s, pkt.AckHandle, make([]byte, 4))
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if actorCharGuildData == nil || !actorCharGuildData.CanRecruit() {
|
||||
DoAckBufFail(s, pkt.AckHandle, make([]byte, 4))
|
||||
broadcast.DoAckBufFail(s, pkt.AckHandle, make([]byte, 4))
|
||||
return
|
||||
}
|
||||
|
||||
guildInfo, err := GetGuildInfoByID(s, actorCharGuildData.GuildID)
|
||||
|
||||
if err != nil {
|
||||
DoAckBufFail(s, pkt.AckHandle, make([]byte, 4))
|
||||
broadcast.DoAckBufFail(s, pkt.AckHandle, make([]byte, 4))
|
||||
panic(err)
|
||||
}
|
||||
|
||||
hasApplication, err := guildInfo.HasApplicationForCharID(s, pkt.CharID)
|
||||
|
||||
if err != nil {
|
||||
DoAckBufFail(s, pkt.AckHandle, make([]byte, 4))
|
||||
broadcast.DoAckBufFail(s, pkt.AckHandle, make([]byte, 4))
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if hasApplication {
|
||||
DoAckBufSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x04})
|
||||
broadcast.DoAckBufSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x04})
|
||||
return
|
||||
}
|
||||
database, err := db.GetDB()
|
||||
@@ -59,7 +60,7 @@ func HandleMsgMhfPostGuildScout(s *Session, p mhfpacket.MHFPacket) {
|
||||
|
||||
if err != nil {
|
||||
rollbackTransaction(s, transaction)
|
||||
DoAckBufFail(s, pkt.AckHandle, nil)
|
||||
broadcast.DoAckBufFail(s, pkt.AckHandle, nil)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -78,18 +79,18 @@ func HandleMsgMhfPostGuildScout(s *Session, p mhfpacket.MHFPacket) {
|
||||
|
||||
if err != nil {
|
||||
rollbackTransaction(s, transaction)
|
||||
DoAckBufFail(s, pkt.AckHandle, nil)
|
||||
broadcast.DoAckBufFail(s, pkt.AckHandle, nil)
|
||||
return
|
||||
}
|
||||
|
||||
err = transaction.Commit()
|
||||
|
||||
if err != nil {
|
||||
DoAckBufFail(s, pkt.AckHandle, nil)
|
||||
broadcast.DoAckBufFail(s, pkt.AckHandle, nil)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
DoAckBufSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00})
|
||||
broadcast.DoAckBufSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00})
|
||||
}
|
||||
|
||||
func HandleMsgMhfCancelGuildScout(s *Session, p mhfpacket.MHFPacket) {
|
||||
@@ -102,25 +103,25 @@ func HandleMsgMhfCancelGuildScout(s *Session, p mhfpacket.MHFPacket) {
|
||||
}
|
||||
|
||||
if guildCharData == nil || !guildCharData.CanRecruit() {
|
||||
DoAckBufFail(s, pkt.AckHandle, make([]byte, 4))
|
||||
broadcast.DoAckBufFail(s, pkt.AckHandle, make([]byte, 4))
|
||||
return
|
||||
}
|
||||
|
||||
guild, err := GetGuildInfoByID(s, guildCharData.GuildID)
|
||||
|
||||
if err != nil {
|
||||
DoAckBufFail(s, pkt.AckHandle, make([]byte, 4))
|
||||
broadcast.DoAckBufFail(s, pkt.AckHandle, make([]byte, 4))
|
||||
return
|
||||
}
|
||||
|
||||
err = guild.CancelInvitation(s, pkt.InvitationID)
|
||||
|
||||
if err != nil {
|
||||
DoAckBufFail(s, pkt.AckHandle, make([]byte, 4))
|
||||
broadcast.DoAckBufFail(s, pkt.AckHandle, make([]byte, 4))
|
||||
return
|
||||
}
|
||||
|
||||
DoAckBufSucceed(s, pkt.AckHandle, make([]byte, 4))
|
||||
broadcast.DoAckBufSucceed(s, pkt.AckHandle, make([]byte, 4))
|
||||
}
|
||||
|
||||
func HandleMsgMhfAnswerGuildScout(s *Session, p mhfpacket.MHFPacket) {
|
||||
@@ -143,7 +144,7 @@ func HandleMsgMhfAnswerGuildScout(s *Session, p mhfpacket.MHFPacket) {
|
||||
)
|
||||
bf.WriteUint32(7)
|
||||
bf.WriteUint32(guild.ID)
|
||||
DoAckBufSucceed(s, pkt.AckHandle, bf.Data())
|
||||
broadcast.DoAckBufSucceed(s, pkt.AckHandle, bf.Data())
|
||||
return
|
||||
}
|
||||
|
||||
@@ -182,11 +183,11 @@ func HandleMsgMhfAnswerGuildScout(s *Session, p mhfpacket.MHFPacket) {
|
||||
if err != nil {
|
||||
bf.WriteUint32(7)
|
||||
bf.WriteUint32(guild.ID)
|
||||
DoAckBufSucceed(s, pkt.AckHandle, bf.Data())
|
||||
broadcast.DoAckBufSucceed(s, pkt.AckHandle, bf.Data())
|
||||
} else {
|
||||
bf.WriteUint32(0)
|
||||
bf.WriteUint32(guild.ID)
|
||||
DoAckBufSucceed(s, pkt.AckHandle, bf.Data())
|
||||
broadcast.DoAckBufSucceed(s, pkt.AckHandle, bf.Data())
|
||||
for _, m := range mail {
|
||||
m.Send(s, nil)
|
||||
}
|
||||
@@ -199,12 +200,12 @@ func HandleMsgMhfGetGuildScoutList(s *Session, p mhfpacket.MHFPacket) {
|
||||
guildInfo, err := GetGuildInfoByCharacterId(s, s.CharID)
|
||||
|
||||
if guildInfo == nil && s.prevGuildID == 0 {
|
||||
DoAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
|
||||
broadcast.DoAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
|
||||
return
|
||||
} else {
|
||||
guildInfo, err = GetGuildInfoByID(s, s.prevGuildID)
|
||||
if guildInfo == nil || err != nil {
|
||||
DoAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
|
||||
broadcast.DoAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -221,7 +222,7 @@ func HandleMsgMhfGetGuildScoutList(s *Session, p mhfpacket.MHFPacket) {
|
||||
|
||||
if err != nil {
|
||||
s.Logger.Error("failed to retrieve scouted characters", zap.Error(err))
|
||||
DoAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
|
||||
broadcast.DoAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -244,7 +245,7 @@ func HandleMsgMhfGetGuildScoutList(s *Session, p mhfpacket.MHFPacket) {
|
||||
err = rows.Scan(&charID, &charName, &HR, &GR, &actorID)
|
||||
|
||||
if err != nil {
|
||||
DoAckSimpleFail(s, pkt.AckHandle, nil)
|
||||
broadcast.DoAckSimpleFail(s, pkt.AckHandle, nil)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -269,7 +270,7 @@ func HandleMsgMhfGetGuildScoutList(s *Session, p mhfpacket.MHFPacket) {
|
||||
|
||||
bf.WriteUint32(count)
|
||||
|
||||
DoAckBufSucceed(s, pkt.AckHandle, bf.Data())
|
||||
broadcast.DoAckBufSucceed(s, pkt.AckHandle, bf.Data())
|
||||
}
|
||||
|
||||
func HandleMsgMhfGetRejectGuildScout(s *Session, p mhfpacket.MHFPacket) {
|
||||
@@ -290,7 +291,7 @@ func HandleMsgMhfGetRejectGuildScout(s *Session, p mhfpacket.MHFPacket) {
|
||||
zap.Error(err),
|
||||
zap.Uint32("charID", s.CharID),
|
||||
)
|
||||
DoAckSimpleFail(s, pkt.AckHandle, nil)
|
||||
broadcast.DoAckSimpleFail(s, pkt.AckHandle, nil)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -300,7 +301,7 @@ func HandleMsgMhfGetRejectGuildScout(s *Session, p mhfpacket.MHFPacket) {
|
||||
response = 0x01
|
||||
}
|
||||
|
||||
DoAckSimpleSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, response})
|
||||
broadcast.DoAckSimpleSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, response})
|
||||
}
|
||||
|
||||
func HandleMsgMhfSetRejectGuildScout(s *Session, p mhfpacket.MHFPacket) {
|
||||
@@ -317,9 +318,9 @@ func HandleMsgMhfSetRejectGuildScout(s *Session, p mhfpacket.MHFPacket) {
|
||||
zap.Error(err),
|
||||
zap.Uint32("charID", s.CharID),
|
||||
)
|
||||
DoAckSimpleFail(s, pkt.AckHandle, nil)
|
||||
broadcast.DoAckSimpleFail(s, pkt.AckHandle, nil)
|
||||
return
|
||||
}
|
||||
|
||||
DoAckSimpleSucceed(s, pkt.AckHandle, nil)
|
||||
broadcast.DoAckSimpleSucceed(s, pkt.AckHandle, nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user