任务提交

This commit is contained in:
1
2025-08-28 19:17:03 +00:00
parent 02c0582fe5
commit 00f38b8c53
10 changed files with 176 additions and 59 deletions

View File

@@ -7,6 +7,7 @@ import (
"blazing/cool"
"blazing/logic/service"
"os"
"strings"
"time"
"bytes"
@@ -89,32 +90,35 @@ func init() { //默认初始化扫描
methodValue := value.MethodByName(method.Name)
fmt.Println("找到注册方法", method.Name)
methodValue.Type().NumIn()
var func_cmd = getcmd(methodValue.Type().In(0))
if func_cmd == 0 { //说明不是注册方法
glog.Warning(context.Background(), "方法参数必须是结构体", method.Name, "跳过注册")
continue
for _, func_cmd := range getcmd(methodValue.Type().In(0)) {
if func_cmd == 0 { //说明不是注册方法
glog.Warning(context.Background(), "方法参数必须是结构体", method.Name, "跳过注册")
continue
}
if cool.Config.PortBL == 0 && func_cmd > 1000 { //判断login服务器
continue
}
if cool.Config.PortBL != 0 && func_cmd < 1000 { //判断login服务器
continue
}
glog.Debug(context.Background(), "注册方法", func_cmd, method.Name)
// fmt.Println(methodValue.Interface().(func(gnet.Conn, handler.TomeeHeader)))
_, ok := cool.CmdCache.LoadOrStore(func_cmd, methodValue) //TODO 待实现对不同用户初始化方法以取消全局cmdcache
if ok { //方法已存在init
glog.Error(context.Background(), "方法已存在init,不会初始化后面的方法", func_cmd)
}
}
if cool.Config.PortBL == 0 && func_cmd > 1000 { //判断login服务器
continue
}
if cool.Config.PortBL != 0 && func_cmd < 1000 { //判断login服务器
continue
}
glog.Debug(context.Background(), "注册方法", func_cmd, method.Name)
// fmt.Println(methodValue.Interface().(func(gnet.Conn, handler.TomeeHeader)))
_, ok := cool.CmdCache.LoadOrStore(func_cmd, methodValue) //TODO 待实现对不同用户初始化方法以取消全局cmdcache
if ok { //方法已存在init
glog.Error(context.Background(), "方法已存在init,不会初始化后面的方法", func_cmd)
}
}
}
func getcmd(t reflect.Type) uint32 {
func getcmd(t reflect.Type) []uint32 {
// 处理指针类型
if t.Kind() == reflect.Ptr {
t = t.Elem() // 获取指针指向的类型
@@ -123,7 +127,7 @@ func getcmd(t reflect.Type) uint32 {
// 确保是结构体
if t.Kind() != reflect.Struct {
return 0
return []uint32{0}
}
// 遍历结构体字段
@@ -135,7 +139,7 @@ func getcmd(t reflect.Type) uint32 {
if field.Type == reflect.TypeOf(handler.TomeeHeader{}) {
// fmt.Println(reflect.ValueOf(field))
return gconv.Uint32(field.Tag.Get("cmd"))
return gconv.SliceUint32(strings.Split(field.Tag.Get("cmd"), "|"))
}
@@ -150,7 +154,7 @@ func getcmd(t reflect.Type) uint32 {
}
// fmt.Println()
}
return 0
return []uint32{0}
}
// 遍历结构体方法并执行RECV_cmd