mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-13 15:34:38 +01:00
track etc points
This commit is contained in:
@@ -3,16 +3,16 @@ package mhfpacket
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"erupe-ce/network/clientctx"
|
|
||||||
"erupe-ce/network"
|
|
||||||
"erupe-ce/common/byteframe"
|
"erupe-ce/common/byteframe"
|
||||||
|
"erupe-ce/network"
|
||||||
|
"erupe-ce/network/clientctx"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MsgMhfUpdateEtcPoint represents the MSG_MHF_UPDATE_ETC_POINT
|
// MsgMhfUpdateEtcPoint represents the MSG_MHF_UPDATE_ETC_POINT
|
||||||
type MsgMhfUpdateEtcPoint struct {
|
type MsgMhfUpdateEtcPoint struct {
|
||||||
AckHandle uint32
|
AckHandle uint32
|
||||||
Unk0 uint8
|
PointType uint8
|
||||||
Unk1 uint16
|
Delta int16
|
||||||
}
|
}
|
||||||
|
|
||||||
// Opcode returns the ID associated with this packet type.
|
// 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
|
// Parse parses the packet from binary
|
||||||
func (m *MsgMhfUpdateEtcPoint) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error {
|
func (m *MsgMhfUpdateEtcPoint) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error {
|
||||||
m.AckHandle = bf.ReadUint32()
|
m.AckHandle = bf.ReadUint32()
|
||||||
m.Unk0 = bf.ReadUint8()
|
m.PointType = bf.ReadUint8()
|
||||||
m.Unk1 = bf.ReadUint16()
|
m.Delta = bf.ReadInt16()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
9
patch-schema/etc-points.sql
Normal file
9
patch-schema/etc-points.sql
Normal 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;
|
||||||
@@ -1502,18 +1502,45 @@ func handleMsgMhfInfoScenarioCounter(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
func handleMsgMhfGetEtcPoints(s *Session, p mhfpacket.MHFPacket) {
|
func handleMsgMhfGetEtcPoints(s *Session, p mhfpacket.MHFPacket) {
|
||||||
pkt := p.(*mhfpacket.MsgMhfGetEtcPoints)
|
pkt := p.(*mhfpacket.MsgMhfGetEtcPoints)
|
||||||
|
|
||||||
resp := byteframe.NewByteFrame()
|
var dailyTime time.Time
|
||||||
resp.WriteUint8(0x3) // Maybe a count of uint32(s)?
|
_ = 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)
|
||||||
resp.WriteUint32(0) // Point bonus quests
|
if Time_Current_Adjusted().After(dailyTime) {
|
||||||
resp.WriteUint32(0) // Daily quests
|
s.server.db.Exec("UPDATE characters SET bonus_quests = 0, daily_quests = 0 WHERE id=$1", s.charID)
|
||||||
resp.WriteUint32(0) // HS promotion points
|
}
|
||||||
|
|
||||||
|
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())
|
doAckBufSucceed(s, pkt.AckHandle, resp.Data())
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleMsgMhfUpdateEtcPoint(s *Session, p mhfpacket.MHFPacket) {
|
func handleMsgMhfUpdateEtcPoint(s *Session, p mhfpacket.MHFPacket) {
|
||||||
pkt := p.(*mhfpacket.MsgMhfUpdateEtcPoint)
|
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) {
|
func handleMsgMhfStampcardStamp(s *Session, p mhfpacket.MHFPacket) {
|
||||||
|
|||||||
@@ -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))
|
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()
|
bf := byteframe.NewByteFrame()
|
||||||
if t.After(dailyTime) {
|
if t.After(dailyTime) {
|
||||||
addPointNetcafe(s, 5)
|
addPointNetcafe(s, 5)
|
||||||
s.server.db.Exec("UPDATE characters SET daily_time=$1 WHERE id=$2", midday, s.charID)
|
|
||||||
bf.WriteBool(true) // Success?
|
|
||||||
bondBonus = 5 // Bond point bonus quests
|
bondBonus = 5 // Bond point bonus quests
|
||||||
pointBonus = 3 // HRP bonus quests?
|
bonusQuests = 3 // HRP bonus quests?
|
||||||
dailyQuests = 1 // Daily 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?
|
||||||
} else {
|
} else {
|
||||||
bf.WriteBool(false)
|
bf.WriteBool(false)
|
||||||
}
|
}
|
||||||
bf.WriteUint32(bondBonus)
|
bf.WriteUint32(bondBonus)
|
||||||
bf.WriteUint32(pointBonus)
|
bf.WriteUint32(bonusQuests)
|
||||||
bf.WriteUint32(dailyQuests)
|
bf.WriteUint32(dailyQuests)
|
||||||
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
|
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user