def _connect(self): """ Establish a connection with the Frostbite server. """ if self._frostbiteConnection: return self.console.verbose('RCON: connecting to Frostbite server ...') self._frostbiteConnection = FrostbiteConnection( self.console, self._rconIp, self._rconPort, self._rconPassword)
def run(self): """ Main worker thread for B3. """ self.bot('Start listening ...') self.screen.write( 'Startup complete : B3 is running! Let\'s get to work!\n\n') self.screen.write( '(If you run into problems, check %s in the B3 root directory for ' 'detailed log info)\n' % self.config.getpath('b3', 'logfile')) self.updateDocumentation() while self.working: # while we are working, connect to the frostbite server if self._paused: if self._pauseNotice is False: self.bot( 'PAUSED - not parsing any lines: B3 will be out of sync' ) self._pauseNotice = True else: try: if self._serverConnection is None: self.verbose('Connecting to frostbite server...') self._serverConnection = FrostbiteConnection( self, self._rconIp, self._rconPort, self._rconPassword) self._serverConnection.subscribeToEvents() self.clients.sync() self._nbConsecutiveConnFailure = 0 nbConsecutiveReadFailure = 0 while self.working: # while we are working and connected, read a packet if not self._paused: try: packet = self._serverConnection.readEvent() self.console("%s" % packet) try: self.routeFrostbitePacket(packet) except SystemExit: raise except Exception as msg: self.error( '%s: %s', msg, traceback.extract_tb( sys.exc_info()[2])) except FrostbiteException as e: nbConsecutiveReadFailure += 1 if nbConsecutiveReadFailure > 5: raise e except FrostbiteException as e: self.debug(e) self._nbConsecutiveConnFailure += 1 self._serverConnection.close() if self._nbConsecutiveConnFailure <= 20: self.debug('sleeping 0.5 sec...') time.sleep(0.5) elif self._nbConsecutiveConnFailure <= 60: self.debug('sleeping 2 sec...') time.sleep(2) else: self.debug('sleeping 30 sec...') time.sleep(30) self.bot('Stop listening...') with self.exiting: #self.input.close() self.output.close() if self.exitcode: sys.exit(self.exitcode)
def _connect(self): if self._frostbiteConnection: return self.console.verbose('RCON: Connecting to Frostbite server ...') self._frostbiteConnection = FrostbiteConnection( self.console, self._rconIp, self._rconPort, self._rconPassword)