-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix loading resources from local dir (+3 squashed commits)
Make a DHCP request for only the Wii U interface Add CLI - run_server wii_u_interface normal_interface - get_ket wii_u_interface wps_pin (first for numbers) Update dependencies
- Loading branch information
1 parent
ce24aa0
commit d682a20
Showing
14 changed files
with
145 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ dist/ | |
*.egg-info/ | ||
setup.cfg | ||
temp/ | ||
.drc-sim/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,103 @@ | ||
import time | ||
|
||
from src.server.control.gamepad import Gamepad | ||
from src.server.data import constants | ||
from src.server.data.args import Args | ||
from src.server.util.interface_util import InterfaceUtil | ||
from src.server.util.logging.logger_cli import LoggerCli | ||
from src.server.util.wpa_supplicant import WpaSupplicant | ||
|
||
|
||
class CliMain: | ||
def __init__(self): | ||
LoggerCli.throw(NotImplementedError("CLI not implemented")) | ||
self.getting_key = False | ||
self.gamepad = None | ||
self.wpa_supplicant = None | ||
|
||
def start(self): | ||
LoggerCli.throw(NotImplementedError("CLI not implemented")) | ||
LoggerCli.warn("The CLI not user friendly. It is here to provide a way to automate" | ||
" the server via a shell. The GUI is a better alternative for normal use.") | ||
if Args.args.run_server: | ||
self.run_server() | ||
elif Args.args.get_key: | ||
self.get_key() | ||
else: | ||
self.stop() | ||
|
||
def stop(self): | ||
LoggerCli.info("Stopping") | ||
self.getting_key = False | ||
if self.gamepad and self.gamepad.running: | ||
self.gamepad.close() | ||
if self.wpa_supplicant: | ||
self.wpa_supplicant.stop() | ||
|
||
def run_server(self): | ||
LoggerCli.info("Starting server") | ||
normal_interface = Args.args.normal_interface | ||
wii_u_interface = Args.args.wii_u_interface | ||
self.check_interfaces(normal_interface, wii_u_interface) | ||
self.prompt_unmanaged(wii_u_interface) | ||
self.wpa_supplicant = WpaSupplicant() | ||
self.wpa_supplicant.connect(constants.PATH_CONF_CONNECT, wii_u_interface) | ||
self.wpa_supplicant.add_status_change_listener(self.status_changed) | ||
InterfaceUtil.dhclient(wii_u_interface) | ||
InterfaceUtil.set_metric(normal_interface, 0) | ||
InterfaceUtil.set_metric(wii_u_interface, 1) | ||
self.gamepad = Gamepad() | ||
self.gamepad.start() | ||
while self.gamepad.running: | ||
time.sleep(1) | ||
|
||
def check_interfaces(self, normal_interface, wii_u_interface): | ||
if normal_interface == wii_u_interface: | ||
LoggerCli.throw(Exception("The Wii U and normal interfaces cannot be the same.")) | ||
try: | ||
InterfaceUtil.get_mac(normal_interface) | ||
InterfaceUtil.get_mac(wii_u_interface) | ||
except ValueError: | ||
LoggerCli.throw(Exception("Invalid interface selected.")) | ||
|
||
def status_changed(self, status): | ||
LoggerCli.info("Connection status changed to %s.", status) | ||
if status in (WpaSupplicant.TERMINATED, WpaSupplicant.NOT_FOUND, WpaSupplicant.DISCONNECTED, | ||
WpaSupplicant.FAILED_START): | ||
self.stop() | ||
|
||
def status_changed_key(self, status): | ||
LoggerCli.info("Connection status changed to %s.", status) | ||
if status == WpaSupplicant.DISCONNECTED: | ||
LoggerCli.info("Successfully received PSK from the Wii U.") | ||
self.stop() | ||
elif status in (WpaSupplicant.TERMINATED, WpaSupplicant.NOT_FOUND, WpaSupplicant.FAILED_START): | ||
self.stop() | ||
|
||
def get_key(self): | ||
LoggerCli.info("Getting key") | ||
wii_u_interface = Args.args.wii_u_interface | ||
try: | ||
InterfaceUtil.get_mac(wii_u_interface) | ||
except ValueError: | ||
LoggerCli.throw(Exception("Invalid interface selected.")) | ||
if len(Args.args.wps_pin) != 4: | ||
LoggerCli.throw(Exception("WPS PIN should be 4 digits")) | ||
self.prompt_unmanaged(wii_u_interface) | ||
self.wpa_supplicant = WpaSupplicant() | ||
self.wpa_supplicant.get_psk(constants.PATH_CONF_CONNECT_TMP, wii_u_interface, Args.args.wps_pin) | ||
self.wpa_supplicant.add_status_change_listener(self.status_changed_key) | ||
self.getting_key = True | ||
while self.getting_key: | ||
time.sleep(1) | ||
|
||
def prompt_unmanaged(self, interface): | ||
if not InterfaceUtil.is_managed_by_network_manager(interface): | ||
return | ||
LoggerCli.info("The interface \"%s\" is managed by Network Manager. It must be set to " | ||
"unmanaged to function with DRC Sim. Network manager will not be able to " | ||
"use this interface after it is set to unmanaged.", interface) | ||
response = raw_input("Set %s as unmanaged? (y/n)" % interface) | ||
LoggerCli.debug(response) | ||
if response in ("y", "yes", "Y", "Yes", "YES"): | ||
InterfaceUtil.set_unmanaged_by_network_manager(interface) | ||
else: | ||
LoggerCli.throw(Exception("Interface is managed by Network Manager.")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters