handle TransitMessage

This commit is contained in:
wish
2022-08-05 01:57:56 +10:00
parent e9cc5cc3e2
commit 08a7b91e11
4 changed files with 94 additions and 21 deletions

View File

@@ -180,7 +180,13 @@ func main() {
DB: db,
DiscordBot: discordBot,
})
err = c.Start(int(ce.Port))
if ee.IP == "" {
c.IP = erupeConfig.Host
} else {
c.IP = ee.IP
}
c.Port = ce.Port
err = c.Start()
if err != nil {
preventClose(fmt.Sprintf("Failed to start channel server: %s", err.Error()))
} else {

View File

@@ -1,20 +1,20 @@
package mhfpacket
import (
"errors"
"errors"
"erupe-ce/network/clientctx"
"erupe-ce/network"
"erupe-ce/common/byteframe"
"erupe-ce/network"
"erupe-ce/network/clientctx"
)
// MsgMhfTransitMessage represents the MSG_MHF_TRANSIT_MESSAGE
type MsgMhfTransitMessage struct {
AckHandle uint32
Unk0 uint8
Unk1 uint8
Unk2 uint16
MessageData []byte
AckHandle uint32
Unk0 uint8
Unk1 uint8
SearchType uint16
MessageData []byte
}
// Opcode returns the ID associated with this packet type.
@@ -24,12 +24,12 @@ func (m *MsgMhfTransitMessage) Opcode() network.PacketID {
// Parse parses the packet from binary
func (m *MsgMhfTransitMessage) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error {
m.AckHandle = bf.ReadUint32()
m.Unk0 = bf.ReadUint8()
m.Unk1 = bf.ReadUint8()
m.Unk2 = bf.ReadUint16()
m.MessageData = bf.ReadBytes(uint(bf.ReadUint16()))
return nil
m.AckHandle = bf.ReadUint32()
m.Unk0 = bf.ReadUint8()
m.Unk1 = bf.ReadUint8()
m.SearchType = bf.ReadUint16()
m.MessageData = bf.ReadBytes(uint(bf.ReadUint16()))
return nil
}
// Build builds a binary packet from the current data.

View File

@@ -4,7 +4,11 @@ import (
"bytes"
"encoding/binary"
"encoding/hex"
"erupe-ce/common/stringsupport"
"fmt"
"io"
"net"
"strings"
"io/ioutil"
"math/bits"
@@ -341,10 +345,71 @@ func handleMsgSysRightsReload(s *Session, p mhfpacket.MHFPacket) {
func handleMsgMhfTransitMessage(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfTransitMessage)
// TODO: figure out what this is supposed to return
// probably what world+land the targeted character is on?
// stubbed response will just say user not found
doAckBufSucceed(s, pkt.AckHandle, make([]byte, 4))
// 1 -> CID
// 2 -> Name
// 4 -> Group
resp := byteframe.NewByteFrame()
resp.WriteUint16(0)
var count uint16
switch pkt.SearchType {
case 1:
bf := byteframe.NewByteFrameFromBytes(pkt.MessageData)
CharID := bf.ReadUint32()
for _, c := range s.server.Channels {
for _, session := range c.sessions {
if session.charID == CharID {
count++
sessionName := stringsupport.UTF8ToSJIS(session.Name)
sessionStage := stringsupport.UTF8ToSJIS(session.stageID)
resp.WriteUint32(binary.LittleEndian.Uint32(net.ParseIP(c.IP).To4()))
resp.WriteUint16(c.Port)
resp.WriteUint32(session.charID)
resp.WriteBool(true)
resp.WriteUint8(uint8(len(sessionName) + 1))
resp.WriteUint16(0x180) // lenUserBinary
resp.WriteBytes(make([]byte, 40))
resp.WriteUint8(uint8(len(sessionStage) + 1))
resp.WriteBytes(make([]byte, 8))
resp.WriteNullTerminatedBytes(sessionName)
resp.WriteBytes(c.userBinaryParts[userBinaryPartID{charID: session.charID, index: 3}])
resp.WriteNullTerminatedBytes(sessionStage)
}
}
}
case 2:
bf := byteframe.NewByteFrameFromBytes(pkt.MessageData)
bf.ReadUint16() // lenSearchTerm
bf.ReadUint16() // maxResults
bf.ReadUint8() // Unk
searchTerm := stringsupport.SJISToUTF8(bf.ReadNullTerminatedBytes())
for _, c := range s.server.Channels {
for _, session := range c.sessions {
if count == 100 {
break
}
if strings.Contains(session.Name, searchTerm) {
count++
sessionName := stringsupport.UTF8ToSJIS(session.Name)
sessionStage := stringsupport.UTF8ToSJIS(session.stageID)
resp.WriteUint32(binary.LittleEndian.Uint32(net.ParseIP(c.IP).To4()))
resp.WriteUint16(c.Port)
resp.WriteUint32(session.charID)
resp.WriteBool(true)
resp.WriteUint8(uint8(len(sessionName) + 1))
resp.WriteUint16(0x180) // lenUserBinary
resp.WriteBytes(make([]byte, 40))
resp.WriteUint8(uint8(len(sessionStage) + 1))
resp.WriteBytes(make([]byte, 8))
resp.WriteNullTerminatedBytes(sessionName)
resp.WriteBytes(c.userBinaryParts[userBinaryPartID{charID: session.charID, index: 3}])
resp.WriteNullTerminatedBytes(sessionStage)
}
}
}
}
resp.Seek(0, io.SeekStart)
resp.WriteUint16(count)
doAckBufSucceed(s, pkt.AckHandle, resp.Data())
}
func handleMsgCaExchangeItem(s *Session, p mhfpacket.MHFPacket) {}

View File

@@ -54,6 +54,8 @@ type Server struct {
sync.Mutex
Channels []*Server
ID uint16
IP string
Port uint16
logger *zap.Logger
db *sqlx.DB
erupeConfig *config.Config
@@ -196,8 +198,8 @@ func NewServer(config *Config) *Server {
}
// Start starts the server in a new goroutine.
func (s *Server) Start(port int) error {
l, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
func (s *Server) Start() error {
l, err := net.Listen("tcp", fmt.Sprintf(":%d", s.Port))
if err != nil {
return err
}