``` refactor(socket): 重构客户端数据处理逻辑,优化玩家信息校验和包处理流程
This commit is contained in:
@@ -13,7 +13,6 @@ import (
|
||||
|
||||
"github.com/gogf/gf/v2/os/glog"
|
||||
"github.com/lunixbochs/struc"
|
||||
"github.com/panjf2000/gnet/v2"
|
||||
)
|
||||
|
||||
// TomeeHeader 结构体字段定义
|
||||
@@ -123,7 +122,7 @@ func MergeBytes(arrays ...[]byte) []byte {
|
||||
}
|
||||
|
||||
// 遍历结构体方法并执行RECV_cmd
|
||||
func Recv(c gnet.Conn, data TomeeHeader) {
|
||||
func (h *ClientData) Recv(data TomeeHeader) {
|
||||
|
||||
cmdlister, ok := cool.CmdCache.Load(data.CMD)
|
||||
if !ok {
|
||||
@@ -132,8 +131,6 @@ func Recv(c gnet.Conn, data TomeeHeader) {
|
||||
return //TODO 待实现cmd未注册
|
||||
}
|
||||
|
||||
// fmt.Println(cmdlister)
|
||||
//glog.Debug(context.Background(), "接收数据", data.UserID, data.CMD)
|
||||
params := []reflect.Value{}
|
||||
|
||||
//funct := cmdlister.Type().NumIn()
|
||||
@@ -154,20 +151,16 @@ func Recv(c gnet.Conn, data TomeeHeader) {
|
||||
if nameField.IsValid() && nameField.CanSet() {
|
||||
nameField.Set(reflect.ValueOf(data))
|
||||
}
|
||||
clientdata := c.Context().(*ClientData)
|
||||
if cmdlister.Type().In(1) == reflect.TypeOf(&Player{}) {
|
||||
|
||||
if data.CMD > 1000 { //if cmdlister.Type().In(1) == reflect.TypeOf(&Player{}) {
|
||||
//t := GetPlayer(c, data.UserID)
|
||||
|
||||
if clientdata.Player == nil {
|
||||
|
||||
return
|
||||
}
|
||||
// fmt.Println(data.CMD, "接收 变量的地址 ", &t.Info, t.Info.UserID)
|
||||
|
||||
params = append(params, ptrValue1, reflect.ValueOf(clientdata.Player))
|
||||
params = append(params, ptrValue1, reflect.ValueOf(h.Conn.Context().(*ClientData).Player))
|
||||
} else {
|
||||
|
||||
params = append(params, ptrValue1, reflect.ValueOf(c))
|
||||
params = append(params, ptrValue1, reflect.ValueOf(h.Conn))
|
||||
}
|
||||
|
||||
ret := cmdlister.Call(params)
|
||||
@@ -182,10 +175,8 @@ func Recv(c gnet.Conn, data TomeeHeader) {
|
||||
return
|
||||
|
||||
}
|
||||
t := clientdata.Player
|
||||
if t == nil {
|
||||
return
|
||||
}
|
||||
t := h.Conn.Context().(*ClientData).Player
|
||||
|
||||
if ok && aa != 0 { //这里实现回复错误包
|
||||
|
||||
cool.Loger.Error(context.Background(), aa.Code())
|
||||
@@ -195,7 +186,7 @@ func Recv(c gnet.Conn, data TomeeHeader) {
|
||||
|
||||
}
|
||||
|
||||
data.Version = 49
|
||||
//data.Version = 49
|
||||
t.SendPack(data.Pack(ret[0].Interface()))
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user