mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-14 16:04:38 +01:00
optimise GuildTresure handlers
This commit is contained in:
@@ -40,6 +40,7 @@
|
|||||||
"MaximumNP": 100000,
|
"MaximumNP": 100000,
|
||||||
"MaximumRP": 50000,
|
"MaximumRP": 50000,
|
||||||
"MaximumFP": 120000,
|
"MaximumFP": 120000,
|
||||||
|
"TreasureHuntExpiry": 604800,
|
||||||
"DisableLoginBoost": false,
|
"DisableLoginBoost": false,
|
||||||
"DisableBoostTime": false,
|
"DisableBoostTime": false,
|
||||||
"BoostTimeDuration": 120,
|
"BoostTimeDuration": 120,
|
||||||
|
|||||||
@@ -125,6 +125,7 @@ type GameplayOptions struct {
|
|||||||
MaximumNP int // Maximum number of NP held by a player
|
MaximumNP int // Maximum number of NP held by a player
|
||||||
MaximumRP uint16 // Maximum number of RP held by a player
|
MaximumRP uint16 // Maximum number of RP held by a player
|
||||||
MaximumFP uint32 // Maximum number of FP held by a player
|
MaximumFP uint32 // Maximum number of FP held by a player
|
||||||
|
TreasureHuntExpiry uint32 // Seconds until a Clan Treasure Hunt will expire
|
||||||
DisableLoginBoost bool // Disables the Login Boost system
|
DisableLoginBoost bool // Disables the Login Boost system
|
||||||
DisableBoostTime bool // Disables the daily NetCafe Boost Time
|
DisableBoostTime bool // Disables the daily NetCafe Boost Time
|
||||||
BoostTimeDuration int // The number of minutes NetCafe Boost Time lasts for
|
BoostTimeDuration int // The number of minutes NetCafe Boost Time lasts for
|
||||||
|
|||||||
@@ -22,54 +22,54 @@ type TreasureHunt struct {
|
|||||||
func handleMsgMhfEnumerateGuildTresure(s *Session, p mhfpacket.MHFPacket) {
|
func handleMsgMhfEnumerateGuildTresure(s *Session, p mhfpacket.MHFPacket) {
|
||||||
pkt := p.(*mhfpacket.MsgMhfEnumerateGuildTresure)
|
pkt := p.(*mhfpacket.MsgMhfEnumerateGuildTresure)
|
||||||
guild, err := GetGuildInfoByCharacterId(s, s.charID)
|
guild, err := GetGuildInfoByCharacterId(s, s.charID)
|
||||||
if err != nil {
|
if err != nil || guild == nil {
|
||||||
panic(err)
|
doAckBufSucceed(s, pkt.AckHandle, make([]byte, 4))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var hunts []TreasureHunt
|
||||||
|
var hunt TreasureHunt
|
||||||
|
rows, err := s.server.db.Queryx(`SELECT id, host_id, destination, level, return, acquired, claimed, hunters, treasure, hunt_data FROM guild_hunts WHERE guild_id=$1 AND $2 < return+$3
|
||||||
|
`, guild.ID, TimeAdjusted().Unix(), s.server.erupeConfig.GameplayOptions.TreasureHuntExpiry)
|
||||||
|
if err != nil {
|
||||||
|
rows.Close()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
bf := byteframe.NewByteFrame()
|
|
||||||
hunts := 0
|
|
||||||
rows, _ := s.server.db.Queryx("SELECT id, host_id, destination, level, return, acquired, claimed, hunters, treasure, hunt_data FROM guild_hunts WHERE guild_id=$1 AND $2 < return+604800", guild.ID, TimeAdjusted().Unix())
|
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
hunt := &TreasureHunt{}
|
|
||||||
err = rows.StructScan(&hunt)
|
err = rows.StructScan(&hunt)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
// Remove self from other hunter count
|
// Remove self from other hunter count
|
||||||
hunt.Hunters = stringsupport.CSVRemove(hunt.Hunters, int(s.charID))
|
hunt.Hunters = stringsupport.CSVRemove(hunt.Hunters, int(s.charID))
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
if pkt.MaxHunts == 1 {
|
if pkt.MaxHunts == 1 {
|
||||||
if hunt.HostID != s.charID || hunt.Acquired {
|
if hunt.HostID != s.charID || hunt.Acquired {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
hunts++
|
hunt.Claimed = false
|
||||||
bf.WriteUint32(hunt.HuntID)
|
hunt.Treasure = ""
|
||||||
bf.WriteUint32(hunt.Destination)
|
hunts = append(hunts, hunt)
|
||||||
bf.WriteUint32(hunt.Level)
|
|
||||||
bf.WriteUint32(uint32(stringsupport.CSVLength(hunt.Hunters)))
|
|
||||||
bf.WriteUint32(hunt.Return)
|
|
||||||
bf.WriteBool(false)
|
|
||||||
bf.WriteBool(false)
|
|
||||||
bf.WriteBytes(hunt.HuntData)
|
|
||||||
break
|
break
|
||||||
} else if pkt.MaxHunts == 30 && hunt.Acquired && hunt.Level == 2 {
|
} else if pkt.MaxHunts == 30 && hunt.Acquired && hunt.Level == 2 {
|
||||||
if hunts == 30 {
|
hunts = append(hunts, hunt)
|
||||||
break
|
|
||||||
}
|
|
||||||
hunts++
|
|
||||||
bf.WriteUint32(hunt.HuntID)
|
|
||||||
bf.WriteUint32(hunt.Destination)
|
|
||||||
bf.WriteUint32(hunt.Level)
|
|
||||||
bf.WriteUint32(uint32(stringsupport.CSVLength(hunt.Hunters)))
|
|
||||||
bf.WriteUint32(hunt.Return)
|
|
||||||
bf.WriteBool(hunt.Claimed)
|
|
||||||
bf.WriteBool(stringsupport.CSVContains(hunt.Treasure, int(s.charID)))
|
|
||||||
bf.WriteBytes(hunt.HuntData)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resp := byteframe.NewByteFrame()
|
if len(hunts) > 30 {
|
||||||
resp.WriteUint16(uint16(hunts))
|
hunts = hunts[:30]
|
||||||
resp.WriteUint16(uint16(hunts))
|
}
|
||||||
resp.WriteBytes(bf.Data())
|
bf := byteframe.NewByteFrame()
|
||||||
doAckBufSucceed(s, pkt.AckHandle, resp.Data())
|
bf.WriteUint16(uint16(len(hunts)))
|
||||||
|
bf.WriteUint16(uint16(len(hunts)))
|
||||||
|
for _, h := range hunts {
|
||||||
|
bf.WriteUint32(h.HuntID)
|
||||||
|
bf.WriteUint32(h.Destination)
|
||||||
|
bf.WriteUint32(h.Level)
|
||||||
|
bf.WriteUint32(uint32(stringsupport.CSVLength(h.Hunters)))
|
||||||
|
bf.WriteUint32(h.Return)
|
||||||
|
bf.WriteBool(h.Claimed)
|
||||||
|
bf.WriteBool(stringsupport.CSVContains(h.Treasure, int(s.charID)))
|
||||||
|
bf.WriteBytes(h.HuntData)
|
||||||
|
}
|
||||||
|
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleMsgMhfRegistGuildTresure(s *Session, p mhfpacket.MHFPacket) {
|
func handleMsgMhfRegistGuildTresure(s *Session, p mhfpacket.MHFPacket) {
|
||||||
@@ -77,8 +77,9 @@ func handleMsgMhfRegistGuildTresure(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
bf := byteframe.NewByteFrameFromBytes(pkt.Data)
|
bf := byteframe.NewByteFrameFromBytes(pkt.Data)
|
||||||
huntData := byteframe.NewByteFrame()
|
huntData := byteframe.NewByteFrame()
|
||||||
guild, err := GetGuildInfoByCharacterId(s, s.charID)
|
guild, err := GetGuildInfoByCharacterId(s, s.charID)
|
||||||
if err != nil {
|
if err != nil || guild == nil {
|
||||||
panic(err)
|
doAckSimpleFail(s, pkt.AckHandle, make([]byte, 4))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
guildCats := getGuildAirouList(s)
|
guildCats := getGuildAirouList(s)
|
||||||
destination := bf.ReadUint32()
|
destination := bf.ReadUint32()
|
||||||
@@ -100,20 +101,14 @@ func handleMsgMhfRegistGuildTresure(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
huntData.WriteBytes(bf.ReadBytes(9))
|
huntData.WriteBytes(bf.ReadBytes(9))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_, err = s.server.db.Exec("INSERT INTO guild_hunts (guild_id, host_id, destination, level, return, hunt_data, cats_used) VALUES ($1, $2, $3, $4, $5, $6, $7)",
|
s.server.db.Exec(`INSERT INTO guild_hunts (guild_id, host_id, destination, level, return, hunt_data, cats_used) VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||||
guild.ID, s.charID, destination, level, TimeAdjusted().Unix(), huntData.Data(), catsUsed)
|
`, guild.ID, s.charID, destination, level, TimeAdjusted().Unix(), huntData.Data(), catsUsed)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
|
doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleMsgMhfAcquireGuildTresure(s *Session, p mhfpacket.MHFPacket) {
|
func handleMsgMhfAcquireGuildTresure(s *Session, p mhfpacket.MHFPacket) {
|
||||||
pkt := p.(*mhfpacket.MsgMhfAcquireGuildTresure)
|
pkt := p.(*mhfpacket.MsgMhfAcquireGuildTresure)
|
||||||
_, err := s.server.db.Exec("UPDATE guild_hunts SET acquired=true WHERE id=$1", pkt.HuntID)
|
s.server.db.Exec("UPDATE guild_hunts SET acquired=true WHERE id=$1", pkt.HuntID)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
|
doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,6 +121,7 @@ func treasureHuntUnregister(s *Session) {
|
|||||||
var hunters string
|
var hunters string
|
||||||
rows, err := s.server.db.Queryx("SELECT id, hunters FROM guild_hunts WHERE guild_id=$1", guild.ID)
|
rows, err := s.server.db.Queryx("SELECT id, hunters FROM guild_hunts WHERE guild_id=$1", guild.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
rows.Close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
@@ -138,41 +134,40 @@ func treasureHuntUnregister(s *Session) {
|
|||||||
func handleMsgMhfOperateGuildTresureReport(s *Session, p mhfpacket.MHFPacket) {
|
func handleMsgMhfOperateGuildTresureReport(s *Session, p mhfpacket.MHFPacket) {
|
||||||
pkt := p.(*mhfpacket.MsgMhfOperateGuildTresureReport)
|
pkt := p.(*mhfpacket.MsgMhfOperateGuildTresureReport)
|
||||||
var csv string
|
var csv string
|
||||||
if pkt.State == 0 { // Report registration
|
switch pkt.State {
|
||||||
|
case 0: // Report registration
|
||||||
// Unregister from all other hunts
|
// Unregister from all other hunts
|
||||||
treasureHuntUnregister(s)
|
treasureHuntUnregister(s)
|
||||||
if pkt.HuntID != 0 {
|
if pkt.HuntID != 0 {
|
||||||
// Register to selected hunt
|
// Register to selected hunt
|
||||||
err := s.server.db.QueryRow("SELECT hunters FROM guild_hunts WHERE id=$1", pkt.HuntID).Scan(&csv)
|
err := s.server.db.QueryRow("SELECT hunters FROM guild_hunts WHERE id=$1", pkt.HuntID).Scan(&csv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
csv = stringsupport.CSVAdd(csv, int(s.charID))
|
csv = stringsupport.CSVAdd(csv, int(s.charID))
|
||||||
_, err = s.server.db.Exec("UPDATE guild_hunts SET hunters=$1 WHERE id=$2", csv, pkt.HuntID)
|
s.server.db.Exec("UPDATE guild_hunts SET hunters=$1 WHERE id=$2", csv, pkt.HuntID)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if pkt.State == 1 { // Collected by hunter
|
case 1: // Collected by hunter
|
||||||
s.server.db.Exec("UPDATE guild_hunts SET hunters='', claimed=true WHERE id=$1", pkt.HuntID)
|
s.server.db.Exec("UPDATE guild_hunts SET hunters='', claimed=true WHERE id=$1", pkt.HuntID)
|
||||||
} else if pkt.State == 2 { // Claim treasure
|
case 2: // Claim treasure
|
||||||
err := s.server.db.QueryRow("SELECT treasure FROM guild_hunts WHERE id=$1", pkt.HuntID).Scan(&csv)
|
err := s.server.db.QueryRow("SELECT treasure FROM guild_hunts WHERE id=$1", pkt.HuntID).Scan(&csv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
csv = stringsupport.CSVAdd(csv, int(s.charID))
|
csv = stringsupport.CSVAdd(csv, int(s.charID))
|
||||||
_, err = s.server.db.Exec("UPDATE guild_hunts SET treasure=$1 WHERE id=$2", csv, pkt.HuntID)
|
s.server.db.Exec("UPDATE guild_hunts SET treasure=$1 WHERE id=$2", csv, pkt.HuntID)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
|
doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleMsgMhfGetGuildTresureSouvenir(s *Session, p mhfpacket.MHFPacket) {
|
func handleMsgMhfGetGuildTresureSouvenir(s *Session, p mhfpacket.MHFPacket) {
|
||||||
pkt := p.(*mhfpacket.MsgMhfGetGuildTresureSouvenir)
|
pkt := p.(*mhfpacket.MsgMhfGetGuildTresureSouvenir)
|
||||||
|
bf := byteframe.NewByteFrame()
|
||||||
doAckBufSucceed(s, pkt.AckHandle, make([]byte, 6))
|
bf.WriteUint32(0)
|
||||||
|
bf.WriteUint16(0)
|
||||||
|
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleMsgMhfAcquireGuildTresureSouvenir(s *Session, p mhfpacket.MHFPacket) {
|
func handleMsgMhfAcquireGuildTresureSouvenir(s *Session, p mhfpacket.MHFPacket) {
|
||||||
|
|||||||
Reference in New Issue
Block a user