mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-14 07:55:33 +01:00
refactor TransitMessage handler
This commit is contained in:
@@ -366,36 +366,41 @@ 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)
|
||||||
|
bf := byteframe.NewByteFrameFromBytes(pkt.MessageData)
|
||||||
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: // CID
|
case 1: // usersearchidx
|
||||||
bf := byteframe.NewByteFrameFromBytes(pkt.MessageData)
|
cid := bf.ReadUint32()
|
||||||
CharID := bf.ReadUint32()
|
|
||||||
for _, c := range s.server.Channels {
|
for _, c := range s.server.Channels {
|
||||||
for _, session := range c.sessions {
|
for _, session := range c.sessions {
|
||||||
if session.charID == CharID {
|
if session.charID == cid {
|
||||||
count++
|
count++
|
||||||
sessionName := stringsupport.UTF8ToSJIS(session.Name)
|
sessionName := stringsupport.UTF8ToSJIS(session.Name)
|
||||||
sessionStage := stringsupport.UTF8ToSJIS(session.stage.id)
|
sessionStage := stringsupport.UTF8ToSJIS(session.stage.id)
|
||||||
resp.WriteUint32(binary.LittleEndian.Uint32(net.ParseIP(c.IP).To4()))
|
resp.WriteUint32(binary.LittleEndian.Uint32(net.ParseIP(c.IP).To4()))
|
||||||
resp.WriteUint16(c.Port)
|
resp.WriteUint16(c.Port)
|
||||||
resp.WriteUint32(session.charID)
|
resp.WriteUint32(session.charID)
|
||||||
resp.WriteBool(true)
|
resp.WriteUint8(uint8(len(sessionStage) + 1))
|
||||||
resp.WriteUint8(uint8(len(sessionName) + 1))
|
resp.WriteUint8(uint8(len(sessionName) + 1))
|
||||||
resp.WriteUint16(uint16(len(c.userBinaryParts[userBinaryPartID{charID: session.charID, index: 3}])))
|
resp.WriteUint16(uint16(len(c.userBinaryParts[userBinaryPartID{charID: session.charID, index: 3}])))
|
||||||
resp.WriteBytes(make([]byte, 40))
|
|
||||||
resp.WriteUint8(uint8(len(sessionStage) + 1))
|
// TODO: These cases might be <=G2
|
||||||
|
if _config.ErupeConfig.RealClientMode <= _config.G1 {
|
||||||
|
resp.WriteBytes(make([]byte, 8))
|
||||||
|
} else {
|
||||||
|
resp.WriteBytes(make([]byte, 40))
|
||||||
|
}
|
||||||
resp.WriteBytes(make([]byte, 8))
|
resp.WriteBytes(make([]byte, 8))
|
||||||
|
|
||||||
|
resp.WriteNullTerminatedBytes(sessionStage)
|
||||||
resp.WriteNullTerminatedBytes(sessionName)
|
resp.WriteNullTerminatedBytes(sessionName)
|
||||||
resp.WriteBytes(c.userBinaryParts[userBinaryPartID{session.charID, 3}])
|
resp.WriteBytes(c.userBinaryParts[userBinaryPartID{session.charID, 3}])
|
||||||
resp.WriteNullTerminatedBytes(sessionStage)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 2: // Name
|
case 2: // usersearchname
|
||||||
bf := byteframe.NewByteFrameFromBytes(pkt.MessageData)
|
|
||||||
bf.ReadUint16() // lenSearchTerm
|
bf.ReadUint16() // lenSearchTerm
|
||||||
bf.ReadUint16() // maxResults
|
bf.ReadUint16() // maxResults
|
||||||
bf.ReadUint8() // Unk
|
bf.ReadUint8() // Unk
|
||||||
@@ -411,28 +416,33 @@ func handleMsgMhfTransitMessage(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
sessionStage := stringsupport.UTF8ToSJIS(session.stage.id)
|
sessionStage := stringsupport.UTF8ToSJIS(session.stage.id)
|
||||||
resp.WriteUint32(binary.LittleEndian.Uint32(net.ParseIP(c.IP).To4()))
|
resp.WriteUint32(binary.LittleEndian.Uint32(net.ParseIP(c.IP).To4()))
|
||||||
resp.WriteUint16(c.Port)
|
resp.WriteUint16(c.Port)
|
||||||
|
|
||||||
resp.WriteUint32(session.charID)
|
resp.WriteUint32(session.charID)
|
||||||
resp.WriteBool(true)
|
resp.WriteUint8(uint8(len(sessionStage) + 1))
|
||||||
resp.WriteUint8(uint8(len(sessionName) + 1))
|
resp.WriteUint8(uint8(len(sessionName) + 1))
|
||||||
resp.WriteUint16(uint16(len(c.userBinaryParts[userBinaryPartID{session.charID, 3}])))
|
resp.WriteUint16(uint16(len(c.userBinaryParts[userBinaryPartID{session.charID, 3}])))
|
||||||
resp.WriteBytes(make([]byte, 40))
|
|
||||||
resp.WriteUint8(uint8(len(sessionStage) + 1))
|
if _config.ErupeConfig.RealClientMode <= _config.G1 {
|
||||||
|
resp.WriteBytes(make([]byte, 8))
|
||||||
|
} else {
|
||||||
|
resp.WriteBytes(make([]byte, 40))
|
||||||
|
}
|
||||||
resp.WriteBytes(make([]byte, 8))
|
resp.WriteBytes(make([]byte, 8))
|
||||||
|
|
||||||
|
resp.WriteNullTerminatedBytes(sessionStage)
|
||||||
resp.WriteNullTerminatedBytes(sessionName)
|
resp.WriteNullTerminatedBytes(sessionName)
|
||||||
resp.WriteBytes(c.userBinaryParts[userBinaryPartID{charID: session.charID, index: 3}])
|
resp.WriteBytes(c.userBinaryParts[userBinaryPartID{charID: session.charID, index: 3}])
|
||||||
resp.WriteNullTerminatedBytes(sessionStage)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 3: // Enumerate Party
|
case 3: // lobbysearchname
|
||||||
bf := byteframe.NewByteFrameFromBytes(pkt.MessageData)
|
|
||||||
ip := bf.ReadBytes(4)
|
ip := bf.ReadBytes(4)
|
||||||
ipString := fmt.Sprintf("%d.%d.%d.%d", ip[3], ip[2], ip[1], ip[0])
|
ipString := fmt.Sprintf("%d.%d.%d.%d", ip[3], ip[2], ip[1], ip[0])
|
||||||
port := bf.ReadUint16()
|
port := bf.ReadUint16()
|
||||||
bf.ReadUint16() // lenStage
|
bf.ReadUint16() // Len stageID
|
||||||
maxResults := bf.ReadUint16()
|
maxResults := bf.ReadUint16()
|
||||||
bf.ReadBytes(1)
|
bf.ReadUint8()
|
||||||
stageID := stringsupport.SJISToUTF8(bf.ReadNullTerminatedBytes())
|
stageID := string(bf.ReadNullTerminatedBytes())
|
||||||
for _, c := range s.server.Channels {
|
for _, c := range s.server.Channels {
|
||||||
if c.IP == ipString && c.Port == port {
|
if c.IP == ipString && c.Port == port {
|
||||||
for _, stage := range c.stages {
|
for _, stage := range c.stages {
|
||||||
@@ -442,9 +452,6 @@ func handleMsgMhfTransitMessage(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
}
|
}
|
||||||
for session := range stage.clients {
|
for session := range stage.clients {
|
||||||
count++
|
count++
|
||||||
hrp := uint16(1)
|
|
||||||
gr := uint16(0)
|
|
||||||
s.server.db.QueryRow("SELECT hrp, gr FROM characters WHERE id=$1", session.charID).Scan(&hrp, &gr)
|
|
||||||
sessionStage := stringsupport.UTF8ToSJIS(session.stage.id)
|
sessionStage := stringsupport.UTF8ToSJIS(session.stage.id)
|
||||||
sessionName := stringsupport.UTF8ToSJIS(session.Name)
|
sessionName := stringsupport.UTF8ToSJIS(session.Name)
|
||||||
resp.WriteUint32(binary.LittleEndian.Uint32(net.ParseIP(c.IP).To4()))
|
resp.WriteUint32(binary.LittleEndian.Uint32(net.ParseIP(c.IP).To4()))
|
||||||
@@ -452,57 +459,60 @@ func handleMsgMhfTransitMessage(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
resp.WriteUint32(session.charID)
|
resp.WriteUint32(session.charID)
|
||||||
resp.WriteUint8(uint8(len(sessionStage) + 1))
|
resp.WriteUint8(uint8(len(sessionStage) + 1))
|
||||||
resp.WriteUint8(uint8(len(sessionName) + 1))
|
resp.WriteUint8(uint8(len(sessionName) + 1))
|
||||||
resp.WriteUint8(0)
|
resp.WriteUint16(uint16(len(c.userBinaryParts[userBinaryPartID{session.charID, 3}])))
|
||||||
resp.WriteUint8(7) // lenBinary
|
|
||||||
resp.WriteBytes(make([]byte, 48))
|
if _config.ErupeConfig.RealClientMode <= _config.G1 {
|
||||||
|
resp.WriteBytes(make([]byte, 8))
|
||||||
|
} else {
|
||||||
|
resp.WriteBytes(make([]byte, 40))
|
||||||
|
}
|
||||||
|
resp.WriteBytes(make([]byte, 8))
|
||||||
|
|
||||||
resp.WriteNullTerminatedBytes(sessionStage)
|
resp.WriteNullTerminatedBytes(sessionStage)
|
||||||
resp.WriteNullTerminatedBytes(sessionName)
|
resp.WriteNullTerminatedBytes(sessionName)
|
||||||
resp.WriteUint16(hrp)
|
resp.WriteBytes(c.userBinaryParts[userBinaryPartID{charID: session.charID, index: 3}])
|
||||||
resp.WriteUint16(gr)
|
|
||||||
resp.WriteBytes([]byte{0x06, 0x10, 0x00}) // Unk
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 4: // Find Party
|
case 4: // lobbysearch
|
||||||
type FindPartyParams struct {
|
type FindPartyParams struct {
|
||||||
StagePrefix string
|
StagePrefix string
|
||||||
RankRestriction uint16
|
RankRestriction int16
|
||||||
Targets []uint16
|
Targets []int16
|
||||||
Unk0 []uint16
|
Unk0 []int16
|
||||||
Unk1 []uint16
|
Unk1 []int16
|
||||||
QuestID []uint16
|
QuestID []int16
|
||||||
}
|
}
|
||||||
findPartyParams := FindPartyParams{
|
findPartyParams := FindPartyParams{
|
||||||
StagePrefix: "sl2Ls210",
|
StagePrefix: "sl2Ls210",
|
||||||
}
|
}
|
||||||
bf := byteframe.NewByteFrameFromBytes(pkt.MessageData)
|
numParams := bf.ReadUint8()
|
||||||
numParams := int(bf.ReadUint8())
|
|
||||||
maxResults := bf.ReadUint16()
|
maxResults := bf.ReadUint16()
|
||||||
for i := 0; i < numParams; i++ {
|
for i := uint8(0); i < numParams; i++ {
|
||||||
switch bf.ReadUint8() {
|
switch bf.ReadUint8() {
|
||||||
case 0:
|
case 0:
|
||||||
values := int(bf.ReadUint8())
|
values := bf.ReadUint8()
|
||||||
for i := 0; i < values; i++ {
|
for i := uint8(0); i < values; i++ {
|
||||||
if _config.ErupeConfig.RealClientMode >= _config.Z1 {
|
if _config.ErupeConfig.RealClientMode >= _config.Z1 {
|
||||||
findPartyParams.RankRestriction = bf.ReadUint16()
|
findPartyParams.RankRestriction = bf.ReadInt16()
|
||||||
} else {
|
} else {
|
||||||
findPartyParams.RankRestriction = uint16(bf.ReadInt8())
|
findPartyParams.RankRestriction = int16(bf.ReadInt8())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 1:
|
case 1:
|
||||||
values := int(bf.ReadUint8())
|
values := bf.ReadUint8()
|
||||||
for i := 0; i < values; i++ {
|
for i := uint8(0); i < values; i++ {
|
||||||
if _config.ErupeConfig.RealClientMode >= _config.Z1 {
|
if _config.ErupeConfig.RealClientMode >= _config.Z1 {
|
||||||
findPartyParams.Targets = append(findPartyParams.Targets, bf.ReadUint16())
|
findPartyParams.Targets = append(findPartyParams.Targets, bf.ReadInt16())
|
||||||
} else {
|
} else {
|
||||||
findPartyParams.Targets = append(findPartyParams.Targets, uint16(bf.ReadInt8()))
|
findPartyParams.Targets = append(findPartyParams.Targets, int16(bf.ReadInt8()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 2:
|
case 2:
|
||||||
values := int(bf.ReadUint8())
|
values := bf.ReadUint8()
|
||||||
for i := 0; i < values; i++ {
|
for i := uint8(0); i < values; i++ {
|
||||||
var value int16
|
var value int16
|
||||||
if _config.ErupeConfig.RealClientMode >= _config.Z1 {
|
if _config.ErupeConfig.RealClientMode >= _config.Z1 {
|
||||||
value = bf.ReadInt16()
|
value = bf.ReadInt16()
|
||||||
@@ -523,30 +533,30 @@ func handleMsgMhfTransitMessage(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 3: // Unknown
|
case 3: // Unknown
|
||||||
values := int(bf.ReadUint8())
|
values := bf.ReadUint8()
|
||||||
for i := 0; i < values; i++ {
|
for i := uint8(0); i < values; i++ {
|
||||||
if _config.ErupeConfig.RealClientMode >= _config.Z1 {
|
if _config.ErupeConfig.RealClientMode >= _config.Z1 {
|
||||||
findPartyParams.Unk0 = append(findPartyParams.Unk0, bf.ReadUint16())
|
findPartyParams.Unk0 = append(findPartyParams.Unk0, bf.ReadInt16())
|
||||||
} else {
|
} else {
|
||||||
findPartyParams.Unk0 = append(findPartyParams.Unk0, uint16(bf.ReadInt8()))
|
findPartyParams.Unk0 = append(findPartyParams.Unk0, int16(bf.ReadInt8()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 4: // Looking for n or already have n
|
case 4: // Looking for n or already have n
|
||||||
values := int(bf.ReadUint8())
|
values := bf.ReadUint8()
|
||||||
for i := 0; i < values; i++ {
|
for i := uint8(0); i < values; i++ {
|
||||||
if _config.ErupeConfig.RealClientMode >= _config.Z1 {
|
if _config.ErupeConfig.RealClientMode >= _config.Z1 {
|
||||||
findPartyParams.Unk1 = append(findPartyParams.Unk1, bf.ReadUint16())
|
findPartyParams.Unk1 = append(findPartyParams.Unk1, bf.ReadInt16())
|
||||||
} else {
|
} else {
|
||||||
findPartyParams.Unk1 = append(findPartyParams.Unk1, uint16(bf.ReadInt8()))
|
findPartyParams.Unk1 = append(findPartyParams.Unk1, int16(bf.ReadInt8()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 5:
|
case 5:
|
||||||
values := int(bf.ReadUint8())
|
values := bf.ReadUint8()
|
||||||
for i := 0; i < values; i++ {
|
for i := uint8(0); i < values; i++ {
|
||||||
if _config.ErupeConfig.RealClientMode >= _config.Z1 {
|
if _config.ErupeConfig.RealClientMode >= _config.Z1 {
|
||||||
findPartyParams.QuestID = append(findPartyParams.QuestID, bf.ReadUint16())
|
findPartyParams.QuestID = append(findPartyParams.QuestID, bf.ReadInt16())
|
||||||
} else {
|
} else {
|
||||||
findPartyParams.QuestID = append(findPartyParams.QuestID, uint16(bf.ReadInt8()))
|
findPartyParams.QuestID = append(findPartyParams.QuestID, int16(bf.ReadInt8()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -559,37 +569,64 @@ func handleMsgMhfTransitMessage(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
if strings.HasPrefix(stage.id, findPartyParams.StagePrefix) {
|
if strings.HasPrefix(stage.id, findPartyParams.StagePrefix) {
|
||||||
sb3 := byteframe.NewByteFrameFromBytes(stage.rawBinaryData[stageBinaryKey{1, 3}])
|
sb3 := byteframe.NewByteFrameFromBytes(stage.rawBinaryData[stageBinaryKey{1, 3}])
|
||||||
sb3.Seek(4, 0)
|
sb3.Seek(4, 0)
|
||||||
stageRankRestriction := sb3.ReadUint16()
|
|
||||||
stageTarget := sb3.ReadUint16()
|
stageDataParams := 8
|
||||||
if stageRankRestriction > findPartyParams.RankRestriction {
|
if _config.ErupeConfig.RealClientMode <= _config.G10 {
|
||||||
|
stageDataParams = 4
|
||||||
|
} else if _config.ErupeConfig.RealClientMode <= _config.Z1 {
|
||||||
|
stageDataParams = 6
|
||||||
|
} else if _config.ErupeConfig.RealClientMode <= _config.Z2 {
|
||||||
|
stageDataParams = 7
|
||||||
|
}
|
||||||
|
|
||||||
|
var stageData []int16
|
||||||
|
for i := 0; i < stageDataParams; i++ {
|
||||||
|
if _config.ErupeConfig.RealClientMode >= _config.Z1 {
|
||||||
|
stageData = append(stageData, sb3.ReadInt16())
|
||||||
|
} else {
|
||||||
|
stageData = append(stageData, int16(sb3.ReadInt8()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if stageData[0] > findPartyParams.RankRestriction {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var hasTarget bool
|
||||||
if len(findPartyParams.Targets) > 0 {
|
if len(findPartyParams.Targets) > 0 {
|
||||||
for _, target := range findPartyParams.Targets {
|
for _, target := range findPartyParams.Targets {
|
||||||
if target == stageTarget {
|
if target == stageData[1] {
|
||||||
|
hasTarget = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
continue
|
if !hasTarget {
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
count++
|
count++
|
||||||
sessionStage := stringsupport.UTF8ToSJIS(stage.id)
|
|
||||||
resp.WriteUint32(binary.LittleEndian.Uint32(net.ParseIP(c.IP).To4()))
|
resp.WriteUint32(binary.LittleEndian.Uint32(net.ParseIP(c.IP).To4()))
|
||||||
resp.WriteUint16(c.Port)
|
resp.WriteUint16(c.Port)
|
||||||
|
|
||||||
resp.WriteUint16(0) // Static?
|
resp.WriteUint16(0) // Static?
|
||||||
resp.WriteUint16(0) // Unk
|
resp.WriteUint16(0) // Unk
|
||||||
resp.WriteUint16(uint16(len(stage.clients)))
|
resp.WriteUint16(uint16(len(stage.reservedClientSlots)))
|
||||||
resp.WriteUint16(stage.maxPlayers)
|
|
||||||
resp.WriteUint16(0) // Num clients entered from stage
|
|
||||||
resp.WriteUint16(stage.maxPlayers)
|
resp.WriteUint16(stage.maxPlayers)
|
||||||
|
resp.WriteUint16(uint16(len(stage.clients))) // Num clients entered from stage
|
||||||
|
|
||||||
|
resp.WriteUint8(0) // Unk
|
||||||
|
resp.WriteUint8(uint8(stage.maxPlayers))
|
||||||
resp.WriteUint8(1) // Static?
|
resp.WriteUint8(1) // Static?
|
||||||
resp.WriteUint8(uint8(len(sessionStage) + 1))
|
resp.WriteUint8(uint8(len(stage.id) + 1))
|
||||||
resp.WriteUint8(uint8(len(stage.rawBinaryData[stageBinaryKey{1, 0}])))
|
resp.WriteUint8(uint8(len(stage.rawBinaryData[stageBinaryKey{1, 0}])))
|
||||||
resp.WriteUint8(uint8(len(stage.rawBinaryData[stageBinaryKey{1, 1}])))
|
resp.WriteUint8(uint8(len(stage.rawBinaryData[stageBinaryKey{1, 1}])))
|
||||||
resp.WriteUint16(stageRankRestriction)
|
|
||||||
resp.WriteUint16(stageTarget)
|
for i := range stageData {
|
||||||
resp.WriteBytes(make([]byte, 12))
|
resp.WriteInt16(stageData[i])
|
||||||
resp.WriteNullTerminatedBytes(sessionStage)
|
}
|
||||||
|
|
||||||
|
resp.WriteNullTerminatedBytes([]byte(stage.id))
|
||||||
resp.WriteBytes(stage.rawBinaryData[stageBinaryKey{1, 0}])
|
resp.WriteBytes(stage.rawBinaryData[stageBinaryKey{1, 0}])
|
||||||
resp.WriteBytes(stage.rawBinaryData[stageBinaryKey{1, 1}])
|
resp.WriteBytes(stage.rawBinaryData[stageBinaryKey{1, 1}])
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user