diff --git a/src/client/client.py b/src/client/client.py index 5c766a2..30a05d2 100644 --- a/src/client/client.py +++ b/src/client/client.py @@ -1,29 +1,39 @@ import asyncio +import sys from src.client.logic import ApplicationController class Client: def get_conmunication_type(self): + if len(sys.argv) > 2: + return sys.argv[2] + return input("Enter the type of communication you want to use (websocket/webrtc): ") - def get_battlebot_name(self): + if len(sys.argv) > 3: + return sys.argv[3] + return input("Enter the name of the battlebot: ") - + + def get_connection_string(self): + if len(sys.argv) > 3: + return sys.argv[3].split(":") + + return input("Enter the ip and port of the server (ip:port): ").split(":") def get_connection_string(self, comunication_type): if comunication_type == "webrtc": bot_name = self.get_battlebot_name() return f"wss://butrosgroot.com/ws/battle_bot/signal/{bot_name}/" elif comunication_type == "websocket": - host, port = input("Enter the ip and port of the server (ip:port): ").split(":") + host, port = self.get_connection_string() return f"ws://{host}:{port}" else: return None - def start(self): comunication_type = self.get_conmunication_type() uri = self.get_connection_string(comunication_type) diff --git a/src/server/communications.py b/src/server/communications.py index f2af1a2..df63ecf 100644 --- a/src/server/communications.py +++ b/src/server/communications.py @@ -11,7 +11,6 @@ def __init__(self, motor_controller, host, port): self.host = host self.port = port - async def handle_client(self, websocket, path): async for message in websocket: try: @@ -27,7 +26,6 @@ async def handle_client(self, websocket, path): # Stop the motor controller when the connection is lost await self.motor_controller.stop() - def print_server_info(self): # Determine the actual IP when the server is bound to '0.0.0.0' if self.host == "0.0.0.0": @@ -42,7 +40,6 @@ def print_server_info(self): else: print(f"Server started at ws://{self.host}:{self.port}") - def run(self): start_server = websockets.serve(self.handle_client, self.host, self.port) diff --git a/src/server/server.py b/src/server/server.py index b9f0388..a1ad923 100644 --- a/src/server/server.py +++ b/src/server/server.py @@ -1,4 +1,5 @@ import asyncio +import sys from src.server.motor_controller import MotorController from src.server.communications import MotorWebSocketServer, MotorWebRTCClient @@ -6,12 +7,21 @@ class Server: def get_conmunication_type(self): + if len(sys.argv) > 2: + return sys.argv[2] + return input("Enter the type of communication you want to use (websocket/webrtc): ") def get_battlebot_name(self): + if len(sys.argv) > 3: + return sys.argv[3] + return input("Enter the name of the battlebot: ") def get_server_ip_port(self): + if len(sys.argv) > 3: + return sys.argv[3] + return input("Enter the ip and port of the server (ip:port): ").split(":") def start(self):