Ai世界玩家人数超过4人测试

This commit is contained in:
flswld
2023-01-10 19:21:56 +08:00
parent 3ecdb6ff70
commit 1793054ef4
22 changed files with 596 additions and 251 deletions

View File

@@ -16,6 +16,10 @@ import (
"github.com/pkg/errors"
)
const (
MaxGsId = 1000
)
var _ api.DiscoveryNATSRPCServer = (*DiscoveryService)(nil)
type ServerInstanceSortList []*ServerInstance
@@ -41,6 +45,7 @@ type ServerInstance struct {
gateServerMqPort uint32
version string
lastAliveTime int64
gsId uint32
}
type DiscoveryService struct {
@@ -100,7 +105,12 @@ func (s *DiscoveryService) RegisterServer(ctx context.Context, req *api.Register
AppId: appId,
}
if req.ServerType == api.GS {
rsp.GsId = atomic.AddUint32(&s.gsIdCounter, 1)
gsId := atomic.AddUint32(&s.gsIdCounter, 1)
if gsId > MaxGsId {
return nil, errors.New("above max gs count")
}
inst.gsId = gsId
rsp.GsId = gsId
}
return rsp, nil
}
@@ -218,6 +228,34 @@ func (s *DiscoveryService) GetAllGateServerInfoList(ctx context.Context, req *ap
}, nil
}
// GetMainGameServerAppId 获取主游戏服务器的appid
func (s *DiscoveryService) GetMainGameServerAppId(ctx context.Context, req *api.NullMsg) (*api.GetMainGameServerAppIdRsp, error) {
logger.Debug("get main game server appid")
instMap, exist := s.serverInstanceMap[api.GS]
if !exist {
return nil, errors.New("game server not exist")
}
if s.getServerInstanceMapLen(instMap) == 0 {
return nil, errors.New("no game server found")
}
appid := ""
minGsId := uint32(MaxGsId)
instMap.Range(func(key, value any) bool {
serverInstance := value.(*ServerInstance)
if serverInstance.gsId < minGsId {
minGsId = serverInstance.gsId
appid = serverInstance.appId
}
return true
})
if appid == "" {
return nil, errors.New("main game server not found")
}
return &api.GetMainGameServerAppIdRsp{
AppId: appid,
}, nil
}
func (s *DiscoveryService) getRandomServerInstance(instMap *sync.Map) *ServerInstance {
instList := make(ServerInstanceSortList, 0)
instMap.Range(func(key, value any) bool {