refactor: 重构运行时ID组合逻辑

将硬编码的 ID 组合逻辑(100000*OnlineID + Port)提取为通用函数 ComposeRuntimeID,
使用 16 位位移掩码优化,并新增辅助方法与类型转换。同时修复踢人流程中的资源清理问题。
This commit is contained in:
xinian
2026-04-28 04:03:13 +08:00
parent deae6d371e
commit 7d49aaa212
10 changed files with 59 additions and 15 deletions

View File

@@ -3,6 +3,7 @@ package rpc
import (
"blazing/common/data/share"
"blazing/cool"
"blazing/cool/coolconfig"
"context"
"fmt"
@@ -190,7 +191,7 @@ func setupLogicReverseClient(ctx context.Context, revClient cool.ClientHandler)
return err
}
key := 100000*id + port
key := coolconfig.ComposeRuntimeID(id, port)
go func() {
<-ctx.Done()
cool.DeleteClientOnly(key)
@@ -210,6 +211,6 @@ func registerReverseLogicClient(ctx context.Context, id, port uint32) error {
if ok && aa != nil { //如果已经存在且这个端口已经被存过
aa.QuitSelf(0)
}
cool.AddClient(100000*id+port, &revClient)
cool.AddClient(coolconfig.ComposeRuntimeID(id, port), &revClient)
return nil
}