elif event.Key == "Volume_Mute": pass elif event.Key == "Volume_Down": pass elif event.Key == "Volume_Up": pass elif event.Key == "Launch_Media_Select": pass else: return True class EchoServerProtocol(WebSocketServerProtocol): def onOpen(self): self.hook = HookHandlerThread() self.hook.socket = self self.hook.start() def onClose(self, wasClean, code, reason): if hasattr(self, "hook"): print "Closing %s" % self.hook.ident win32api.PostThreadMessage(self.hook.ident, win32con.WM_QUIT, 0, 0); print "Closed" if __name__ == '__main__': factory = WebSocketServerFactory() factory.protocol = EchoServerProtocol factory.port = 8002 reactor.listenTCP(8002, factory) reactor.run()
def tick_flames(): traceerr(GAME._flames_process) reactor.callLater(FLAME_TICK_TIME, tick_flames) def tick_actions(): traceerr(GAME._actions_process) reactor.callLater(ACTION_TICK_TIME, tick_actions) def tick_bombs(): traceerr(GAME._bombs_process) reactor.callLater(BOMB_TICK_TIME, tick_bombs) factory = WebSocketServerFactory() # TODO: choose a more sensible port # TODO: add a REST interface to get the port factory.port = 9000 # ugh, why do I have to do this twice? factory.protocol = GameProtocol reactor.listenTCP(interface=hostname, port=9000, factory=factory) reactor.listenTCP(factory=server.Site(ServerRoot(None)), interface=hostname, port=port) reactor.callWhenRunning(tick_flames) reactor.callWhenRunning(tick_actions) reactor.callWhenRunning(tick_bombs) print "Listening on: http://%s:%d" % (hostname, port) print "Admin uid:", ADMIN_UID reactor.run()