From affca29e7500fc8e2e65cf15d19496a370f6329e Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期四, 27 十二月 2018 16:22:58 +0800
Subject: [PATCH] 860312 机器人

---
 Tool/RobotTest/AI/AIFile/AILoginout.py                |    2 
 Tool/RobotTest/AI/AIFile/AIOnlineReply.py             |   27 ++++----
 Tool/RobotTest/Main.py                                |    4 
 Tool/RobotTest/Configuration/Config.ini               |    7 ++
 Tool/RobotTest/ConfigurationReader/ConfigIniReader.py |   11 +++
 Tool/RobotTest/framework/frame.py                     |   85 +++++++++++++++------------
 Tool/RobotTest/Robot/RobotBase.py                     |    6 +
 7 files changed, 85 insertions(+), 57 deletions(-)

diff --git a/Tool/RobotTest/AI/AIFile/AILoginout.py b/Tool/RobotTest/AI/AIFile/AILoginout.py
index fefd377..462d3d8 100644
--- a/Tool/RobotTest/AI/AIFile/AILoginout.py
+++ b/Tool/RobotTest/AI/AIFile/AILoginout.py
@@ -270,6 +270,8 @@
         cAccessLogin.AppID = appID
         cAccessLogin.ServerID = int(sid[1:])
         cAccessLogin.Adult = self.robot.GetRobotConfig()[3]
+        cAccessLogin.ExtraLen = len(appID)
+        cAccessLogin.Extra = appID
         
         self.robot.Send(cAccessLogin)
         #print "New Player Login ---------- ", self.robot.GetRobotConfig()[1]
diff --git a/Tool/RobotTest/AI/AIFile/AIOnlineReply.py b/Tool/RobotTest/AI/AIFile/AIOnlineReply.py
index a193244..9c8fe28 100644
--- a/Tool/RobotTest/AI/AIFile/AIOnlineReply.py
+++ b/Tool/RobotTest/AI/AIFile/AIOnlineReply.py
@@ -11,25 +11,26 @@
 import time
 
 #在线回复间隔(Second)
-OnlineReplyPeriod = 15
+OnlineReplyPeriod = 30
 
 class AIOnlineReply(AIBase):
     #所有AI必须采用这中固定的初始化原型,以便AIMgr自动加载
     def __init__(self, robot ):
         AIBase.__init__(self, robot, OnlineReplyPeriod, True, True )
         self.lastTime = 0
-        
-        
     def _Process( self ):
-        if time.time() - self.lastTime < OnlineReplyPeriod:
-            return
-        
-        # 清除没有心跳包的机器人
-        logging.info("危险超过15秒没有处理心跳包-%s"%self.robot.GetPlayerInfo().GetAccID())
-        #self.robot.SetNeedDestroy(True)
-        #from Robot import RobotMgr
-        #RobotMgr.GetRobotMgr().DisconnectServer(self.robot)
-        pass
+        return
+        #=======================================================================
+        # if time.time() - self.lastTime < OnlineReplyPeriod:
+        #    return
+        # 
+        # # 清除没有心跳包的机器人
+        # logging.info("clear no heart robot")
+        # self.robot.SetIsLoginOK(False)
+        # from Robot import RobotMgr
+        # RobotMgr.GetRobotMgr().DisconnectServer(self.robot)
+        # pass
+        #=======================================================================
         
     def _RegisterPacket(self, aiMgr):
         #//01 13 服务器心跳包#tagServerHeart
@@ -39,10 +40,8 @@
         
     
     def OnHeart(self, pack):
-        nowTime = time.time()
         onlineR = tagCOnlineReturn()
         self.robot.Send( onlineR )
-            
         self.lastTime = time.time()
         #print "------回复0113心跳包"
         
diff --git a/Tool/RobotTest/Configuration/Config.ini b/Tool/RobotTest/Configuration/Config.ini
index 0b1faf4..ef1d0ec 100644
--- a/Tool/RobotTest/Configuration/Config.ini
+++ b/Tool/RobotTest/Configuration/Config.ini
@@ -25,4 +25,9 @@
 PlayerOffTime=10
 ProcessFindTJGTime=10
 ServerDBConfigPath=D:\ProjectServer\db\PyMongoDataServer
-StartRunTime=10
\ No newline at end of file
+StartRunTime=10
+
+;账号获取来源 0:自动生成, 1:取库中已有账号
+AccountSource = 1
+;登录玩家数量
+MaxPlayerCnt = 300
\ No newline at end of file
diff --git a/Tool/RobotTest/ConfigurationReader/ConfigIniReader.py b/Tool/RobotTest/ConfigurationReader/ConfigIniReader.py
index afa4c07..36b9343 100644
--- a/Tool/RobotTest/ConfigurationReader/ConfigIniReader.py
+++ b/Tool/RobotTest/ConfigurationReader/ConfigIniReader.py
@@ -61,7 +61,16 @@
         self.ProcessFindTJGTime = config.GetIntValue( "ProcessFindTJGTime")
         self.ServerDBConfigPath = config.GetValue( "ServerDBConfigPath")
         self.StartRunTime = config.GetIntValue( "StartRunTime")
-        
+        self.AccountSource = config.GetIntValue( "AccountSource")
+        self.MaxPlayerCnt = config.GetIntValue( "MaxPlayerCnt")
+    
+    def GetMaxPlayerCnt(self):
+        return self.MaxPlayerCnt
+    
+    # 账号获取来源 0:自动生成, 1:取库中已有账号
+    def GetAccountSource(self):
+        return self.AccountSource
+    
     def GetIOThreadNum(self):
         return self.IOThreadNum
     
diff --git a/Tool/RobotTest/Main.py b/Tool/RobotTest/Main.py
index c341ebc..622060b 100644
--- a/Tool/RobotTest/Main.py
+++ b/Tool/RobotTest/Main.py
@@ -28,11 +28,11 @@
     logname = sys.argv[1]
 if HaveDEBUG:
     #gc.set_debug(gc.DEBUG_LEAK)
-    InitMyLog("InsideRobot%s"%logname, True, logging.DEBUG)
+    InitMyLog("RobotTest%s"%logname, True, logging.DEBUG)
 else:
     #gc.set_debug(gc.DEBUG_LEAK)
     #gc.disable()
-    InitMyLog("InsideRobot%s"%logname, True, logging.INFO)
+    InitMyLog("RobotTest%s"%logname, True, logging.INFO)
 
 
 from framework.frame import StartApp
diff --git a/Tool/RobotTest/Robot/RobotBase.py b/Tool/RobotTest/Robot/RobotBase.py
index 211c67a..9806d0c 100644
--- a/Tool/RobotTest/Robot/RobotBase.py
+++ b/Tool/RobotTest/Robot/RobotBase.py
@@ -371,7 +371,11 @@
             self.allsend += sendPack.GetLength()
             logging.debug( "%s send %d bytes data. recvAll:%d sendAll:%d ALL:%d" % \
                           ( str(self), sendPack.GetLength(), self.allrecv, self.allsend, self.allrecv+self.allsend ) )
-        self.__mgr.SendData( self.__peer, sendPack.GetBuffer(), sendPack.GetLength() )
+            
+        try:
+            self.__mgr.SendData( self.__peer, sendPack.GetBuffer(), sendPack.GetLength() )
+        except:
+            print self.__peer, sendPack.OutputString()
         
     
     ## py自定义包mapserver包
diff --git a/Tool/RobotTest/framework/frame.py b/Tool/RobotTest/framework/frame.py
index 7ee4cae..1366547 100644
--- a/Tool/RobotTest/framework/frame.py
+++ b/Tool/RobotTest/framework/frame.py
@@ -27,7 +27,7 @@
 
 import traceback
 import base64
-#import pymongo
+import pymongo
 import datetime
 
 
@@ -83,50 +83,54 @@
         
         self.PlayerOffTime = config.GetPlayerOffTime() #玩家下线时长
         self.ServerDBConfigPath = config.GetServerDBConfigPath()    #数据库路径
-        #self.InitDBCon()
+        self.InitDBCon()
         
         self.tokenList = []   # 数据库获取,登录去除
-        self.maxPlayerCnt = 200
+        self.maxPlayerCnt = config.GetMaxPlayerCnt()
         self.loginCnt = 0
-    #===========================================================================
-    # def InitDBCon(self):
-    #    dbConfig = ConfigurationReader.ConfigIniReader.AppConfig(self.ServerDBConfigPath + ServerDBConfigPath1)
-    #    dbConfig.SetSection( "auth" )
-    #    self.user = dbConfig.GetValue("logdb_user")
-    #    self.pwd = GetEncodePsw(dbConfig.GetValue("logdb_pwd"))[1]
-    #    
-    #    dbConfig2 = ConfigurationReader.ConfigIniReader.AppConfig(self.ServerDBConfigPath + ServerDBConfigPath2)
-    #    dbConfig2.SetSection( "connect" )
-    #    self.dbIP = dbConfig2.GetValue("LOG_DB_IP")
-    #    self.connection = pymongo.Connection(self.dbIP, 27017, auto_start_request=False)
-    #    db = self.connection.admin
-    #    if not db.authenticate(self.user, self.pwd):
-    #        logging.error( "!!!InitDBCon error" )
-    #        return
-    #    
-    #    #print dbConfig2.GetValue("LOG_DB_NAME"), "--------------"
-    #    
-    #    self.logdb = self.connection[dbConfig2.GetValue("LOG_DB_NAME")]
-    #    #self.interfaceDatadb = self.connection[dbConfig2.GetValue("INTERFACE_DB_NAME")]
-    #    self.userdb = self.connection[dbConfig2.GetValue("USER_DB_NAME")]
-    #    
-    #    logging.info("conn ok-----------")
-    #===========================================================================
+        self.AccountSource = config.GetAccountSource()
+        
+    def InitDBCon(self):
+        dbConfig = ConfigurationReader.ConfigIniReader.AppConfig(self.ServerDBConfigPath + ServerDBConfigPath1)
+        dbConfig.SetSection( "auth" )
+        self.user = dbConfig.GetValue("userdb_user")
+        self.pwd = GetEncodePsw(dbConfig.GetValue("userdb_pwd"))[1]
+        
+        dbConfig2 = ConfigurationReader.ConfigIniReader.AppConfig(self.ServerDBConfigPath + ServerDBConfigPath2)
+        dbConfig2.SetSection( "connect" )
+        self.dbIP = dbConfig2.GetValue("USER_DB_IP")
+        self.connection = pymongo.Connection(self.dbIP, 27017, auto_start_request=False)
+        db = self.connection.admin
+        if not db.authenticate(self.user, self.pwd):
+            logging.error( "!!!InitDBCon error" )
+            return
+        
+        self.userdb = self.connection[dbConfig2.GetValue("USER_DB_NAME")]
+        
+        logging.info("conn ok-----------")
         
     # 1.获取脱机挂玩家数据--GameLog
     def GetTJGRobot(self):
-        index = 0
-        if len(sys.argv) == 2:
-            index = sys.argv[1]
-        clientMac = "abc"
-        for i in xrange(self.maxPlayerCnt):
-            accID = "ice%s_%s@yun@s1"%(index, i)
-
-            account = ("123456789012345678901234567890ab", accID, clientMac, 1)
-            if account not in self.tokenList:
-                self.tokenList.append(account)
+        if self.AccountSource == 0:
+            index = 0
+            if len(sys.argv) == 2:
+                index = sys.argv[1]
+            clientMac = "abc"
+            for i in xrange(self.maxPlayerCnt):
+                accID = "ice%s_%s@yun@s1"%(index, i)
+    
+                account = ("123456789012345678901234567890ab", accID, clientMac, 1)
+                if account not in self.tokenList:
+                    self.tokenList.append(account)
+        else:
+            col = self.userdb["tagDSAccount"]
+            account = None
+            for rec in col.find(limit=self.maxPlayerCnt):
+                account = ("123456789012345678901234567890ab", str(rec['ACCID']), 'anc', 1)
+                if account not in self.tokenList:
+                    self.tokenList.append(account)
             
-            
+            print account
         if self.tokenList:
             logging.info( "待登录的脱机挂玩家----:%s"%(len(self.tokenList)))
             #logging.debug( "待登录的脱机挂玩家----tokenList:%s"%(self.tokenList))
@@ -136,6 +140,11 @@
     def GetTokenList(self):
         return self.tokenList
     
+    def AddCrossRobotInfo(self, accID, IPList):
+        account = ("123456789012345678901234567890ab", accID, "abc", 1, IPList)
+        if account not in self.tokenList:
+            self.tokenList.append(account)
+    
     def RemoveToken(self, value):
         self.tokenList.remove(value)
     

--
Gitblit v1.8.0