mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-15 08:25:09 +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,18 +40,22 @@ 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.
|
||||||
func NewServer(config *Config) *Server {
|
func NewServer(config *Config) *Server {
|
||||||
s := &Server{
|
s := &Server{
|
||||||
logger: config.Logger,
|
logger: config.Logger,
|
||||||
db: config.DB,
|
db: config.DB,
|
||||||
erupeConfig: config.ErupeConfig,
|
erupeConfig: config.ErupeConfig,
|
||||||
acceptConns: make(chan net.Conn),
|
acceptConns: make(chan net.Conn),
|
||||||
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,28 +714,42 @@ 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 pkt.BinaryType == 1 {
|
|
||||||
// Stub name response with character ID
|
// If we can't get the real data, use a placeholder.
|
||||||
resp.WriteBytes([]byte(fmt.Sprintf("CID%d", s.charID)))
|
if !ok {
|
||||||
resp.WriteUint8(0) // NULL terminator.
|
if pkt.BinaryType == 1 {
|
||||||
} else if pkt.BinaryType == 2 {
|
// Stub name response with character ID
|
||||||
data, err := base64.StdEncoding.DecodeString("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBn8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAwAAAAAAAAAAAAAABAAAAAAAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==")
|
resp.WriteBytes([]byte(fmt.Sprintf("CID%d", s.charID)))
|
||||||
if err != nil {
|
resp.WriteUint8(0) // NULL terminator.
|
||||||
panic(err)
|
} else if pkt.BinaryType == 2 {
|
||||||
}
|
data, err := base64.StdEncoding.DecodeString("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBn8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAwAAAAAAAAAAAAAABAAAAAAAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==")
|
||||||
resp.WriteBytes(data)
|
if err != nil {
|
||||||
} else if pkt.BinaryType == 3 {
|
panic(err)
|
||||||
data, err := base64.StdEncoding.DecodeString("AQAAA2ea5P8ATgEA/wEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBn8AAAAAAAAAAAABAKAMAAAAAAAAAAAAACgAAAAAAAAAAAABAsQOAAAAAAAAAAABA6UMAAAAAAAAAAABBKAMAAAAAAAAAAABBToNAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAgACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
|
}
|
||||||
if err != nil {
|
resp.WriteBytes(data)
|
||||||
panic(err)
|
} else if pkt.BinaryType == 3 {
|
||||||
|
data, err := base64.StdEncoding.DecodeString("AQAAA2ea5P8ATgEA/wEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBn8AAAAAAAAAAAABAKAMAAAAAAAAAAAAACgAAAAAAAAAAAABAsQOAAAAAAAAAAABA6UMAAAAAAAAAAABBKAMAAAAAAAAAAABBToNAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAgACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
resp.WriteBytes(data)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
resp.WriteBytes(data)
|
resp.WriteBytes(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user