Skip to content

Commit

Permalink
Project Name: BattleBot
Browse files Browse the repository at this point in the history
Commit Type: Enhacement

Added suport for commandline startup configs

Signed-off-by: ButrosGroot <[email protected]>
  • Loading branch information
butros10games committed Feb 17, 2024
1 parent 5f06d06 commit 7e6c6cd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
18 changes: 14 additions & 4 deletions src/client/client.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
3 changes: 0 additions & 3 deletions src/server/communications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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":
Expand All @@ -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)

Expand Down
10 changes: 10 additions & 0 deletions src/server/server.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
import asyncio
import sys

from src.server.motor_controller import MotorController
from src.server.communications import MotorWebSocketServer, MotorWebRTCClient


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):
Expand Down

0 comments on commit 7e6c6cd

Please sign in to comment.