Esempio n. 1
0
    def build_building(self, bld_gid, bld_lvl):
        from_lvl = bld_lvl - 1

        bld_bid = None
        bld_new = None
        for bid, gid, lvl in self.buildings + self.resource_fields:
            if gid == bld_gid and lvl == from_lvl:
                bld_bid = bid
                bld_new = False
                break

        if bld_bid is None:
            for bid, gid, lvl in self.buildings + self.resource_fields:
                if gid == 0:
                    bld_bid = bid
                    bld_new = True
                    break
                
        if bld_new is None:
            logger.log_error("build not found", "Nothing to build found! ")
            return False

        if bld_new == True:
            logger.log_info("build", "Building %s new lvl %s at %s" % (db.buildings[bld_gid]['gname'], bld_lvl, bld_bid) )
            action.action_build_new(self.account, bld_bid, bld_gid)
        else:
            logger.log_info("build", "Building %s up from lvl %s to %s at %s" % (db.buildings[bld_gid]['gname'], from_lvl, bld_lvl, bld_bid) )
            action.action_build_up(self.account, bld_bid)
            
        self.fire_event(Event(self, 'resources_spent', datetime.now()))
Esempio n. 2
0
    def login(self, doc_login = None):
        logger.log_info("login", "logging in...")
        self.clear_cookie()
        doc = doc_login or self.request_GET("/dorf1.php")

        # retrieve current login POST data
        params = {}
        for inpt in doc.find("form[name=login] input"):
            name = inpt.attr('name')
            value = None
            if inpt._is("[value]"):
                value = inpt.attr('value')
            params[name] = value

        # alter it
        params['name'] = self.user_name
        params['password'] = self.password
        params['lowRes'] = '1'
        params['s1'] = 'Einloggen'
        params['w'] = '1920:1080'

        # perform login and return village overview
        doc = self.request_POST("/dorf1.php", params)
        self.ajax_token = reader.read_ajax_token(doc)
        return doc
Esempio n. 3
0
 def request_village(self, village_id, doc_login = None):
     '''
     If village_id is None, doc_login will be used and a list of villages will be stored.
     '''
     
     doc_resources = doc_login or self.request_GET("/dorf1.php?newdid=%d" % village_id)
         
     pages = { 'resources': doc_resources,
               'village': self.request_GET("/dorf2.php") }
     
     active_village = reader.read_villages(doc_resources, True)[0]
     if village_id is None:
         all_villages = reader.read_villages(doc_resources)
         
         self.villages.clear()
         self.villages.update( { vill['village_id']: Village(self, **vill) for vill in all_villages } )
     
     if active_village['village_id'] not in self.villages:
         self.villages[active_village['village_id']] = Village(self, **active_village)
         self.current_village = self.villages[active_village['village_id']]
     
     village = self.villages[active_village['village_id']]
     if active_village['name'] != village.name:
         logger.log_info("village renamed", "Village %s renamed to %s" % (village.name, active_village['name']))
     village.name = active_village['name']
     
     village.read_content(pages)
     village.read_events(pages)
     
     village.new_refresh_time()
     
     return village
Esempio n. 4
0
 def refresh(self, *page_names):
     '''
     Refreshes all pages related with this village, or only 
     with the given pages.
     '''
     if self.suppress_refresh:
         return
     logger.log_note('refresh', 'refreshing %s' % str(page_names))
     pages = {}
     page_names = page_names or self.url_mapping.keys()
     for page_name in page_names:
         doc = self.account.request_GET(self.url_mapping[page_name])
         if 'type="password"' in doc.find("html").html():
             logger.log_info("logout", "Logout detected")
             self.account.clear_cookie()
             self.account.login()
             self.account.save_cookie()
             self.next_refresh_time = datetime.now() + timedelta(seconds=30)
             
             return
             
         pages[page_name] = doc
         
     self.read_content(pages)
     self.read_events(pages)
     
     if not self.resources:
         self.account.login()
         self.refresh(*page_names)
         
     print(self.events.build)
     
     if not self.resources or not self.production or not self.storage_capacity:
         logger.log_error("page error", [ "%s: %s" % (t, p.find("html").html().strip()) for t,p in pages.items() ], 'Could not fetch village data')
         
     self.save_status()
     
     self.new_refresh_time()
     
     return pages
Esempio n. 5
0
server = (3, 'de')

account = Account(server, name)

logger.log_name = name
logger.log_note("start", "Started the bot")

#db.users.remove({}) # wipe users
#db.states.remove({})

jobs_from_db = True

if account.get_db() is None or account.get_db()['activated'] == False:
    
    logger.log_info("register account", "need to register this account first: ensure the mailserver is running")
    if account.get_db() is None:
        account.init_db(email, password, nation, proxies)
        account.load_db()
        action.action_register(account)
        jobs_from_db = False
    
    logger.log_info("wait for email", "wait for activation email to receive...")
    user_db = account.get_db()
    while 'activation_code' not in user_db:
        time.sleep(1)
        user_db = account.get_db()
    
    account.perform_activation("so")
    
account.loadup()