``refactor(rpc): 优化RPC客户端管理逻辑,移除冗余clientidmap,整合blazing服务调用``

This commit is contained in:
1
2025-10-15 22:53:14 +00:00
parent ebe50f18a9
commit 09c6189b80
6 changed files with 55 additions and 45 deletions

View File

@@ -9,6 +9,8 @@ import (
"log"
"net/http"
blservice "blazing/modules/blazing/service"
"github.com/filecoin-project/go-jsonrpc"
"github.com/gogf/gf/v2/util/gconv"
)
@@ -16,10 +18,7 @@ import (
var rpcport = gconv.String(cool.Config.RPC)
var clientmap = make(map[uint16]*ClientHandler) //客户端map
var clientidmap = make(map[uint16]uint16) //客户端map
//var usermap = make(map[int]int) //用户->客户端的map
// Define the client handler interface
type ClientHandler struct {
KickPerson func(uint32) error //踢人,这里是返回具体的logic
QuitSelf func(int) error //关闭服务器进程
@@ -34,7 +33,7 @@ func (h *ServerHandler) Kick(ctx context.Context, userid uint32) error {
useid1, err := share.ShareManager.GetUserOnline(userid)
if err != nil {
return fmt.Errorf("user not found")
return fmt.Errorf("user not found", err)
}
cl, ok := clientmap[useid1]
if ok {
@@ -50,15 +49,13 @@ func (h *ServerHandler) RegisterLogic(ctx context.Context, id, port uint16) erro
if !ok {
return fmt.Errorf("no reverse client")
}
aa, ok := clientidmap[id]
blservice.NewLoginServiceService().GetServerID(id)
aa, ok := clientmap[port]
if ok { //如果已经存在且这个端口已经被存过
t := clientmap[aa]
t.QuitSelf(0)
aa.QuitSelf(0)
}
clientmap[port] = &revClient
clientidmap[id] = port
return nil
}