feat(campaign): implement Event Tent campaign system

Adds the full campaign/event-tent feature:

Packet layer:
- MsgMhfApplyCampaign: Unk0/Unk1/Unk2 → CampaignID/Code (null-terminated 16-byte string)
- MsgMhfAcquireItem: Unk0/Length/Unk1 → RewardIDs []uint32
- MsgMhfEnumerateItem: remove Unk0/Unk1 (RE'd: zeroed + always-2, ignored)
- MsgMhfStateCampaign: Unk1 → NullPadding (RE'd: always zero)
- MsgMhfTransferItem: Unk0/Unk1/Unk2 → QuestID/ItemType/Quantity (RE'd)

Handler layer (handlers_campaign.go):
- handleMsgMhfEnumerateCampaign: reads campaigns, categories, links from DB;
  prefix moved into pascal string slot 3 of each event entry (RE confirmed
  3-section response format — removes spurious intermediate section)
- handleMsgMhfStateCampaign: returns stamp count and redeemable flag
- handleMsgMhfApplyCampaign: validates and records code redemption
- handleMsgMhfEnumerateItem: lists rewards gated by stamp count
- handleMsgMhfAcquireItem: marks rewards as claimed
- handleMsgMhfTransferItem: records campaign quest completion (item_type=9)

Quest gating (handlers_quest.go):
- makeEventQuest: for QuestTypeSpecialTool, check campaign stamp count and
  deadline before allowing the quest (WriteBool true/false)

Database:
- 0010_campaign.sql: 8-table schema (campaigns, categories, links, rewards,
  claimed, state, codes, quest)
- CampaignDemo.sql: community-researched live game campaign data
This commit is contained in:
Houmgaor
2026-03-20 11:22:25 +01:00
parent 97ef09be64
commit 77e7969579
10 changed files with 5528 additions and 120 deletions

View File

@@ -11,9 +11,7 @@ import (
// MsgMhfAcquireItem represents the MSG_MHF_ACQUIRE_ITEM // MsgMhfAcquireItem represents the MSG_MHF_ACQUIRE_ITEM
type MsgMhfAcquireItem struct { type MsgMhfAcquireItem struct {
AckHandle uint32 AckHandle uint32
Unk0 uint16 RewardIDs []uint32
Length uint16
Unk1 []uint32
} }
// Opcode returns the ID associated with this packet type. // Opcode returns the ID associated with this packet type.
@@ -24,10 +22,10 @@ func (m *MsgMhfAcquireItem) Opcode() network.PacketID {
// Parse parses the packet from binary // Parse parses the packet from binary
func (m *MsgMhfAcquireItem) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error { func (m *MsgMhfAcquireItem) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error {
m.AckHandle = bf.ReadUint32() m.AckHandle = bf.ReadUint32()
m.Unk0 = bf.ReadUint16() bf.ReadUint16() // Zeroed
m.Length = bf.ReadUint16() ids := bf.ReadUint16()
for i := 0; i < int(m.Length); i++ { for i := uint16(0); i < ids; i++ {
m.Unk1 = append(m.Unk1, bf.ReadUint32()) m.RewardIDs = append(m.RewardIDs, bf.ReadUint32())
} }
return nil return nil
} }

View File

@@ -2,6 +2,7 @@ package mhfpacket
import ( import (
"errors" "errors"
"erupe-ce/common/bfutil"
"erupe-ce/common/byteframe" "erupe-ce/common/byteframe"
"erupe-ce/network" "erupe-ce/network"
"erupe-ce/network/clientctx" "erupe-ce/network/clientctx"
@@ -9,10 +10,9 @@ import (
// MsgMhfApplyCampaign represents the MSG_MHF_APPLY_CAMPAIGN // MsgMhfApplyCampaign represents the MSG_MHF_APPLY_CAMPAIGN
type MsgMhfApplyCampaign struct { type MsgMhfApplyCampaign struct {
AckHandle uint32 AckHandle uint32
Unk0 uint32 CampaignID uint32
Unk1 uint16 Code string
Unk2 []byte
} }
// Opcode returns the ID associated with this packet type. // Opcode returns the ID associated with this packet type.
@@ -23,9 +23,9 @@ func (m *MsgMhfApplyCampaign) Opcode() network.PacketID {
// Parse parses the packet from binary // Parse parses the packet from binary
func (m *MsgMhfApplyCampaign) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error { func (m *MsgMhfApplyCampaign) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error {
m.AckHandle = bf.ReadUint32() m.AckHandle = bf.ReadUint32()
m.Unk0 = bf.ReadUint32() m.CampaignID = bf.ReadUint32()
m.Unk1 = bf.ReadUint16() bf.ReadUint16() // Zeroed
m.Unk2 = bf.ReadBytes(16) m.Code = string(bfutil.UpToNull(bf.ReadBytes(16)))
return nil return nil
} }

View File

@@ -11,8 +11,6 @@ import (
// MsgMhfEnumerateItem represents the MSG_MHF_ENUMERATE_ITEM // MsgMhfEnumerateItem represents the MSG_MHF_ENUMERATE_ITEM
type MsgMhfEnumerateItem struct { type MsgMhfEnumerateItem struct {
AckHandle uint32 AckHandle uint32
Unk0 uint16
Unk1 uint16
CampaignID uint32 CampaignID uint32
} }
@@ -24,8 +22,8 @@ func (m *MsgMhfEnumerateItem) Opcode() network.PacketID {
// Parse parses the packet from binary // Parse parses the packet from binary
func (m *MsgMhfEnumerateItem) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error { func (m *MsgMhfEnumerateItem) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error {
m.AckHandle = bf.ReadUint32() m.AckHandle = bf.ReadUint32()
m.Unk0 = bf.ReadUint16() bf.ReadUint16() // Zeroed
m.Unk1 = bf.ReadUint16() bf.ReadUint16() // Always 2
m.CampaignID = bf.ReadUint32() m.CampaignID = bf.ReadUint32()
return nil return nil
} }

View File

@@ -10,9 +10,9 @@ import (
// MsgMhfStateCampaign represents the MSG_MHF_STATE_CAMPAIGN // MsgMhfStateCampaign represents the MSG_MHF_STATE_CAMPAIGN
type MsgMhfStateCampaign struct { type MsgMhfStateCampaign struct {
AckHandle uint32 AckHandle uint32
CampaignID uint32 CampaignID uint32
Unk1 uint16 NullPadding uint16
} }
// Opcode returns the ID associated with this packet type. // Opcode returns the ID associated with this packet type.
@@ -24,7 +24,7 @@ func (m *MsgMhfStateCampaign) Opcode() network.PacketID {
func (m *MsgMhfStateCampaign) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error { func (m *MsgMhfStateCampaign) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error {
m.AckHandle = bf.ReadUint32() m.AckHandle = bf.ReadUint32()
m.CampaignID = bf.ReadUint32() m.CampaignID = bf.ReadUint32()
m.Unk1 = bf.ReadUint16() m.NullPadding = bf.ReadUint16() //0 in Z2
return nil return nil
} }

View File

@@ -11,12 +11,9 @@ import (
// MsgMhfTransferItem represents the MSG_MHF_TRANSFER_ITEM // MsgMhfTransferItem represents the MSG_MHF_TRANSFER_ITEM
type MsgMhfTransferItem struct { type MsgMhfTransferItem struct {
AckHandle uint32 AckHandle uint32
// looking at packets, these were static across sessions and did not actually QuestID uint32
// correlate with any item IDs that would make sense to get after quests so ItemType uint8
// I have no idea what this actually does Quantity uint16
Unk0 uint32
Unk1 uint8
Unk2 uint16
} }
// Opcode returns the ID associated with this packet type. // Opcode returns the ID associated with this packet type.
@@ -27,10 +24,10 @@ func (m *MsgMhfTransferItem) Opcode() network.PacketID {
// Parse parses the packet from binary // Parse parses the packet from binary
func (m *MsgMhfTransferItem) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error { func (m *MsgMhfTransferItem) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error {
m.AckHandle = bf.ReadUint32() m.AckHandle = bf.ReadUint32()
m.Unk0 = bf.ReadUint32() m.QuestID = bf.ReadUint32()
m.Unk1 = bf.ReadUint8() m.ItemType = bf.ReadUint8()
bf.ReadUint8() // Zeroed bf.ReadUint8() // Zeroed
m.Unk2 = bf.ReadUint16() m.Quantity = bf.ReadUint16()
return nil return nil
} }

View File

@@ -9,55 +9,83 @@ import (
"time" "time"
) )
// CampaignEvent represents a promotional campaign event.
type CampaignEvent struct { type CampaignEvent struct {
ID uint32 ID uint32 `db:"id"`
Unk0 uint32 MinHR int16 `db:"min_hr"`
MinHR int16 MaxHR int16 `db:"max_hr"`
MaxHR int16 MinSR int16 `db:"min_sr"`
MinSR int16 MaxSR int16 `db:"max_sr"`
MaxSR int16 MinGR int16 `db:"min_gr"`
MinGR int16 MaxGR int16 `db:"max_gr"`
MaxGR int16 RewardType uint16 `db:"reward_type"`
Unk1 uint16 Stamps uint8 `db:"stamps"`
Unk2 uint8 ReceiveType uint8 `db:"receive_type"`
Unk3 uint8 BackgroundID uint16 `db:"background_id"`
Unk4 uint16 Start time.Time `db:"start_time"`
Unk5 uint16 End time.Time `db:"end_time"`
Start time.Time Title string `db:"title"`
End time.Time Reward string `db:"reward"`
Unk6 uint8 Link string `db:"link"`
String0 string Prefix string `db:"code_prefix"`
String1 string
String2 string
String3 string
Link string
Prefix string
Categories []uint16
} }
// CampaignCategory represents a category grouping for campaign events.
type CampaignCategory struct { type CampaignCategory struct {
ID uint16 ID uint16 `db:"id"`
Type uint8 Type uint8 `db:"type"`
Title string Title string `db:"title"`
Description string Description string `db:"description"`
} }
// CampaignLink links a campaign event to its items/rewards.
type CampaignLink struct { type CampaignLink struct {
CategoryID uint16 CategoryID uint16 `db:"category_id"`
CampaignID uint32 CampaignID uint32 `db:"campaign_id"`
}
type CampaignReward struct {
ID uint32 `db:"id"`
ItemType uint16 `db:"item_type"`
Quantity uint16 `db:"quantity"`
ItemID uint16 `db:"item_id"`
Deadline time.Time `db:"deadline"`
}
// campaignRequiredStamps returns the stamp requirement for a campaign,
// clamping to a minimum of 1. Campaigns with 0 stamps in the DB are
// treated as requiring a single stamp (code redemption) to unlock.
func campaignRequiredStamps(stamps int) int {
if stamps < 1 {
return 1
}
return stamps
} }
func handleMsgMhfEnumerateCampaign(s *Session, p mhfpacket.MHFPacket) { func handleMsgMhfEnumerateCampaign(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfEnumerateCampaign) pkt := p.(*mhfpacket.MsgMhfEnumerateCampaign)
if s.server.db == nil {
doAckBufFail(s, pkt.AckHandle, make([]byte, 4))
return
}
bf := byteframe.NewByteFrame() bf := byteframe.NewByteFrame()
events := []CampaignEvent{} var events []CampaignEvent
categories := []CampaignCategory{} var categories []CampaignCategory
var campaignLinks []CampaignLink var campaignLinks []CampaignLink
err := s.server.db.Select(&events, "SELECT id,min_hr,max_hr,min_sr,max_sr,min_gr,max_gr,reward_type,stamps,receive_type,background_id,start_time,end_time,title,reward,link,code_prefix FROM campaigns")
if err != nil {
doAckBufFail(s, pkt.AckHandle, make([]byte, 4))
return
}
err = s.server.db.Select(&categories, "SELECT id, type, title, description FROM campaign_categories")
if err != nil {
doAckBufFail(s, pkt.AckHandle, make([]byte, 4))
return
}
err = s.server.db.Select(&campaignLinks, "SELECT campaign_id, category_id FROM campaign_category_links")
if err != nil {
doAckBufFail(s, pkt.AckHandle, make([]byte, 4))
return
}
if len(events) > 255 { if len(events) > 255 {
bf.WriteUint8(255) bf.WriteUint8(255)
bf.WriteUint16(uint16(len(events))) bf.WriteUint16(uint16(len(events)))
@@ -66,7 +94,7 @@ func handleMsgMhfEnumerateCampaign(s *Session, p mhfpacket.MHFPacket) {
} }
for _, event := range events { for _, event := range events {
bf.WriteUint32(event.ID) bf.WriteUint32(event.ID)
bf.WriteUint32(event.Unk0) bf.WriteUint32(0)
bf.WriteInt16(event.MinHR) bf.WriteInt16(event.MinHR)
bf.WriteInt16(event.MaxHR) bf.WriteInt16(event.MaxHR)
bf.WriteInt16(event.MinSR) bf.WriteInt16(event.MinSR)
@@ -75,34 +103,19 @@ func handleMsgMhfEnumerateCampaign(s *Session, p mhfpacket.MHFPacket) {
bf.WriteInt16(event.MinGR) bf.WriteInt16(event.MinGR)
bf.WriteInt16(event.MaxGR) bf.WriteInt16(event.MaxGR)
} }
bf.WriteUint16(event.Unk1) bf.WriteUint16(event.RewardType)
bf.WriteUint8(event.Unk2) bf.WriteUint8(event.Stamps)
bf.WriteUint8(event.Unk3) bf.WriteUint8(event.ReceiveType)
bf.WriteUint16(event.Unk4) bf.WriteUint16(event.BackgroundID)
bf.WriteUint16(event.Unk5) bf.WriteUint16(0)
bf.WriteUint32(uint32(event.Start.Unix())) bf.WriteUint32(uint32(event.Start.Unix()))
bf.WriteUint32(uint32(event.End.Unix())) bf.WriteUint32(uint32(event.End.Unix()))
bf.WriteUint8(event.Unk6) bf.WriteBool(event.End.Before(time.Now()))
ps.Uint8(bf, event.String0, true) ps.Uint8(bf, event.Title, true)
ps.Uint8(bf, event.String1, true) ps.Uint8(bf, event.Reward, true)
ps.Uint8(bf, event.String2, true) ps.Uint8(bf, event.Prefix, true)
ps.Uint8(bf, event.String3, true) ps.Uint8(bf, "", false)
ps.Uint8(bf, event.Link, true) ps.Uint8(bf, event.Link, true)
for i := range event.Categories {
campaignLinks = append(campaignLinks, CampaignLink{event.Categories[i], event.ID})
}
}
if len(events) > 255 {
bf.WriteUint8(255)
bf.WriteUint16(uint16(len(events)))
} else {
bf.WriteUint8(uint8(len(events)))
}
for _, event := range events {
bf.WriteUint32(event.ID)
bf.WriteUint8(1) // Always 1?
bf.WriteBytes([]byte(event.Prefix))
} }
if len(categories) > 255 { if len(categories) > 255 {
@@ -137,43 +150,185 @@ func handleMsgMhfEnumerateCampaign(s *Session, p mhfpacket.MHFPacket) {
func handleMsgMhfStateCampaign(s *Session, p mhfpacket.MHFPacket) { func handleMsgMhfStateCampaign(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfStateCampaign) pkt := p.(*mhfpacket.MsgMhfStateCampaign)
if s.server.db == nil {
doAckBufFail(s, pkt.AckHandle, make([]byte, 4))
return
}
bf := byteframe.NewByteFrame() bf := byteframe.NewByteFrame()
bf.WriteUint16(1) var required int
bf.WriteUint16(0) var deadline time.Time
var stamps []uint32
err := s.server.db.Select(&stamps, "SELECT id FROM campaign_state WHERE campaign_id = $1 AND character_id = $2", pkt.CampaignID, s.charID)
if err != nil {
doAckBufFail(s, pkt.AckHandle, make([]byte, 4))
return
}
err = s.server.db.QueryRow(`SELECT stamps, end_time FROM campaigns WHERE id = $1`, pkt.CampaignID).Scan(&required, &deadline)
if err != nil {
doAckBufFail(s, pkt.AckHandle, make([]byte, 4))
return
}
bf.WriteUint16(uint16(len(stamps)))
required = campaignRequiredStamps(required)
if len(stamps) >= required && deadline.After(time.Now()) {
bf.WriteUint16(2)
} else {
bf.WriteUint16(0)
}
for _, v := range stamps {
bf.WriteUint32(v)
}
doAckBufSucceed(s, pkt.AckHandle, bf.Data()) doAckBufSucceed(s, pkt.AckHandle, bf.Data())
} }
func handleMsgMhfApplyCampaign(s *Session, p mhfpacket.MHFPacket) { func handleMsgMhfApplyCampaign(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfApplyCampaign) pkt := p.(*mhfpacket.MsgMhfApplyCampaign)
bf := byteframe.NewByteFrame() if s.server.db == nil {
bf.WriteUint32(1) doAckSimpleFail(s, pkt.AckHandle, make([]byte, 4))
doAckSimpleSucceed(s, pkt.AckHandle, bf.Data()) return
}
// Check if the code exists, belongs to this campaign, and check if it's a multi-code
var multi bool
err := s.server.db.QueryRow(`SELECT multi FROM public.campaign_codes WHERE code = $1 AND campaign_id = $2`, pkt.Code, pkt.CampaignID).Scan(&multi)
if err != nil {
doAckSimpleFail(s, pkt.AckHandle, make([]byte, 4))
return
}
// Check if the code is already used
var exists bool
if multi {
err = s.server.db.QueryRow(`SELECT COUNT(*) > 0 FROM public.campaign_state WHERE code = $1 AND character_id = $2`, pkt.Code, s.charID).Scan(&exists)
} else {
err = s.server.db.QueryRow(`SELECT COUNT(*) > 0 FROM public.campaign_state WHERE code = $1`, pkt.Code).Scan(&exists)
}
if err != nil || exists {
doAckSimpleFail(s, pkt.AckHandle, make([]byte, 4))
return
}
_, err = s.server.db.Exec(`INSERT INTO public.campaign_state (code, campaign_id, character_id) VALUES ($1, $2, $3)`, pkt.Code, pkt.CampaignID, s.charID)
if err != nil {
doAckSimpleFail(s, pkt.AckHandle, make([]byte, 4))
return
}
doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
} }
func handleMsgMhfEnumerateItem(s *Session, p mhfpacket.MHFPacket) { func handleMsgMhfEnumerateItem(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfEnumerateItem) pkt := p.(*mhfpacket.MsgMhfEnumerateItem)
items := []struct { if s.server.db == nil {
Unk0 uint32 doAckBufFail(s, pkt.AckHandle, make([]byte, 4))
Unk1 uint16 return
Unk2 uint16 }
Unk3 uint16 bf := byteframe.NewByteFrame()
Unk4 uint32
Unk5 uint32 var stamps, required, rewardType uint16
}{} err := s.server.db.QueryRow(`SELECT COUNT(*) FROM campaign_state WHERE campaign_id = $1 AND character_id = $2`, pkt.CampaignID, s.charID).Scan(&stamps)
bf := byteframe.NewByteFrame() if err != nil {
bf.WriteUint16(uint16(len(items))) doAckBufFail(s, pkt.AckHandle, make([]byte, 4))
for _, item := range items { return
bf.WriteUint32(item.Unk0) }
bf.WriteUint16(item.Unk1) err = s.server.db.QueryRow(`SELECT stamps, reward_type FROM campaigns WHERE id = $1`, pkt.CampaignID).Scan(&required, &rewardType)
bf.WriteUint16(item.Unk2) if err != nil {
bf.WriteUint16(item.Unk3) doAckBufFail(s, pkt.AckHandle, make([]byte, 4))
bf.WriteUint32(item.Unk4) return
bf.WriteUint32(item.Unk5) }
required = uint16(campaignRequiredStamps(int(required)))
if stamps >= required {
var items []CampaignReward
if rewardType == 2 {
var exists int
err = s.server.db.QueryRow(`SELECT COUNT(*) FROM campaign_quest WHERE campaign_id = $1 AND character_id = $2`, pkt.CampaignID, s.charID).Scan(&exists)
if err != nil {
doAckBufFail(s, pkt.AckHandle, make([]byte, 4))
return
}
if exists > 0 {
err = s.server.db.Select(&items, `
SELECT id, item_type, quantity, item_id, TO_TIMESTAMP(0) AS deadline FROM campaign_rewards
WHERE campaign_id = $1 AND item_type != 9
AND NOT EXISTS (SELECT 1 FROM campaign_rewards_claimed WHERE reward_id = campaign_rewards.id AND character_id = $2)
`, pkt.CampaignID, s.charID)
} else {
err = s.server.db.Select(&items, `
SELECT cr.id, cr.item_type, cr.quantity, cr.item_id, COALESCE(c.end_time, TO_TIMESTAMP(0)) AS deadline FROM campaign_rewards cr
JOIN campaigns c ON cr.campaign_id = c.id
WHERE campaign_id = $1 AND item_type = 9`, pkt.CampaignID)
}
} else {
err = s.server.db.Select(&items, `
SELECT id, item_type, quantity, item_id, TO_TIMESTAMP(0) AS deadline FROM campaign_rewards
WHERE campaign_id = $1
AND NOT EXISTS (SELECT 1 FROM campaign_rewards_claimed WHERE reward_id = campaign_rewards.id AND character_id = $2)
`, pkt.CampaignID, s.charID)
}
if err != nil {
doAckBufFail(s, pkt.AckHandle, make([]byte, 4))
return
}
bf.WriteUint16(uint16(len(items)))
for _, item := range items {
bf.WriteUint32(item.ID)
bf.WriteUint16(item.ItemType)
bf.WriteUint16(item.Quantity)
bf.WriteUint16(item.ItemID) //HACK:placed quest id in this field to fit with Item No pattern. however it could be another field... possibly the other unks.
bf.WriteUint16(0) //Unk4, gets cast to uint8
bf.WriteUint32(0) //Unk5
bf.WriteUint32(uint32(item.Deadline.Unix()))
}
if len(items) == 0 {
doAckBufSucceed(s, pkt.AckHandle, make([]byte, 4))
} else {
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
}
} else {
doAckBufSucceed(s, pkt.AckHandle, make([]byte, 4))
} }
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
} }
func handleMsgMhfAcquireItem(s *Session, p mhfpacket.MHFPacket) { func handleMsgMhfAcquireItem(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfAcquireItem) pkt := p.(*mhfpacket.MsgMhfAcquireItem)
if s.server.db == nil {
doAckSimpleFail(s, pkt.AckHandle, make([]byte, 4))
return
}
for _, id := range pkt.RewardIDs {
_, err := s.server.db.Exec(`INSERT INTO campaign_rewards_claimed (reward_id, character_id) VALUES ($1, $2)`, id, s.charID)
if err != nil {
doAckSimpleFail(s, pkt.AckHandle, make([]byte, 4))
return
}
}
doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
}
func handleMsgMhfTransferItem(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfTransferItem)
if s.server.db == nil {
doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
return
}
if pkt.ItemType == 9 {
var campaignID uint32
err := s.server.db.QueryRow(`
SELECT ce.campaign_id FROM campaign_rewards ce
JOIN event_quests eq ON ce.item_id = eq.quest_id
WHERE eq.id = $1
`, pkt.QuestID).Scan(&campaignID)
if err == nil {
_, err = s.server.db.Exec(`INSERT INTO campaign_quest (campaign_id, character_id) VALUES ($1, $2)`, campaignID, s.charID)
if err != nil {
doAckSimpleFail(s, pkt.AckHandle, make([]byte, 4))
return
}
}
}
doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4)) doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
} }

View File

@@ -9,11 +9,6 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
) )
func handleMsgMhfTransferItem(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfTransferItem)
doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00})
}
func handleMsgMhfEnumeratePrice(s *Session, p mhfpacket.MHFPacket) { func handleMsgMhfEnumeratePrice(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfEnumeratePrice) pkt := p.(*mhfpacket.MsgMhfEnumeratePrice)
bf := byteframe.NewByteFrame() bf := byteframe.NewByteFrame()

View File

@@ -313,7 +313,34 @@ func makeEventQuest(s *Session, eq EventQuest) ([]byte, error) {
} }
bf.WriteUint8(eq.QuestType) bf.WriteUint8(eq.QuestType)
if eq.QuestType == QuestTypeSpecialTool { if eq.QuestType == QuestTypeSpecialTool {
bf.WriteBool(false) var stamps, required int
var deadline time.Time
err := s.server.db.QueryRow(`SELECT COUNT(*) FROM campaign_state WHERE campaign_id = (
SELECT campaign_id
FROM campaign_rewards
WHERE item_type = 9
AND item_id = $1
LIMIT 1
) AND character_id = $2`, eq.QuestID, s.charID).Scan(&stamps)
if err != nil {
bf.WriteBool(false)
} else {
err = s.server.db.QueryRow(`SELECT stamps, end_time
FROM campaigns
WHERE id = (
SELECT campaign_id
FROM campaign_rewards
WHERE item_type = 9
AND item_id = $1
LIMIT 1
)`, eq.QuestID).Scan(&required, &deadline)
required = campaignRequiredStamps(required)
if err == nil && stamps >= required && deadline.After(time.Now()) {
bf.WriteBool(true)
} else {
bf.WriteBool(false)
}
}
} else { } else {
bf.WriteBool(true) bf.WriteBool(true)
} }

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,69 @@
BEGIN;
CREATE TABLE IF NOT EXISTS public.campaigns (
id INTEGER PRIMARY KEY,
min_hr INTEGER,
max_hr INTEGER,
min_sr INTEGER,
max_sr INTEGER,
min_gr INTEGER,
max_gr INTEGER,
reward_type INTEGER,
stamps INTEGER,
receive_type INTEGER,
background_id INTEGER,
start_time TIMESTAMP WITH TIME ZONE,
end_time TIMESTAMP WITH TIME ZONE,
title TEXT,
reward TEXT,
link TEXT,
code_prefix TEXT
);
CREATE TABLE IF NOT EXISTS public.campaign_categories (
id SERIAL PRIMARY KEY,
type INTEGER,
title TEXT,
description TEXT
);
CREATE TABLE IF NOT EXISTS public.campaign_category_links (
id SERIAL PRIMARY KEY,
campaign_id INTEGER REFERENCES public.campaigns(id) ON DELETE CASCADE,
category_id INTEGER REFERENCES public.campaign_categories(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS public.campaign_rewards (
id SERIAL PRIMARY KEY,
campaign_id INTEGER REFERENCES public.campaigns(id) ON DELETE CASCADE,
item_type INTEGER,
quantity INTEGER,
item_id INTEGER
);
CREATE TABLE IF NOT EXISTS public.campaign_rewards_claimed (
character_id INTEGER REFERENCES public.characters(id) ON DELETE CASCADE,
reward_id INTEGER REFERENCES public.campaign_rewards(id) ON DELETE CASCADE,
PRIMARY KEY (character_id, reward_id)
);
CREATE TABLE IF NOT EXISTS public.campaign_state (
id SERIAL PRIMARY KEY,
campaign_id INTEGER REFERENCES public.campaigns(id) ON DELETE CASCADE,
character_id INTEGER REFERENCES public.characters(id) ON DELETE CASCADE,
code TEXT
);
CREATE TABLE IF NOT EXISTS public.campaign_codes (
code TEXT PRIMARY KEY,
campaign_id INTEGER REFERENCES public.campaigns(id) ON DELETE CASCADE,
multi BOOLEAN NOT NULL DEFAULT FALSE
);
CREATE TABLE IF NOT EXISTS public.campaign_quest (
campaign_id INTEGER REFERENCES public.campaigns(id) ON DELETE CASCADE,
character_id INTEGER REFERENCES public.characters(id) ON DELETE CASCADE,
PRIMARY KEY (campaign_id, character_id)
);
END;