mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-02-04 09:15:08 +01:00
handle TransitMessage
This commit is contained in:
8
main.go
8
main.go
@@ -180,7 +180,13 @@ func main() {
|
|||||||
DB: db,
|
DB: db,
|
||||||
DiscordBot: discordBot,
|
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 {
|
if err != nil {
|
||||||
preventClose(fmt.Sprintf("Failed to start channel server: %s", err.Error()))
|
preventClose(fmt.Sprintf("Failed to start channel server: %s", err.Error()))
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,20 +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"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MsgMhfTransitMessage represents the MSG_MHF_TRANSIT_MESSAGE
|
// MsgMhfTransitMessage represents the MSG_MHF_TRANSIT_MESSAGE
|
||||||
type MsgMhfTransitMessage struct {
|
type MsgMhfTransitMessage struct {
|
||||||
AckHandle uint32
|
AckHandle uint32
|
||||||
Unk0 uint8
|
Unk0 uint8
|
||||||
Unk1 uint8
|
Unk1 uint8
|
||||||
Unk2 uint16
|
SearchType uint16
|
||||||
MessageData []byte
|
MessageData []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
// Opcode returns the ID associated with this packet type.
|
// 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
|
// Parse parses the packet from binary
|
||||||
func (m *MsgMhfTransitMessage) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error {
|
func (m *MsgMhfTransitMessage) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error {
|
||||||
m.AckHandle = bf.ReadUint32()
|
m.AckHandle = bf.ReadUint32()
|
||||||
m.Unk0 = bf.ReadUint8()
|
m.Unk0 = bf.ReadUint8()
|
||||||
m.Unk1 = bf.ReadUint8()
|
m.Unk1 = bf.ReadUint8()
|
||||||
m.Unk2 = bf.ReadUint16()
|
m.SearchType = bf.ReadUint16()
|
||||||
m.MessageData = bf.ReadBytes(uint(bf.ReadUint16()))
|
m.MessageData = bf.ReadBytes(uint(bf.ReadUint16()))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build builds a binary packet from the current data.
|
// Build builds a binary packet from the current data.
|
||||||
|
|||||||
@@ -4,7 +4,11 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"erupe-ce/common/stringsupport"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math/bits"
|
"math/bits"
|
||||||
@@ -341,10 +345,71 @@ func handleMsgSysRightsReload(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
|
|
||||||
func handleMsgMhfTransitMessage(s *Session, p mhfpacket.MHFPacket) {
|
func handleMsgMhfTransitMessage(s *Session, p mhfpacket.MHFPacket) {
|
||||||
pkt := p.(*mhfpacket.MsgMhfTransitMessage)
|
pkt := p.(*mhfpacket.MsgMhfTransitMessage)
|
||||||
// TODO: figure out what this is supposed to return
|
// 1 -> CID
|
||||||
// probably what world+land the targeted character is on?
|
// 2 -> Name
|
||||||
// stubbed response will just say user not found
|
// 4 -> Group
|
||||||
doAckBufSucceed(s, pkt.AckHandle, make([]byte, 4))
|
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) {}
|
func handleMsgCaExchangeItem(s *Session, p mhfpacket.MHFPacket) {}
|
||||||
|
|||||||
@@ -54,6 +54,8 @@ type Server struct {
|
|||||||
sync.Mutex
|
sync.Mutex
|
||||||
Channels []*Server
|
Channels []*Server
|
||||||
ID uint16
|
ID uint16
|
||||||
|
IP string
|
||||||
|
Port uint16
|
||||||
logger *zap.Logger
|
logger *zap.Logger
|
||||||
db *sqlx.DB
|
db *sqlx.DB
|
||||||
erupeConfig *config.Config
|
erupeConfig *config.Config
|
||||||
@@ -196,8 +198,8 @@ func NewServer(config *Config) *Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start starts the server in a new goroutine.
|
// Start starts the server in a new goroutine.
|
||||||
func (s *Server) Start(port int) error {
|
func (s *Server) Start() error {
|
||||||
l, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
|
l, err := net.Listen("tcp", fmt.Sprintf(":%d", s.Port))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user