decode UD packets & preliminary handling & schema

This commit is contained in:
wish
2023-10-27 00:02:35 +11:00
parent d32cf39eea
commit 06e32cae6e
4 changed files with 28 additions and 22 deletions

View File

@@ -1,18 +1,17 @@
package mhfpacket
import (
"errors"
import (
"errors"
"erupe-ce/network/clientctx"
"erupe-ce/network"
"erupe-ce/common/byteframe"
"erupe-ce/network"
"erupe-ce/network/clientctx"
)
// MsgMhfAddUdPoint represents the MSG_MHF_ADD_UD_POINT
type MsgMhfAddUdPoint struct {
AckHandle uint32
Unk1 uint32
Unk2 uint32
Points uint32
}
// Opcode returns the ID associated with this packet type.
@@ -23,11 +22,10 @@ func (m *MsgMhfAddUdPoint) Opcode() network.PacketID {
// Parse parses the packet from binary
func (m *MsgMhfAddUdPoint) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error {
m.AckHandle = bf.ReadUint32()
m.Unk1 = bf.ReadUint32()
m.Unk2 = bf.ReadUint32()
m.Points += bf.ReadUint32()
// Premium Course bonus
m.Points += bf.ReadUint32()
return nil
//panic("Not implemented")
}
// Build builds a binary packet from the current data.

View File

@@ -1,17 +1,17 @@
package mhfpacket
import (
"errors"
import (
"errors"
"erupe-ce/network/clientctx"
"erupe-ce/network"
"erupe-ce/common/byteframe"
"erupe-ce/network"
"erupe-ce/network/clientctx"
)
// MsgMhfSetKiju represents the MSG_MHF_SET_KIJU
type MsgMhfSetKiju struct {
AckHandle uint32
Unk1 uint16
BeadIndex uint8
}
// Opcode returns the ID associated with this packet type.
@@ -22,9 +22,8 @@ func (m *MsgMhfSetKiju) Opcode() network.PacketID {
// Parse parses the packet from binary
func (m *MsgMhfSetKiju) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error {
m.AckHandle = bf.ReadUint32()
m.Unk1 = bf.ReadUint16()
m.BeadIndex = bf.ReadUint8()
return nil
//panic("Not implemented")
}
// Build builds a binary packet from the current data.

View File

@@ -21,4 +21,14 @@ CREATE TABLE IF NOT EXISTS public.diva_beads (
type INTEGER
);
ALTER TABLE IF EXISTS public.characters
ADD COLUMN IF NOT EXISTS diva_bead INTEGER;
CREATE TABLE IF NOT EXISTS public.diva_beads_points (
character_id INTEGER,
points INTEGER,
timestamp TIMESTAMP WITH TIME ZONE,
bead_index INTEGER
);
END;

View File

@@ -82,10 +82,7 @@ func handleMsgMhfGetUdSchedule(s *Session, p mhfpacket.MHFPacket) {
bf := byteframe.NewByteFrame()
id, start := uint32(0xCAFEBEEF), uint32(0)
rows, _ := s.server.db.Queryx("SELECT id, (EXTRACT(epoch FROM start_time)::int) as start_time FROM events WHERE event_type='diva'")
for rows.Next() {
rows.Scan(&id, &start)
}
_ = s.server.db.QueryRow("SELECT id, (EXTRACT(epoch FROM start_time)::int) as start_time FROM events WHERE event_type='diva'").Scan(&id, &start)
var timestamps []uint32
if s.server.erupeConfig.DevMode && s.server.erupeConfig.DevModeOptions.DivaEvent >= 0 {
@@ -141,7 +138,7 @@ func handleMsgMhfGetUdInfo(s *Session, p mhfpacket.MHFPacket) {
func handleMsgMhfGetKijuInfo(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfGetKijuInfo)
beads := []uint8{1, 3, 4, 8}
rows, err := s.server.db.Queryx(`SELECT * FROM diva_beads`)
rows, err := s.server.db.Query(`SELECT * FROM diva_beads`)
if err == nil {
var i int
for rows.Next() {
@@ -173,11 +170,13 @@ func handleMsgMhfGetKijuInfo(s *Session, p mhfpacket.MHFPacket) {
func handleMsgMhfSetKiju(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfSetKiju)
s.server.db.Exec(`UPDATE characters SET diva_bead=$1 WHERE id=$2`, pkt.BeadIndex, s.charID)
doAckBufSucceed(s, pkt.AckHandle, []byte{0})
}
func handleMsgMhfAddUdPoint(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfAddUdPoint)
s.server.db.Exec(`INSERT INTO diva_beads_points VALUES ($1, $2, now(), (SELECT diva_bead FROM characters WHERE id=$1))`, s.charID, pkt.Points)
doAckBufSucceed(s, pkt.AckHandle, []byte{0})
}