hch
2019-04-19 519a8605a41e9e4cb72da4d58f55a52c3b83263d
Tool/Robot/Robot/RobotMgr.py
@@ -19,12 +19,13 @@
        self.robotMgr = robotMgr
        self.AIList = []
        config =  ConfigurationReader.ConfigIniReader.GetConfig()
        self.tjgLimitCnt = config.GetTJGLimitCnt()
        self.lastTime = 0
        self.tjgLimitCnt = config.GetTJGLimitCnt()  # 限制脱机数量
        self.offTime = config.GetPlayerOffTime()    # 获取下线多久的玩家时间
        self.lastTime = 0   # 控制日志输出频率
        self.badRobotCnt = 0 # 历史异常脱机挂个数
        
        self.ProcessFindTJGTime = 5
        self.lastLoginTime = 0
        self.lastLoginTime = 0  # 处理机器人登录的频率
        
    def runThread(self):   
        logging.info( "thread %s start" % self.getName() )
@@ -47,9 +48,14 @@
                    robotList = []
                    for i in xrange(len(tokenList)):
                        tokenInfo = tokenList.pop()
                        if tokenInfo[1] in logoningList:
                            print "正在登录中------", tokenInfo[1]
                        accID = tokenInfo[1]
                        if accID in logoningList:
                            print "正在登录中------", accID
                            continue
                        lastTime = self.robotMgr.GetNoteLastTimeByAccID(accID)   # 上一次加入队列的时间
                        if lastTime != 0 and nowTime - lastTime < self.offTime:
                            # 登录有问题则进入排队
                            continue
                        robot = self.robotMgr.AddRobot(tokenInfo)
                        robotList.append(robot)
@@ -63,7 +69,7 @@
                            continue
                        
                        # 连接-登录-运行AI
                        if not robot.IsConnected():
                        if not robot.IsConnected() and robot.GetReconnectCount() < 2:
                            robot.ReCreateRobot()
                            
                    
@@ -135,12 +141,22 @@
        self.dbRobot = dbRobot
        self.TeamMgr = {}
        
        self.LoginHistory = {}  # 记录历史添加时间 {账号:时间} 登录失败需3分钟后方可尝试
        #启动AI线程    
        #config =  ConfigurationReader.ConfigIniReader.GetConfig()
        #AI_THREAD_NUM = config.GetAIThreadNum()
        th = AIThread(self, 0)
        th.start()
    def NoteHistory(self, accID):
        self.LoginHistory[accID] = time.time()
    def GetNoteLastTimeByAccID(self, accID):
        return self.LoginHistory.get(accID, 0)
    def GetRobotAccIDList(self):
        self.__robotAccIDs = []
@@ -149,7 +165,9 @@
        return self.__robotAccIDs
    def AddRobot(self, tokenInfo):
        self.LoginHistory[tokenInfo[1]] = time.time()   # 账号记录
        #创建Robot实例,具体项目实现相应的RobotBase的子类,在这里创建子类的实例
        logging.debug( "Create Robot index:%s....." % (tokenInfo,)  )
        robot = ProjectRobot( self.__asioMgr, tokenInfo )
@@ -180,19 +198,6 @@
        return n     
        
        
#===============================================================================
#    def ConnectServer(self, index ):
#
#        robot = self.GetRobot(index)
#        if not robot:
#            return False
#
#        logging.debug( "ConnectServer for %d" % index )
#        #创建了实例了,这时只需要再次连接即可
#        robot.ReCreateRobot()
#        return True
#===============================================================================
    def GetRobot(self, index ):
        #logging.debug( "GetRobot for %d" % index )
        
@@ -200,6 +205,7 @@
        
    def Remove(self, robot):
        self.__robots.remove(robot)
        logging.info( "Remove robot 剩余: %s"%len(self.__robots) )
        
        
    def DisconnectServer(self, robot ):