1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- coding: GBK -*-
# ÔÚÏ߻ظ´AI
# author: Alee
# Date: 2011.9.1
# history:  2011.9.1     Created
 
from AI.AIBase import *
from Protocol.PacketsSend import tagCOnlineReturn
import logging
 
import time
 
#ÔÚÏ߻ظ´¼ä¸ô(Second)
OnlineReplyPeriod = 30
 
class AIOnlineReply(AIBase):
    #ËùÓÐAI±ØÐë²ÉÓÃÕâÖй̶¨µÄ³õʼ»¯Ô­ÐÍ£¬ÒÔ±ãAIMgr×Ô¶¯¼ÓÔØ
    def __init__(self, robot ):
        AIBase.__init__(self, robot, OnlineReplyPeriod, True, True )
        self.lastTime = 0
    def _Process( self ):
        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
        aiMgr.RegNetMsg(0x0113, self.OnHeart, False)
        #//01 11 ÔÚÏß»ØÓ¦»Ø±¨#tagOnlineReply
        #aiMgr.RegNetMsg(0x0111, self.OnHeartReply, False)
        
    
    def OnHeart(self, pack):
        onlineR = tagCOnlineReturn()
        self.robot.Send( onlineR )
        self.lastTime = time.time()
        #print "------»Ø¸´0113ÐÄÌø°ü"
        
        
    def OnHeartReply(self, pack):
        print "--------------------------ÏìÓ¦ÐÄÌø"