mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-13 23:44:52 +01:00
matchmaking support
This commit is contained in:
@@ -1,15 +1,19 @@
|
|||||||
package mhfpacket
|
package mhfpacket
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"erupe-ce/common/bfutil"
|
||||||
|
|
||||||
"erupe-ce/network/clientctx"
|
|
||||||
"erupe-ce/network"
|
|
||||||
"erupe-ce/common/byteframe"
|
"erupe-ce/common/byteframe"
|
||||||
|
"erupe-ce/network"
|
||||||
|
"erupe-ce/network/clientctx"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MsgSysAcquireSemaphore represents the MSG_SYS_ACQUIRE_SEMAPHORE
|
// MsgSysAcquireSemaphore represents the MSG_SYS_ACQUIRE_SEMAPHORE
|
||||||
type MsgSysAcquireSemaphore struct{}
|
type MsgSysAcquireSemaphore struct {
|
||||||
|
AckHandle uint32
|
||||||
|
SemaphoreID string
|
||||||
|
}
|
||||||
|
|
||||||
// Opcode returns the ID associated with this packet type.
|
// Opcode returns the ID associated with this packet type.
|
||||||
func (m *MsgSysAcquireSemaphore) Opcode() network.PacketID {
|
func (m *MsgSysAcquireSemaphore) Opcode() network.PacketID {
|
||||||
@@ -18,7 +22,10 @@ func (m *MsgSysAcquireSemaphore) Opcode() network.PacketID {
|
|||||||
|
|
||||||
// Parse parses the packet from binary
|
// Parse parses the packet from binary
|
||||||
func (m *MsgSysAcquireSemaphore) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error {
|
func (m *MsgSysAcquireSemaphore) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error {
|
||||||
return errors.New("NOT IMPLEMENTED")
|
m.AckHandle = bf.ReadUint32()
|
||||||
|
SemaphoreIDLength := bf.ReadUint8()
|
||||||
|
m.SemaphoreID = string(bfutil.UpToNull(bf.ReadBytes(uint(SemaphoreIDLength))))
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build builds a binary packet from the current data.
|
// Build builds a binary packet from the current data.
|
||||||
|
|||||||
@@ -345,14 +345,11 @@ 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)
|
||||||
// 1 -> CID
|
|
||||||
// 2 -> Name
|
|
||||||
// 4 -> Group
|
|
||||||
resp := byteframe.NewByteFrame()
|
resp := byteframe.NewByteFrame()
|
||||||
resp.WriteUint16(0)
|
resp.WriteUint16(0)
|
||||||
var count uint16
|
var count uint16
|
||||||
switch pkt.SearchType {
|
switch pkt.SearchType {
|
||||||
case 1:
|
case 1: // CID
|
||||||
bf := byteframe.NewByteFrameFromBytes(pkt.MessageData)
|
bf := byteframe.NewByteFrameFromBytes(pkt.MessageData)
|
||||||
CharID := bf.ReadUint32()
|
CharID := bf.ReadUint32()
|
||||||
for _, c := range s.server.Channels {
|
for _, c := range s.server.Channels {
|
||||||
@@ -366,17 +363,17 @@ func handleMsgMhfTransitMessage(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
resp.WriteUint32(session.charID)
|
resp.WriteUint32(session.charID)
|
||||||
resp.WriteBool(true)
|
resp.WriteBool(true)
|
||||||
resp.WriteUint8(uint8(len(sessionName) + 1))
|
resp.WriteUint8(uint8(len(sessionName) + 1))
|
||||||
resp.WriteUint16(0x180) // lenUserBinary
|
resp.WriteUint16(uint16(len(c.userBinaryParts[userBinaryPartID{charID: session.charID, index: 3}])))
|
||||||
resp.WriteBytes(make([]byte, 40))
|
resp.WriteBytes(make([]byte, 40))
|
||||||
resp.WriteUint8(uint8(len(sessionStage) + 1))
|
resp.WriteUint8(uint8(len(sessionStage) + 1))
|
||||||
resp.WriteBytes(make([]byte, 8))
|
resp.WriteBytes(make([]byte, 8))
|
||||||
resp.WriteNullTerminatedBytes(sessionName)
|
resp.WriteNullTerminatedBytes(sessionName)
|
||||||
resp.WriteBytes(c.userBinaryParts[userBinaryPartID{charID: session.charID, index: 3}])
|
resp.WriteBytes(c.userBinaryParts[userBinaryPartID{session.charID, 3}])
|
||||||
resp.WriteNullTerminatedBytes(sessionStage)
|
resp.WriteNullTerminatedBytes(sessionStage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 2:
|
case 2: // Name
|
||||||
bf := byteframe.NewByteFrameFromBytes(pkt.MessageData)
|
bf := byteframe.NewByteFrameFromBytes(pkt.MessageData)
|
||||||
bf.ReadUint16() // lenSearchTerm
|
bf.ReadUint16() // lenSearchTerm
|
||||||
bf.ReadUint16() // maxResults
|
bf.ReadUint16() // maxResults
|
||||||
@@ -396,7 +393,7 @@ func handleMsgMhfTransitMessage(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
resp.WriteUint32(session.charID)
|
resp.WriteUint32(session.charID)
|
||||||
resp.WriteBool(true)
|
resp.WriteBool(true)
|
||||||
resp.WriteUint8(uint8(len(sessionName) + 1))
|
resp.WriteUint8(uint8(len(sessionName) + 1))
|
||||||
resp.WriteUint16(0x180) // lenUserBinary
|
resp.WriteUint16(uint16(len(c.userBinaryParts[userBinaryPartID{session.charID, 3}])))
|
||||||
resp.WriteBytes(make([]byte, 40))
|
resp.WriteBytes(make([]byte, 40))
|
||||||
resp.WriteUint8(uint8(len(sessionStage) + 1))
|
resp.WriteUint8(uint8(len(sessionStage) + 1))
|
||||||
resp.WriteBytes(make([]byte, 8))
|
resp.WriteBytes(make([]byte, 8))
|
||||||
@@ -406,6 +403,95 @@ func handleMsgMhfTransitMessage(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case 3: // Enumerate Party
|
||||||
|
bf := byteframe.NewByteFrameFromBytes(pkt.MessageData)
|
||||||
|
ip := bf.ReadBytes(4)
|
||||||
|
ipString := fmt.Sprintf("%d.%d.%d.%d", ip[3], ip[2], ip[1], ip[0])
|
||||||
|
port := bf.ReadUint16()
|
||||||
|
bf.ReadUint16() // lenStage
|
||||||
|
maxResults := bf.ReadUint16()
|
||||||
|
bf.ReadBytes(1)
|
||||||
|
stageID := stringsupport.SJISToUTF8(bf.ReadNullTerminatedBytes())
|
||||||
|
for _, c := range s.server.Channels {
|
||||||
|
if c.IP == ipString && c.Port == port {
|
||||||
|
for _, stage := range c.stages {
|
||||||
|
if stage.id == stageID {
|
||||||
|
if count == maxResults {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
for session := range stage.clients {
|
||||||
|
count++
|
||||||
|
sessionStage := stringsupport.UTF8ToSJIS(session.stageID)
|
||||||
|
sessionName := stringsupport.UTF8ToSJIS(session.Name)
|
||||||
|
resp.WriteUint32(binary.LittleEndian.Uint32(net.ParseIP(c.IP).To4()))
|
||||||
|
resp.WriteUint16(c.Port)
|
||||||
|
resp.WriteUint32(session.charID)
|
||||||
|
resp.WriteUint8(uint8(len(sessionStage) + 1))
|
||||||
|
resp.WriteUint8(uint8(len(sessionName) + 1))
|
||||||
|
resp.WriteUint8(0)
|
||||||
|
resp.WriteUint8(7) // lenBinary
|
||||||
|
resp.WriteBytes(make([]byte, 48))
|
||||||
|
resp.WriteNullTerminatedBytes(sessionStage)
|
||||||
|
resp.WriteNullTerminatedBytes(sessionName)
|
||||||
|
resp.WriteUint16(999) // HR
|
||||||
|
resp.WriteUint16(999) // GR
|
||||||
|
resp.WriteBytes([]byte{0x06, 0x10, 0x00}) // Unk
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case 4: // Find Party
|
||||||
|
bf := byteframe.NewByteFrameFromBytes(pkt.MessageData)
|
||||||
|
bf.ReadUint8()
|
||||||
|
maxResults := bf.ReadUint16()
|
||||||
|
bf.ReadUint8()
|
||||||
|
bf.ReadUint8()
|
||||||
|
partyType := bf.ReadUint16()
|
||||||
|
_ = bf.DataFromCurrent() // Restrictions
|
||||||
|
var stagePrefix string
|
||||||
|
switch partyType {
|
||||||
|
case 0: // Public Bar
|
||||||
|
stagePrefix = "sl2Ls210"
|
||||||
|
case 1: // Tokotoko Partnya
|
||||||
|
stagePrefix = "sl2Ls463"
|
||||||
|
case 2: // Hunting Prowess Match
|
||||||
|
stagePrefix = "sl2Ls286"
|
||||||
|
case 3: // Volpakkun Together
|
||||||
|
stagePrefix = "sl2Ls465"
|
||||||
|
case 5: // Quick Party
|
||||||
|
// Unk
|
||||||
|
}
|
||||||
|
for _, c := range s.server.Channels {
|
||||||
|
for _, stage := range c.stages {
|
||||||
|
if count == maxResults {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(stage.id, stagePrefix) {
|
||||||
|
count++
|
||||||
|
sessionStage := stringsupport.UTF8ToSJIS(stage.id)
|
||||||
|
resp.WriteUint32(binary.LittleEndian.Uint32(net.ParseIP(c.IP).To4()))
|
||||||
|
resp.WriteUint16(c.Port)
|
||||||
|
|
||||||
|
// TODO: This is half right, could be trimmed
|
||||||
|
resp.WriteUint16(0)
|
||||||
|
resp.WriteUint16(uint16(len(stage.clients)))
|
||||||
|
resp.WriteUint16(uint16(len(stage.clients)))
|
||||||
|
resp.WriteUint16(stage.maxPlayers)
|
||||||
|
resp.WriteUint16(0)
|
||||||
|
resp.WriteUint16(uint16(len(stage.clients)))
|
||||||
|
//
|
||||||
|
|
||||||
|
resp.WriteUint16(uint16(len(sessionStage) + 1))
|
||||||
|
resp.WriteUint8(1)
|
||||||
|
resp.WriteUint8(uint8(len(stage.rawBinaryData[stageBinaryKey{1, 1}])))
|
||||||
|
resp.WriteBytes(make([]byte, 16))
|
||||||
|
resp.WriteNullTerminatedBytes(sessionStage)
|
||||||
|
resp.WriteBytes([]byte{0x00})
|
||||||
|
resp.WriteBytes(stage.rawBinaryData[stageBinaryKey{1, 1}])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
resp.Seek(0, io.SeekStart)
|
resp.Seek(0, io.SeekStart)
|
||||||
resp.WriteUint16(count)
|
resp.WriteUint16(count)
|
||||||
|
|||||||
@@ -124,7 +124,16 @@ func handleMsgSysCreateAcquireSemaphore(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handleMsgSysAcquireSemaphore(s *Session, p mhfpacket.MHFPacket) {
|
func handleMsgSysAcquireSemaphore(s *Session, p mhfpacket.MHFPacket) {
|
||||||
//pkt := p.(*mhfpacket.MsgSysAcquireSemaphore)
|
pkt := p.(*mhfpacket.MsgSysAcquireSemaphore)
|
||||||
|
if sema, exists := s.server.semaphore[pkt.SemaphoreID]; exists {
|
||||||
|
sema.clients[s] = s.charID
|
||||||
|
bf := byteframe.NewByteFrame()
|
||||||
|
bf.WriteUint32(sema.id)
|
||||||
|
doAckSimpleSucceed(s, pkt.AckHandle, bf.Data())
|
||||||
|
} else {
|
||||||
|
doAckSimpleFail(s, pkt.AckHandle, make([]byte, 4))
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleMsgSysReleaseSemaphore(s *Session, p mhfpacket.MHFPacket) {
|
func handleMsgSysReleaseSemaphore(s *Session, p mhfpacket.MHFPacket) {
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ func (s *Session) makeSignInResp(uid int) []byte {
|
|||||||
bf.WriteUint32(uint32(channelserver.Time_Current_Adjusted().Add(24 * time.Hour * 7).Unix()))
|
bf.WriteUint32(uint32(channelserver.Time_Current_Adjusted().Add(24 * time.Hour * 7).Unix()))
|
||||||
bf.WriteUint8(2) // Unk
|
bf.WriteUint8(2) // Unk
|
||||||
bf.WriteUint32(20) // Single tickets
|
bf.WriteUint32(20) // Single tickets
|
||||||
bf.WriteUint32(0) // Group tickets
|
bf.WriteUint32(10) // Group tickets
|
||||||
bf.WriteUint8(8) // Stalls open
|
bf.WriteUint8(8) // Stalls open
|
||||||
bf.WriteUint8(0xA) // Unk
|
bf.WriteUint8(0xA) // Unk
|
||||||
bf.WriteUint8(0x3) // Pachinko
|
bf.WriteUint8(0x3) // Pachinko
|
||||||
|
|||||||
Reference in New Issue
Block a user