change Airou struct definition & remove airoulist.bin

This commit is contained in:
wish
2023-10-12 23:27:54 +11:00
parent 0de15e8440
commit 94f9174afa
2 changed files with 21 additions and 35 deletions

View File

@@ -9,8 +9,6 @@ import (
"erupe-ce/server/channelserver/compression/nullcomp"
"go.uber.org/zap"
"io"
"os"
"path/filepath"
"time"
)
@@ -299,18 +297,12 @@ func handleMsgMhfSaveOtomoAirou(s *Session, p mhfpacket.MHFPacket) {
func handleMsgMhfEnumerateAiroulist(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfEnumerateAiroulist)
resp := byteframe.NewByteFrame()
if _, err := os.Stat(filepath.Join(s.server.erupeConfig.BinPath, "airoulist.bin")); err == nil {
data, _ := os.ReadFile(filepath.Join(s.server.erupeConfig.BinPath, "airoulist.bin"))
resp.WriteBytes(data)
doAckBufSucceed(s, pkt.AckHandle, resp.Data())
return
}
airouList := getGuildAirouList(s)
resp.WriteUint16(uint16(len(airouList)))
resp.WriteUint16(uint16(len(airouList)))
for _, cat := range airouList {
resp.WriteUint32(cat.CatID)
resp.WriteBytes(cat.CatName)
resp.WriteUint32(cat.ID)
resp.WriteBytes(cat.Name)
resp.WriteUint32(cat.Experience)
resp.WriteUint8(cat.Personality)
resp.WriteUint8(cat.Class)
@@ -321,11 +313,10 @@ func handleMsgMhfEnumerateAiroulist(s *Session, p mhfpacket.MHFPacket) {
doAckBufSucceed(s, pkt.AckHandle, resp.Data())
}
// CatDefinition holds values needed to populate the guild cat list
type CatDefinition struct {
CatID uint32
CatName []byte
CurrentTask uint8
type Airou struct {
ID uint32
Name []byte
Task uint8
Personality uint8
Class uint8
Experience uint32
@@ -333,10 +324,10 @@ type CatDefinition struct {
WeaponID uint16
}
func getGuildAirouList(s *Session) []CatDefinition {
func getGuildAirouList(s *Session) []Airou {
var guild *Guild
var err error
var guildCats []CatDefinition
var guildCats []Airou
// returning 0 cats on any guild issues
// can probably optimise all of the guild queries pretty heavily
@@ -365,7 +356,6 @@ func getGuildAirouList(s *Session) []CatDefinition {
}
}
// ellie's GetGuildMembers didn't seem to pull leader?
rows, err = s.server.db.Query(`SELECT c.otomoairou
FROM characters c
INNER JOIN guild_characters gc
@@ -381,11 +371,7 @@ func getGuildAirouList(s *Session) []CatDefinition {
for rows.Next() {
var data []byte
err = rows.Scan(&data)
if err != nil {
s.logger.Warn("select failure", zap.Error(err))
continue
} else if len(data) == 0 {
// non extant cats that aren't null in DB
if err != nil || len(data) == 0 {
continue
}
// first byte has cat existence in general, can skip if 0
@@ -396,10 +382,10 @@ func getGuildAirouList(s *Session) []CatDefinition {
continue
}
bf := byteframe.NewByteFrameFromBytes(decomp)
cats := GetCatDetails(bf)
cats := GetAirouDetails(bf)
for _, cat := range cats {
_, exists := bannedCats[cat.CatID]
if cat.CurrentTask == 4 && !exists {
_, exists := bannedCats[cat.ID]
if cat.Task == 4 && !exists {
guildCats = append(guildCats, cat)
}
}
@@ -408,20 +394,20 @@ func getGuildAirouList(s *Session) []CatDefinition {
return guildCats
}
func GetCatDetails(bf *byteframe.ByteFrame) []CatDefinition {
func GetAirouDetails(bf *byteframe.ByteFrame) []Airou {
catCount := bf.ReadUint8()
cats := make([]CatDefinition, catCount)
cats := make([]Airou, catCount)
for x := 0; x < int(catCount); x++ {
var catDef CatDefinition
var catDef Airou
// cat sometimes has additional bytes for whatever reason, gift items? timestamp?
// until actual variance is known we can just seek to end based on start
catDefLen := bf.ReadUint32()
catStart, _ := bf.Seek(0, io.SeekCurrent)
catDef.CatID = bf.ReadUint32()
bf.Seek(1, io.SeekCurrent) // unknown value, probably a bool
catDef.CatName = bf.ReadBytes(18) // always 18 len, reads first null terminated string out of section and discards rest
catDef.CurrentTask = bf.ReadUint8()
catDef.ID = bf.ReadUint32()
bf.Seek(1, io.SeekCurrent) // unknown value, probably a bool
catDef.Name = bf.ReadBytes(18) // always 18 len, reads first null terminated string out of section and discards rest
catDef.Task = bf.ReadUint8()
bf.Seek(16, io.SeekCurrent) // appearance data and what is seemingly null bytes
catDef.Personality = bf.ReadUint8()
catDef.Class = bf.ReadUint8()