From fa35141f9748942d5168b68d578c1bf8a2e65998 Mon Sep 17 00:00:00 2001 From: stratic-dev Date: Thu, 17 Oct 2024 02:55:46 +0100 Subject: [PATCH] Add more constants to central place --- internal/constant/festa.go | 15 +++++++++++++ internal/constant/guild.go | 8 +++++++ server/channelserver/handlers_festa.go | 12 ++++++----- server/channelserver/handlers_guild.go | 22 +++----------------- server/channelserver/handlers_guild_scout.go | 6 ++++-- 5 files changed, 37 insertions(+), 26 deletions(-) create mode 100644 internal/constant/festa.go create mode 100644 internal/constant/guild.go diff --git a/internal/constant/festa.go b/internal/constant/festa.go new file mode 100644 index 000000000..cfeb683f8 --- /dev/null +++ b/internal/constant/festa.go @@ -0,0 +1,15 @@ +package constant + +import "erupe-ce/internal/model" + +const ( + FestivalColorNone model.FestivalColor = "none" + FestivalColorBlue model.FestivalColor = "blue" + FestivalColorRed model.FestivalColor = "red" +) + +var FestivalColorCodes = map[model.FestivalColor]int16{ + FestivalColorNone: -1, + FestivalColorBlue: 0, + FestivalColorRed: 1, +} diff --git a/internal/constant/guild.go b/internal/constant/guild.go new file mode 100644 index 000000000..d292d63d6 --- /dev/null +++ b/internal/constant/guild.go @@ -0,0 +1,8 @@ +package constant + +import "erupe-ce/internal/model" + +const ( + GuildApplicationTypeApplied model.GuildApplicationType = "applied" + GuildApplicationTypeInvited model.GuildApplicationType = "invited" +) diff --git a/server/channelserver/handlers_festa.go b/server/channelserver/handlers_festa.go index 01b448a9b..3692107ae 100644 --- a/server/channelserver/handlers_festa.go +++ b/server/channelserver/handlers_festa.go @@ -2,7 +2,9 @@ package channelserver import ( "erupe-ce/config" + "erupe-ce/internal/constant" "erupe-ce/internal/model" + "erupe-ce/network/mhfpacket" "erupe-ce/utils/byteframe" "erupe-ce/utils/db" @@ -229,7 +231,7 @@ func handleMsgMhfInfoFesta(s *Session, db *sqlx.DB, p mhfpacket.MHFPacket) { bf.WriteUint16(trial.TimesReq) bf.WriteUint16(trial.Locale) bf.WriteUint16(trial.Reward) - bf.WriteInt16(FestivalColorCodes[trial.Monopoly]) + bf.WriteInt16(constant.FestivalColorCodes[trial.Monopoly]) if config.GetConfig().ClientID >= config.F4 { // Not in S6.0 bf.WriteUint16(trial.Unk) } @@ -294,7 +296,7 @@ func handleMsgMhfInfoFesta(s *Session, db *sqlx.DB, p mhfpacket.MHFPacket) { for i := uint16(0); i < 4; i++ { var guildID uint32 var guildName string - var guildTeam = FestivalColorNone + var guildTeam = constant.FestivalColorNone db.QueryRow(` SELECT fs.guild_id, g.name, fr.team, SUM(fs.souls) as _ FROM festa_submissions fs @@ -306,14 +308,14 @@ func handleMsgMhfInfoFesta(s *Session, db *sqlx.DB, p mhfpacket.MHFPacket) { `, i+1).Scan(&guildID, &guildName, &guildTeam, &temp) bf.WriteUint32(guildID) bf.WriteUint16(i + 1) - bf.WriteInt16(FestivalColorCodes[guildTeam]) + bf.WriteInt16(constant.FestivalColorCodes[guildTeam]) ps.Uint8(bf, guildName, true) } bf.WriteUint16(7) for i := uint16(0); i < 7; i++ { var guildID uint32 var guildName string - var guildTeam = FestivalColorNone + var guildTeam = constant.FestivalColorNone offset := 86400 * uint32(i) db.QueryRow(` SELECT fs.guild_id, g.name, fr.team, SUM(fs.souls) as _ @@ -326,7 +328,7 @@ func handleMsgMhfInfoFesta(s *Session, db *sqlx.DB, p mhfpacket.MHFPacket) { `, timestamps[1]+offset, timestamps[1]+offset+86400).Scan(&guildID, &guildName, &guildTeam, &temp) bf.WriteUint32(guildID) bf.WriteUint16(i + 1) - bf.WriteInt16(FestivalColorCodes[guildTeam]) + bf.WriteInt16(constant.FestivalColorCodes[guildTeam]) ps.Uint8(bf, guildName, true) } diff --git a/server/channelserver/handlers_guild.go b/server/channelserver/handlers_guild.go index a5e05f29c..e63bce2df 100644 --- a/server/channelserver/handlers_guild.go +++ b/server/channelserver/handlers_guild.go @@ -6,6 +6,7 @@ import ( "encoding/json" "errors" "erupe-ce/config" + "erupe-ce/internal/constant" "erupe-ce/internal/model" "erupe-ce/internal/service" @@ -60,23 +61,6 @@ type GuildIcon struct { Parts []model.GuildIconPart } -const ( - FestivalColorNone model.FestivalColor = "none" - FestivalColorBlue model.FestivalColor = "blue" - FestivalColorRed model.FestivalColor = "red" -) - -var FestivalColorCodes = map[model.FestivalColor]int16{ - FestivalColorNone: -1, - FestivalColorBlue: 0, - FestivalColorRed: 1, -} - -const ( - GuildApplicationTypeApplied model.GuildApplicationType = "applied" - GuildApplicationTypeInvited model.GuildApplicationType = "invited" -) - func (gi *GuildIcon) Scan(val interface{}) (err error) { switch v := val.(type) { case []byte: @@ -709,7 +693,7 @@ func HandleMsgMhfOperateGuild(s *Session, db *sqlx.DB, p mhfpacket.MHFPacket) { guild.Save(s) } case mhfpacket.OperateGuildApply: - err = guild.CreateApplication(s, s.CharID, GuildApplicationTypeApplied, nil) + err = guild.CreateApplication(s, s.CharID, constant.GuildApplicationTypeApplied, nil) if err == nil { bf.WriteUint32(guild.LeaderCharID) } else { @@ -1019,7 +1003,7 @@ func HandleMsgMhfInfoGuild(s *Session, db *sqlx.DB, p mhfpacket.MHFPacket) { bf.WriteUint8(uint8(len(guildLeaderName))) bf.WriteBytes(guildName) bf.WriteBytes(guildComment) - bf.WriteInt8(int8(FestivalColorCodes[guild.FestivalColor])) + bf.WriteInt8(int8(constant.FestivalColorCodes[guild.FestivalColor])) bf.WriteUint32(guild.RankRP) bf.WriteBytes(guildLeaderName) bf.WriteUint32(0) // Unk diff --git a/server/channelserver/handlers_guild_scout.go b/server/channelserver/handlers_guild_scout.go index e65ab6f07..283aa4485 100644 --- a/server/channelserver/handlers_guild_scout.go +++ b/server/channelserver/handlers_guild_scout.go @@ -1,7 +1,9 @@ package channelserver import ( + "erupe-ce/internal/constant" "erupe-ce/internal/service" + "erupe-ce/network/mhfpacket" "erupe-ce/utils/byteframe" "erupe-ce/utils/gametime" @@ -53,7 +55,7 @@ func HandleMsgMhfPostGuildScout(s *Session, db *sqlx.DB, p mhfpacket.MHFPacket) panic(err) } - err = guildInfo.CreateApplication(s, pkt.CharID, GuildApplicationTypeInvited, transaction) + err = guildInfo.CreateApplication(s, pkt.CharID, constant.GuildApplicationTypeInvited, transaction) if err != nil { rollbackTransaction(s, transaction) @@ -130,7 +132,7 @@ func HandleMsgMhfAnswerGuildScout(s *Session, db *sqlx.DB, p mhfpacket.MHFPacket panic(err) } - app, err := guild.GetApplicationForCharID(s, s.CharID, GuildApplicationTypeInvited) + app, err := guild.GetApplicationForCharID(s, s.CharID, constant.GuildApplicationTypeInvited) if app == nil || err != nil { s.Logger.Warn(