mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-13 07:25:03 +01:00
implement netcafe points and boost time
This commit is contained in:
@@ -11,8 +11,7 @@ import (
|
|||||||
// MsgMhfPostCafeDurationBonusReceived represents the MSG_MHF_POST_CAFE_DURATION_BONUS_RECEIVED
|
// MsgMhfPostCafeDurationBonusReceived represents the MSG_MHF_POST_CAFE_DURATION_BONUS_RECEIVED
|
||||||
type MsgMhfPostCafeDurationBonusReceived struct {
|
type MsgMhfPostCafeDurationBonusReceived struct {
|
||||||
AckHandle uint32
|
AckHandle uint32
|
||||||
Unk0 uint32
|
CafeBonusID []uint32
|
||||||
CafeBonusID uint32
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Opcode returns the ID associated with this packet type.
|
// Opcode returns the ID associated with this packet type.
|
||||||
@@ -23,8 +22,10 @@ func (m *MsgMhfPostCafeDurationBonusReceived) Opcode() network.PacketID {
|
|||||||
// Parse parses the packet from binary
|
// Parse parses the packet from binary
|
||||||
func (m *MsgMhfPostCafeDurationBonusReceived) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error {
|
func (m *MsgMhfPostCafeDurationBonusReceived) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error {
|
||||||
m.AckHandle = bf.ReadUint32()
|
m.AckHandle = bf.ReadUint32()
|
||||||
m.Unk0 = bf.ReadUint32()
|
ids := int(bf.ReadUint32())
|
||||||
m.CafeBonusID = bf.ReadUint32()
|
for i := 0; i < ids; i++ {
|
||||||
|
m.CafeBonusID = append(m.CafeBonusID, bf.ReadUint32())
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,16 @@
|
|||||||
BEGIN;
|
BEGIN;
|
||||||
|
|
||||||
ALTER TABLE IF EXISTS public.characters
|
ALTER TABLE IF EXISTS public.characters
|
||||||
ADD COLUMN cafe_time integer DEFAULT 0;
|
ADD COLUMN IF NOT EXISTS cafe_time integer DEFAULT 0;
|
||||||
|
|
||||||
|
ALTER TABLE IF EXISTS public.characters
|
||||||
|
DROP COLUMN IF EXISTS netcafe_points;
|
||||||
|
|
||||||
|
ALTER TABLE IF EXISTS public.characters
|
||||||
|
ADD COLUMN IF NOT EXISTS netcafe_points int DEFAULT 0;
|
||||||
|
|
||||||
|
ALTER TABLE IF EXISTS public.characters
|
||||||
|
ADD COLUMN IF NOT EXISTS boost_time timestamp without time zone;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS public.cafebonus
|
CREATE TABLE IF NOT EXISTS public.cafebonus
|
||||||
(
|
(
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ func handleMsgMhfUpdateCafepoint(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
s.logger.Fatal("Failed to get netcate points from db", zap.Error(err))
|
s.logger.Fatal("Failed to get netcate points from db", zap.Error(err))
|
||||||
}
|
}
|
||||||
resp := byteframe.NewByteFrame()
|
resp := byteframe.NewByteFrame()
|
||||||
resp.WriteUint32(0)
|
|
||||||
resp.WriteUint32(netcafePoints)
|
resp.WriteUint32(netcafePoints)
|
||||||
doAckSimpleSucceed(s, pkt.AckHandle, resp.Data())
|
doAckSimpleSucceed(s, pkt.AckHandle, resp.Data())
|
||||||
}
|
}
|
||||||
@@ -58,7 +57,7 @@ func handleMsgMhfCheckDailyCafepoint(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
|
|
||||||
if t.After(dailyTime) {
|
if t.After(dailyTime) {
|
||||||
// +5 netcafe points and setting next valid window
|
// +5 netcafe points and setting next valid window
|
||||||
_, err := s.server.db.Exec("UPDATE characters SET daily_time=$1, netcafe_points=netcafe_points::int + 5 WHERE id=$2", midday, s.charID)
|
_, err := s.server.db.Exec("UPDATE characters SET daily_time=$1, netcafe_points=netcafe_points+5 WHERE id=$2", midday, s.charID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.Fatal("Failed to update daily_time and netcafe_points savedata in db", zap.Error(err))
|
s.logger.Fatal("Failed to update daily_time and netcafe_points savedata in db", zap.Error(err))
|
||||||
}
|
}
|
||||||
@@ -172,16 +171,69 @@ func handleMsgMhfReceiveCafeDurationBonus(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
|
|
||||||
func handleMsgMhfPostCafeDurationBonusReceived(s *Session, p mhfpacket.MHFPacket) {
|
func handleMsgMhfPostCafeDurationBonusReceived(s *Session, p mhfpacket.MHFPacket) {
|
||||||
pkt := p.(*mhfpacket.MsgMhfPostCafeDurationBonusReceived)
|
pkt := p.(*mhfpacket.MsgMhfPostCafeDurationBonusReceived)
|
||||||
|
var cafeBonus CafeBonus
|
||||||
_, err := s.server.db.Exec("INSERT INTO public.cafe_accepted VALUES ($1, $2)", pkt.CafeBonusID, s.charID)
|
for _, cbID := range pkt.CafeBonusID {
|
||||||
if err != nil {
|
err := s.server.db.QueryRow(`
|
||||||
s.logger.Error("Error updating accepted CafeBonus count", zap.Error(err))
|
SELECT cb.id, item_type, quantity FROM cafebonus cb WHERE cb.id=$1
|
||||||
|
`, cbID).Scan(&cafeBonus.ID, &cafeBonus.ItemType, &cafeBonus.Quantity)
|
||||||
|
if err == nil {
|
||||||
|
if cafeBonus.ItemType == 17 {
|
||||||
|
s.server.db.Exec("UPDATE characters SET netcafe_points=netcafe_points+$1 WHERE id=$2", cafeBonus.Quantity, s.charID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s.server.db.Exec("INSERT INTO public.cafe_accepted VALUES ($1, $2)", cbID, s.charID)
|
||||||
}
|
}
|
||||||
|
|
||||||
doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
|
doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleMsgMhfStartBoostTime(s *Session, p mhfpacket.MHFPacket) {
|
func handleMsgMhfStartBoostTime(s *Session, p mhfpacket.MHFPacket) {
|
||||||
pkt := p.(*mhfpacket.MsgMhfStartBoostTime)
|
pkt := p.(*mhfpacket.MsgMhfStartBoostTime)
|
||||||
|
bf := byteframe.NewByteFrame()
|
||||||
|
boostLimit := Time_Current_Adjusted().Add(100 * time.Minute)
|
||||||
|
s.server.db.Exec("UPDATE characters SET boost_time=$1 WHERE id=$2", boostLimit, s.charID)
|
||||||
|
bf.WriteUint32(uint32(boostLimit.Unix()))
|
||||||
|
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleMsgMhfGetBoostTime(s *Session, p mhfpacket.MHFPacket) {
|
||||||
|
pkt := p.(*mhfpacket.MsgMhfGetBoostTime)
|
||||||
|
doAckBufSucceed(s, pkt.AckHandle, []byte{})
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleMsgMhfGetBoostTimeLimit(s *Session, p mhfpacket.MHFPacket) {
|
||||||
|
pkt := p.(*mhfpacket.MsgMhfGetBoostTimeLimit)
|
||||||
|
bf := byteframe.NewByteFrame()
|
||||||
|
var boostLimit time.Time
|
||||||
|
err := s.server.db.QueryRow("SELECT boost_time FROM characters WHERE id=$1", s.charID).Scan(&boostLimit)
|
||||||
|
if err != nil {
|
||||||
|
bf.WriteUint32(0)
|
||||||
|
} else {
|
||||||
|
bf.WriteUint32(uint32(boostLimit.Unix()))
|
||||||
|
}
|
||||||
|
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
|
||||||
doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
|
doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handleMsgMhfGetBoostRight(s *Session, p mhfpacket.MHFPacket) {
|
||||||
|
pkt := p.(*mhfpacket.MsgMhfGetBoostRight)
|
||||||
|
var boostLimit time.Time
|
||||||
|
err := s.server.db.QueryRow("SELECT boost_time FROM characters WHERE id=$1", s.charID).Scan(&boostLimit)
|
||||||
|
if err != nil {
|
||||||
|
doAckBufSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if boostLimit.Unix() < Time_Current_Adjusted().Unix() {
|
||||||
|
doAckBufSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x02})
|
||||||
|
} else {
|
||||||
|
doAckBufSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x01})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleMsgMhfPostBoostTimeQuestReturn(s *Session, p mhfpacket.MHFPacket) {
|
||||||
|
pkt := p.(*mhfpacket.MsgMhfPostBoostTimeQuestReturn)
|
||||||
|
doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00})
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleMsgMhfPostBoostTime(s *Session, p mhfpacket.MHFPacket) {}
|
||||||
|
|
||||||
|
func handleMsgMhfPostBoostTimeLimit(s *Session, p mhfpacket.MHFPacket) {}
|
||||||
|
|||||||
@@ -303,32 +303,6 @@ func handleMsgMhfGetUdInfo(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
doAckBufSucceed(s, pkt.AckHandle, resp.Data())
|
doAckBufSucceed(s, pkt.AckHandle, resp.Data())
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleMsgMhfGetBoostTime(s *Session, p mhfpacket.MHFPacket) {
|
|
||||||
pkt := p.(*mhfpacket.MsgMhfGetBoostTime)
|
|
||||||
|
|
||||||
doAckBufSucceed(s, pkt.AckHandle, []byte{})
|
|
||||||
updateRights(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleMsgMhfGetBoostTimeLimit(s *Session, p mhfpacket.MHFPacket) {
|
|
||||||
pkt := p.(*mhfpacket.MsgMhfGetBoostTimeLimit)
|
|
||||||
doAckBufSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00})
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleMsgMhfGetBoostRight(s *Session, p mhfpacket.MHFPacket) {
|
|
||||||
pkt := p.(*mhfpacket.MsgMhfGetBoostRight)
|
|
||||||
doAckBufSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00})
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleMsgMhfPostBoostTimeQuestReturn(s *Session, p mhfpacket.MHFPacket) {
|
|
||||||
pkt := p.(*mhfpacket.MsgMhfPostBoostTimeQuestReturn)
|
|
||||||
doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00})
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleMsgMhfPostBoostTime(s *Session, p mhfpacket.MHFPacket) {}
|
|
||||||
|
|
||||||
func handleMsgMhfPostBoostTimeLimit(s *Session, p mhfpacket.MHFPacket) {}
|
|
||||||
|
|
||||||
func handleMsgMhfGetRestrictionEvent(s *Session, p mhfpacket.MHFPacket) {}
|
func handleMsgMhfGetRestrictionEvent(s *Session, p mhfpacket.MHFPacket) {}
|
||||||
|
|
||||||
func handleMsgMhfSetRestrictionEvent(s *Session, p mhfpacket.MHFPacket) {
|
func handleMsgMhfSetRestrictionEvent(s *Session, p mhfpacket.MHFPacket) {
|
||||||
|
|||||||
Reference in New Issue
Block a user