refactor: 重构运行时ID组合逻辑
将硬编码的 ID 组合逻辑(100000*OnlineID + Port)提取为通用函数 ComposeRuntimeID, 使用 16 位位移掩码优化,并新增辅助方法与类型转换。同时修复踢人流程中的资源清理问题。
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user