add support for guild meals

This commit is contained in:
wishu
2022-07-10 00:53:41 +10:00
parent d0ef594b81
commit 56cad91261
4 changed files with 68 additions and 31 deletions

12
Erupe/guild-food.sql Normal file
View File

@@ -0,0 +1,12 @@
BEGIN;
CREATE TABLE IF NOT EXISTS public.guild_meals
(
id serial NOT NULL PRIMARY KEY,
guild_id int NOT NULL,
meal_id int NOT NULL,
level int NOT NULL,
expires int NOT NULL
);
END;

View File

@@ -11,7 +11,7 @@ import (
// MsgMhfLoadGuildCooking represents the MSG_MHF_LOAD_GUILD_COOKING // MsgMhfLoadGuildCooking represents the MSG_MHF_LOAD_GUILD_COOKING
type MsgMhfLoadGuildCooking struct{ type MsgMhfLoadGuildCooking struct{
AckHandle uint32 AckHandle uint32
Unk0 uint8 MaxMeals uint8
} }
// Opcode returns the ID associated with this packet type. // Opcode returns the ID associated with this packet type.
@@ -22,7 +22,7 @@ func (m *MsgMhfLoadGuildCooking) Opcode() network.PacketID {
// Parse parses the packet from binary // Parse parses the packet from binary
func (m *MsgMhfLoadGuildCooking) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error { func (m *MsgMhfLoadGuildCooking) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error {
m.AckHandle = bf.ReadUint32() m.AckHandle = bf.ReadUint32()
m.Unk0 = bf.ReadUint8() _ = bf.ReadUint8()
return nil return nil
} }

View File

@@ -11,9 +11,9 @@ import (
// MsgMhfRegistGuildCooking represents the MSG_MHF_REGIST_GUILD_COOKING // MsgMhfRegistGuildCooking represents the MSG_MHF_REGIST_GUILD_COOKING
type MsgMhfRegistGuildCooking struct{ type MsgMhfRegistGuildCooking struct{
AckHandle uint32 AckHandle uint32
Unk0 uint32 OverwriteID uint32
Unk1 uint16 MealID uint16
Unk2 uint8 Success uint8
} }
// Opcode returns the ID associated with this packet type. // Opcode returns the ID associated with this packet type.
@@ -24,9 +24,9 @@ func (m *MsgMhfRegistGuildCooking) Opcode() network.PacketID {
// Parse parses the packet from binary // Parse parses the packet from binary
func (m *MsgMhfRegistGuildCooking) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error { func (m *MsgMhfRegistGuildCooking) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error {
m.AckHandle = bf.ReadUint32() m.AckHandle = bf.ReadUint32()
m.Unk0 = bf.ReadUint32() m.OverwriteID = bf.ReadUint32()
m.Unk1 = bf.ReadUint16() m.MealID = bf.ReadUint16()
m.Unk2 = bf.ReadUint8() m.Success = bf.ReadUint8()
return nil return nil
} }

View File

@@ -1637,31 +1637,56 @@ func handleMsgMhfGetGuildMissionRecord(s *Session, p mhfpacket.MHFPacket) {
doAckBufSucceed(s, pkt.AckHandle, make([]byte, 0x190)) doAckBufSucceed(s, pkt.AckHandle, make([]byte, 0x190))
} }
type GuildMeal struct {
ID uint32 `db:"id"`
MealID uint32 `db:"meal_id"`
Level uint32 `db:"level"`
Expires uint32 `db:"expires"`
}
func handleMsgMhfLoadGuildCooking(s *Session, p mhfpacket.MHFPacket) { func handleMsgMhfLoadGuildCooking(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfLoadGuildCooking) pkt := p.(*mhfpacket.MsgMhfLoadGuildCooking)
// MealData
// uint16 meal count
// Meal
// uint32 hash?
// uint32 unk
// uint32 success level
// uint32 expiration timestamp
// encourage food guild, _ := GetGuildInfoByCharacterId(s, s.charID)
data := []byte{0x00, 0x06, data, err := s.server.db.Queryx("SELECT id, meal_id, level, expires FROM guild_meals WHERE guild_id = $1", guild.ID)
0x0F, 0x51, 0x97, 0xFF, 0x00, 0x00, 0x02, 0xc4, 0x00, 0x00, 0x00, 0x03, 0xFF, 0xFC, 0x0B, 0x51, if err != nil {
0x0F, 0x51, 0x97, 0xFF, 0x00, 0x00, 0x02, 0x9c, 0x00, 0x00, 0x00, 0x03, 0xFF, 0xFC, 0x0B, 0x52, s.logger.Fatal("Failed to get guild meals from db", zap.Error(err))
0x0F, 0x51, 0x97, 0xFF, 0x00, 0x00, 0x02, 0x07, 0x00, 0x00, 0x00, 0x03, 0xFF, 0xFC, 0x0B, 0x51, }
0x0F, 0x51, 0x97, 0xFF, 0x00, 0x00, 0x01, 0x8b, 0x00, 0x00, 0x00, 0x03, 0xFF, 0xFD, 0x0B, 0x51, temp := byteframe.NewByteFrame()
0x0F, 0x51, 0x97, 0xFF, 0x00, 0x00, 0x02, 0x54, 0x00, 0x00, 0x00, 0x03, 0xFF, 0xFC, 0x0B, 0x51, count := 0
0x0F, 0x51, 0x97, 0xFF, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x03, 0xF3, 0xFC, 0x0B, 0x51} for data.Next() {
doAckBufSucceed(s, pkt.AckHandle, data) mealData := &GuildMeal{}
//data := []byte{0x00, 0x01, 0x1C, 0x72, 0x54, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x5F, 0xF8, 0x2F, 0xE1} err = data.StructScan(&mealData)
//doAckBufSucceed(s, pkt.AckHandle, data) if err != nil {
s.logger.Fatal("Failed to scan meal data", zap.Error(err))
}
if mealData.Expires > uint32(Time_Current_Adjusted().Add(-60 * time.Minute).Unix()) {
count++
temp.WriteUint32(mealData.ID)
temp.WriteUint32(mealData.MealID)
temp.WriteUint32(mealData.Level)
temp.WriteUint32(mealData.Expires)
}
}
bf := byteframe.NewByteFrame()
bf.WriteUint16(uint16(count))
bf.WriteBytes(temp.Data())
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
} }
func handleMsgMhfRegistGuildCooking(s *Session, p mhfpacket.MHFPacket) { func handleMsgMhfRegistGuildCooking(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfRegistGuildCooking) pkt := p.(*mhfpacket.MsgMhfRegistGuildCooking)
guild, _ := GetGuildInfoByCharacterId(s, s.charID)
if pkt.OverwriteID != 0 {
_, err := s.server.db.Exec("DELETE FROM guild_meals WHERE id = $1", pkt.OverwriteID)
if err != nil {
s.logger.Fatal("Failed to delete meal in db", zap.Error(err))
}
}
_, err := s.server.db.Exec("INSERT INTO guild_meals (guild_id, meal_id, level, expires) VALUES ($1, $2, $3, $4)", guild.ID, pkt.MealID, pkt.Success, Time_Current_Adjusted().Add(30 * time.Minute).Unix())
if err != nil {
s.logger.Fatal("Failed to register meal in db", zap.Error(err))
}
doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x01, 0x00}) doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x01, 0x00})
} }