mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-13 23:44:52 +01:00
rewrite EnumerateDistItem handler
This commit is contained in:
@@ -26,7 +26,7 @@ func (m *MsgMhfEnumerateDistItem) Parse(bf *byteframe.ByteFrame, ctx *clientctx.
|
|||||||
m.AckHandle = bf.ReadUint32()
|
m.AckHandle = bf.ReadUint32()
|
||||||
m.DistType = bf.ReadUint8()
|
m.DistType = bf.ReadUint8()
|
||||||
m.Unk1 = bf.ReadUint8()
|
m.Unk1 = bf.ReadUint8()
|
||||||
m.Unk2 = bf.ReadUint16()
|
m.Unk2 = bf.ReadUint16() // Maximum? Hardcoded to 256
|
||||||
m.Unk3 = bf.ReadBytes(uint(bf.ReadUint8()))
|
m.Unk3 = bf.ReadBytes(uint(bf.ReadUint8()))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ItemDist struct {
|
type Distribution struct {
|
||||||
ID uint32 `db:"id"`
|
ID uint32 `db:"id"`
|
||||||
Deadline time.Time `db:"deadline"`
|
Deadline time.Time `db:"deadline"`
|
||||||
TimesAcceptable uint16 `db:"times_acceptable"`
|
TimesAcceptable uint16 `db:"times_acceptable"`
|
||||||
@@ -27,74 +27,72 @@ type ItemDist struct {
|
|||||||
|
|
||||||
func handleMsgMhfEnumerateDistItem(s *Session, p mhfpacket.MHFPacket) {
|
func handleMsgMhfEnumerateDistItem(s *Session, p mhfpacket.MHFPacket) {
|
||||||
pkt := p.(*mhfpacket.MsgMhfEnumerateDistItem)
|
pkt := p.(*mhfpacket.MsgMhfEnumerateDistItem)
|
||||||
|
|
||||||
|
var itemDists []Distribution
|
||||||
bf := byteframe.NewByteFrame()
|
bf := byteframe.NewByteFrame()
|
||||||
distCount := 0
|
rows, err := s.server.db.Queryx(`
|
||||||
dists, err := s.server.db.Queryx(`
|
|
||||||
SELECT d.id, event_name, description, times_acceptable,
|
SELECT d.id, event_name, description, times_acceptable,
|
||||||
COALESCE(min_hr, -1) AS min_hr, COALESCE(max_hr, -1) AS max_hr,
|
COALESCE(min_hr, -1) AS min_hr, COALESCE(max_hr, -1) AS max_hr,
|
||||||
COALESCE(min_sr, -1) AS min_sr, COALESCE(max_sr, -1) AS max_sr,
|
COALESCE(min_sr, -1) AS min_sr, COALESCE(max_sr, -1) AS max_sr,
|
||||||
COALESCE(min_gr, -1) AS min_gr, COALESCE(max_gr, -1) AS max_gr,
|
COALESCE(min_gr, -1) AS min_gr, COALESCE(max_gr, -1) AS max_gr,
|
||||||
(
|
(
|
||||||
SELECT count(*)
|
SELECT count(*) FROM distributions_accepted da
|
||||||
FROM distributions_accepted da
|
WHERE d.id = da.distribution_id AND da.character_id = $1
|
||||||
WHERE d.id = da.distribution_id
|
|
||||||
AND da.character_id = $1
|
|
||||||
) AS times_accepted,
|
) AS times_accepted,
|
||||||
COALESCE(deadline, TO_TIMESTAMP(0)) AS deadline
|
COALESCE(deadline, TO_TIMESTAMP(0)) AS deadline
|
||||||
FROM distribution d
|
FROM distribution d
|
||||||
WHERE character_id = $1 AND type = $2 OR character_id IS NULL AND type = $2 ORDER BY id DESC;
|
WHERE character_id = $1 AND type = $2 OR character_id IS NULL AND type = $2 ORDER BY id DESC
|
||||||
`, s.charID, pkt.DistType)
|
`, s.charID, pkt.DistType)
|
||||||
if err != nil {
|
|
||||||
s.logger.Error("Error getting distribution data from db", zap.Error(err))
|
if err == nil {
|
||||||
doAckBufSucceed(s, pkt.AckHandle, make([]byte, 4))
|
var itemDist Distribution
|
||||||
} else {
|
for rows.Next() {
|
||||||
for dists.Next() {
|
err = rows.StructScan(&itemDist)
|
||||||
distCount++
|
|
||||||
distData := &ItemDist{}
|
|
||||||
err = dists.StructScan(&distData)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.Error("Error parsing item distribution data", zap.Error(err))
|
continue
|
||||||
}
|
}
|
||||||
bf.WriteUint32(distData.ID)
|
itemDists = append(itemDists, itemDist)
|
||||||
bf.WriteUint32(uint32(distData.Deadline.Unix()))
|
}
|
||||||
bf.WriteUint32(0) // Unk
|
}
|
||||||
bf.WriteUint16(distData.TimesAcceptable)
|
|
||||||
bf.WriteUint16(distData.TimesAccepted)
|
bf.WriteUint16(uint16(len(itemDists)))
|
||||||
bf.WriteUint16(0) // Unk
|
for _, dist := range itemDists {
|
||||||
bf.WriteInt16(distData.MinHR)
|
bf.WriteUint32(dist.ID)
|
||||||
bf.WriteInt16(distData.MaxHR)
|
bf.WriteUint32(uint32(dist.Deadline.Unix()))
|
||||||
bf.WriteInt16(distData.MinSR)
|
bf.WriteUint32(0) // Unk
|
||||||
bf.WriteInt16(distData.MaxSR)
|
bf.WriteUint16(dist.TimesAcceptable)
|
||||||
bf.WriteInt16(distData.MinGR)
|
bf.WriteUint16(dist.TimesAccepted)
|
||||||
bf.WriteInt16(distData.MaxGR)
|
bf.WriteUint16(0) // Unk
|
||||||
bf.WriteUint8(0)
|
bf.WriteInt16(dist.MinHR)
|
||||||
bf.WriteUint16(0)
|
bf.WriteInt16(dist.MaxHR)
|
||||||
bf.WriteUint8(0)
|
bf.WriteInt16(dist.MinSR)
|
||||||
bf.WriteUint16(0)
|
bf.WriteInt16(dist.MaxSR)
|
||||||
bf.WriteUint16(0)
|
bf.WriteInt16(dist.MinGR)
|
||||||
bf.WriteUint8(0)
|
bf.WriteInt16(dist.MaxGR)
|
||||||
ps.Uint8(bf, distData.EventName, true)
|
bf.WriteUint8(0)
|
||||||
for i := 0; i < 6; i++ {
|
bf.WriteUint16(0)
|
||||||
for j := 0; j < 13; j++ {
|
bf.WriteUint8(0)
|
||||||
bf.WriteUint8(0)
|
bf.WriteUint16(0)
|
||||||
bf.WriteUint32(0)
|
bf.WriteUint16(0)
|
||||||
}
|
bf.WriteUint8(0)
|
||||||
}
|
ps.Uint8(bf, dist.EventName, true)
|
||||||
i := uint8(0)
|
for i := 0; i < 6; i++ {
|
||||||
bf.WriteUint8(i)
|
for j := 0; j < 13; j++ {
|
||||||
if i <= 10 {
|
bf.WriteUint8(0)
|
||||||
for j := uint8(0); j < i; j++ {
|
bf.WriteUint32(0)
|
||||||
bf.WriteUint32(0)
|
}
|
||||||
bf.WriteUint32(0)
|
}
|
||||||
bf.WriteUint32(0)
|
i := uint8(0)
|
||||||
}
|
bf.WriteUint8(i)
|
||||||
|
if i <= 10 {
|
||||||
|
for j := uint8(0); j < i; j++ {
|
||||||
|
bf.WriteUint32(0)
|
||||||
|
bf.WriteUint32(0)
|
||||||
|
bf.WriteUint32(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resp := byteframe.NewByteFrame()
|
|
||||||
resp.WriteUint16(uint16(distCount))
|
|
||||||
resp.WriteBytes(bf.Data())
|
|
||||||
doAckBufSucceed(s, pkt.AckHandle, resp.Data())
|
|
||||||
}
|
}
|
||||||
|
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
|
||||||
}
|
}
|
||||||
|
|
||||||
type DistributionItem struct {
|
type DistributionItem struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user