def displayThread(self): """ Thread handler for the "display" part.""" try: self.display.start() except Exception, msg: bt = getBacktrace() log.error("EXCEPTION IN DISPLAY THREAD:\n%s\n%s" % (msg, bt))
def runThread(self, port, max_connection): try: self.__running = True self.start(port, max_connection) except Exception, msg: log.error("EXCEPTION IN TCP SERVER WAITER!\n%s\n%s" \ % (msg, getBacktrace()))
def __clientChallenge(self, client, func): try: func(client) except Exception, msg: log.error( \ "EXCEPTION WHEN A CLIENT TRY TO CONNECT :\n%s\n%s" \ % (msg, getBacktrace())) self.stop()
def run_io_thread(self): try: while self.__io.isRunning(): self.__io.live() time.sleep(0.001) except Exception, msg: log.error( \ "EXCEPTION IN IO THREAD :\n%s\n%s" \ % (msg, getBacktrace())) self.server.stop()
def run_thread(self): """ Function which should be called in a thread. """ try: while self._running: self.live() time.sleep(self.thread_sleep) except Exception, msg: log.error( \ "EXCEPTION DANS LE THREAD IO :\n%s\n%s" % (msg, getBacktrace()))
def run_thread(self): """ Function which should be called in a thread : call L{live()} with a sleep. """ try: while self.__running: self.live() time.sleep(self.thread_sleep) except Exception, msg: log.error( \ "EXCEPTION IN UDP SERVER:\n%s\n%s" \ % (msg, getBacktrace())) self.stop()
class Client(Happyboom, EventListener): """ The main class of the client of BoomBoom. @ivar display: Display manager of the game. @type display: C{L{BoomBoomDisplay}} @ivar input: Input manager of the game. @type input: C{L{BoomBoomInput}} @ivar __verbose: Verbose mode flag. @type __verbose: C{bool} @ivar __stopped: Stopped game flag. @type __stopped: C{bool} @ivar __stoplock: Mutex for synchronizing __stopped. @type __stoplock: C{thread.lock} """ def __init__(self, args): """ BoomBoomClient constructor. @param host: Server hostname. @type host: C{str} @param display_port: Server port for "display"/"view" connection. @type display_port: C{int} @param input_port: Server port for "input" connection. @type input_port: C{int} @param verbose: Verbose mode flag. @type verbose: C{bool} @param debug: Debug mode flag. @type debug: C{bool} @param max_fps: Maximal number of frames per second, for optimization. @type max_fps: C{int} """ args["protocol"] = protocol.loadProtocol("protocol.xml") args["features"] = ["game"] # Constant features Happyboom.__init__(self, args) EventListener.__init__(self, prefix="evt_") self.display = Display(args) self.input = Input(args) self.__verbose = args.get("verbose", False) self.registerEvent("happyboom") self.registerEvent("game") def start(self): """ Starts the game client.""" if self.__verbose: log.info("[BOOMBOOM] Starting client...") Happyboom.start(self) # Create thread for display thread.start_new_thread(self.displayThread, ()) quit = False while not quit: self.input.process() time.sleep(0.100) quit = self.stopped def stop(self): """ Stops the game client.""" if self.__verbose: log.info("[BOOMBOOM] Stopping client...") Happyboom.stop(self) self.launchEvent("happyboom", "disconnection", self._io, u"Quit.") self.display.stop() def evt_game_stop(self): self.stop() def evt_happyboom_stop(self): """ Stop event handler. """ self.stop() def displayThread(self): """ Thread handler for the "display" part.""" try: self.display.start() except Exception, msg: bt = getBacktrace() log.error("EXCEPTION IN DISPLAY THREAD:\n%s\n%s" % (msg, bt)) try: self.stop() except Exception, msg: bt = getBacktrace() log.error("EXCEPTION (2) IN DISPLAY THREAD:\n%s\n%s" % (msg, bt))