コード例 #1
0
ファイル: TradeDumper.py プロジェクト: internety/smarTSO
def response(context, flow):
    """========================================================================
    "Called when a server response has been received"... łapię wyłącznie
    odpowiedzi, bo interesują mnie zestawy (request/response). Przechwycony
    response wraz z requestem wchodzą w skład transakcji, reprezentowanej przez
    mitmproxy.models.HTTPFlow()
    "HTTPFlow is collection of objects representing a single HTTP transaction".
    Więcej info na WWW:  http://docs.mitmproxy.org/en/stable/dev/models.html
 ==========================================================================="""
    if flow.request.host.endswith('.thesettlersonline.pl'):
        if "application/x-amf" in flow.response.headers.get("Content-Type", "_"):
            with decoded(flow.response):
                res = flow.response.content
                req = flow.request.content
                if  search( 'defaultGame.Communication.VO.TradeWindow.dTradeWindowResultVO', res )\
                and search( 'userAcceptedTradeIDs', res ) and search( 'tradeOffers', res )\
                and search( 'GetAvailableOffers', req ):
                    log.debug("got trade REQ/RESP pair, feeding TDD thread...")
                    try:
                        t= Thread(target=ttd._incoming_traffic_handler, args=(context, flow,))
                        t.setDaemon(True) 
                        t.start()
                    except (KeyboardInterrupt, SystemExit):
                        log.info('caught either KeyboardInterrupt or SystemExit, quitting threads')
                        t.__stop()
                        import thread
                        thread.interrupt_main()
コード例 #2
0
ファイル: mate.py プロジェクト: ktosiek/mate
        def run(*args, **kwargs):
            timer = False
            def f_and_timer(*args, **kwargs):
                f(*args, **kwargs)
                timer and timer.cancel()

            log.debug( 'starting bg thread with timeout %s', timeout )
            thread = Thread( target = f_and_timer, args=args, kwargs=kwargs )

            def stop():
                log.debug( 'stopping thread %s', thread )
                thread.terminate()

            if timeout != None:
                timer = Timer(timeout, stop)
                timer.start()

            thread.start()
            return thread
コード例 #3
0
ファイル: bot.py プロジェクト: DuoBelt/ScytheBot
        def run(*args, **kwargs):
            timer = False
            def f_and_timer(*args, **kwargs):
                func(*args, **kwargs)
                if timer:
                    timer.cancel()

            print( 'starting bg thread with timeout %s' % timeout )
            thread = Thread( target = f_and_timer, args=args, kwargs=kwargs )

            def stop():
                print( 'stopping thread %s' % thread )
                thread.terminate()

            if timeout != None:
                timer = Timer(timeout, stop)
                timer.start()

            thread.start()
            return thread
コード例 #4
0
ファイル: FtpClient.py プロジェクト: pynisher/FTPClient
 def timeout_timer(self):
     query = "SELECT is_run FROM sync_tasks WHERE id=" + str(self.sync_data[0])
     data_cur.execute(query)
     is_run = data_cur.fetchall()
     if not is_run[0][0]:                # Проверяем не запущена ли уже задача
         # Ставим метку о запуске задачи
         query = "UPDATE sync_tasks SET is_run=1, status=1 WHERE id=" + str(self.sync_data[0])
         try:
             data_cur.execute(query)
             data_conn.commit()
         except:
             pass
         write_to_log(self.sync_data[1], 'Начинаем ' + self.sync_data[1])
         if self.sync_data[9]:
             thr = Thread(target=sync_from_ftp,
                                    args=(self.sync_data[4], (self.sync_data[6], self.sync_data[7]),
                                          self.sync_data[8], self.sync_data[2], self.sync_data[1],
                                          self.sync_data[3]))
         else:
             thr = Thread(target=sync_to_ftp,
                                    args=(self.sync_data[4], (self.sync_data[6], self.sync_data[7]),
                                          self.sync_data[8], self.sync_data[2], self.sync_data[1],
                                          self.sync_data[3]))
         thr.start()
         control_threads[self.sync_data[1]] = [thr, int(time.time())]
     if self.sync_data[10]:
         self.timer.setInterval(self.delay * 1000)
     else:
         next_time = get_next_time(self.sync_data[11])
         self.timer.setInterval(int(time.mktime(next_time.timetuple()) - time.time())*1000)
コード例 #5
0
ファイル: SzpieGwiazdor.py プロジェクト: internety/smarTSO
def response(context, flow):
    """========================================================================

 ==========================================================================="""
    if flow.request.host.endswith('.thesettlersonline.pl'):
	if "application/x-amf" in flow.response.headers.get("Content-Type", "_"):
            with decoded(flow.response):
                res = flow.response.content
                if  search( 'defaultGame.Communication.VO.dZoneVO',  res )\
                and search( 'defaultGame.Communication.VO.dBuffVO',  res )\
                and search( 'defaultGame.Communication.VO.dPlayerVO',res ):
                    log.debug("got type 1001 response... wysyłam szpiega...")
                    try:
                        t= Thread(target=sgd._incoming_traffic_handler, args=(flow.response.content,))
                        t.setDaemon(True) 
                        t.start()
                    except (KeyboardInterrupt, SystemExit):
                        log.info('caught either KeyboardInterrupt or SystemExit, quitting threads')
                        t.__stop()
                        import thread
                        thread.interrupt_main()
コード例 #6
0
ファイル: TradeDumper.py プロジェクト: internety/smarTSO
                            self.c.mysql_pass,
                            self.c.mysql_db )
        db.autocommit(False)
        db.ping(reconnect=True)
        
        cur = db.cursor()
        cur.executemany(sql, sql_ins_data_list)
        db.commit()
        db.close()
        
        self.market = captured
        self.c.lastupdatedTS = self.now()
        self.updatecounter += 1
        log.info('updatecounter %d'%self.updatecounter)
        
        t= Thread(target=self.market_research_a, args=(captured,))
        t.setDaemon(True)
        t.start()        
        
###############################################################################
    class Offer(object):
        """ oferta handlowa """
        def __init__(self, r_offer, r_slotPos, r_created, r_type, r_senderID,\
                     r_senderName, r_lotsRemaining, r_id, r_slotType, realmName,\
                     servercurrtime):
            self.r_offer    = r_offer
            self.r_slotPos  = r_slotPos
            self.r_created  = r_created
            self.r_type     = r_type
            self.r_senderID = r_senderID
            self.r_senderName=r_senderName