mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-16 08:55:31 +01:00
Implement user binary parts propagation
This commit is contained in:
@@ -19,6 +19,12 @@ type Config struct {
|
|||||||
ErupeConfig *config.Config
|
ErupeConfig *config.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Map key type for a user binary part.
|
||||||
|
type userBinaryPartID struct {
|
||||||
|
charID uint32
|
||||||
|
index uint8
|
||||||
|
}
|
||||||
|
|
||||||
// Server is a MHF channel server.
|
// Server is a MHF channel server.
|
||||||
type Server struct {
|
type Server struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
@@ -34,6 +40,9 @@ type Server struct {
|
|||||||
|
|
||||||
stagesLock sync.RWMutex
|
stagesLock sync.RWMutex
|
||||||
stages map[string]*Stage
|
stages map[string]*Stage
|
||||||
|
|
||||||
|
userBinaryPartsLock sync.RWMutex
|
||||||
|
userBinaryParts map[userBinaryPartID][]byte
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewServer creates a new Server type.
|
// NewServer creates a new Server type.
|
||||||
@@ -46,6 +55,7 @@ func NewServer(config *Config) *Server {
|
|||||||
deleteConns: make(chan net.Conn),
|
deleteConns: make(chan net.Conn),
|
||||||
sessions: make(map[net.Conn]*Session),
|
sessions: make(map[net.Conn]*Session),
|
||||||
stages: make(map[string]*Stage),
|
stages: make(map[string]*Stage),
|
||||||
|
userBinaryParts: make(map[userBinaryPartID][]byte),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default town stage that clients try to enter without creating.
|
// Default town stage that clients try to enter without creating.
|
||||||
|
|||||||
@@ -714,13 +714,24 @@ func handleMsgSysInsertUser(s *Session, p mhfpacket.MHFPacket) {}
|
|||||||
func handleMsgSysDeleteUser(s *Session, p mhfpacket.MHFPacket) {}
|
func handleMsgSysDeleteUser(s *Session, p mhfpacket.MHFPacket) {}
|
||||||
|
|
||||||
func handleMsgSysSetUserBinary(s *Session, p mhfpacket.MHFPacket) {
|
func handleMsgSysSetUserBinary(s *Session, p mhfpacket.MHFPacket) {
|
||||||
//pkt := p.(*mhfpacket.MsgSysSetUserBinary)
|
pkt := p.(*mhfpacket.MsgSysSetUserBinary)
|
||||||
|
s.server.userBinaryPartsLock.Lock()
|
||||||
|
s.server.userBinaryParts[userBinaryPartID{charID: s.charID, index: pkt.BinaryType}] = pkt.RawDataPayload
|
||||||
|
s.server.userBinaryPartsLock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleMsgSysGetUserBinary(s *Session, p mhfpacket.MHFPacket) {
|
func handleMsgSysGetUserBinary(s *Session, p mhfpacket.MHFPacket) {
|
||||||
pkt := p.(*mhfpacket.MsgSysGetUserBinary)
|
pkt := p.(*mhfpacket.MsgSysGetUserBinary)
|
||||||
|
|
||||||
|
// Try to get the data.
|
||||||
|
s.server.userBinaryPartsLock.RLock()
|
||||||
|
defer s.server.userBinaryPartsLock.RUnlock()
|
||||||
|
data, ok := s.server.userBinaryParts[userBinaryPartID{charID: pkt.CharID, index: pkt.BinaryType}]
|
||||||
|
|
||||||
resp := byteframe.NewByteFrame()
|
resp := byteframe.NewByteFrame()
|
||||||
|
|
||||||
|
// If we can't get the real data, use a placeholder.
|
||||||
|
if !ok {
|
||||||
if pkt.BinaryType == 1 {
|
if pkt.BinaryType == 1 {
|
||||||
// Stub name response with character ID
|
// Stub name response with character ID
|
||||||
resp.WriteBytes([]byte(fmt.Sprintf("CID%d", s.charID)))
|
resp.WriteBytes([]byte(fmt.Sprintf("CID%d", s.charID)))
|
||||||
@@ -738,6 +749,9 @@ func handleMsgSysGetUserBinary(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
}
|
}
|
||||||
resp.WriteBytes(data)
|
resp.WriteBytes(data)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
resp.WriteBytes(data)
|
||||||
|
}
|
||||||
|
|
||||||
doSizedAckResp(s, pkt.AckHandle, resp.Data())
|
doSizedAckResp(s, pkt.AckHandle, resp.Data())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user