Esempio n. 1
0
    def __init__(self): 
        print 'EchoService.__init__'
        self.BM = CBattleManager()

        self.Clients = {} #所有用户信息库
        Gcore.IsServer = True #定义为服务器核心
Esempio n. 2
0
class Service(object):
    
    def __init__(self): 
        print 'EchoService.__init__'
        self.BM = CBattleManager()

        self.Clients = {} #所有用户信息库
        Gcore.IsServer = True #定义为服务器核心

    def handle(self, channel, request):
        #print 'ps '+ str(Cfg.CFG_BATTLESERV_PORT)+' Echo',request
        recData = comm.decodePacket(request) #(协议号,内容)
        if not recData: #参数异常
            channel._send("xxxx Wu ask send xxxx")
            return
        ckey = channel.getpeername()

        if not ckey in self.Clients:
            self.Clients[ckey] = {}
            self.Clients[ckey]['uid'] = 0 
            self.Clients[ckey]['Channel'] = channel
        
        if Cfg.TEST: #获取开发人员指定用户ID
            uid_tmp = Setting.developer(ckey[0]) 
            if uid_tmp:
                self.Clients[ckey]['uid'] = uid_tmp
                #print 'get developer uid',uid_tmp
                
        self.checkOpt(ckey, recData[0], recData[1], recData[2])
        

    def checkOpt(self,ckey,optId,optKey,para):
        #print 'checkOpt',ckey,optId,optKey,para
        response = False
        strExcept = ''
        if optId == 888888:
            Gcore.reload()
            response = Gcore.out(optId,{'Result':'Reload Success!'})
            self.Send(ckey,response) 
            print 'Gcore.reload()'
        elif optId == 10001: #登录
            self.checkLogin(ckey,optId,optKey,para)
        else:
            startTime = time.time()
            
            try:
                uid = self.Clients[ckey]['uid']
                if uid==0:
                    #self.Clients[ckey]['Channel'].close() #关闭socket连接
                    response = Gcore.error(optId,-88888888) #未登录
                    
                elif optId>90000 and optId<=90999: #开始战役
                    if optId == 90001: #开启战斗
                        response = self.BM.createWar(uid,para) 
                    else:
                        response = self.BM.doBattle(uid, optId, para) #暂未使用
                        
                elif optId>91000 and optId<=91999: #战役信息(开始战役战斗前)
                    response = proManager.checkOpt(uid, optId, para)
                    
                elif optId>93000 and optId<=93999: #攻城
                    if optId == 93001: #攻城入口
                        response = self.BM.findSiege(uid,para) #para: {storyBattleId:1} 任务战斗id
                    elif optId == 93002: #开始攻城
                        response = self.BM.startSiege(uid,para) 
                    elif optId == 93003: #离开攻城
                        response = self.BM.leftSiege(uid,para) 
                    elif optId == 93004: #同步  PVE PVC PVG
                        response = self.BM.synBattle(uid,para) 
                    elif optId == 93009: #结束战斗
                        response = self.BM.endBattle(uid,para) 
                    else:
                        response = self.BM.doWBattle(uid, optId, para)
                elif optId>94000 and optId<=94999: #比武
                    if optId == 94001: #开启比武
                        response = self.BM.createRankFight(uid,para) 
                else:
                    response = Gcore.error(optId,-33333333) #协议号未定义 
            except Exception,e: #错误日志
                try:
                    import traceback
                    strExcept = traceback.format_exc()
                    print >>sys.stderr, 'Time:' + time.strftime('%Y-%m-%d %H:%M:%S') + '\n' \
                            + 'UserId:' + str(uid) + '\n' \
                            + 'OptId:' + str(optId) + '\n' \
                            + 'Para:' + str(para) + '\n' \
                            + strExcept
                    sys.stderr.flush()
                except:
                    pass
                
                strExcept = ' >> '+str(e)
                response = False
            finally: