feat(player): 添加玩家登录状态检查和等待机制

- 在 Player 结构中添加登录状态标志和登录完成通知通道
- 实现 IsLoggedIn、WaitForLogin、WaitForLoginWithTimeout 和 WaitForLoginWithCtx 方法
- 在登录逻辑中使用 CompleteLogin 标记登录完成并通知等待者
- 在控制器中添加登录状态检查,确保处理已登录玩家的请求
This commit is contained in:
2025-07-17 06:09:52 +08:00
parent bf72b91fc6
commit 84d6d99356
7 changed files with 164 additions and 19 deletions

View File

@@ -194,9 +194,14 @@ func Recv(c gnet.Conn, data handler.TomeeHeader) {
if nameField.IsValid() && nameField.CanSet() {
nameField.Set(reflect.ValueOf(data))
}
if cmdlister.Type().In(1) == reflect.TypeOf(entity.Player{}) {
if cmdlister.Type().In(1) == reflect.TypeOf(&entity.Player{}) {
c1 := service.GetPlayer(c, data.UserID)
err := c1.WaitForLoginWithCtx(context.Background())
if err != nil {
fmt.Println("登录失败")
}
params = append(params, ptrValue1, reflect.ValueOf(service.GetPlayer(c, data.UserID)))
params = append(params, ptrValue1, reflect.ValueOf(c1))
} else {
params = append(params, ptrValue1, reflect.ValueOf(c))
@@ -205,22 +210,7 @@ func Recv(c gnet.Conn, data handler.TomeeHeader) {
cmdlister.Call(params)
r := entity.Conn{MainConn: c}
// // 遍历结构体字段
// // fmt.Printf("结构体 %s 的字段信息:\n", t.Name())
// for i := 0; i < ptrValue1.Type().NumField(); i++ {
// field := ptrValue1.Type().Field(i)
// if field.Name == "Ret" { //判断Ret
// }
// }
// if cmdlister.Type().In(0).Implements(reflect.TypeOf((*Blazingservice)(nil)).Elem()) {
// fmt.Printf("参数 %d 是结构体且实现了 MyInterface 接口\n" )
// tt1
// } else {
// fmt.Printf("参数 %d 是结构体但未实现 MyInterface 接口\n", i)
// }
aa := ptrValue1.Elem().Field(0).Addr().Interface()
@@ -228,6 +218,7 @@ func Recv(c gnet.Conn, data handler.TomeeHeader) {
//st, ok := aa.(Blazingservice)
//fmt.Println(t.Ret())
if t.Ret() != nil {
err := r.SendPack(t.Ret())
if err != nil {
fmt.Println(err)