This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"time"
|
||||
|
||||
"blazing/cool"
|
||||
"blazing/logic/service/common"
|
||||
"blazing/logic/service/player"
|
||||
"blazing/modules/config/service"
|
||||
|
||||
@@ -74,8 +75,8 @@ func (s *Server) OnClose(c gnet.Conn, err error) (action gnet.Action) {
|
||||
|
||||
//logging.Infof("conn[%v] disconnected", c.RemoteAddr().String())
|
||||
v, _ := c.Context().(*player.ClientData)
|
||||
v.LF.Close()
|
||||
|
||||
v.LF.Close()
|
||||
if v.Player != nil {
|
||||
v.Player.Save() //保存玩家数据
|
||||
|
||||
@@ -248,15 +249,70 @@ func handle(c gnet.Conn) {
|
||||
//return
|
||||
}
|
||||
|
||||
func (s *Server) onevent(c gnet.Conn, data []byte) {
|
||||
func (s *Server) onevent(c gnet.Conn, v []byte) {
|
||||
if t, ok := c.Context().(*player.ClientData); ok {
|
||||
var header common.TomeeHeader
|
||||
// 解析Len(0-3字节)
|
||||
header.Len = binary.BigEndian.Uint32(v[0:4])
|
||||
// 解析Version(第4字节)
|
||||
//header.Version = v[4]
|
||||
// 解析CMD(5-8字节)
|
||||
header.CMD = binary.BigEndian.Uint32(v[5:9])
|
||||
// 解析UserID(9-12字节)
|
||||
header.UserID = binary.BigEndian.Uint32(v[9:13])
|
||||
// 解析Result(13-16字节)
|
||||
//header.Result = binary.BigEndian.Uint32(v[13:17])
|
||||
// 解析数据部分(17字节之后)
|
||||
if len(v) > 17 {
|
||||
header.Data = v[17:]
|
||||
|
||||
if t.LF.Running() {
|
||||
t.LF.Producer().Write(data)
|
||||
} else {
|
||||
header.Data = []byte{} // 数据部分为空时显式初始化
|
||||
}
|
||||
if header.CMD > 1001 {
|
||||
if t.Player == nil {
|
||||
fmt.Println(header.UserID, "账号未注册")
|
||||
return
|
||||
}
|
||||
if t.Player.Info == nil {
|
||||
fmt.Println(header.UserID, "未创建角色")
|
||||
return
|
||||
}
|
||||
if len(header.Data) > 0 {
|
||||
header.Data = XORDecryptU(header.Data, t.Player.Hash)
|
||||
}
|
||||
|
||||
}
|
||||
if cool.Config.ServerInfo.IsDebug != 0 {
|
||||
fmt.Println("接收数据", header.UserID, header.CMD)
|
||||
}
|
||||
|
||||
t.LF.Producer().Write(header)
|
||||
// s.workerPool.Submit(func() { //提交任务
|
||||
// t.OnEvent(data)
|
||||
// })
|
||||
|
||||
}
|
||||
}
|
||||
func XORDecryptU(encryptedData []byte, key uint32) []byte {
|
||||
// 边界条件:待解密数据为空,直接返回空
|
||||
if len(encryptedData) == 0 {
|
||||
return []byte{}
|
||||
}
|
||||
|
||||
// 1. 将uint32密钥转换为4字节数组(关键步骤)
|
||||
// 字节序选择:BigEndian(大端)是AS3/Java等语言的默认二进制处理方式,若需小端可改为binary.LittleEndian
|
||||
keyBytes := make([]byte, 4) // uint32固定占4个字节
|
||||
binary.BigEndian.PutUint32(keyBytes, key)
|
||||
keyLen := len(keyBytes) // 固定为4,无需额外判断长度
|
||||
|
||||
// 2. 执行异或解密(逻辑与原版本一致,仅密钥来源不同)
|
||||
decrypted := make([]byte, len(encryptedData))
|
||||
for i, b := range encryptedData {
|
||||
// 循环复用4字节密钥(索引取模,i%4)
|
||||
keyIndex := i % keyLen
|
||||
decrypted[i] = b ^ keyBytes[keyIndex]
|
||||
}
|
||||
|
||||
return decrypted
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user