package rpcCenter import ( cfacade "github.com/mhaya/facade" "github.com/mhaya/game/game_cluster/internal/code" "github.com/mhaya/game/game_cluster/internal/param" "github.com/mhaya/game/game_cluster/internal/pb" clog "github.com/mhaya/logger" ) // route = 节点类型.节点handler.remote函数 const ( centerType = "center" gameType = "game" ) const ( opsActor = ".ops" accountActor = ".account" ) const ( ping = "ping" registerAccount = "registerAccount" ) const ( sourcePath = ".system" ) // Ping 访问center节点,确认center已启动 func Ping(app cfacade.IApplication) bool { nodeId := GetCenterNodeID(app) if nodeId == "" { return false } rsp := &pb.Bool{} targetPath := nodeId + opsActor errCode := app.ActorSystem().CallWait(sourcePath, targetPath, ping, nil, rsp) if code.IsFail(errCode) { return false } return rsp.Value } // RegisterAccount 注册帐号 func RegisterAccount(app cfacade.IApplication, openID, ip, plt, channel string) *param.LoginResp { req := ¶m.LoginReq{ OpenID: openID, IP: ip, Platform: plt, Channel: channel, } targetPath := GetTargetPath(app, accountActor) rsp := ¶m.LoginResp{} errCode := app.ActorSystem().CallWait(sourcePath, targetPath, registerAccount, req, rsp) if code.IsFail(errCode) { clog.Warnf("[RegisterAccount] openID = %s, errCode = %v", openID, errCode) return nil } return rsp } func GetCenterNodeID(app cfacade.IApplication) string { list := app.Discovery().ListByType(centerType) if len(list) > 0 { return list[0].GetNodeId() } return "" } func GetTargetPath(app cfacade.IApplication, actorID string) string { nodeId := GetCenterNodeID(app) return nodeId + actorID }