revise gook enumeration

This commit is contained in:
wish
2022-07-25 19:39:20 +10:00
parent 9dcb68e8e7
commit 9d4d820f86
3 changed files with 27 additions and 29 deletions

View File

@@ -21,4 +21,6 @@ ALTER TABLE IF EXISTS public.gook
ALTER TABLE IF EXISTS public.gook ALTER TABLE IF EXISTS public.gook
DROP COLUMN IF EXISTS gook5; DROP COLUMN IF EXISTS gook5;
UPDATE public.gook SET gook1=NULL, gook2=NULL, gook3=NULL, gook4=NULL;
END; END;

View File

@@ -9,14 +9,12 @@ import (
) )
type Gook struct { type Gook struct {
Exists bool Exists bool
Index uint32 Index uint32
Type uint16 Type uint16
Data []byte Data []byte
Birthday1 uint32 NameLen uint8
Birthday2 uint32 Name []byte
NameLen uint8
Name []byte
} }
// MsgMhfUpdateGuacot represents the MSG_MHF_UPDATE_GUACOT // MsgMhfUpdateGuacot represents the MSG_MHF_UPDATE_GUACOT
@@ -41,9 +39,7 @@ func (m *MsgMhfUpdateGuacot) Parse(bf *byteframe.ByteFrame, ctx *clientctx.Clien
e := Gook{} e := Gook{}
e.Index = bf.ReadUint32() e.Index = bf.ReadUint32()
e.Type = bf.ReadUint16() e.Type = bf.ReadUint16()
e.Data = bf.ReadBytes(42) e.Data = bf.ReadBytes(50)
e.Birthday1 = bf.ReadUint32()
e.Birthday2 = bf.ReadUint32()
e.NameLen = bf.ReadUint8() e.NameLen = bf.ReadUint8()
e.Name = bf.ReadBytes(uint(e.NameLen)) e.Name = bf.ReadBytes(uint(e.NameLen))
if e.Type > 0 { if e.Type > 0 {

View File

@@ -577,22 +577,35 @@ func handleMsgMhfCheckWeeklyStamp(s *Session, p mhfpacket.MHFPacket) {
func handleMsgMhfExchangeWeeklyStamp(s *Session, p mhfpacket.MHFPacket) {} func handleMsgMhfExchangeWeeklyStamp(s *Session, p mhfpacket.MHFPacket) {}
func handleMsgMhfEnumerateGuacot(s *Session, p mhfpacket.MHFPacket) { func getGookData(s *Session, cid uint32) []byte {
pkt := p.(*mhfpacket.MsgMhfEnumerateGuacot)
var data []byte var data []byte
var count uint16 var count uint16
bf := byteframe.NewByteFrame() bf := byteframe.NewByteFrame()
for i := 0; i < 5; i++ { for i := 0; i < 5; i++ {
err := s.server.db.QueryRow(fmt.Sprintf("SELECT gook%d FROM gook WHERE id=$1", i), s.charID).Scan(&data) err := s.server.db.QueryRow(fmt.Sprintf("SELECT gook%d FROM gook WHERE id=$1", i), cid).Scan(&data)
if err == nil && data != nil { if err == nil && data != nil {
count++ count++
bf.WriteBytes(data) if s.charID == cid && count == 1 {
gook := byteframe.NewByteFrameFromBytes(data)
bf.WriteBytes(gook.ReadBytes(4))
d := gook.ReadBytes(2)
bf.WriteBytes(d)
bf.WriteBytes(d)
bf.WriteBytes(gook.DataFromCurrent())
} else {
bf.WriteBytes(data)
}
} }
} }
resp := byteframe.NewByteFrame() resp := byteframe.NewByteFrame()
resp.WriteUint16(count) resp.WriteUint16(count)
resp.WriteBytes(bf.Data()) resp.WriteBytes(bf.Data())
doAckBufSucceed(s, pkt.AckHandle, resp.Data()) return resp.Data()
}
func handleMsgMhfEnumerateGuacot(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfEnumerateGuacot)
doAckBufSucceed(s, pkt.AckHandle, getGookData(s, s.charID))
} }
func handleMsgMhfUpdateGuacot(s *Session, p mhfpacket.MHFPacket) { func handleMsgMhfUpdateGuacot(s *Session, p mhfpacket.MHFPacket) {
@@ -601,23 +614,10 @@ func handleMsgMhfUpdateGuacot(s *Session, p mhfpacket.MHFPacket) {
if !gook.Exists { if !gook.Exists {
s.server.db.Exec(fmt.Sprintf("UPDATE gook SET gook%d=NULL WHERE id=$1", gook.Index), s.charID) s.server.db.Exec(fmt.Sprintf("UPDATE gook SET gook%d=NULL WHERE id=$1", gook.Index), s.charID)
} else { } else {
// TODO: Birthdays are still 7 years in the past
//var data []byte
//err := s.server.db.QueryRow(fmt.Sprintf("SELECT gook%d FROM gook WHERE id=$1", gook.Index), s.charID).Scan(&data)
//if err != nil && data == nil { // If index doesn't exist
// // Give gook a birthday not 7 years ago
// gook.Birthday1 = uint32(time.Now().Unix())
// gook.Birthday2 = uint32(time.Now().Unix())
//}
bf := byteframe.NewByteFrame() bf := byteframe.NewByteFrame()
bf.WriteUint32(gook.Index) bf.WriteUint32(gook.Index)
if gook.Index == 0 {
bf.WriteUint16(gook.Type)
}
bf.WriteUint16(gook.Type) bf.WriteUint16(gook.Type)
bf.WriteBytes(gook.Data) bf.WriteBytes(gook.Data)
bf.WriteUint32(gook.Birthday1)
bf.WriteUint32(gook.Birthday2)
bf.WriteUint8(gook.NameLen) bf.WriteUint8(gook.NameLen)
bf.WriteBytes(gook.Name) bf.WriteBytes(gook.Name)
s.server.db.Exec(fmt.Sprintf("UPDATE gook SET gook%d=$1 WHERE id=$2", gook.Index), bf.Data(), s.charID) s.server.db.Exec(fmt.Sprintf("UPDATE gook SET gook%d=$1 WHERE id=$2", gook.Index), bf.Data(), s.charID)