package base import ( "time" "mongo.games.com/goserver/core/logger" "mongo.games.com/goserver/core/module" "mongo.games.com/goserver/core/netlib" ) const ( // RobotSessionStartId 机器人session开始id RobotSessionStartId = 100000000 ) var ( BenchMarkModule = &BenchMark{} WaitConnectSessions []*netlib.SessionConfig ) // NewSession 新建session // id 连接id, 默认自动分配 func NewSession(id ...int) { cfg := Config.Connects if len(id) > 0 && id[0] > 0 { cfg.Id = id[0] } else { BenchMarkModule.idx++ cfg.Id = BenchMarkModule.idx } cfg.Init() logger.Logger.Info("waite connect session id=", cfg.Id) WaitConnectSessions = append(WaitConnectSessions, &cfg) } type BenchMark struct { idx int } func (m *BenchMark) ModuleName() string { return "benchmark-module" } func (m *BenchMark) Init() { m.idx = RobotSessionStartId for i := 0; i < Config.Count; i++ { NewSession() } } // Update 机器开始连接游戏服务器 func (m *BenchMark) Update() { n := len(WaitConnectSessions) if n > 0 { config := WaitConnectSessions[n-1] WaitConnectSessions = WaitConnectSessions[:n-1] if err := netlib.Connect(config); err != nil { logger.Logger.Error("netlib.Connect error", err) } } } func (m *BenchMark) Shutdown() { module.UnregisteModule(m) } func init() { module.RegisteModule(BenchMarkModule, time.Millisecond, 1) }