Exemple #1
0
 def Send(self, ckey, sendData):
     try:
         self.Clients[ckey]['Channel']._send(
             comm.json_encode(sendData))  #abu已经有做打包的操作 不用重复操作
     except Exception, e:
         '''用户可能已经下线'''
         pass
Exemple #2
0
    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)
Exemple #3
0
    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)
Exemple #4
0
 def Send(self,ckey,sendData):
     try:
         self.Clients[ckey]['Channel']._send( comm.json_encode(sendData) ) #abu已经有做打包的操作 不用重复操作
     except Exception,e:
         '''用户可能已经下线'''
         pass
Exemple #5
0
    def PayCoin(self, optId, coinType, coinValue, classMethod, param=''):
        ''' 使用货币
        @param optId:协议号
        @param coinType:货币类型 1,2,3,4
        @param coinValue: 货币值
        @param classMethod: 类和方法 class.method
        @param param: 参数
        @return:
             1:成功
            -1:输入货币类型或货币值异常,非法操作 
            -2: 货币不足
            -3:支付失败
        '''
        if isinstance(param, (tuple, dict)):
            param = json_encode(param)

        coinType = int(coinType)
        if coinType == 1:
            table = 'tb_user'
            field = 'GoldCoin'
            #Vip黄金消耗折扣  add by zhanggh 5.28

            vipLevel = Gcore.getUserData(self.uid, 'VipLevel')
            discount = Gcore.getCfg('tb_cfg_vip_up', vipLevel, 'Discount')
            discount = discount if discount else 1
            print '未打折前', coinValue
            print 'vip折扣是', discount

            coinValue = math.ceil(coinValue * discount)

        elif coinType == 2:
            table = 'tb_currency'
            field = 'Jcoin'
        elif coinType == 3:
            table = 'tb_currency'
            field = 'Gcoin'
        elif coinType == 4:
            table = 'tb_currency'
            field = 'Mcoin'
        else:
            return -1

        if coinValue <= 0:
            return -1

        MyCoin = self.getCoinNum(coinType)
        #print '当前货币数量', MyCoin
        if MyCoin < coinValue:  #货币不足
            return -2
        else:
            NowCoin = MyCoin - coinValue
            #sql = "UPDATE "+table+" SET "+field+"=%s WHERE UserId='%s'"%(NowCoin,self.uid) #并发有问题
            sql = "UPDATE " + table + " SET " + field + "=" + field + "-" + str(
                coinValue) + " WHERE " + field + ">=" + str(
                    coinValue) + " AND UserId='%s'" % self.uid
            print '支付货币:', sql

            result = self.db.execute(sql)
            if not result:
                return -3
            else:
                #记录日志
                table = 'tb_log_coin_%s' % coinType
                d = {}
                d['OptId'] = optId
                d['UserId'] = self.uid
                d['UserType'] = Gcore.getUserData(self.uid, 'UserType')
                d['UserLevel'] = Gcore.getUserData(self.uid, 'UserLevel')
                d['OldCoin'] = MyCoin
                d['CoinNumber'] = coinValue
                d['Action'] = 2  # 1获得 2消耗
                d['NowCoin'] = NowCoin
                d['Func'] = classMethod
                d['Param'] = str(param)
                d['CreateTime'] = int(time.time())
                print ' >>> Logging CoinMod.PayCoin', d
                self.db.insert(table, d, isdelay=False)  #货币日志不采用延迟插入,怕丢
                Gcore.getMod('Event',
                             self.uid).payCoinTrigger(optId, coinValue)
                return coinValue
Exemple #6
0
    def GainCoin(self, optId, coinType, coinValue, classMethod, param=''):
        ''' 获取货币
        @param optId:协议号
        @param coinType:货币类型 1,2,3,4
        @param coinValue: 货币值
        @param classMethod: 类和方法 class.method
        @param param: 参数
        @return:
            False 获取货币失败
            int   获得的货币数量
        '''

        if isinstance(param, (tuple, dict)):
            param = json_encode(param)

        coinType = int(coinType)
        if coinType == 1:
            table = 'tb_user'
            field = 'GoldCoin'
        elif coinType == 2:
            table = 'tb_currency'
            field = 'Jcoin'
        elif coinType == 3:
            table = 'tb_currency'
            field = 'Gcoin'
        elif coinType == 4:
            table = 'tb_currency'
            field = 'Mcoin'

        MyCoin = self.getCoinNum(coinType)
        NowCoin = MyCoin + coinValue
        isFull = False

        if coinType == 2 or coinType == 3:
            storageSpace = Gcore.getMod('Building',
                                        self.uid).cacStorageSpace(coinType)
            if NowCoin > storageSpace:  #存满
                isFull = True
                NowCoin = storageSpace
                coinValue = storageSpace - MyCoin  #增加的数值

        if MyCoin == NowCoin:  #没有可增空间
            print ' >> CoinMod Coin full GainCoin fail coinType:%s %s' % (
                coinType, coinValue)
            return 0

        #sql = "UPDATE "+table+" SET "+field+"=%s WHERE UserId='%s'"%(NowCoin,self.uid)
        sql = "UPDATE " + table + " SET " + field + "=" + field + "+" + str(
            coinValue) + " WHERE UserId='%s'" % self.uid
        result = self.db.execute(sql)
        if not result:
            return -2
        else:
            #记录日志
            table = 'tb_log_coin_%s' % coinType
            d = {}
            d['OptId'] = optId
            d['UserId'] = self.uid
            d['UserType'] = Gcore.getUserData(self.uid, 'UserType')
            d['UserLevel'] = Gcore.getUserData(self.uid, 'UserLevel')
            d['OldCoin'] = MyCoin
            d['CoinNumber'] = coinValue
            d['Action'] = 1  # 1获得 2消耗
            d['NowCoin'] = NowCoin
            d['Func'] = classMethod
            d['Param'] = str(param)
            d['CreateTime'] = int(time.time())
            print ' >>> Logging CoinMod.GainCoin', d
            self.db.insert(table, d, isdelay=False)  #货币日志不采用延迟插入,怕丢
            Gcore.getMod('Event',
                         self.uid).gainCoinTrigger(optId, coinType, coinValue,
                                                   NowCoin, isFull)
            return coinValue  #当前拥有大于容量时候会返回负值
Exemple #7
0
 def Send(self, ckey, sendData):
     try:
         self.Clients[ckey]["Channel"]._send(comm.json_encode(sendData))  # abu已经有做打包的操作 不用重复操作
     except Exception, e:
         """用户可能已经下线"""
         pass
Exemple #8
0
    def PayCoin(self,optId,coinType,coinValue,classMethod,param=''):
        ''' 使用货币
        @param optId:协议号
        @param coinType:货币类型 1,2,3,4
        @param coinValue: 货币值
        @param classMethod: 类和方法 class.method
        @param param: 参数
        @return:
             1:成功
            -1:输入货币类型或货币值异常,非法操作 
            -2: 货币不足
            -3:支付失败
        '''
        if isinstance(param, (tuple,dict)):
            param = json_encode(param)
            
        coinType = int(coinType)
        if coinType==1:
            table = 'tb_user'
            field = 'GoldCoin'
            #Vip黄金消耗折扣  add by zhanggh 5.28
            
            vipLevel = Gcore.getUserData(self.uid, 'VipLevel')
            discount = Gcore.getCfg('tb_cfg_vip_up',vipLevel,'Discount')
            discount = discount if discount else 1
            print '未打折前', coinValue
            print 'vip折扣是', discount
            
            coinValue = math.ceil(coinValue*discount)
            
        elif coinType==2:    
            table = 'tb_currency'
            field = 'Jcoin'
        elif coinType==3:
            table = 'tb_currency'
            field = 'Gcoin'
        elif coinType==4:
            table = 'tb_currency'
            field = 'Mcoin'
        else:
            return -1

        if coinValue<=0:
            return -1
        
        MyCoin = self.getCoinNum(coinType)
        #print '当前货币数量', MyCoin
        if MyCoin<coinValue: #货币不足
            return -2 
        else:
            NowCoin = MyCoin-coinValue
            #sql = "UPDATE "+table+" SET "+field+"=%s WHERE UserId='%s'"%(NowCoin,self.uid) #并发有问题
            sql = "UPDATE "+table+" SET "+field+"="+field+"-"+str(coinValue)+" WHERE "+field+">="+str(coinValue)+" AND UserId='%s'"%self.uid
            print '支付货币:',sql
            
            result = self.db.execute(sql)
            if not result:
                return -3
            else:
                #记录日志 
                table = 'tb_log_coin_%s'%coinType
                d = {}
                d['OptId'] = optId
                d['UserId'] = self.uid
                d['UserType'] = Gcore.getUserData(self.uid,'UserType')
                d['UserLevel'] = Gcore.getUserData(self.uid, 'UserLevel')
                d['OldCoin'] = MyCoin
                d['CoinNumber'] = coinValue
                d['Action'] = 2 # 1获得 2消耗
                d['NowCoin'] = NowCoin
                d['Func'] = classMethod
                d['Param'] = str(param)
                d['CreateTime'] = int(time.time())
                print ' >>> Logging CoinMod.PayCoin',d
                self.db.insert(table,d,isdelay=False) #货币日志不采用延迟插入,怕丢
                Gcore.getMod('Event',self.uid).payCoinTrigger(optId,coinValue)
                return coinValue
Exemple #9
0
 def GainCoin(self,optId,coinType,coinValue,classMethod,param=''):
     ''' 获取货币
     @param optId:协议号
     @param coinType:货币类型 1,2,3,4
     @param coinValue: 货币值
     @param classMethod: 类和方法 class.method
     @param param: 参数
     @return:
         False 获取货币失败
         int   获得的货币数量
     '''
     
     if isinstance(param,(tuple,dict)):
         param = json_encode(param)
         
     coinType = int(coinType)
     if coinType==1:
         table = 'tb_user'
         field = 'GoldCoin'
     elif coinType==2:    
         table = 'tb_currency'
         field = 'Jcoin'
     elif coinType==3:
         table = 'tb_currency'
         field = 'Gcoin'
     elif coinType==4:
         table = 'tb_currency'
         field = 'Mcoin'
     
     MyCoin = self.getCoinNum(coinType)
     NowCoin = MyCoin+coinValue
     isFull = False
     
     if coinType==2 or coinType==3:
         storageSpace = Gcore.getMod('Building', self.uid).cacStorageSpace(coinType)
         if NowCoin > storageSpace:#存满
             isFull = True
             NowCoin = storageSpace
             coinValue = storageSpace - MyCoin #增加的数值
     
     if MyCoin == NowCoin: #没有可增空间
         print ' >> CoinMod Coin full GainCoin fail coinType:%s %s'%(coinType,coinValue)
         return 0
     
     #sql = "UPDATE "+table+" SET "+field+"=%s WHERE UserId='%s'"%(NowCoin,self.uid)
     sql = "UPDATE "+table+" SET "+field+"="+field+"+"+str(coinValue)+" WHERE UserId='%s'"%self.uid
     result = self.db.execute(sql)
     if not result:
         return -2
     else:
         #记录日志 
         table = 'tb_log_coin_%s'%coinType
         d = {}
         d['OptId'] = optId
         d['UserId'] = self.uid
         d['UserType'] = Gcore.getUserData(self.uid,'UserType')
         d['UserLevel'] = Gcore.getUserData(self.uid, 'UserLevel')
         d['OldCoin'] = MyCoin
         d['CoinNumber'] = coinValue
         d['Action'] = 1 # 1获得 2消耗
         d['NowCoin'] = NowCoin
         d['Func'] = classMethod
         d['Param'] = str(param)
         d['CreateTime'] = int(time.time())
         print ' >>> Logging CoinMod.GainCoin',d
         self.db.insert(table,d,isdelay=False) #货币日志不采用延迟插入,怕丢
         Gcore.getMod('Event',self.uid).gainCoinTrigger(optId,coinType,coinValue,NowCoin,isFull)
         return coinValue #当前拥有大于容量时候会返回负值
Exemple #10
0
 def Send(self,ckey,sendData):
     try:
         self.Clients[ckey]['Channel']._send( comm.json_encode(sendData) ) #abu已经有做打包的操作 不用重复操作
     except Exception,e:
         print 'Send Exception',e