Merge pull request #4 from ZeruLight/feature/simplegook

merge gook simplification into my series improvements
This commit is contained in:
wish
2022-07-25 19:41:06 +10:00
committed by GitHub
4 changed files with 92 additions and 219 deletions

26
Erupe/gook.sql Normal file
View File

@@ -0,0 +1,26 @@
BEGIN;
ALTER TABLE IF EXISTS public.gook
DROP COLUMN IF EXISTS gook0status;
ALTER TABLE IF EXISTS public.gook
DROP COLUMN IF EXISTS gook1status;
ALTER TABLE IF EXISTS public.gook
DROP COLUMN IF EXISTS gook2status;
ALTER TABLE IF EXISTS public.gook
DROP COLUMN IF EXISTS gook3status;
ALTER TABLE IF EXISTS public.gook
DROP COLUMN IF EXISTS gook4status;
ALTER TABLE IF EXISTS public.gook
DROP COLUMN IF EXISTS gook5status;
ALTER TABLE IF EXISTS public.gook
DROP COLUMN IF EXISTS gook5;
UPDATE public.gook SET gook1=NULL, gook2=NULL, gook3=NULL, gook4=NULL;
END;

View File

@@ -1,42 +1,20 @@
package mhfpacket 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"
) )
// GuacotUpdateEntry represents an entry inside the MsgMhfUpdateGuacot packet. type Gook struct {
type GuacotUpdateEntry struct { Exists bool
Unk0 uint32 Index uint32
Unk1 uint16 Type uint16
Unk2 uint16 Data []byte
Unk3 uint16 NameLen uint8
Unk4 uint16 Name []byte
Unk5 uint16
Unk6 uint16
Unk7 uint16
Unk8 uint16
Unk9 uint16
Unk10 uint16
Unk11 uint16
Unk12 uint16
Unk13 uint16
Unk14 uint16
Unk15 uint16
Unk16 uint16
Unk17 uint16
Unk18 uint16
Unk19 uint16
Unk20 uint16
Unk21 uint16
Unk22 uint16
Unk23 uint32
Unk24 uint32
DataSize uint8
RawDataPayload []byte
} }
// MsgMhfUpdateGuacot represents the MSG_MHF_UPDATE_GUACOT // MsgMhfUpdateGuacot represents the MSG_MHF_UPDATE_GUACOT
@@ -44,7 +22,7 @@ type MsgMhfUpdateGuacot struct {
AckHandle uint32 AckHandle uint32
EntryCount uint16 EntryCount uint16
Unk0 uint16 // Hardcoded 0 in binary Unk0 uint16 // Hardcoded 0 in binary
Entries []*GuacotUpdateEntry Gooks []Gook
} }
// Opcode returns the ID associated with this packet type. // Opcode returns the ID associated with this packet type.
@@ -58,38 +36,18 @@ func (m *MsgMhfUpdateGuacot) Parse(bf *byteframe.ByteFrame, ctx *clientctx.Clien
m.EntryCount = bf.ReadUint16() m.EntryCount = bf.ReadUint16()
m.Unk0 = bf.ReadUint16() m.Unk0 = bf.ReadUint16()
for i := 0; i < int(m.EntryCount); i++ { for i := 0; i < int(m.EntryCount); i++ {
// Yikes. e := Gook{}
e := &GuacotUpdateEntry{} e.Index = bf.ReadUint32()
e.Type = bf.ReadUint16()
e.Unk0 = bf.ReadUint32() e.Data = bf.ReadBytes(50)
e.Unk1 = bf.ReadUint16() e.NameLen = bf.ReadUint8()
e.Unk2 = bf.ReadUint16() e.Name = bf.ReadBytes(uint(e.NameLen))
e.Unk3 = bf.ReadUint16() if e.Type > 0 {
e.Unk4 = bf.ReadUint16() e.Exists = true
e.Unk5 = bf.ReadUint16() } else {
e.Unk6 = bf.ReadUint16() e.Exists = false
e.Unk7 = bf.ReadUint16() }
e.Unk8 = bf.ReadUint16() m.Gooks = append(m.Gooks, e)
e.Unk9 = bf.ReadUint16()
e.Unk10 = bf.ReadUint16()
e.Unk11 = bf.ReadUint16()
e.Unk12 = bf.ReadUint16()
e.Unk13 = bf.ReadUint16()
e.Unk14 = bf.ReadUint16()
e.Unk15 = bf.ReadUint16()
e.Unk16 = bf.ReadUint16()
e.Unk17 = bf.ReadUint16()
e.Unk18 = bf.ReadUint16()
e.Unk19 = bf.ReadUint16()
e.Unk20 = bf.ReadUint16()
e.Unk21 = bf.ReadUint16()
e.Unk22 = bf.ReadUint16()
e.Unk23 = bf.ReadUint32()
e.Unk24 = bf.ReadUint32()
e.DataSize = bf.ReadUint8()
e.RawDataPayload = bf.ReadBytes(uint(e.DataSize))
m.Entries = append(m.Entries, e)
} }
return nil return nil
} }
@@ -98,36 +56,3 @@ func (m *MsgMhfUpdateGuacot) Parse(bf *byteframe.ByteFrame, ctx *clientctx.Clien
func (m *MsgMhfUpdateGuacot) Build(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error { func (m *MsgMhfUpdateGuacot) Build(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error {
return errors.New("NOT IMPLEMENTED") return errors.New("NOT IMPLEMENTED")
} }
func (m *MsgMhfUpdateGuacot) GuacotUpdateEntryToBytes(Entry *GuacotUpdateEntry) []byte {
resp:= byteframe.NewByteFrame()
resp.WriteUint32(Entry.Unk0)
resp.WriteUint16(Entry.Unk1)
resp.WriteUint16(Entry.Unk1)
resp.WriteUint16(Entry.Unk2)
resp.WriteUint16(Entry.Unk3)
resp.WriteUint16(Entry.Unk4)
resp.WriteUint16(Entry.Unk5)
resp.WriteUint16(Entry.Unk6)
resp.WriteUint16(Entry.Unk7)
resp.WriteUint16(Entry.Unk8)
resp.WriteUint16(Entry.Unk9)
resp.WriteUint16(Entry.Unk10)
resp.WriteUint16(Entry.Unk11)
resp.WriteUint16(Entry.Unk12)
resp.WriteUint16(Entry.Unk13)
resp.WriteUint16(Entry.Unk14)
resp.WriteUint16(Entry.Unk15)
resp.WriteUint16(Entry.Unk16)
resp.WriteUint16(Entry.Unk17)
resp.WriteUint16(Entry.Unk18)
resp.WriteUint16(Entry.Unk19)
resp.WriteUint16(Entry.Unk20)
resp.WriteUint16(Entry.Unk21)
resp.WriteUint16(Entry.Unk22)
resp.WriteUint32(Entry.Unk23)
resp.WriteUint32(Entry.Unk24)
resp.WriteUint8(Entry.DataSize)
resp.WriteBytes(Entry.RawDataPayload)
return resp.Data()
}

View File

@@ -4,8 +4,8 @@ import (
"bytes" "bytes"
"encoding/binary" "encoding/binary"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"math/bits" "math/bits"
"math/rand" "math/rand"
@@ -577,125 +577,50 @@ func handleMsgMhfCheckWeeklyStamp(s *Session, p mhfpacket.MHFPacket) {
func handleMsgMhfExchangeWeeklyStamp(s *Session, p mhfpacket.MHFPacket) {} func handleMsgMhfExchangeWeeklyStamp(s *Session, p mhfpacket.MHFPacket) {}
func getGookData(s *Session, cid uint32) []byte {
var data []byte
var count uint16
bf := byteframe.NewByteFrame()
for i := 0; i < 5; i++ {
err := s.server.db.QueryRow(fmt.Sprintf("SELECT gook%d FROM gook WHERE id=$1", i), cid).Scan(&data)
if err == nil && data != nil {
count++
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.WriteUint16(count)
resp.WriteBytes(bf.Data())
return resp.Data()
}
func handleMsgMhfEnumerateGuacot(s *Session, p mhfpacket.MHFPacket) { func handleMsgMhfEnumerateGuacot(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfEnumerateGuacot) pkt := p.(*mhfpacket.MsgMhfEnumerateGuacot)
var data bool doAckBufSucceed(s, pkt.AckHandle, getGookData(s, s.charID))
err := s.server.db.QueryRow("SELECT gook0status FROM gook WHERE id = $1", s.charID).Scan(&data)
if err == nil {
tempresp := byteframe.NewByteFrame()
count := uint16(0)
var gook0 []byte
var gook1 []byte
var gook2 []byte
var gook3 []byte
var gook4 []byte
var gook5 []byte
var gook0status bool
var gook1status bool
var gook2status bool
var gook3status bool
var gook4status bool
var gook5status bool
_ = s.server.db.QueryRow("SELECT gook0 FROM gook WHERE id = $1", s.charID).Scan(&gook0)
_ = s.server.db.QueryRow("SELECT gook1 FROM gook WHERE id = $1", s.charID).Scan(&gook1)
_ = s.server.db.QueryRow("SELECT gook2 FROM gook WHERE id = $1", s.charID).Scan(&gook2)
_ = s.server.db.QueryRow("SELECT gook3 FROM gook WHERE id = $1", s.charID).Scan(&gook3)
_ = s.server.db.QueryRow("SELECT gook4 FROM gook WHERE id = $1", s.charID).Scan(&gook4)
_ = s.server.db.QueryRow("SELECT gook5 FROM gook WHERE id = $1", s.charID).Scan(&gook5)
_ = s.server.db.QueryRow("SELECT gook0status FROM gook WHERE id = $1", s.charID).Scan(&gook0status)
_ = s.server.db.QueryRow("SELECT gook1status FROM gook WHERE id = $1", s.charID).Scan(&gook1status)
_ = s.server.db.QueryRow("SELECT gook2status FROM gook WHERE id = $1", s.charID).Scan(&gook2status)
_ = s.server.db.QueryRow("SELECT gook3status FROM gook WHERE id = $1", s.charID).Scan(&gook3status)
_ = s.server.db.QueryRow("SELECT gook4status FROM gook WHERE id = $1", s.charID).Scan(&gook4status)
_ = s.server.db.QueryRow("SELECT gook5status FROM gook WHERE id = $1", s.charID).Scan(&gook5status)
if gook0status == true {
count++
tempresp.WriteBytes(gook0)
}
if gook1status == true {
count++
tempresp.WriteBytes(gook1)
}
if gook2status == true {
count++
tempresp.WriteBytes(gook2)
}
if gook3status == true {
count++
tempresp.WriteBytes(gook3)
}
if gook4status == true {
count++
tempresp.WriteBytes(gook4)
}
if gook5status == true {
count++
tempresp.WriteBytes(gook5)
}
if count == uint16(0) {
doAckBufSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00})
} else {
resp := byteframe.NewByteFrame()
resp.WriteUint16(count)
resp.WriteBytes(tempresp.Data())
doAckBufSucceed(s, pkt.AckHandle, resp.Data())
}
} else {
doAckBufSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00})
}
} }
func handleMsgMhfUpdateGuacot(s *Session, p mhfpacket.MHFPacket) { func handleMsgMhfUpdateGuacot(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfUpdateGuacot) pkt := p.(*mhfpacket.MsgMhfUpdateGuacot)
count := int(pkt.EntryCount) for _, gook := range pkt.Gooks {
fmt.Printf("handleMsgMhfUpdateGuacot:%d\n", count) if !gook.Exists {
if count == 0 { s.server.db.Exec(fmt.Sprintf("UPDATE gook SET gook%d=NULL WHERE id=$1", gook.Index), s.charID)
_, err := s.server.db.Exec("INSERT INTO gook(id,gook0status,gook1status,gook2status,gook3status,gook4status,gook5status) VALUES($1,bool(false),bool(false),bool(false),bool(false),bool(false),bool(false))", s.charID) } else {
if err != nil { bf := byteframe.NewByteFrame()
fmt.Printf("INSERT INTO gook failure\n") bf.WriteUint32(gook.Index)
} bf.WriteUint16(gook.Type)
} else { bf.WriteBytes(gook.Data)
for i := 0; i < int(pkt.EntryCount); i++ { bf.WriteUint8(gook.NameLen)
gookindex := int(pkt.Entries[i].Unk0) bf.WriteBytes(gook.Name)
buf := pkt.GuacotUpdateEntryToBytes(pkt.Entries[i]) s.server.db.Exec(fmt.Sprintf("UPDATE gook SET gook%d=$1 WHERE id=$2", gook.Index), bf.Data(), s.charID)
//fmt.Printf("gookindex:%d\n", gookindex)
switch gookindex {
case 0:
s.server.db.Exec("UPDATE gook SET gook0 = $1 WHERE id = $2", buf, s.charID)
if pkt.Entries[i].Unk1 != uint16(0) {
s.server.db.Exec("UPDATE gook SET gook0status = $1 WHERE id = $2", bool(true), s.charID)
} else {
s.server.db.Exec("UPDATE gook SET gook0status = $1 WHERE id = $2", bool(false), s.charID)
}
case 1:
s.server.db.Exec("UPDATE gook SET gook1 = $1 WHERE id = $2", buf, s.charID)
if pkt.Entries[i].Unk1 != uint16(0) {
s.server.db.Exec("UPDATE gook SET gook1status = $1 WHERE id = $2", bool(true), s.charID)
} else {
s.server.db.Exec("UPDATE gook SET gook1status = $1 WHERE id = $2", bool(false), s.charID)
}
case 2:
s.server.db.Exec("UPDATE gook SET gook2 = $1 WHERE id = $2", buf, s.charID)
if pkt.Entries[i].Unk1 != uint16(0) {
s.server.db.Exec("UPDATE gook SET gook2status = $1 WHERE id = $2", bool(true), s.charID)
} else {
s.server.db.Exec("UPDATE gook SET gook2status = $1 WHERE id = $2", bool(false), s.charID)
}
case 3:
s.server.db.Exec("UPDATE gook SET gook3 = $1 WHERE id = $2", buf, s.charID)
if pkt.Entries[i].Unk1 != uint16(0) {
s.server.db.Exec("UPDATE gook SET gook3status = $1 WHERE id = $2", bool(true), s.charID)
} else {
s.server.db.Exec("UPDATE gook SET gook3status = $1 WHERE id = $2", bool(false), s.charID)
}
case 4:
s.server.db.Exec("UPDATE gook SET gook4 = $1 WHERE id = $2", buf, s.charID)
if pkt.Entries[i].Unk1 != uint16(0) {
s.server.db.Exec("UPDATE gook SET gook4status = $1 WHERE id = $2", bool(true), s.charID)
} else {
s.server.db.Exec("UPDATE gook SET gook4status = $1 WHERE id = $2", bool(false), s.charID)
}
}
} }
} }
doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00}) doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00})

View File

@@ -116,8 +116,8 @@ func handleMsgMhfAcquireGuildTresure(s *Session, p mhfpacket.MHFPacket) {
func treasureHuntUnregister(s *Session) { func treasureHuntUnregister(s *Session) {
guild, err := GetGuildInfoByCharacterId(s, s.charID) guild, err := GetGuildInfoByCharacterId(s, s.charID)
if err != nil { if err != nil || guild == nil {
panic(err) return
} }
var huntID int var huntID int
var hunters string var hunters string
@@ -125,10 +125,7 @@ func treasureHuntUnregister(s *Session) {
for rows.Next() { for rows.Next() {
rows.Scan(&huntID, &hunters) rows.Scan(&huntID, &hunters)
hunters = stringsupport.CSVRemove(hunters, int(s.charID)) hunters = stringsupport.CSVRemove(hunters, int(s.charID))
_, err = s.server.db.Exec("UPDATE guild_hunts SET hunters=$1 WHERE id=$2", hunters, huntID) s.server.db.Exec("UPDATE guild_hunts SET hunters=$1 WHERE id=$2", hunters, huntID)
if err != nil {
panic(err)
}
} }
} }