implement guild adventure cat

This commit is contained in:
wishu
2022-07-08 13:17:47 +10:00
parent a45b8175be
commit b1fb80ea3f
5 changed files with 130 additions and 20 deletions

14
Erupe/guild-adventure.sql Normal file
View File

@@ -0,0 +1,14 @@
BEGIN;
CREATE TABLE IF NOT EXISTS public.guild_adventures
(
id serial NOT NULL PRIMARY KEY,
guild_id int NOT NULL,
destination int NOT NULL,
charge int NOT NULL DEFAULT 0,
depart int NOT NULL,
return int NOT NULL,
collected_by text NOT NULL DEFAULT ''
);
END;

View File

@@ -1,7 +1,7 @@
package mhfpacket package mhfpacket
import ( import (
"errors" "errors"
"erupe-ce/network/clientctx" "erupe-ce/network/clientctx"
"erupe-ce/network" "erupe-ce/network"
@@ -9,7 +9,10 @@ import (
) )
// MsgMhfAcquireGuildAdventure represents the MSG_MHF_ACQUIRE_GUILD_ADVENTURE // MsgMhfAcquireGuildAdventure represents the MSG_MHF_ACQUIRE_GUILD_ADVENTURE
type MsgMhfAcquireGuildAdventure struct{} type MsgMhfAcquireGuildAdventure struct {
AckHandle uint32
ID uint32
}
// Opcode returns the ID associated with this packet type. // Opcode returns the ID associated with this packet type.
func (m *MsgMhfAcquireGuildAdventure) Opcode() network.PacketID { func (m *MsgMhfAcquireGuildAdventure) Opcode() network.PacketID {
@@ -18,7 +21,9 @@ func (m *MsgMhfAcquireGuildAdventure) Opcode() network.PacketID {
// Parse parses the packet from binary // Parse parses the packet from binary
func (m *MsgMhfAcquireGuildAdventure) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error { func (m *MsgMhfAcquireGuildAdventure) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error {
return errors.New("NOT IMPLEMENTED") m.AckHandle = bf.ReadUint32()
m.ID = bf.ReadUint32()
return nil
} }
// Build builds a binary packet from the current data. // Build builds a binary packet from the current data.

View File

@@ -1,7 +1,7 @@
package mhfpacket package mhfpacket
import ( import (
"errors" "errors"
"erupe-ce/network/clientctx" "erupe-ce/network/clientctx"
"erupe-ce/network" "erupe-ce/network"
@@ -9,7 +9,11 @@ import (
) )
// MsgMhfChargeGuildAdventure represents the MSG_MHF_CHARGE_GUILD_ADVENTURE // MsgMhfChargeGuildAdventure represents the MSG_MHF_CHARGE_GUILD_ADVENTURE
type MsgMhfChargeGuildAdventure struct{} type MsgMhfChargeGuildAdventure struct {
AckHandle uint32
ID uint32
Amount uint32
}
// Opcode returns the ID associated with this packet type. // Opcode returns the ID associated with this packet type.
func (m *MsgMhfChargeGuildAdventure) Opcode() network.PacketID { func (m *MsgMhfChargeGuildAdventure) Opcode() network.PacketID {
@@ -18,7 +22,10 @@ func (m *MsgMhfChargeGuildAdventure) Opcode() network.PacketID {
// Parse parses the packet from binary // Parse parses the packet from binary
func (m *MsgMhfChargeGuildAdventure) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error { func (m *MsgMhfChargeGuildAdventure) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error {
return errors.New("NOT IMPLEMENTED") m.AckHandle = bf.ReadUint32()
m.ID = bf.ReadUint32()
m.Amount = bf.ReadUint32()
return nil
} }
// Build builds a binary packet from the current data. // Build builds a binary packet from the current data.

View File

@@ -1,7 +1,7 @@
package mhfpacket package mhfpacket
import ( import (
"errors" "errors"
"erupe-ce/network/clientctx" "erupe-ce/network/clientctx"
"erupe-ce/network" "erupe-ce/network"
@@ -9,7 +9,10 @@ import (
) )
// MsgMhfRegistGuildAdventure represents the MSG_MHF_REGIST_GUILD_ADVENTURE // MsgMhfRegistGuildAdventure represents the MSG_MHF_REGIST_GUILD_ADVENTURE
type MsgMhfRegistGuildAdventure struct{} type MsgMhfRegistGuildAdventure struct {
AckHandle uint32
Destination uint32
}
// Opcode returns the ID associated with this packet type. // Opcode returns the ID associated with this packet type.
func (m *MsgMhfRegistGuildAdventure) Opcode() network.PacketID { func (m *MsgMhfRegistGuildAdventure) Opcode() network.PacketID {
@@ -18,7 +21,10 @@ func (m *MsgMhfRegistGuildAdventure) Opcode() network.PacketID {
// Parse parses the packet from binary // Parse parses the packet from binary
func (m *MsgMhfRegistGuildAdventure) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error { func (m *MsgMhfRegistGuildAdventure) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error {
return errors.New("NOT IMPLEMENTED") m.AckHandle = bf.ReadUint32()
m.Destination = bf.ReadUint32()
_ = bf.ReadUint32() // CharID
return nil
} }
// Build builds a binary packet from the current data. // Build builds a binary packet from the current data.

View File

@@ -1665,10 +1665,94 @@ func handleMsgMhfRegistGuildCooking(s *Session, p mhfpacket.MHFPacket) {
doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x01, 0x00}) doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x01, 0x00})
} }
type GuildAdventure struct {
ID uint32 `db:"id"`
Destination uint32 `db:"destination"`
Charge uint32 `db:"charge"`
Depart uint32 `db:"depart"`
Return uint32 `db:"return"`
CollectedBy string `db:"collected_by"`
}
func handleMsgMhfLoadGuildAdventure(s *Session, p mhfpacket.MHFPacket) { func handleMsgMhfLoadGuildAdventure(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfLoadGuildAdventure) pkt := p.(*mhfpacket.MsgMhfLoadGuildAdventure)
data := []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00} guild, _ := GetGuildInfoByCharacterId(s, s.charID)
doAckBufSucceed(s, pkt.AckHandle, data) data, err := s.server.db.Queryx("SELECT id, destination, charge, depart, return, collected_by FROM guild_adventures WHERE guild_id = $1", guild.ID)
if err != nil {
s.logger.Fatal("Failed to get guild adventures from db", zap.Error(err))
}
temp := byteframe.NewByteFrame()
count := 0
for data.Next() {
count++
adventureData := &GuildAdventure{}
err = data.StructScan(&adventureData)
if err != nil {
s.logger.Fatal("Failed to scan adventure data", zap.Error(err))
}
temp.WriteUint32(adventureData.ID)
temp.WriteUint32(adventureData.Destination)
temp.WriteUint32(adventureData.Charge)
temp.WriteUint32(adventureData.Depart)
temp.WriteUint32(adventureData.Return)
collected := false
collectedBySlice := strings.Split(adventureData.CollectedBy, ",")
for i := 0; i < len(collectedBySlice); i++ {
j, _ := strconv.ParseInt(collectedBySlice[i], 10, 64)
if int(j) == int(s.charID) {
collected = true
break
}
}
if collected {
temp.WriteBool(true)
} else {
temp.WriteBool(false)
}
}
bf := byteframe.NewByteFrame()
bf.WriteUint8(uint8(count))
bf.WriteBytes(temp.Data())
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
}
func handleMsgMhfRegistGuildAdventure(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfRegistGuildAdventure)
guild, _ := GetGuildInfoByCharacterId(s, s.charID)
_, err := s.server.db.Exec("INSERT INTO guild_adventures (guild_id, destination, depart, return) VALUES ($1, $2, $3, $4)", guild.ID, pkt.Destination, Time_Current_Adjusted().Unix(), Time_Current_Adjusted().Add(6 * time.Hour).Unix())
if err != nil {
s.logger.Fatal("Failed to register guild adventure", zap.Error(err))
}
doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
}
func handleMsgMhfAcquireGuildAdventure(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfAcquireGuildAdventure)
var collectedBy string
err := s.server.db.QueryRow("SELECT collected_by FROM guild_adventures WHERE id = $1", pkt.ID).Scan(&collectedBy)
if err != nil {
s.logger.Fatal("Error parsing adventure collected by", zap.Error(err))
} else {
if len(collectedBy) == 0 {
collectedBy = strconv.Itoa(int(s.charID))
} else {
collectedBy += "," + strconv.Itoa(int(s.charID))
}
_, err := s.server.db.Exec("UPDATE guild_adventures SET collected_by = $1 WHERE id = $2", collectedBy, pkt.ID)
if err != nil {
s.logger.Fatal("Failed to collect adventure in db", zap.Error(err))
}
}
doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
}
func handleMsgMhfChargeGuildAdventure(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfChargeGuildAdventure)
_, err := s.server.db.Exec("UPDATE guild_adventures SET charge = charge + $1 WHERE id = $2", pkt.Amount, pkt.ID)
if err != nil {
s.logger.Fatal("Failed to charge guild adventure", zap.Error(err))
}
doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
} }
func handleMsgMhfGetGuildWeeklyBonusMaster(s *Session, p mhfpacket.MHFPacket) { func handleMsgMhfGetGuildWeeklyBonusMaster(s *Session, p mhfpacket.MHFPacket) {
@@ -1886,12 +1970,6 @@ func handleMsgMhfAddGuildWeeklyBonusExceptionalUser(s *Session, p mhfpacket.MHFP
doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00}) doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00})
} }
func handleMsgMhfRegistGuildAdventure(s *Session, p mhfpacket.MHFPacket) {}
func handleMsgMhfAcquireGuildAdventure(s *Session, p mhfpacket.MHFPacket) {}
func handleMsgMhfChargeGuildAdventure(s *Session, p mhfpacket.MHFPacket) {}
func handleMsgMhfAddGuildMissionCount(s *Session, p mhfpacket.MHFPacket) {} func handleMsgMhfAddGuildMissionCount(s *Session, p mhfpacket.MHFPacket) {}
func handleMsgMhfSetGuildMissionTarget(s *Session, p mhfpacket.MHFPacket) { func handleMsgMhfSetGuildMissionTarget(s *Session, p mhfpacket.MHFPacket) {