def run_game(self) -> None: while True: clock.tick(self.settings.frames_per_second) self._check_events() if self.stats.is_changing_level: if not self.pause_animations: self.ship.hide_ship() self.scripted_ship = ScriptedShip() self.pause_animations.add(self.scripted_ship) self.pause_animations.add(Tunnel()) if self.scripted_ship.has_finished(): self.level_display.update() if self.stats.is_level_changed: self.pause_animations.empty() self._set_stage() self.stats.set_game_mode(Mode.ACTIVE) if self.stats.is_active: self.ship.update() self._update_bullets() self._change_level() self._update_aliens() self._update_screen()
def forward_request(self): uri = self.path cmd = self.command if cmd == "CONNECT": self.send_response(200) # in Python 3.4, end_headers need access _headers_buffer. Invoke send_header # will make sure the field is created self.send_header("Date", self.date_time_string()) self.end_headers() return Tunnel(self.connection, uri).handle() if uri.startswith("https://"): raise NotSupportedError("https not supported yet") elif uri.startswith("http://"): uri = uri[len("http://") :] else: raise InvalidRequest("Invalid uri for proxy: {0}".format(uri)) start_ind = uri.find("/") if start_ind == -1: start_ind = uri.find("?") if start_ind == -1: addr = uri resource = "/" else: addr = uri[:start_ind] resource = uri[start_ind:] if not resource.startswith("/"): resource = "/" + resource conn = HTTPConnection(addr) if cmd not in ["GET", "POST"]: raise NotSupportedError("http method {0} not supported".format(cmd)) headers = {name: self.headers[name] for name in self.headers } if headers.get("Content-Length"): cl = int(headers["Content-Length"]) else: cl = None body = None # get body for post if cmd in ["POST"]: self.handleExpect100(headers) if cl: body = self.rfile.read(cl) else: body = self.rfile.read() print("body is [{0}]".format(body)) if "Proxy-Connection" in headers: del headers["Proxy-Connection"] conn.request(cmd, resource, body, headers) resp = conn.getresponse() self.forward_response(resp)
def add_tunnel(self, dstname, physport, dstvlan): # NOTE: this doesn't check for whether or not this is a valid thing to # do. The user of this function should be confirming with the switch # that a particular VLAN/Port combination is valid. # Make sure there isn't already a 'dstname' in the tunnels list for tunnel in self.tunnels: if tunnel.get_name() == dstname: tunnel_names = [] for t in self.tunnels: tunnel_names.append(t.get_name()) raise Exception("%s already exists as a tunnel name: %s" % (dstname, tunnel_names)) # Find open virtual port number self.current_vport += 1 vport = self.current_vport # Create the Tunnel object tunnel_href = self.href + "/tunnels/" + str(dstname) tunnel = Tunnel(tunnel_href, dstname, physport, dstvlan, vport) # Make REST calls to instantiate this new tunnel self.add_tunnel_REST_helper(physport, vport, dstvlan) # Finally, add it to the local list of tunnels self.tunnels.append(tunnel) return tunnel
def __new_tunnel(self): tunnel = Tunnel() port = tunnel.new_tunnel(self.req_data.get('port', 0), self.req_data.get('client_id')) res = { 'tunnel_port': port, 'client_id': self.req_data.get('client_id'), 'res': 'start_tunnel' } self.protocol.sendString(json.dumps(res).encode('utf8'))
def test_steps(self): tunnel = Tunnel(5, 5, 5, orient=Orientation.right) positions = tunnel.steps() message = 'Positions {}: '.format(len(positions)) for pos in positions: message += str(pos) print(message) self.assertTrue(Position(5, 9) in positions)
def readSettings(self): if os.name == 'nt': settings = QSettings() else: settings = QSettings(os.path.expanduser("~/.iosshy.ini"), QSettings.IniFormat) for name in settings.childGroups(): tunnel = Tunnel(self) tunnel.name = name tunnel.readSettings(settings) self._tunnels.append(tunnel) self.tray.menu.insertAction(self.actionLastSep, tunnel.action) self.tray.menu.removeAction(self.actionNoTun)
def on_btnDuplicateTunnel_clicked(self): cur = self.currentTunnel() if cur is not None: tunnel = Tunnel(self) tunnel.name = cur.name+" (copy)" tunnel.host = cur.host tunnel.localPort = cur.localPort tunnel.port = cur.port tunnel.username = cur.username tunnel.command = cur.command tunnel.autoClose = cur.autoClose self._tunnels.append(tunnel) self.listTunnels.setCurrentItem(tunnel.item) self.tray.menu.insertAction(self.actionLastSep, tunnel.action)
def __init__(self): super(QMainWindow, self).__init__() self.setupUi(self) self.connButtonBox.button(QDialogButtonBox.Ok).setText("Connect") self.runButtonBox.button(QDialogButtonBox.Ok).setText("Run") self.tunnelButton.clicked[bool].connect(self.toggle_tunnel) self.tunnelWidget.hide() self.keyFileButton.clicked.connect(self.choose_keyfile) self.clearButton.clicked.connect(self.clear_tunnel) self.keyComboBox.activated[str].connect(self.set_key_type) self.db_engine = DBEngine() self.db_engine.result_signal.connect(self.show_results) self.db_engine.progress_signal.connect(self.set_progress) self.db_engine.error_signal.connect(self.show_error) self.db_engine.msg_signal.connect(self.show_msg) self.stmt_signal.connect(self.db_engine.receive_stmt) self.db_lite = DBLite() self.tunnel = Tunnel() self.tunnel_keyfile = "" self.data_schema = [] self.settings = QSettings() self.restore_settings() history = self.db_lite.history() self.historyMenuBar = QMenuBar(self.sqlWidget) self.historyMenuBar.setNativeMenuBar(False) self.historyMenu = self.historyMenuBar.addMenu(' &History ⇲ ') actions = [ QAction(sql.replace('\n', ' '), self.historyMenu) for sql in history ] for i in range(len(actions)): actions[i].triggered.connect(partial(self.use_history, history[i])) self.historyMenu.addActions(actions) self.history_cache = pylru.lrucache(history_limit, self.remove_action) for i in reversed(range(len(history))): self.history_cache[history[i]] = { KEY_ACTION: actions[i], KEY_RESULTS: [], KEY_COLUMNS: [] } self.historyMenu.setStyleSheet(""" QMenu { max-width: 1000px; font-size: 12px; } """) self.historyMenuBar.setStyleSheet(""" QMenuBar { border: None; } QMenuBar::item { background: #404040; color: #ffffff; border-radius: 4px; } QMenuBar::item:selected { background: rgba(1, 1, 1, 0.2);; color: #404040; border-radius: 4px; } """) self.sqlWidgetLayout.insertWidget(0, self.historyMenuBar) self.connButtonBox.accepted.connect(self.connect) self.connButtonBox.rejected.connect(self.disconnect) self.runButtonBox.accepted.connect(self.run) self.runButtonBox.rejected.connect(self.cancel) self.tablesWidget.itemDoubleClicked.connect(self.get_meta) self.tablesWidget.itemExpanded.connect(self.get_meta) self.progressBar = QProgressBar() self.statusbar.addPermanentWidget(self.progressBar) self.progressBar.setValue(100) QApplication.processEvents() self.highlight = syntax.PrestoHighlighter(self.sqlEdit) self.dataWidget.setContextMenuPolicy(Qt.CustomContextMenu) self.dataWidget.customContextMenuRequested.connect( self.show_table_context_menu) self.dataWidget.horizontalHeader().setStretchLastSection(False) self.dataWidget.horizontalHeader().setSectionResizeMode( QHeaderView.ResizeToContents) self.schemaView.header().setStretchLastSection(False) self.schemaView.header().setSectionResizeMode( QHeaderView.ResizeToContents) self.runButtonBox.button( QDialogButtonBox.Ok).setShortcut("Ctrl+Return") self.completer = SQLCompleter(self) self.sqlEdit.setCompleter(self.completer) self.set_key_type(self.keyComboBox.currentText()) self.sqlEdit.setFocus()
def handle(self): StreamRequestHandler.handle(self) t = Tunnel(self._tcp_sock, self._icmp_sock, self._peer, self._id) t.loop()
def on_btnAddTunnel_clicked(self): tunnel = Tunnel(self) self._tunnels.append(tunnel) self.listTunnels.setCurrentItem(tunnel.item) self.tray.menu.insertAction(self.actionLastSep, tunnel.action) self.tray.menu.removeAction(self.actionNoTun)
def main(args): mods = dict() #Parse commandline args if len(args) != 4: print "host.py MAC IP IFACE" return mymac = args[1] myip = args[2] myiface = args[3] while True: #Read and Parse Message line = "" msg = None try: line = sys.stdin.readline() except Exception as e: print e print "Exiting" return if len(line) == 0: continue try: msg = eval(line) except Exception as e: continue if not isinstance(msg, dict): continue if not 'module' in msg: continue #Select Module and send command m = None if msg['module'] is "ping": if "ping" in mods: m = mods['ping'] else: m = Ping(mymac, myip, myiface) mods['ping'] = m out = response(m.cmd(msg)) send_response(out) elif msg['module'] is "iperf": if "iperf" in mods: m = mods['iperf'] else: m = Iperf(mymac, myip, myiface) mods['iperf'] = m out = response(m.cmd(msg)) send_response(out) elif msg['module'] is "http": if "http" in mods: m = mods["http"] else: m = HttpTest(mymac, myip, myiface) mods['http'] = m out = response(m.cmd(msg)) send_response(out) elif msg['module'] is "arp": if "arp" in mods: m = mods['arp'] else: m = Arp(mymac, myip, myiface) mods['arp'] = m out = response(m.cmd(msg)) send_response(out) elif msg['module'] is "lldp": if "lldp" in mods: m = mods['lldp'] else: m = LLDPAttack(mymac, myip, myiface) mods['lldp'] = m out = response(m.cmd(msg)) send_response(out) elif msg['module'] is "tunnel": if "tunnel" in mods: m = mods['tunnel'] else: m = Tunnel(mymac, myip, myiface) mods['tunnel'] = m out = response(m.cmd(msg)) send_response(out) elif msg['module'] is "magic": if "magic" in mods: m = mods["magic"] else: m = Magic(mymac, myip, myiface) mods["magic"] = m out = response(m.cmd(msg)) send_response(out) else: print "Unknown Module"
player = Player(w, h) # create pellet array pellet_list = [] # list of actual nodes nodeList = [] # create powerPellet array powerPellet_list = [] # create ghostNodes array ghostNodes = [] # create two way tunnel tunnel = Tunnel(10, 290, w-10, 290) # (x1, y1, x2, y2) startTime = 0 # pre load background image pygame.image.load('colourmap.png').convert() image_rect = pygame.image.load('colourmap.png').convert().get_rect() image_surface = pygame.Surface((image_rect.width, image_rect.height)) image_surface.blit(pygame.image.load("colourmap.png"), image_rect) # have the ghost get the path to its target pinky_node = player.findNode(ghostNodes) def get_pinky_node(): global pinky_node # global ghostNodes