implement basic my series functionality

This commit is contained in:
wish
2022-07-24 12:32:41 +10:00
parent bfd2671832
commit b8f5aa87a2
6 changed files with 175 additions and 42 deletions

View File

@@ -2,6 +2,7 @@ package mhfpacket
import ( import (
"errors" "errors"
"erupe-ce/common/stringsupport"
"erupe-ce/common/byteframe" "erupe-ce/common/byteframe"
"erupe-ce/network" "erupe-ce/network"
@@ -14,7 +15,7 @@ type MsgMhfEnumerateHouse struct {
CharID uint32 CharID uint32
Method uint8 Method uint8
Unk uint16 Unk uint16
Name []byte Name string
} }
// Opcode returns the ID associated with this packet type. // Opcode returns the ID associated with this packet type.
@@ -29,7 +30,7 @@ func (m *MsgMhfEnumerateHouse) Parse(bf *byteframe.ByteFrame, ctx *clientctx.Cli
m.Method = bf.ReadUint8() m.Method = bf.ReadUint8()
m.Unk = bf.ReadUint16() m.Unk = bf.ReadUint16()
_ = bf.ReadUint8() // len _ = bf.ReadUint8() // len
m.Name = bf.ReadNullTerminatedBytes() m.Name = stringsupport.SJISToUTF8(bf.ReadNullTerminatedBytes())
return nil return nil
} }

View File

@@ -1,29 +1,22 @@
package mhfpacket package mhfpacket
import ( import (
"errors" "errors"
"erupe-ce/common/stringsupport"
"erupe-ce/network/clientctx"
"erupe-ce/network"
"erupe-ce/common/byteframe" "erupe-ce/common/byteframe"
"erupe-ce/network"
"erupe-ce/network/clientctx"
) )
// MsgMhfLoadHouse represents the MSG_MHF_LOAD_HOUSE // MsgMhfLoadHouse represents the MSG_MHF_LOAD_HOUSE
type MsgMhfLoadHouse struct { type MsgMhfLoadHouse struct {
AckHandle uint32 AckHandle uint32
CharID uint32 CharID uint32
// dest? Destination uint8
// 0x3 = house InMezeporta bool
// 0x4 = bookshelf Unk3 uint16 // Hardcoded 0 in binary
// 0x5 = gallery Password string
// 0x8 = tore
// 0x9 = own house
// 0xA = garden
Unk1 uint8
// bool inMezSquare?
Unk2 uint8
Unk3 uint16 // Hardcoded 0 in binary
Password []byte
} }
// Opcode returns the ID associated with this packet type. // Opcode returns the ID associated with this packet type.
@@ -35,11 +28,11 @@ func (m *MsgMhfLoadHouse) Opcode() network.PacketID {
func (m *MsgMhfLoadHouse) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error { func (m *MsgMhfLoadHouse) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error {
m.AckHandle = bf.ReadUint32() m.AckHandle = bf.ReadUint32()
m.CharID = bf.ReadUint32() m.CharID = bf.ReadUint32()
m.Unk1 = bf.ReadUint8() m.Destination = bf.ReadUint8()
m.Unk2 = bf.ReadUint8() m.InMezeporta = bf.ReadBool()
_ = bf.ReadUint16() _ = bf.ReadUint16()
_ = bf.ReadUint8() // Password length _ = bf.ReadUint8() // Password length
m.Password = bf.ReadNullTerminatedBytes() m.Password = stringsupport.SJISToUTF8(bf.ReadNullTerminatedBytes())
return nil return nil
} }

View File

@@ -2,6 +2,7 @@ package mhfpacket
import ( import (
"errors" "errors"
"erupe-ce/common/stringsupport"
"erupe-ce/common/byteframe" "erupe-ce/common/byteframe"
"erupe-ce/network" "erupe-ce/network"
@@ -11,15 +12,10 @@ import (
// MsgMhfUpdateHouse represents the MSG_MHF_UPDATE_HOUSE // MsgMhfUpdateHouse represents the MSG_MHF_UPDATE_HOUSE
type MsgMhfUpdateHouse struct { type MsgMhfUpdateHouse struct {
AckHandle uint32 AckHandle uint32
// 01 = closed State uint8
// 02 = open anyone Unk1 uint8 // Always 0x01
// 03 = open friends Unk2 uint16 // Always 0x0000
// 04 = open guild Password string
// 05 = open friends guild
State uint8
Unk1 uint8 // Always 0x01
Unk2 uint16 // Always 0x0000
Password string
} }
// Opcode returns the ID associated with this packet type. // Opcode returns the ID associated with this packet type.
@@ -33,8 +29,8 @@ func (m *MsgMhfUpdateHouse) Parse(bf *byteframe.ByteFrame, ctx *clientctx.Client
m.State = bf.ReadUint8() m.State = bf.ReadUint8()
m.Unk1 = bf.ReadUint8() m.Unk1 = bf.ReadUint8()
m.Unk2 = bf.ReadUint16() m.Unk2 = bf.ReadUint16()
_ = bf.ReadUint8() _ = bf.ReadUint8() // Password length
m.Password = string(bf.ReadNullTerminatedBytes()) m.Password = stringsupport.SJISToUTF8(bf.ReadNullTerminatedBytes())
return nil return nil
} }

View File

@@ -61,6 +61,8 @@ func handleMsgMhfSavedata(s *Session, p mhfpacket.MHFPacket) {
s.logger.Fatal("Failed to character weapon type in db", zap.Error(err)) s.logger.Fatal("Failed to character weapon type in db", zap.Error(err))
} }
s.house.tier = decompressedData[129904]
isMale := uint8(decompressedData[80]) // 0x50 isMale := uint8(decompressedData[80]) // 0x50
if isMale == 1 { if isMale == 1 {
_, err = s.server.db.Exec("UPDATE characters SET is_female=true WHERE id=$1", s.charID) _, err = s.server.db.Exec("UPDATE characters SET is_female=true WHERE id=$1", s.charID)

View File

@@ -2,6 +2,8 @@ package channelserver
import ( import (
"erupe-ce/common/byteframe" "erupe-ce/common/byteframe"
ps "erupe-ce/common/pascalstring"
"erupe-ce/common/stringsupport"
"erupe-ce/network/mhfpacket" "erupe-ce/network/mhfpacket"
"go.uber.org/zap" "go.uber.org/zap"
) )
@@ -15,28 +17,160 @@ func handleMsgMhfUpdateInterior(s *Session, p mhfpacket.MHFPacket) {
doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4)) doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
} }
func handleMsgMhfEnumerateHouse(s *Session, p mhfpacket.MHFPacket) { type HouseData struct {
pkt := p.(*mhfpacket.MsgMhfEnumerateHouse) CharID uint32 `db:"id"`
doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00}) HRP uint16 `db:"hrp"`
GR uint16 `db:"gr"`
Name string `db:"name"`
} }
func handleMsgMhfUpdateHouse(s *Session, p mhfpacket.MHFPacket) {} func handleMsgMhfEnumerateHouse(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfEnumerateHouse)
bf := byteframe.NewByteFrame()
var houses []HouseData
switch pkt.Method {
case 1:
var friendsList string
s.server.db.QueryRow("SELECT friends FROM characters WHERE id=$1", s.charID).Scan(&friendsList)
cids := stringsupport.CSVElems(friendsList)
for _, cid := range cids {
house := HouseData{}
row := s.server.db.QueryRowx("SELECT id, hrp, gr, name FROM characters WHERE id=$1", cid)
err := row.StructScan(&house)
if err != nil {
panic(err)
} else {
houses = append(houses, house)
}
}
case 2:
guild, err := GetGuildInfoByCharacterId(s, s.charID)
if err != nil {
break
}
guildMembers, err := GetGuildMembers(s, guild.ID, false)
if err != nil {
break
}
for _, member := range guildMembers {
house := HouseData{}
row := s.server.db.QueryRowx("SELECT id, hrp, gr, name FROM characters WHERE id=$1", member.CharID)
err := row.StructScan(&house)
if err != nil {
panic(err)
} else {
houses = append(houses, house)
}
}
case 3:
house := HouseData{}
row := s.server.db.QueryRowx("SELECT id, hrp, gr, name FROM characters WHERE name=$1", pkt.Name)
err := row.StructScan(&house)
if err != nil {
panic(err)
} else {
houses = append(houses, house)
}
case 4:
house := HouseData{}
row := s.server.db.QueryRowx("SELECT id, hrp, gr, name FROM characters WHERE id=$1", pkt.CharID)
err := row.StructScan(&house)
if err != nil {
panic(err)
} else {
houses = append(houses, house)
}
case 5: // Recent visitors
break
}
var exists int
for _, house := range houses {
for _, session := range s.server.sessions {
if session.charID == house.CharID {
exists++
bf.WriteUint32(house.CharID)
bf.WriteUint8(session.house.state)
if len(session.house.password) > 0 {
bf.WriteUint8(3)
} else {
bf.WriteUint8(0)
}
bf.WriteUint16(house.HRP)
bf.WriteUint16(house.GR)
ps.Uint8(bf, house.Name, true)
break
}
}
}
resp := byteframe.NewByteFrame()
resp.WriteUint16(uint16(exists))
resp.WriteBytes(bf.Data())
doAckBufSucceed(s, pkt.AckHandle, resp.Data())
}
func handleMsgMhfUpdateHouse(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfUpdateHouse)
// 01 = closed
// 02 = open anyone
// 03 = open friends
// 04 = open guild
// 05 = open friends+guild
s.house.state = pkt.State
s.house.password = pkt.Password
doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
}
func handleMsgMhfLoadHouse(s *Session, p mhfpacket.MHFPacket) { func handleMsgMhfLoadHouse(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfLoadHouse) pkt := p.(*mhfpacket.MsgMhfLoadHouse)
bf := byteframe.NewByteFrame() bf := byteframe.NewByteFrame()
var data []byte var data []byte
err := s.server.db.QueryRow("SELECT house FROM characters WHERE id=$1", s.charID).Scan(&data) err := s.server.db.QueryRow("SELECT house FROM characters WHERE id=$1", pkt.CharID).Scan(&data)
if err != nil { if err != nil {
panic(err) panic(err)
} }
if data == nil { if data == nil {
data = make([]byte, 20) data = make([]byte, 20)
} }
if pkt.CharID != s.charID { // TODO: Find where the missing data comes from, savefile offset?
bf.WriteBytes(make([]byte, 219)) switch pkt.Destination {
case 3: // Others house
houseTier := uint8(2) // Fallback if can't find
for _, session := range s.server.sessions {
if session.charID == pkt.CharID {
if pkt.Password != session.house.password {
// Not the correct error code but works
doAckSimpleFail(s, pkt.AckHandle, make([]byte, 4))
return
}
houseTier = session.house.tier
}
}
bf.WriteBytes(make([]byte, 4))
bf.WriteUint8(houseTier) // House tier 0x1FB70
// Item box style
// Rastae
// Partner
bf.WriteBytes(make([]byte, 214))
bf.WriteBytes(data)
case 4: // Bookshelf
// Hunting log
// Street names/Aliases
bf.WriteBytes(make([]byte, 5576))
case 5: // Gallery
// Furniture placement
bf.WriteBytes(make([]byte, 1748))
case 8: // Tore
// Sister
// Cat shops
// Pugis
bf.WriteBytes(make([]byte, 240))
case 9: // Own house
bf.WriteBytes(data)
case 10: // Garden
// Gardening upgrades
// Gooks
bf.WriteBytes(make([]byte, 72))
} }
bf.WriteBytes(data)
doAckBufSucceed(s, pkt.AckHandle, bf.Data()) doAckBufSucceed(s, pkt.AckHandle, bf.Data())
} }

View File

@@ -27,6 +27,7 @@ type Session struct {
sendPackets chan []byte sendPackets chan []byte
clientContext *clientctx.ClientContext clientContext *clientctx.ClientContext
house House
stageID string stageID string
stage *Stage stage *Stage
reservationStage *Stage // Required for the stateful MsgSysUnreserveStage packet. reservationStage *Stage // Required for the stateful MsgSysUnreserveStage packet.
@@ -54,6 +55,12 @@ type Session struct {
Name string Name string
} }
type House struct {
tier uint8
state uint8
password string
}
// NewSession creates a new Session type. // NewSession creates a new Session type.
func NewSession(server *Server, conn net.Conn) *Session { func NewSession(server *Server, conn net.Conn) *Session {
s := &Session{ s := &Session{