import json
import socket
import threading
from Classes.System.GameManager import GameManager

from Classes.System.Network.NetworkManger import NetworkManager
from Classes.System.PlayerManager import Player
from Classes.System.World import World
from Classes.System.Logger import Logger

class Server:

    __address:str
    __tcpPort:str
    __udpPort:str
    __world:World
    __gameManager:GameManager

    networkManager:NetworkManager

    def __init__(self, address:str, tcpPort:str, udpPort:str, logger:Logger):
        self.__address = address
        self.__tcpPort = tcpPort
        self.__udpPort = udpPort
        self.__world = World()
        self.logger = logger

        self.logger.info("starting up game manager")
        self.__gameManager = GameManager(logger)

        self.logger.info("preparing to start server")
        self.startServer(self.__gameManager)

    # handles starting the server and assigning socket values to the local reference
    def startServer(self, gameManager:GameManager):
        self.logger.info("starting up network manager")
        self.__networkManager = NetworkManager(self.__address, self.__tcpPort, self.__udpPort, gameManager)

    def getNetworkManager(self) -> NetworkManager:
        return self.__networkManager