Ejemplo n.º 1
0
    def AgreeApply(self, p={}):
        '''
        :同意申请
        '''
        optId = 15070
        userId = p.get('UserId')
        building = self.mod.getClubBuildingInfo()
        if building is None:
            return Gcore.error(optId, -15070901)  #外史院建筑不存在
        clubId = self.mod.getUserClubId()
        if not clubId:
            return Gcore.error(optId, -15070920)  #军团不存在

        memberNum = self.mod.getClubMemberNum(clubId)
        if memberNum.get('CurNum') >= memberNum.get('MaxNum'):
            return Gcore.error(optId, -15070001)  #军团成员已满

        if self.uid == userId:
            return Gcore.error(optId, -15070998)  #对自己操作,非法权限
        memberInfo = self.mod.getMemberInfo(clubId, userId)
        if not memberInfo:
            return Gcore.error(optId, -15070002)  #没有申请记录
        elif memberInfo.get('MemberState') != 0 and memberInfo.get(
                'MemberState') != 4:
            return Gcore.error(optId, -15070996)  #操作失败
        self.mod.agreeApply(optId, clubId, userId)
        Gcore.setUserData(userId, {'ClubId': clubId})  #成员被允许加入,更新的军团信息
        Gcore.push(113, userId, {'ClubId': clubId})  #推送军团ID
        recordData = {'uid': userId, 'ValType': 0, 'Val': 1}
        return Gcore.out(optId, mission=recordData)
Ejemplo n.º 2
0
 def AgreeApply(self,p={}):
     '''
     :同意申请
     '''
     optId = 15070
     userId = p.get('UserId')
     building = self.mod.getClubBuildingInfo()
     if building is None:
         return  Gcore.error(optId,-15070901)#外史院建筑不存在
     clubId = self.mod.getUserClubId()
     if not clubId:
         return Gcore.error(optId,-15070920)#军团不存在
     
     memberNum = self.mod.getClubMemberNum(clubId)
     if memberNum.get('CurNum')>=memberNum.get('MaxNum'):
         return Gcore.error(optId,-15070001)#军团成员已满
     
     if self.uid == userId:
         return Gcore.error(optId, -15070998)#对自己操作,非法权限
     memberInfo = self.mod.getMemberInfo(clubId,userId)
     if not memberInfo:
         return Gcore.error(optId,-15070002)#没有申请记录
     elif memberInfo.get('MemberState') != 0 and memberInfo.get('MemberState')!=4:
         return Gcore.error(optId,-15070996)#操作失败
     self.mod.agreeApply(optId, clubId, userId)
     Gcore.setUserData(userId, {'ClubId':clubId})#成员被允许加入,更新的军团信息
     Gcore.push(113,userId,{'ClubId':clubId})#推送军团ID
     recordData = {'uid':userId,'ValType':0,'Val':1}
     return Gcore.out(optId,mission=recordData)
Ejemplo n.º 3
0
 def vipAddTotal(self, optId, goldNum):
     '''
     :玩家充值黄金,增加玩家累积黄金,更新Vip等级
     @param goldNum:增加的黄金数量
     '''
     userInfo = self.getUserInfo(['VipLevel','VipTotalPay'])
     curLevel = userInfo.get('VipLevel')
     curVipTotal = userInfo.get('VipTotalPay')
     
     totalPay = goldNum+curVipTotal
     levelCfg = Gcore.getCfg('tb_cfg_vip_up')
     levelUp = max([levelCfg[level]['VipLevel'] for level in levelCfg if totalPay>=levelCfg[level]['TotalPay']])
     data = {'VipTotalPay':totalPay,'VipLevel':levelUp}
     self.db.update('tb_user',data,'UserId=%s'%self.uid)
     if levelUp>curLevel:#VIP升级
         interMod = Gcore.getMod('Inter',self.uid)
         interMod.updateInterVip()#更新VIP内政加成
         Gcore.setUserData(self.uid,{'VipLevel':levelUp}) #更新用户缓存  Lizr
         Gcore.push(107,self.uid,{'VipLevel':levelUp}) #推送给前端升级 Lizr
     if curVipTotal==0:
         #增加首冲奖励
         Gcore.getMod('Activity',self.uid).insertGifts(1,0)
     #发送系统邮件
     mailMod = Gcore.getMod('Mail', self.uid)
     mailMod.sendSystemMail(self.uid, [], optId, other=[goldNum,])
     
     return levelUp
Ejemplo n.º 4
0
    def vipAddTotal(self, optId, goldNum):
        '''
        :玩家充值黄金,增加玩家累积黄金,更新Vip等级
        @param goldNum:增加的黄金数量
        '''
        userInfo = self.getUserInfo(['VipLevel', 'VipTotalPay'])
        curLevel = userInfo.get('VipLevel')
        curVipTotal = userInfo.get('VipTotalPay')

        totalPay = goldNum + curVipTotal
        levelCfg = Gcore.getCfg('tb_cfg_vip_up')
        levelUp = max([
            levelCfg[level]['VipLevel'] for level in levelCfg
            if totalPay >= levelCfg[level]['TotalPay']
        ])
        data = {'VipTotalPay': totalPay, 'VipLevel': levelUp}
        self.db.update('tb_user', data, 'UserId=%s' % self.uid)
        if levelUp > curLevel:  #VIP升级
            interMod = Gcore.getMod('Inter', self.uid)
            interMod.updateInterVip()  #更新VIP内政加成
            Gcore.setUserData(self.uid, {'VipLevel': levelUp})  #更新用户缓存  Lizr
            Gcore.push(107, self.uid, {'VipLevel': levelUp})  #推送给前端升级 Lizr
        if curVipTotal == 0:
            #增加首冲奖励
            Gcore.getMod('Activity', self.uid).insertGifts(1, 0)
        #发送系统邮件
        mailMod = Gcore.getMod('Mail', self.uid)
        mailMod.sendSystemMail(self.uid, [], optId, other=[
            goldNum,
        ])

        return levelUp
Ejemplo n.º 5
0
 def ApplyClub(self,p={}):
     '''
     :申请加入
     '''
     optId = 15064
     clubId = p['ClubId']
     building = self.mod.getClubBuildingInfo()
     if building is None:
         return  Gcore.error(optId,-15064901)#外史院建筑不存在
     clubInfo = self.mod.getClubInfo(clubId)
     if not clubInfo:
         return Gcore.error(optId,-15064920)#军团不存在
     if self.mod.getUserClubId():
         return Gcore.error(optId,-15064001)#只能加入一个军团
     
     if not self.mod.validApplyInterval():
         return Gcore.error(optId,-15064004)#离上次退出军团时间间隔不合法
     
     memberNum = self.mod.getClubMemberNum(clubId)
     if memberNum.get('CurNum')>=memberNum.get('MaxNum'):
         return Gcore.error(optId,-15064002)#军团成员已满
     allowState = clubInfo.get('AllowState')
     if allowState == 1:#需要审核
         self.mod.applyClub(clubId)
         return Gcore.out(optId,{'Passed':0,'ClubId':clubId})#申请成功,审核中
     elif allowState ==2:#不需审核
         self.mod.applyClub(clubId)
         self.mod.agreeApply(optId, clubId, self.uid)
         Gcore.setUserData(self.uid, {'ClubId':clubId})#更新用户缓存
         
         recordData = {'uid':self.uid,'ValType':0,'Val':1}#任务
         return Gcore.out(optId,{'Passed':1,'ClubId':clubId},mission=recordData)#成功加入军团
     else:
         return Gcore.out(optId,{'Passed':2})#不允许加入
Ejemplo n.º 6
0
 def addUserExp(self,getWay,amount=0,optId=0):
     '''
     :增加主角经验(动作触发)
     @param getWay: 用户获得经验方式0:直接加经验,1-99:消耗加经验 101-199: 事件加经验
     @param amount: if getWay==0:amount='增加的经验值';elif 1<1getWay<99:amount='消耗货币量';
     @return: 返回主角经验等级,当前经验
     '''
     
     expCfg = Gcore.getCfg('tb_cfg_exp_get',getWay)
     fields = ['UserLevel','UserExp']
     userInfo = self.db.out_fields('tb_user',fields,'UserId=%s'%self.uid)
     userLevel = userInfo['UserLevel']
     userExp = userInfo['UserExp']
     getExp = 0
       
     if expCfg:#动作增加经验方式
         segment = getWay/100#判断是消耗还是事件      
         if segment==0:#消耗
             factor1 = expCfg.get('Factor1',0)
             factor2 = expCfg.get('Factor2',0)
             getExp = int(factor1*amount+factor2*userLevel)
             
         elif segment==1 and self._getLimitOfEvent(getWay):#事件
             baseExp = expCfg.get('BaseExp',0)
             getExp = int(baseExp*(userLevel+1)*(1+userLevel/200.0)+1)
             
     elif getWay==0:#直接加经验
         getExp=amount
     
     #增加经验,同时更新等级
     if getExp>0:
         updateExp = self._calUserLevel(userLevel, userExp+getExp)
         self.db.update('tb_user',updateExp,'UserId=%s'%self.uid)
         newLevel = updateExp.get('UserLevel')
         
         #获得经验记录
         logData = {'UserId':self.uid,'GetWay':getWay,'OptId':optId,
                    'UserType':Gcore.getUserData(self.uid,'UserType'),
                    'UserLevel':newLevel,'ExpValue':getExp,'CreateTime':time.time()}
         self.db.insert('tb_log_exp',logData,isdelay=True)
         
         #主角升级
         if newLevel>userLevel:
             #升级推送
             Gcore.push(108,self.uid,{'UserLevel':newLevel})
             mMod = Gcore.getMod('Mission',self.uid)
             mMod.getNewMission(userLevel=newLevel)#用户升级查看有没有新任务
             Gcore.setUserData(self.uid, {'UserLevel':newLevel}) #更新缓存中的用户等级  Lizr
             Gcore.getMod('General',self.uid).touchGeneralLv(newLevel)
             Gcore.getMod('War',self.uid).touchActPoint(userLevel,newLevel) #更新行动力
             modActivity=Gcore.getMod('Activity',self.uid)#报错
             modActivity.growUpAward(newLevel, userLevel)#成长奖励活动Yew
             if newLevel >= Gcore.loadCfg(Gcore.defined.CFG_RANK_FIGHT).get('RankFightOpenLevel',20):
                 Gcore.getMod('RankFight',self.uid).joinRankFight() #每次升级都尝试加入排行榜 防止有漏
                 
         return updateExp
     else:
         return userInfo   
Ejemplo n.º 7
0
 def _getMissionCache(self,action=''):
     '''获取任务缓存'''
     activeMission = Gcore.getUserData(self.uid,'ActiveMission')#缓存查询
     if (activeMission is None) or (not isinstance(activeMission,dict)):
         myLog = Gcore.getLogger('zhanggh','mission')
         myLog.error("任务缓存有异常,UserId:%s,动作:%s,用户缓存内容:"%(self.uid,action))
         myLog.error( Gcore.StorageUser.get(self.uid))
         
         activeMission = self.db.out_rows('tb_mission',['MissionId','GetValue'],'UserId=%s AND Status in (1,2)'%self.uid)
         activeMission = {k['MissionId']:k for k in activeMission}
         Gcore.setUserData(self.uid,{'ActiveMission':activeMission})
     return activeMission
Ejemplo n.º 8
0
 def _getAchieveCache(self,action=''):
     '''获取成就缓存'''
     activeAchieve = Gcore.getUserData(self.uid, 'ActiveAchieve')#缓存活跃成就
     if (activeAchieve is None) or (not isinstance(activeAchieve,list or tuple)):
         myLog = Gcore.getLogger('zhanggh','achieve')
         myLog.error("成就缓存有异常,UserId:%s,动作:%s,用户缓存内容:"%(self.uid,action))
         myLog.error( Gcore.StorageUser.get(self.uid))
         
         activeAchieve = self.getAchievements()
         activeAchieve = [k for k in activeAchieve if activeAchieve[k]['Finished']==0]
         Gcore.setUserData(self.uid,{'ActiveAchieve':activeAchieve})
     return activeAchieve
Ejemplo n.º 9
0
    def warSweepNew(self, warId, SweepTimes):
        '''扫荡'''
        result = {}
        UserData = self.getUserInfo(['ProcessWarId'])
        ProcessWarId = UserData['ProcessWarId']

        rowStar = self.db.out_fields('tb_war_star', '*',
                                     'UserId=%s' % self.uid)
        RestPoint, MaxPoint = self.getActPoint()
        if warId > ProcessWarId or not rowStar.get('War%s' % warId):
            return False

        if RestPoint < Gcore.getCfg('tb_cfg_pve', warId,
                                    'ActPointNeed') * SweepTimes:
            return False
        else:
            Gcore.setUserData(self.uid, {'Sweeping': True})

            #@todo 自动补兵
            for i in xrange(SweepTimes):
                restTimes = SweepTimes - i - 1
                if not Gcore.getUserData(self.uid, 'Sweeping'):  #用户落线也会停止
                    break
                else:
                    gevent.sleep(
                        Gcore.loadCfg(9101).get('SweepSleep'))  #每场间隔3秒 读配置

                modBattle = Gcore.getMod('Battle', self.uid, True)
                initWarResult = modBattle.initWar(warId, 1)  #定义为扫荡战役
                if not initWarResult:
                    print '初始化战斗失败'
                    break
                modBattle.getWarInfo()
                re = modBattle.endBattle({"resultType": 5})
                #print '战斗结果',re
                result[warId] = re  #结构不能更改 需要和前台一样
                self.warlog(WarId=warId,
                            IsWarSweep=1,
                            Result=re.get('Result', 0))  #@todo 添加更完整战役结果

                Gcore.push(
                    111, self.uid, {
                        'result': result,
                        'restPoint': RestPoint,
                        'restTimes': restTimes
                    })
                if not re.get('Result'):
                    break
                else:
                    RestPoint -= 1

            return True
Ejemplo n.º 10
0
 def initMission(self,mIds,userId=None,pushMsg=True):
     '''
     :给玩家添加一个或者多个任务
     @param mId:任务Id,一个或者多个
     @param userId:用户ID
     '''
     if userId is None:
         userId = self.uid
     if not isinstance(mIds, (list, tuple)):
         mIds = [mIds]
     tb_m = 'tb_mission'
     mCfgs = Gcore.getCfg('tb_cfg_mission')
     
     now = time.time()
     insertdata = []
     missionCaches = {}
     pushMids = []
     
     for mid in mIds:
         data = {'MissionId':mid,'UserId':userId,
                 'GetValue':0,'Status':1,
                 'CreateTime':now,'CompleteTime':0}
         missionCache = {}
         #处理需要特需处理的任务
         getVal = self.getMissionUpdateVal(mid)
         if getVal:
             data['GetValue'] = getVal
             paramB = mCfgs[mid]['ParamB']
             if getVal>=paramB:#任务完成
                 data['GetValue'] = paramB
                 data['Status'] = 3
                 data['CompleteTime'] = now
             else:
                 missionCache = {'MissionId':mid,'GetValue':getVal}
         else:
             missionCache = {'MissionId':mid,'GetValue':0}
             
         if self.db.insert(tb_m,data):
             insertdata.append(data)
             pushMids.append(mid)
             if missionCache:#增加缓存
                 missionCaches[mid] = missionCache
     
     # 更新任务缓存
     if missionCaches:
         activeMission = self._getMissionCache('initMision')
         activeMission.update(missionCaches)
         Gcore.setUserData(self.uid, {'ActiveMission':activeMission})
     # 推送新任务
     if pushMsg and pushMids:
         Gcore.push(102,self.uid,{'MT':1,'MIDS':pushMids})
     return insertdata
Ejemplo n.º 11
0
    def updateAchieve(self,aData):
        '''更新成就,(更新相应缓存)'''
        aCfgs = Gcore.getCfg('tb_cfg_achieve')
        activeAction = self._getAchieveCache('updateAchieve')
#         
#         print 'Building_homeMod更新成就',aData
        
        pusAID = []
        updateNum = 0
        
        for aType in aData:
            data = aData[aType]
            curAchieve = data.get('CurrentAchieve')
            nextAchieveId = data.get('NextAchieveId')
            finished = data.get('Finished')
            overMax = 0
            
            #判断成就是否达成
            if curAchieve and nextAchieveId:
                aCfg = aCfgs[aType]
                nextAchieve = aCfg[nextAchieveId]['AchieveRequire']#下一成就值
                if curAchieve>=nextAchieve:
                    pusAID.append(aType)
                    
                    #成就记录不能超出最成就值
                    maxAchieve = aCfg[max(aCfg.keys())]['AchieveRequire']
                    if curAchieve>=maxAchieve:
                        overMax = 1
                        data['CurrentAchieve'] = maxAchieve
            
            #更新缓存
            if (aType in activeAction) and (overMax or finished):
                activeAction.remove(aType)
                
            flag = self.db.update('tb_achieve',data,'UserId=%s AND AchieveType=%s'%(self.uid,aType))
            if flag:
                updateNum += 1
                
        #更新缓存       
        Gcore.setUserData(self.uid, {'ActiveAchieve':activeAction})
           
        #成就达成推送
        if pusAID:
            print '成就达成',pusAID
            #暂不推送
#             Gcore.push(103,self.uid,{'ACT':pusAID})
            
        return updateNum
Ejemplo n.º 12
0
 def ExitClub(self,p={}):
     '''退出军团'''
     optId = 15072
     building = self.mod.getClubBuildingInfo()
     if building is None:
         return  Gcore.error(optId,-15072901)#外史院建筑不存在
     clubId = self.mod.getUserClubId()
     if not clubId:
         return Gcore.error(optId,-15072920)#军团不存在
     userType = 3#普通成员
     clubLeader = self.mod.getClubLeader(clubId)
     if self.uid == clubLeader.get('UserId'):
         userType = 1#团长
     self.mod.dismissMember(optId, clubId, self.uid, way=3, userType=userType)
     Gcore.setUserData(self.uid, {'ClubId':0})#更新用户缓存
     return Gcore.out(optId,{})
Ejemplo n.º 13
0
    def CreateClub(self,p={}):
        '''创建军团
        @logoId :1-6
        '''
        optId = 15060
        CfgClub = Gcore.loadCfg(defined.CFG_BUILDING_CLUB)
        
        s_Name = p.get('ClubName')
        LogoId = p.get('LogoId')
        i_Min = CfgClub.get('ClubNameLimitMin')
        i_Max = CfgClub.get('ClubNameLimitMax')
    
        flag = com.filterInput(s_Name, i_Min, i_Max)
        if flag == -1:
            return Gcore.error(optId, -15060993) #长度不符合要求
        elif flag == -2:
            return Gcore.error(optId, -15060992) #不能含有敏感字符
        building = self.mod.getClubBuildingInfo()
        if building is None:
            return  Gcore.error(optId,-15060901)#外史院建筑不存在
        MyClubId = self.mod.getUserClubId()
        if MyClubId:
            return Gcore.error(optId, -15060001) #你已加入军团,不能创建
        
        if self.mod.hadSameName(s_Name):
            return Gcore.error(optId, -15060002) #该军团名称已存在
            

        #开始支付
        CoinType = CfgClub.get('ClubCreateCostType')
        CoinValue = CfgClub.get('ClubCreateCost')
        
        modCoin = Gcore.getMod('Coin',self.uid)
        classMethod = self.__class__.__name__+'.CreateClub'
        result = modCoin.PayCoin(optId, CoinType, CoinValue, classMethod, p)
        
        
        if result < 0:
            return Gcore.error(optId,-15060995) #支付失败
        else:
            ClubId = self.mod.createClub(LogoId,s_Name) #创建军团
            Gcore.setUserData(self.uid, {'ClubId':ClubId})#更新用户缓存
            body = {'ClubId':ClubId}
            recordData = {'uid':self.uid,'ValType':0,'Val':1}#任务
            return Gcore.out(optId,body,mission=recordData)
Ejemplo n.º 14
0
    def CreateClub(self, p={}):
        '''创建军团
        @logoId :1-6
        '''
        optId = 15060
        CfgClub = Gcore.loadCfg(defined.CFG_BUILDING_CLUB)

        s_Name = p.get('ClubName')
        LogoId = p.get('LogoId')
        i_Min = CfgClub.get('ClubNameLimitMin')
        i_Max = CfgClub.get('ClubNameLimitMax')

        flag = com.filterInput(s_Name, i_Min, i_Max)
        if flag == -1:
            return Gcore.error(optId, -15060993)  #长度不符合要求
        elif flag == -2:
            return Gcore.error(optId, -15060992)  #不能含有敏感字符
        building = self.mod.getClubBuildingInfo()
        if building is None:
            return Gcore.error(optId, -15060901)  #外史院建筑不存在
        MyClubId = self.mod.getUserClubId()
        if MyClubId:
            return Gcore.error(optId, -15060001)  #你已加入军团,不能创建

        if self.mod.hadSameName(s_Name):
            return Gcore.error(optId, -15060002)  #该军团名称已存在

        #开始支付
        CoinType = CfgClub.get('ClubCreateCostType')
        CoinValue = CfgClub.get('ClubCreateCost')

        modCoin = Gcore.getMod('Coin', self.uid)
        classMethod = self.__class__.__name__ + '.CreateClub'
        result = modCoin.PayCoin(optId, CoinType, CoinValue, classMethod, p)

        if result < 0:
            return Gcore.error(optId, -15060995)  #支付失败
        else:
            ClubId = self.mod.createClub(LogoId, s_Name)  #创建军团
            Gcore.setUserData(self.uid, {'ClubId': ClubId})  #更新用户缓存
            body = {'ClubId': ClubId}
            recordData = {'uid': self.uid, 'ValType': 0, 'Val': 1}  #任务
            return Gcore.out(optId, body, mission=recordData)
Ejemplo n.º 15
0
    def warSweepNew(self,warId,SweepTimes):
        '''扫荡'''
        result = {}
        UserData = self.getUserInfo(['ProcessWarId'])
        ProcessWarId = UserData['ProcessWarId']
        
        rowStar = self.db.out_fields('tb_war_star','*','UserId=%s'%self.uid)
        RestPoint,MaxPoint = self.getActPoint()
        if warId>ProcessWarId or not rowStar.get('War%s'%warId):
            return False
              
        if RestPoint< Gcore.getCfg('tb_cfg_pve',warId,'ActPointNeed')*SweepTimes:
            return False
        else:
            Gcore.setUserData(self.uid, {'Sweeping':True} )
            
            #@todo 自动补兵
            for i in xrange(SweepTimes):
                restTimes = SweepTimes-i-1
                if not Gcore.getUserData(self.uid, 'Sweeping'): #用户落线也会停止
                    break
                else:
                    gevent.sleep( Gcore.loadCfg(9101).get('SweepSleep') ) #每场间隔3秒 读配置
                    
                modBattle = Gcore.getMod('Battle',self.uid,True)
                initWarResult = modBattle.initWar(warId,1) #定义为扫荡战役
                if not initWarResult:
                    print '初始化战斗失败'
                    break
                modBattle.getWarInfo()
                re = modBattle.endBattle({"resultType":5})
                #print '战斗结果',re
                result[warId] = re #结构不能更改 需要和前台一样
                self.warlog(WarId=warId,IsWarSweep=1,Result=re.get('Result',0)) #@todo 添加更完整战役结果
                
                Gcore.push(111,self.uid,{'result':result,'restPoint':RestPoint,'restTimes':restTimes})
                if not re.get('Result'):
                    break
                else:
                    RestPoint-=1

            return True  
Ejemplo n.º 16
0
 def ExitClub(self, p={}):
     '''退出军团'''
     optId = 15072
     building = self.mod.getClubBuildingInfo()
     if building is None:
         return Gcore.error(optId, -15072901)  #外史院建筑不存在
     clubId = self.mod.getUserClubId()
     if not clubId:
         return Gcore.error(optId, -15072920)  #军团不存在
     userType = 3  #普通成员
     clubLeader = self.mod.getClubLeader(clubId)
     if self.uid == clubLeader.get('UserId'):
         userType = 1  #团长
     self.mod.dismissMember(optId,
                            clubId,
                            self.uid,
                            way=3,
                            userType=userType)
     Gcore.setUserData(self.uid, {'ClubId': 0})  #更新用户缓存
     return Gcore.out(optId, {})
Ejemplo n.º 17
0
    def updateMissions(self,mData):
        '''更新多个任务(更新相应的任务缓存数据)
        @param mData: {MId:updateData} MId:任务ID,updateData:更新内容
        @return: 更新数目
        '''
        tb_m = 'tb_mission'
        mCfg = Gcore.getCfg('tb_cfg_mission')
        activeMission = Gcore.getUserData(self.uid, 'ActiveMission')
        
#         print '更新任务信息=>',mData
#         print '任务缓存信息=>',activeMission
        
        pusMId = []
        updateNum = 0
        for mId in mData:
            data = mData[mId]
            getVal = data.get('GetValue',0)
            paramB = mCfg[mId]['ParamB']
            
            #如果任务完成推送消息
            if getVal>=paramB:
                data['GetValue']=paramB
                data['Status']=3
                data['CompleteTime'] = time.time()
                pusMId.append(mId)
                activeMission.pop(mId,None)#任务完成删除缓存任务
                
            elif getVal:
                activeMission[mId]['GetValue'] = getVal#更新缓存任务信息
            
            if self.db.update(tb_m,data,'UserId=%s AND MissionId=%s'%(self.uid,mId)):
                updateNum +=1
       
        #更新任务缓存
        Gcore.setUserData(self.uid, {'ActiveMission':activeMission})
        #推送通知任务完成
        if pusMId:
            print '任务完成',str(pusMId)
            Gcore.push(102,self.uid,{'MT':2,'MIDS':pusMId})
        return updateNum
Ejemplo n.º 18
0
 def DismissMember(self, p={}):
     '''
     :开除成员(团长操作)
     '''
     optId = 15068
     userId = p.get('UserId')
     building = self.mod.getClubBuildingInfo()
     if building is None:
         return Gcore.error(optId, -15068901)  #外史院建筑不存在
     clubId = self.mod.getUserClubId()
     if not clubId:
         return Gcore.error(optId, -15068920)  #军团不存在
     clubLeader = self.mod.getClubLeader(clubId)
     if self.uid != clubLeader.get('UserId') or self.uid == userId:
         return Gcore.error(optId, -15068998)  #非法权限
     userClubId = self.mod.getUserClubId(userId)
     if userClubId != clubId:
         return Gcore.error(optId, -15068002)  #该用户非军团成员
     self.mod.dismissMember(optId, clubId, userId)
     Gcore.setUserData(userId, {'ClubId': 0})  #更新被开除成员的军团信息
     Gcore.push(113, userId, {'ClubId': 0})  #推送军团ID
     return Gcore.out(optId)
Ejemplo n.º 19
0
 def DismissMember(self,p={}):
     '''
     :开除成员(团长操作)
     '''
     optId = 15068
     userId = p.get('UserId')
     building = self.mod.getClubBuildingInfo()
     if building is None:
         return  Gcore.error(optId,-15068901)#外史院建筑不存在
     clubId = self.mod.getUserClubId()
     if not clubId:
         return Gcore.error(optId,-15068920)#军团不存在
     clubLeader = self.mod.getClubLeader(clubId)
     if self.uid != clubLeader.get('UserId') or self.uid == userId:
         return Gcore.error(optId,-15068998)#非法权限
     userClubId = self.mod.getUserClubId(userId)
     if userClubId != clubId:
         return Gcore.error(optId,-15068002)#该用户非军团成员
     self.mod.dismissMember(optId, clubId, userId)
     Gcore.setUserData(userId, {'ClubId':0})#更新被开除成员的军团信息
     Gcore.push(113,userId,{'ClubId':0})#推送军团ID
     return Gcore.out(optId)
Ejemplo n.º 20
0
    def ApplyClub(self, p={}):
        '''
        :申请加入
        '''
        optId = 15064
        clubId = p['ClubId']
        building = self.mod.getClubBuildingInfo()
        if building is None:
            return Gcore.error(optId, -15064901)  #外史院建筑不存在
        clubInfo = self.mod.getClubInfo(clubId)
        if not clubInfo:
            return Gcore.error(optId, -15064920)  #军团不存在
        if self.mod.getUserClubId():
            return Gcore.error(optId, -15064001)  #只能加入一个军团

        if not self.mod.validApplyInterval():
            return Gcore.error(optId, -15064004)  #离上次退出军团时间间隔不合法

        memberNum = self.mod.getClubMemberNum(clubId)
        if memberNum.get('CurNum') >= memberNum.get('MaxNum'):
            return Gcore.error(optId, -15064002)  #军团成员已满
        allowState = clubInfo.get('AllowState')
        if allowState == 1:  #需要审核
            self.mod.applyClub(clubId)
            return Gcore.out(optId, {'Passed': 0, 'ClubId': clubId})  #申请成功,审核中
        elif allowState == 2:  #不需审核
            self.mod.applyClub(clubId)
            self.mod.agreeApply(optId, clubId, self.uid)
            Gcore.setUserData(self.uid, {'ClubId': clubId})  #更新用户缓存

            recordData = {'uid': self.uid, 'ValType': 0, 'Val': 1}  #任务
            return Gcore.out(optId, {
                'Passed': 1,
                'ClubId': clubId
            },
                             mission=recordData)  #成功加入军团
        else:
            return Gcore.out(optId, {'Passed': 2})  #不允许加入
Ejemplo n.º 21
0
 def cacheUserData(self, UserId=None, CacheAll=True):
     '''获取用户的信息,用于缓存,登录时调用'''
     
     #获取用户的阵营
     if not UserId:
         UserId =  self.uid
     print 'LoginMod.cacheUserInfo()',UserId
     #UserCamp ,NickName 暂不会改变
     row = self.getUserInfo(['UserCamp', 'NickName','VipLevel','UserLevel','UserIcon','UserType'])
     if not row:
         print 'error: not found user %s'%UserId
         return 
     UserCamp = row['UserCamp']
     NickName = row['NickName']
     VipLevel = row['VipLevel']
     UserLevel = row['UserLevel']
     UserIcon = row['UserIcon']
     UserType = row['UserType']
     
     if CacheAll:
         #获取用户的军团,用户更换军团的时候必须调用Gcore.setUserData(self.uid,{'ClubId':'xx'})
         ClubId = self.db.out_field('tb_club_member', 'ClubId', 'UserId="%s" AND MemberState="%s"' % (UserId, 1))
         
         #玩家未完成的成就
         activeAchieve = Gcore.getMod('Building_home',self.uid).getAchievements()
         activeAchieve = [k for k in activeAchieve if activeAchieve[k]['Finished']==0]
         
         #玩家活跃任务
         activeMission = self.db.out_rows('tb_mission',['MissionId','GetValue'],'UserId=%s AND Status in (1,2)'%UserId)
         activeMission = {k['MissionId']:k for k in activeMission}
         
         #用户升级或Vip升级的时候必须调用Gcore.setUserData(self.uid,{'xxx':'xx'})
         DataDict =  {'UserCamp':UserCamp, 'UserIcon':UserIcon, 'ClubId':ClubId, 'NickName':NickName,
                      'VipLevel':VipLevel,'UserLevel':UserLevel,'UserType':UserType,
                      'ActiveMission':activeMission,'ActiveAchieve':activeAchieve} 
     else: #战斗服务器使用
         DataDict =  {'UserCamp':UserCamp, 'NickName':NickName,'VipLevel':VipLevel,'UserLevel':UserLevel, 'UserIcon':UserIcon} 
     Gcore.setUserData(UserId, DataDict)
Ejemplo n.º 22
0
 def StopSweep(self,para={}):
     '''停止 扫荡'''
     optId = 91006
     Gcore.setUserData(self.uid, {'Sweeping':False} )
     return Gcore.out(optId)
Ejemplo n.º 23
0
 def StopSweep(self, para={}):
     '''停止 扫荡'''
     optId = 91006
     Gcore.setUserData(self.uid, {'Sweeping': False})
     return Gcore.out(optId)
Ejemplo n.º 24
0
    def cacheUserData(self, UserId=None, CacheAll=True):
        '''获取用户的信息,用于缓存,登录时调用'''

        #获取用户的阵营
        if not UserId:
            UserId = self.uid
        print 'LoginMod.cacheUserInfo()', UserId
        #UserCamp ,NickName 暂不会改变
        row = self.getUserInfo([
            'UserCamp', 'NickName', 'VipLevel', 'UserLevel', 'UserIcon',
            'UserType'
        ])
        if not row:
            print 'error: not found user %s' % UserId
            return
        UserCamp = row['UserCamp']
        NickName = row['NickName']
        VipLevel = row['VipLevel']
        UserLevel = row['UserLevel']
        UserIcon = row['UserIcon']
        UserType = row['UserType']

        if CacheAll:
            #获取用户的军团,用户更换军团的时候必须调用Gcore.setUserData(self.uid,{'ClubId':'xx'})
            ClubId = self.db.out_field(
                'tb_club_member', 'ClubId',
                'UserId="%s" AND MemberState="%s"' % (UserId, 1))

            #玩家未完成的成就
            activeAchieve = Gcore.getMod('Building_home',
                                         self.uid).getAchievements()
            activeAchieve = [
                k for k in activeAchieve if activeAchieve[k]['Finished'] == 0
            ]

            #玩家活跃任务
            activeMission = self.db.out_rows(
                'tb_mission', ['MissionId', 'GetValue'],
                'UserId=%s AND Status in (1,2)' % UserId)
            activeMission = {k['MissionId']: k for k in activeMission}

            #用户升级或Vip升级的时候必须调用Gcore.setUserData(self.uid,{'xxx':'xx'})
            DataDict = {
                'UserCamp': UserCamp,
                'UserIcon': UserIcon,
                'ClubId': ClubId,
                'NickName': NickName,
                'VipLevel': VipLevel,
                'UserLevel': UserLevel,
                'UserType': UserType,
                'ActiveMission': activeMission,
                'ActiveAchieve': activeAchieve
            }
        else:  #战斗服务器使用
            DataDict = {
                'UserCamp': UserCamp,
                'NickName': NickName,
                'VipLevel': VipLevel,
                'UserLevel': UserLevel,
                'UserIcon': UserIcon
            }
        Gcore.setUserData(UserId, DataDict)
Ejemplo n.º 25
0
class Service(object):
    def __init__(self):
        #self.validate = Validate()
        self.Clients = {}  #所有用户信息库
        Gcore.objCfg.loadAllCfg()  #读取所有配置
        Gcore.IsServer = True  #定义为服务器核心

        Gcore.startNotice()  #开启公告自动发布协程

    def handle(self, channel, request):

        ckey = channel.getpeername()
        recData = comm.decodePacket(request)  #(协议号,内容)

        if not recData:  #参数异常
            channel._send("xxxx Wu ask send xxxx")
            return

        if not ckey in self.Clients:
            self.Clients[ckey] = {}
            self.Clients[ckey]['uid'] = 0
            self.Clients[ckey]['Channel'] = channel

        optId = recData[0]
        optKey = recData[1]
        para = recData[2]

        if 1001 <= optId <= 9999:  #系统内部预留
            if optId == 1001:  #聊天监控
                from sgLib.pyMcrypt import checkListenKey
                if checkListenKey(para.get('keyWord')):
                    print '聊天接入成功'
                    Gcore.setListenerData(ckey, channel,
                                          para.get('chatChannel'))
                    response = Gcore.out(1001)
                    channel._send(comm.json_encode(response))
                else:
                    print '聊天接入失败'

        else:
            if Cfg.TEST:  #获取开发人员指定用户ID
                uid_tmp = Setting.developer(ckey[0])
                if uid_tmp:
                    self.Clients[ckey]['uid'] = uid_tmp

            self.checkOpt(ckey, optId, optKey, para)

    def checkOpt(self, ckey, optId, optKey, para):

        if optId == 888888:
            result = Gcore.reload()
            print 'Gcore.reload()'
            msg = '<font color=green>Reload Success!</font>' if result is True else "<font color=red>" + str(
                result) + "</font>"
            response = Gcore.out(optId, {'Result': msg})
            self.Send(ckey, response)
        elif 10001 <= optId <= 10005:  #帐户相关: 10001登录,10002创建帐号,10003随机姓名,10004推荐阵营,10005检查帐户名是否合法
            self.checkLogin(ckey, optId, optKey, para)
        else:
            if optId == 8888:  #测试
                #print 'Gcore.getDB(uid)>',Gcore.getDB(uid)
                self.mqPush(ckey, optId, optKey, para)
            else:
                uid = self.Clients[ckey]['uid']
                if uid == 0:
                    response = Gcore.error(optId, -88888888)
                    self.Send(ckey, response)
                    print 'Please login first'
                    return
                response = proManager.checkOpt(uid, optId, para)
                if type(response) is not dict:
                    #print 'type(response)',type(response),response
                    response = Gcore.error(optId, -33333333)  #协议号未定义 或返回出错

                response['opt_key'] = optKey
                self.Send(ckey, response)

    def checkLogin(self, ckey, optId, optKey, para):
        """登录验证"""
        from sgLib.pyMcrypt import TokenDecode
        response = None

        #tokenDict: {u'TotalServiceId': u'42', u'LoginMode': 2, u'PlayerId': 0, u'LoginVersion': 101, u'Lan': 1, u'LockTime': 1367994093}
        tokenDict = {}
        if not self.Clients[ckey]['uid']:
            try:
                objToken = TokenDecode()
                tokenDict = objToken.getTokenMsg(para.get("pyKey"))
                print 'tokenDict > ', tokenDict
                para.update(tokenDict)

            except Exception, e:
                response = Gcore.error(optId, -10001003,
                                       {'Error': str(e)})  #登录验证失败

        if tokenDict or self.Clients[ckey]['uid']:
            uid = self.Clients[ckey]['uid']
            if uid:
                para['uid'] = uid
            elif tokenDict.get('PlayerId'):
                para['uid'] = tokenDict.get('PlayerId')
                del para['PlayerId']

            c = Login()
            if optId == 10001:
                Result = c.LoginAccount(para)
            elif optId == 10002:
                Result = c.CreateRole(para)

            elif optId == 10003:  #随机昵称
                resp = c.randomName(para)
                resp['opt_key'] = optKey
                self.Send(ckey, resp)
                return

            elif optId == 10004:  #推荐阵营
                resp = c.getRecCamp(optId)
                resp['opt_key'] = optKey
                self.Send(ckey, resp)
                return

            elif optId == 10005:  #验证昵称合法性
                resp = c.checkNickNameValid(para)
                resp['opt_key'] = optKey
                self.Send(ckey, resp)
                return

            if isinstance(Result, dict):
                UserData = Result
                uid = UserData.get('UserId')
                if ckey not in self.Clients:
                    response = Gcore.error(optId, 0)
                else:
                    self.Clients[ckey]['uid'] = uid
                    Gcore.setUserData(
                        uid, {'Channel': self.Clients[ckey]['Channel']
                              })  #储存用户channel
                    Gcore.onlineUser[uid] = 1
                    print ' ----------  Logined,uid=', uid

                    loginIp = ckey[0]  #登录IP
                    loginModel = tokenDict.get('LoginMode', 0)  #登录方式0:开发者

                    Gcore.getMod('Login', uid).login(loginIp, loginModel)
                    response = Gcore.out(optId, UserData)
            else:
                if Result < 0:  #错误编号
                    response = Gcore.error(optId, Result)

        if not response:
            response = Gcore.error(optId, 0)
        response['opt_key'] = optKey
        #print 'response',response
        self.Send(ckey, response)  #验证失败
Ejemplo n.º 26
0
    def addUserExp(self, getWay, amount=0, optId=0):
        '''
        :增加主角经验(动作触发)
        @param getWay: 用户获得经验方式0:直接加经验,1-99:消耗加经验 101-199: 事件加经验
        @param amount: if getWay==0:amount='增加的经验值';elif 1<1getWay<99:amount='消耗货币量';
        @return: 返回主角经验等级,当前经验
        '''

        expCfg = Gcore.getCfg('tb_cfg_exp_get', getWay)
        fields = ['UserLevel', 'UserExp']
        userInfo = self.db.out_fields('tb_user', fields,
                                      'UserId=%s' % self.uid)
        userLevel = userInfo['UserLevel']
        userExp = userInfo['UserExp']
        getExp = 0

        if expCfg:  #动作增加经验方式
            segment = getWay / 100  #判断是消耗还是事件
            if segment == 0:  #消耗
                factor1 = expCfg.get('Factor1', 0)
                factor2 = expCfg.get('Factor2', 0)
                getExp = int(factor1 * amount + factor2 * userLevel)

            elif segment == 1 and self._getLimitOfEvent(getWay):  #事件
                baseExp = expCfg.get('BaseExp', 0)
                getExp = int(baseExp * (userLevel + 1) *
                             (1 + userLevel / 200.0) + 1)

        elif getWay == 0:  #直接加经验
            getExp = amount

        #增加经验,同时更新等级
        if getExp > 0:
            updateExp = self._calUserLevel(userLevel, userExp + getExp)
            self.db.update('tb_user', updateExp, 'UserId=%s' % self.uid)
            newLevel = updateExp.get('UserLevel')

            #获得经验记录
            logData = {
                'UserId': self.uid,
                'GetWay': getWay,
                'OptId': optId,
                'UserType': Gcore.getUserData(self.uid, 'UserType'),
                'UserLevel': newLevel,
                'ExpValue': getExp,
                'CreateTime': time.time()
            }
            self.db.insert('tb_log_exp', logData, isdelay=True)

            #主角升级
            if newLevel > userLevel:
                #升级推送
                Gcore.push(108, self.uid, {'UserLevel': newLevel})
                mMod = Gcore.getMod('Mission', self.uid)
                mMod.getNewMission(userLevel=newLevel)  #用户升级查看有没有新任务
                Gcore.setUserData(self.uid,
                                  {'UserLevel': newLevel})  #更新缓存中的用户等级  Lizr
                Gcore.getMod('General', self.uid).touchGeneralLv(newLevel)
                Gcore.getMod('War',
                             self.uid).touchActPoint(userLevel,
                                                     newLevel)  #更新行动力
                modActivity = Gcore.getMod('Activity', self.uid)  #报错
                modActivity.growUpAward(newLevel, userLevel)  #成长奖励活动Yew
                if newLevel >= Gcore.loadCfg(Gcore.defined.CFG_RANK_FIGHT).get(
                        'RankFightOpenLevel', 20):
                    Gcore.getMod('RankFight',
                                 self.uid).joinRankFight()  #每次升级都尝试加入排行榜 防止有漏

            return updateExp
        else:
            return userInfo