示例#1
0
 def go(self):
     if self.connect():
         self.face(self.facing)
         self.sit()
         self.main()
     else:
         log(ERROR, 'The %s slave failed to connect!' % self.account)
示例#2
0
 def periodic(self):
     while 1:
         start = time.time()
         
         for cb in self.periodic_cbs:
             try:
                 cb(self)
             except Exception:
                 sys.excepthook(*sys.exc_info())
         
         # I'm willing to take a nanosec or two of error for some 
         # self-explanatory variable names...
         finish = time.time()
         delta = finish - start
         # 12 seconds = 5 runs a minute
         adjusted = 12 - delta
         if adjusted < 0:
             log(IMPORTANT, 'Periodic loop too loaded for sleep period!')
             log(IMPORTANT, '(time taken: %s)' % delta)
         else:
             time.sleep(adjusted)
示例#3
0
 def got_xxx_ad2(self, *args):
     log(INFO, 'sending reload finish 2')
示例#4
0
 def got_xxx_ad(self, *args):
     log(INFO, 'sending reload finish')
     PacketOut(C_MAP_LOADED).send(self.conn)
示例#5
0
 def got_whisper(self, whom, msg):
     log(INFO, '%s: %s' % (whom, msg))
     response = commands.evaluate(self, whom, msg)
     if response:
         for L in response.split('\n'):
             self.whisper(whom, L)
示例#6
0
    def connect(self):
        """
        Does protocol with the server to get all the way into the game. 
        Returns the boolean success of the connection.
        """
        
        self.ready = False
        
        self.buff = PacketBuffer()
        
        self.log(IMPORTANT, 'Connecting to the login server...')
        
        try:
            login = socket.socket()
            login.connect((self.server, self.port))
        except socket.error:
            log(ERROR, 'Could not connect to the login server!')
            return False
        
        self.log(IMPORTANT, 'Connected to the login server!')
        
        p = PacketOut(C_L_LOGIN, self.account, self.pswd)
        p.send(login)
        
        charip = charport = None
        
        while True:
            data = login.recv(2048)
            if not data:
                break
            self.buff.feed(data)
            for packet in self.buff:
                if packet == S_LOGIN_ERROR:
                    self.log(ERROR, 'Could not log in!')
                    return False
                elif packet == S_CSERV:
                    self.log(IMPORTANT, 'Successfully logged in!')
                    id1, accid, id2, sex, charip, charport = packet.parse()
                    login.close()
                    break
            if charip:
                break
        
        if not charport:
            return False
        
        self.buff.reset()
        
        charserv = (self.server if self.same_ip else charip, charport)
        self.log(IMPORTANT, 'Connecting to the character server (%s:%s)...' % charserv)
        
        try:
            char = socket.socket()
            char.connect(charserv)
        except socket.error as e:
            log(ERROR, 'Could not connect to the character server (%s)!' % e)
            return False
        
        p = PacketOut(C_C_LOGIN, accid, id1, id2, sex)
        p.send(char)
        
        # What's this?
        char.recv(4)
        
        mapip = mapport = None
        
        while True:
            data = char.recv(2048)
            if not data:
                break
            self.buff.feed(data)
            for packet in self.buff:
                if packet == S_PICK_CHAR:
                    self.log(IMPORTANT, 'Picking character...')
                    PacketOut(C_PICK_CHAR, self.cindex).send(char)
                elif packet == S_MSERV:
                    self.log(IMPORTANT, 'Received MServ information.')
                    charid, mapip, mapport = packet.parse()
                    char.close()
                    break
            if mapip:
                break

        if not mapport:
            return False
        
        self.buff.reset()
        
        self.log(IMPORTANT, 'Connecting to the map server...')
        
        try:
            mapserv = socket.socket()
            mapserv.connect((self.server if self.same_ip else mapip, mapport))
        except socket.error:
            self.log(ERROR, 'Could not connect to the map server!')
            return False
        
        p = PacketOut(C_M_LOGIN, accid, charid, id1, id2, sex)
        p.send(mapserv)
        
        # Again, what are we trashing?
        mapserv.recv(4)
        
        done = False
        pos = Vector(0, 0)
        while not done:
            data = mapserv.recv(2024)
            if not data:
                break
            self.buff.feed(data)
            for packet in self.buff:
                if packet == S_CONNECTED:
                    self.log(IMPORTANT, 'Successfully connected!')
                    x, y, d = packet.parse()
                    pos = Vector(x, y)
                    PacketOut(C_MAP_LOADED).send(mapserv)
                    done = True
                    break
        
        self.conn = mapserv
        
        self.pos = pos
        self.account_id = accid
        self.ready = True
        self.done = False
        
        return True
示例#7
0
    ### Build master...
    
    bot = LOFBot(server=config.server,
                 port=config.port,
                 account=config.account,
                 pswd=config.password,
                 # Whether or not to use the passed server IP/address for each 
                 # of the tmwAthena sub-servers. If boolean False, the IPs sent 
                 # during the connection process will be used instead.
                 same_ip=config.same_ip,
                 # The slot the character is in, a zero-based index
                 cindex=0)
    
    ### Go!
    
    try:
        log(IMPORTANT, heading % 'STARTING')
        if bot.connect():
            bot.spawn_slaves(config.slaves)
            bot.face(config.direction)
            bot.sit()
            bot.main()
        else:
            log(ERROR, 'Could not connect!')
    except Exception as e:
        sys.excepthook(*sys.exc_info())
        log(ERROR, 'BUG: %s' % str(e))
    finally:
        log(IMPORTANT, heading % 'STOPPING')
        log.close_children()