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:
@@ -372,126 +372,72 @@ func handleMsgMhfTransitMessage(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
local = true
|
local = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var maxResults, port, count uint16
|
||||||
|
var cid uint32
|
||||||
|
var term, ip string
|
||||||
bf := byteframe.NewByteFrameFromBytes(pkt.MessageData)
|
bf := byteframe.NewByteFrameFromBytes(pkt.MessageData)
|
||||||
|
switch pkt.SearchType {
|
||||||
|
case 1:
|
||||||
|
maxResults = 1
|
||||||
|
cid = bf.ReadUint32()
|
||||||
|
case 2:
|
||||||
|
bf.ReadUint16() // term length
|
||||||
|
maxResults = bf.ReadUint16()
|
||||||
|
bf.ReadUint8() // Unk
|
||||||
|
term = stringsupport.SJISToUTF8(bf.ReadNullTerminatedBytes())
|
||||||
|
case 3:
|
||||||
|
_ip := bf.ReadBytes(4)
|
||||||
|
ip = fmt.Sprintf("%d.%d.%d.%d", _ip[3], _ip[2], _ip[1], _ip[0])
|
||||||
|
port = bf.ReadUint16()
|
||||||
|
bf.ReadUint16() // term length
|
||||||
|
maxResults = bf.ReadUint16()
|
||||||
|
bf.ReadUint8()
|
||||||
|
term = string(bf.ReadNullTerminatedBytes())
|
||||||
|
}
|
||||||
|
|
||||||
resp := byteframe.NewByteFrame()
|
resp := byteframe.NewByteFrame()
|
||||||
resp.WriteUint16(0)
|
resp.WriteUint16(0)
|
||||||
var count uint16
|
|
||||||
switch pkt.SearchType {
|
switch pkt.SearchType {
|
||||||
case 1: // usersearchidx
|
case 1, 2, 3: // usersearchidx, usersearchname, lobbysearchname
|
||||||
cid := 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 == cid {
|
if count == maxResults {
|
||||||
count++
|
|
||||||
sessionName := stringsupport.UTF8ToSJIS(session.Name)
|
|
||||||
sessionStage := stringsupport.UTF8ToSJIS(session.stage.id)
|
|
||||||
if !local {
|
|
||||||
resp.WriteUint32(binary.LittleEndian.Uint32(net.ParseIP(c.IP).To4()))
|
|
||||||
} else {
|
|
||||||
resp.WriteUint32(0x0100007F)
|
|
||||||
}
|
|
||||||
resp.WriteUint16(c.Port)
|
|
||||||
resp.WriteUint32(session.charID)
|
|
||||||
resp.WriteUint8(uint8(len(sessionStage) + 1))
|
|
||||||
resp.WriteUint8(uint8(len(sessionName) + 1))
|
|
||||||
resp.WriteUint16(uint16(len(c.userBinaryParts[userBinaryPartID{charID: session.charID, index: 3}])))
|
|
||||||
|
|
||||||
// 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.WriteNullTerminatedBytes(sessionStage)
|
|
||||||
resp.WriteNullTerminatedBytes(sessionName)
|
|
||||||
resp.WriteBytes(c.userBinaryParts[userBinaryPartID{session.charID, 3}])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case 2: // usersearchname
|
|
||||||
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
|
break
|
||||||
}
|
}
|
||||||
if strings.Contains(session.Name, searchTerm) {
|
if pkt.SearchType == 1 && session.charID != cid {
|
||||||
count++
|
continue
|
||||||
sessionName := stringsupport.UTF8ToSJIS(session.Name)
|
}
|
||||||
sessionStage := stringsupport.UTF8ToSJIS(session.stage.id)
|
if pkt.SearchType == 2 && !strings.Contains(session.Name, term) {
|
||||||
if !local {
|
continue
|
||||||
resp.WriteUint32(binary.LittleEndian.Uint32(net.ParseIP(c.IP).To4()))
|
}
|
||||||
} else {
|
if pkt.SearchType == 3 && session.server.IP != ip && session.server.Port != port && session.stage.id != term {
|
||||||
resp.WriteUint32(0x0100007F)
|
continue
|
||||||
}
|
}
|
||||||
resp.WriteUint16(c.Port)
|
count++
|
||||||
|
sessionName := stringsupport.UTF8ToSJIS(session.Name)
|
||||||
|
sessionStage := stringsupport.UTF8ToSJIS(session.stage.id)
|
||||||
|
if !local {
|
||||||
|
resp.WriteUint32(binary.LittleEndian.Uint32(net.ParseIP(c.IP).To4()))
|
||||||
|
} else {
|
||||||
|
resp.WriteUint32(0x0100007F)
|
||||||
|
}
|
||||||
|
resp.WriteUint16(c.Port)
|
||||||
|
resp.WriteUint32(session.charID)
|
||||||
|
resp.WriteUint8(uint8(len(sessionStage) + 1))
|
||||||
|
resp.WriteUint8(uint8(len(sessionName) + 1))
|
||||||
|
resp.WriteUint16(uint16(len(c.userBinaryParts[userBinaryPartID{charID: session.charID, index: 3}])))
|
||||||
|
|
||||||
resp.WriteUint32(session.charID)
|
// TODO: This case might be <=G2
|
||||||
resp.WriteUint8(uint8(len(sessionStage) + 1))
|
if _config.ErupeConfig.RealClientMode <= _config.G1 {
|
||||||
resp.WriteUint8(uint8(len(sessionName) + 1))
|
|
||||||
resp.WriteUint16(uint16(len(c.userBinaryParts[userBinaryPartID{session.charID, 3}])))
|
|
||||||
|
|
||||||
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))
|
||||||
|
} else {
|
||||||
resp.WriteNullTerminatedBytes(sessionStage)
|
resp.WriteBytes(make([]byte, 40))
|
||||||
resp.WriteNullTerminatedBytes(sessionName)
|
|
||||||
resp.WriteBytes(c.userBinaryParts[userBinaryPartID{charID: session.charID, index: 3}])
|
|
||||||
}
|
}
|
||||||
}
|
resp.WriteBytes(make([]byte, 8))
|
||||||
}
|
|
||||||
case 3: // lobbysearchname
|
|
||||||
ip := bf.ReadBytes(4)
|
|
||||||
ipString := fmt.Sprintf("%d.%d.%d.%d", ip[3], ip[2], ip[1], ip[0])
|
|
||||||
port := bf.ReadUint16()
|
|
||||||
bf.ReadUint16() // Len stageID
|
|
||||||
maxResults := bf.ReadUint16()
|
|
||||||
bf.ReadUint8()
|
|
||||||
stageID := string(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.stage.id)
|
|
||||||
sessionName := stringsupport.UTF8ToSJIS(session.Name)
|
|
||||||
if !local {
|
|
||||||
resp.WriteUint32(binary.LittleEndian.Uint32(net.ParseIP(c.IP).To4()))
|
|
||||||
} else {
|
|
||||||
resp.WriteUint32(0x0100007F)
|
|
||||||
}
|
|
||||||
resp.WriteUint16(c.Port)
|
|
||||||
resp.WriteUint32(session.charID)
|
|
||||||
resp.WriteUint8(uint8(len(sessionStage) + 1))
|
|
||||||
resp.WriteUint8(uint8(len(sessionName) + 1))
|
|
||||||
resp.WriteUint16(uint16(len(c.userBinaryParts[userBinaryPartID{session.charID, 3}])))
|
|
||||||
|
|
||||||
if _config.ErupeConfig.RealClientMode <= _config.G1 {
|
resp.WriteNullTerminatedBytes(sessionStage)
|
||||||
resp.WriteBytes(make([]byte, 8))
|
resp.WriteNullTerminatedBytes(sessionName)
|
||||||
} else {
|
resp.WriteBytes(c.userBinaryParts[userBinaryPartID{session.charID, 3}])
|
||||||
resp.WriteBytes(make([]byte, 40))
|
|
||||||
}
|
|
||||||
resp.WriteBytes(make([]byte, 8))
|
|
||||||
|
|
||||||
resp.WriteNullTerminatedBytes(sessionStage)
|
|
||||||
resp.WriteNullTerminatedBytes(sessionName)
|
|
||||||
resp.WriteBytes(c.userBinaryParts[userBinaryPartID{charID: session.charID, index: 3}])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 4: // lobbysearch
|
case 4: // lobbysearch
|
||||||
@@ -507,7 +453,7 @@ func handleMsgMhfTransitMessage(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
StagePrefix: "sl2Ls210",
|
StagePrefix: "sl2Ls210",
|
||||||
}
|
}
|
||||||
numParams := bf.ReadUint8()
|
numParams := bf.ReadUint8()
|
||||||
maxResults := bf.ReadUint16()
|
maxResults = bf.ReadUint16()
|
||||||
for i := uint8(0); i < numParams; i++ {
|
for i := uint8(0); i < numParams; i++ {
|
||||||
switch bf.ReadUint8() {
|
switch bf.ReadUint8() {
|
||||||
case 0:
|
case 0:
|
||||||
|
|||||||
Reference in New Issue
Block a user