track etc points

This commit is contained in:
wish
2023-01-22 15:16:00 +11:00
parent 605b247f21
commit 7bede20f38
4 changed files with 56 additions and 20 deletions

View File

@@ -1,18 +1,18 @@
package mhfpacket
import (
"errors"
import (
"errors"
"erupe-ce/network/clientctx"
"erupe-ce/network"
"erupe-ce/common/byteframe"
"erupe-ce/network"
"erupe-ce/network/clientctx"
)
// MsgMhfUpdateEtcPoint represents the MSG_MHF_UPDATE_ETC_POINT
type MsgMhfUpdateEtcPoint struct {
AckHandle uint32
Unk0 uint8
Unk1 uint16
PointType uint8
Delta int16
}
// Opcode returns the ID associated with this packet type.
@@ -23,8 +23,8 @@ func (m *MsgMhfUpdateEtcPoint) Opcode() network.PacketID {
// Parse parses the packet from binary
func (m *MsgMhfUpdateEtcPoint) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error {
m.AckHandle = bf.ReadUint32()
m.Unk0 = bf.ReadUint8()
m.Unk1 = bf.ReadUint16()
m.PointType = bf.ReadUint8()
m.Delta = bf.ReadInt16()
return nil
}

View File

@@ -0,0 +1,9 @@
BEGIN;
ALTER TABLE characters ADD bonus_quests INT NOT NULL DEFAULT 0;
ALTER TABLE characters ADD daily_quests INT NOT NULL DEFAULT 0;
ALTER TABLE characters ADD promo_points INT NOT NULL DEFAULT 0;
END;

View File

@@ -1502,18 +1502,45 @@ func handleMsgMhfInfoScenarioCounter(s *Session, p mhfpacket.MHFPacket) {
func handleMsgMhfGetEtcPoints(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfGetEtcPoints)
resp := byteframe.NewByteFrame()
resp.WriteUint8(0x3) // Maybe a count of uint32(s)?
resp.WriteUint32(0) // Point bonus quests
resp.WriteUint32(0) // Daily quests
resp.WriteUint32(0) // HS promotion points
var dailyTime time.Time
_ = s.server.db.QueryRow("SELECT COALESCE(daily_time, $2) FROM characters WHERE id = $1", s.charID, time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC)).Scan(&dailyTime)
if Time_Current_Adjusted().After(dailyTime) {
s.server.db.Exec("UPDATE characters SET bonus_quests = 0, daily_quests = 0 WHERE id=$1", s.charID)
}
var bonusQuests, dailyQuests, promoPoints uint32
_ = s.server.db.QueryRow(`SELECT bonus_quests, daily_quests, promo_points FROM characters WHERE id = $1`, s.charID).Scan(&bonusQuests, &dailyQuests, &promoPoints)
resp := byteframe.NewByteFrame()
resp.WriteUint8(3) // Maybe a count of uint32(s)?
resp.WriteUint32(bonusQuests)
resp.WriteUint32(dailyQuests)
resp.WriteUint32(promoPoints)
doAckBufSucceed(s, pkt.AckHandle, resp.Data())
}
func handleMsgMhfUpdateEtcPoint(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfUpdateEtcPoint)
doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})
var column string
switch pkt.PointType {
case 0:
column = "bonus_quests"
case 1:
column = "daily_quests"
case 2:
column = "promo_points"
}
var value int
err := s.server.db.QueryRow(fmt.Sprintf(`SELECT %s FROM characters WHERE id = $1`, column), s.charID).Scan(&value)
if err == nil {
if value-int(pkt.Delta) < 0 {
s.server.db.Exec(fmt.Sprintf(`UPDATE characters SET %s = 0 WHERE id = $1`, column), s.charID)
} else {
s.server.db.Exec(fmt.Sprintf(`UPDATE characters SET %s = %s + $1 WHERE id = $2`, column, column), pkt.Delta, s.charID)
}
}
doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
}
func handleMsgMhfStampcardStamp(s *Session, p mhfpacket.MHFPacket) {

View File

@@ -52,20 +52,20 @@ func handleMsgMhfCheckDailyCafepoint(s *Session, p mhfpacket.MHFPacket) {
s.logger.Fatal("Failed to get daily_time savedata from db", zap.Error(err))
}
var bondBonus, pointBonus, dailyQuests uint32
var bondBonus, bonusQuests, dailyQuests uint32
bf := byteframe.NewByteFrame()
if t.After(dailyTime) {
addPointNetcafe(s, 5)
s.server.db.Exec("UPDATE characters SET daily_time=$1 WHERE id=$2", midday, s.charID)
bondBonus = 5 // Bond point bonus quests
bonusQuests = 3 // HRP bonus quests?
dailyQuests = 1 // Daily quests
s.server.db.Exec("UPDATE characters SET daily_time=$1, bonus_quests = $2, daily_quests = $3 WHERE id=$4", midday, bonusQuests, dailyQuests, s.charID)
bf.WriteBool(true) // Success?
bondBonus = 5 // Bond point bonus quests
pointBonus = 3 // HRP bonus quests?
dailyQuests = 1 // Daily quests
} else {
bf.WriteBool(false)
}
bf.WriteUint32(bondBonus)
bf.WriteUint32(pointBonus)
bf.WriteUint32(bonusQuests)
bf.WriteUint32(dailyQuests)
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
}