Esempio n. 1
0
def sync_time():
    retry = 10
    t = 1
    while t <= retry:
        try:
            sanguo = Sanguo()
            stime = sanguo.login()
            if not stime:
                raise Exception()
            ltime = int(time.time())
            sanguo.close()
            Server_Time = stime
            Local_Server_Diff = ltime - stime
            return (Server_Time, Local_Server_Diff)
        except:
            time.sleep(2)
            t += 1
Esempio n. 2
0
def send_command(cmd, *args):
    retry = 10
    t = 1
    while t <= retry:
        try:
            sanguo = Sanguo()
            sanguo.login()
            function = getattr(sanguo, cmd)
            res = function(*args)
            sanguo.close()
            if res == None:
                raise Exception()
            return res
        except:
            #logger.error(cmd + "\n" + traceback.format_exc())
            time.sleep(2*t)
            t += 1
Esempio n. 3
0
 def sync_time(self):
     global Local_Server_Diff
     retry = 10
     t = 1
     while t <= retry:
         try:
             sanguo = Sanguo()
             stime = sanguo.login()
             if not stime:
                 raise Exception()
             ltime = int(time.time())
             sanguo.close()
             Local_Server_Diff = ltime - stime
             logger.info('sync time succeed. ltime=%d stime=%d diff=%d'%(ltime, stime, Local_Server_Diff))
             return
         except:
             logger.debug(traceback.format_exc())
             time.sleep(t*2)
             t += 1
 def get_pozen_info(self, campaignid):
     dicdata = {
             'op' : 3001,
             'campaignId' : int(campaignid)
         }
     retry = 10
     t = 1
     while t <= retry:
         try:
             res = ''
             sanguo = Sanguo()
             sanguo.login()
             sanguo.login()
             data = sanguo.compose_data(dicdata)
             sanguo.tcpClientSock.send(data)
             time.sleep(2)
             res += sanguo.tcpClientSock.recv(4096)
             if len(res) < 5:
                 raise Exception()
             data = util.decode_data(res)
             if not data or len(data) < 1:
                 logger.error('no data')
                 raise Exception()
             sanguo.close()
             return data[1]['armys']
         except:
             time.sleep(2)
             t += 1
Esempio n. 5
0
 def do_weipai(self, tpe, level):
     dicdata = {
             'level' : str(level),
             'op' : 1021,
             'type' : str(tpe),
         }
     retry = 10
     t = 1
     while t <= retry:
         try:
             res = ''
             sanguo = Sanguo()
             sanguo.login()
             sanguo.login()
             data = sanguo.compose_data(dicdata)
             sanguo.tcpClientSock.send(data)
             #res += sanguo.tcpClientSock.recv(1024)
             time.sleep(2)
             res += sanguo.tcpClientSock.recv(4096)
             if len(res) < 5:
                 raise Exception()
             data = util.decode_data(res)
             if not data or len(data) < 1:
                 logger.error('no data')
                 raise Exception()
             sanguo.close()
             if not data[0].has_key('exception'):
                 self.add_cost(tpe, level)
             return data
         except:
             #logger.error(traceback.format_exc())
             time.sleep(2)
             t += 1
Esempio n. 6
0
def tongsang(uname):
    retry = 10
    t = 1
    while t <= retry:
        try:
            sanguo = Sanguo()
            sanguo.login()
            data = sanguo.tongsang(uname)
            sanguo.close()
            if not data:
                raise Exception()
            logger.info("Tongsang %s succeed." % (uname))
            return data
        except:
            time.sleep(3)
            t += 1
 def suaxin_husong_list(self):
     retry = 10
     t = 1
     while t <= retry:
         try:
             sanguo = Sanguo()
             sanguo.login()
             data = sanguo.husong_suaxin()
             sanguo.close()
             if not data:
                 raise Exception()
             return data
         except:
             logger.info('husong_suaxin failed, will sleep %d seconds'%(t*2))
             time.sleep(t*2)
             t += 1
Esempio n. 8
0
 def get_equip_info(self):
     retry = 10
     t = 1
     while t <= retry:
         try:
             sanguo = Sanguo()
             sanguo.login()
             data = sanguo.get_equip_info()
             sanguo.close()
             if not data:
                 raise Exception()
             else:
                 return data
         except:
             time.sleep(2)
             t += 1
Esempio n. 9
0
 def do_zengzan(self, nstr):
     retry = 10
     t = 1 
     while t <= retry:
         try:
             sanguo = Sanguo()
             sanguo.login()
             data = sanguo.zengzan(nstr)
             sanguo.close()
             if not data:
                 raise Exception()
             return data
         except:
             logger.info('do_zengzan failed, will sleep 2 seconds')
             time.sleep(2)
             t += 1
Esempio n. 10
0
 def do_upgrade(self, eid, magic, buymagic=0):
     retry = 10
     t = 1 
     while t <= retry:
         try:
             sanguo = Sanguo()
             sanguo.login()
             data = sanguo.upgradeEquip(eid, magic, buymagic)
             sanguo.close()
             if not data:
                 raise Exception()
             logger.info('Upgrade %s succeed'%(eid))
             return data
         except:
             time.sleep(2)
             t += 1
Esempio n. 11
0
def get_user(uid):
    retry = 10
    t = 1
    while t <= retry:
        try:
            sanguo = Sanguo()
            sanguo.login()
            data = sanguo.getUserInfo(uid)
            sanguo.close()
            if not data:
                raise Exception()
            else:
                return data
        except:
            time.sleep(2)
            t += 1
Esempio n. 12
0
 def do_ttt(self):
     retry = 10
     t = 1 
     while t <= retry:
         try:
             sanguo = Sanguo()
             sanguo.login()
             data = sanguo.tongtianta()
             sanguo.close()
             if not data:
                 logger.error('ttt failed, data None')
                 raise Exception()
             logger.info('tongtianta succeed, result %d'%(data['result']))
             return data
         except:
             logger.info('do_ttt failed, will sleep %d seconds'%(t*2))
             time.sleep(t*2)
Esempio n. 13
0
def sell_baowu(bid):
    retry = 10
    t = 1
    while t <= retry:
        try:
            sanguo = Sanguo()
            sanguo.login()
            data = sanguo.sell_baowu(bid)
            sanguo.close()
            if not data:
                raise Exception()
            logger.info("sell baowu %s succeed"%(str(bid)))
            return data
        except:
            #logger.error("sell baowu %s failed"%(str(bid)))
            time.sleep(2)
            t += 1
Esempio n. 14
0
 def bianzhen(self, keji):
     retry = 10
     t = 1 
     while t <= retry:
         try:
             sanguo = Sanguo()
             sanguo.login()
             data = sanguo.bianzhen(keji)
             sanguo.close()
             if not data:
                 logger.error('bianzhen failed, data None')
                 raise Exception()
             return data
         except:
             logger.info('bianzhen failed, will sleep %d seconds'%(t*2))
             time.sleep(t*2)
             t += 1
Esempio n. 15
0
def get_user(uid):
    retry = 10
    t = 1
    while t <= retry:
        try:
            sanguo = Sanguo()
            sanguo.login()
            data = sanguo.getUserInfo(uid)
            sanguo.close()
            if not data:
                raise Exception()
            if not data.has_key('protectTime'):
                raise Exception('No protectTime')
            return data
        except:
            time.sleep(2 * t)
            t += 1
Esempio n. 16
0
 def get_city_info(self, cityid, zoneid):
     retry = 10
     t = 1
     while t <= retry:
         try:
             sanguo = Sanguo()
             sanguo.login()
             data = sanguo.getCityInfo(cityid, zoneid)
             sanguo.close()
             if not data:
                 logger.error('get_city_info failed')
                 raise Exception()
             else:
                 return data
         except:
             time.sleep(2)
             t += 1
Esempio n. 17
0
 def get_keji_info(self):
     retry = 10
     t = 1
     while t <= retry:
         try:
             sanguo = Sanguo()
             sanguo.login()
             data = sanguo.getKejiInfo()
             sanguo.close()
             if not data:
                 raise Exception()
             if not self.check_result(data):
                 raise Exception()
             return data
         except:
             time.sleep(2)
             t += 1
Esempio n. 18
0
 def do_tax(self):
     retry = 10
     t = 1 
     while t <= retry:
         try:
             sanguo = Sanguo()
             sanguo.login()
             data = sanguo.tax()
             sanguo.close()
             if not data:
                 logger.error('Tax failed, data None')
                 raise Exception()
             logger.info('Tax succeed')
             return data
         except:
             logger.info('do_tax failed, will sleep %d seconds'%(t*2))
             time.sleep(t*2)
             t += 1
 def do_downgrade(self, eid):
     retry = 10
     t = 1 
     while t <= retry:
         try:
             sanguo = Sanguo()
             sanguo.login()
             data = sanguo.downgradeEquip(eid)
             sanguo.close()
             if not data:
                 logger.error('downgrade failed, data None')
                 raise Exception()
             #logger.info('downgrade succeed')
             return data
         except:
             logger.info('do_downgrade failed, will sleep %d seconds'%(t*2))
             time.sleep(t*2)
             t += 1
 def do_soukuang(self, pid):
     retry = 10
     t = 1
     while t <= retry:
         try:
             sanguo = Sanguo()
             sanguo.login()
             data = sanguo.soukuang(pid)
             sanguo.close()
             if not data:
                 logger.error('soukuang %s failed.'%(pid))
                 raise Exception()
             logger.info('soukuang %s succeed. data len %d'%(pid, len(data)))
             return data
         except:
             logger.info('do_soukuang failed, will sleep %d seconds'%(t*2))
             time.sleep(t*2)
             t += 1
Esempio n. 21
0
 def do_tufei(self, hero):
     retry = 10
     t = 1
     while t <= retry:
         try:
             sanguo = Sanguo()
             sanguo.login()
             data = sanguo.tufei(hero)
             sanguo.close()
             if not data:
                 logger.error('Tufei %s failed.'%(hero))
                 raise Exception()
             logger.info('tufei %s succeed'%(hero))
             return data
         except:
             t += 1
             logger.info('do_tufei failed, will sleep %d seconds'%(t*2))
             time.sleep(t*2)
 def do_enter(self):
     retry = 10
     t = 1
     while t <= retry:
         try:
             sanguo = Sanguo()
             sanguo.login()
             data = sanguo.kuangzan()
             sanguo.close()
             if not data:
                 logger.error('Enter kuangzan failed. data None')
                 raise Exception()
             logger.info('Enter kuangzan succeed.')
             return data
         except:
             logger.info('do_enter failed, will sleep %d seconds'%(t*2))
             time.sleep(t*2)
             t += 1
Esempio n. 23
0
 def get_equip_info(self):
     retry = 10
     t = 1
     while t <= retry:
         try:
             sanguo = Sanguo()
             sanguo.login()
             data = sanguo.get_equip_info()
             sanguo.close()
             if not data:
                 raise Exception()
             if not data.has_key('userEquipInfo'):
                 print data
                 raise Exception()
             return data
         except:
             time.sleep(2)
             t += 1
def get_arena_reward():
    retry = 10
    t = 1
    while t <= retry:
        try:
            sanguo = Sanguo()
            sanguo.login()
            data = sanguo.get_arena_reward()
            sanguo.close()
            if not data:
                logger.error('get_arena_reward failed')
                raise Exception()
            logger.info('get_arena_reward succeed')
            return data
        except:
            logger.info('get_arena_reward failed, will sleep %d seconds'%(t*2))
            time.sleep(t*2)
            t += 1
Esempio n. 25
0
 def do_touzi(self):
     retry = 10
     t = 1
     while t <= retry:
         try:
             sanguo = Sanguo()
             sanguo.login()
             data = sanguo.touzi(CITY_ID[CityName], Thrive)
             sanguo.close()
             if not data:
                 logger.error('Touzi %s failed.'%(CityName))
                 raise Exception()
             logger.info('Touzi %s succeed.'%(CityName))
             return data
         except:
             logger.info('do_touzi %s failed, will sleep %d seconds'%(CityName, t*2))
             time.sleep(t*2)
             t += 1
 def do_lanjie(self, people):
     retry = 10
     t = 1
     while t <= retry:
         try:
             sanguo = Sanguo()
             sanguo.login()
             data = sanguo.lanjie(people)
             sanguo.close()
             if not data:
                 logger.error('lanjie failed. return None')
                 raise Exception()
             logger.info('lanjie %s succeed.'%(people))
             return data
         except:
             logger.info('do_lanjie failed, will sleep %d seconds'%(t*2))
             time.sleep(t*2)
             t += 1
Esempio n. 27
0
 def get_hero_info(self):
     retry = 10
     t = 1
     while t <= retry:
         try:
             sanguo = Sanguo()
             sanguo.login()
             data = sanguo.baowu_list()
             self.local_time = int(time.time())
             sanguo.close()
             if not data:
                 raise Exception()
             if not self.check_result(data):
                 raise Exception()
             return data
         except:
             time.sleep(2)
             t += 1
Esempio n. 28
0
 def do_keji(self, kid):
     retry = 10
     t = 1
     while t <= retry:
         try:
             sanguo = Sanguo()
             sanguo.login()
             data = sanguo.keji(kid)
             sanguo.close()
             if not data:
                 logger.error('Keji %s failed.'%(kid))
                 raise Exception()
             logger.info('Keji %s succeed.'%(kid))
             return data
         except:
             logger.info('do_keji %s failed, will sleep %d seconds'%(kid, t*2))
             time.sleep(t*2)
             t += 1
Esempio n. 29
0
 def do_pozen(self, armyid):
     retry = 10
     t = 1 
     while t <= retry:
         try:
             sanguo = Sanguo()
             sanguo.login()
             data = None
             if op_config.has_key(armyid):
                 data = sanguo.pozen(armyid, op_config[armyid])
             else:
                 data = sanguo.pozen(armyid)
             sanguo.close()
             if not data:
                 logger.error('pozen failed, data None')
                 raise Exception()
             logger.info('pozen succeed')
             return data
         except:
             logger.info('do_pozen failed, will sleep %d seconds'%(t*2))
             time.sleep(t*2)
             t += 1
 def do_husong(self):
     retry = 10
     t = 1 
     while t <= retry:
         try:
             sanguo = Sanguo()
             sanguo.login()
             data = sanguo.husong()
             sanguo.close()
             if not data:
                 logger.error('Husong failed, data None')
                 raise Exception()
             logger.info('Husong succeed')
             return data
         except:
             logger.info('do_husong failed, will sleep %d seconds'%(t*2))
             logger.info(traceback.format_exc())
             time.sleep(t*2)
             t += 1