Example #1
0
        public static TcpConnectionHandler GetInstance(ITcpLogger logger, CommandHandler commandHandler)
        {
            if (TcpConnectionHandler._instance == null)
            {
                TcpConnectionHandler._instance = new TcpConnectionHandler(logger, commandHandler);
            }

            return(TcpConnectionHandler._instance);
        }
Example #2
0
        /// <summary>
        /// Gets singleton instance of game manager
        /// </summary>
        public static GameManager GetInstance(ILogger logger, ITcpLogger tcpLogger, UiHandler uiHandler)
        {
            if (GameManager._instance == null)
            {
                GameManager._instance = new GameManager();
            }

            GameManager._instance._logger    = logger;
            GameManager._instance._tcpLogger = tcpLogger;
            GameManager._instance._uiHandler = uiHandler;
            return(GameManager._instance);
        }
        public static TcpConnectionHandler GetInstance(ITcpLogger logger, CommandHandler commandHandler, PlayerHandler playerHandler)
        {
            if (TcpConnectionHandler._instance == null)
            {
                TcpConnectionHandler._instance = new TcpConnectionHandler();
            }

            TcpConnectionHandler._instance._logger         = logger;
            TcpConnectionHandler._instance._commandHandler = commandHandler;
            TcpConnectionHandler._instance._playerHandler  = playerHandler;
            return(TcpConnectionHandler._instance);
        }
        public ClientHandler(TcpClient client, ITcpLogger logger, int cmdContainerSize)
        {
            this.IsWorking = true;
            this.client    = client;
            this.logger    = logger;

            this.ClientId = clientIdCounter;
            clientIdCounter++;

            this.ClientIp = ((IPEndPoint)client.Client.RemoteEndPoint).Address.ToString();
            this.logger.UpdateLog($"Creating new ClientHandler object for connection: [{this.ClientIp}], ID [{this.ClientId}]...");

            this.toSendCmdContainer   = new CommandContainer(cmdContainerSize);
            this.receivedCmdContainer = new CommandContainer(cmdContainerSize);

            HandleSendingAsync();
            HandleReceivingAsync();
        }
        /// <summary>
        /// Starts TCP client
        /// </summary>
        public static TcpServerClient RunServerClient(ConnectionData connData, ITcpLogger logger)
        {
            if (connData == null)
            {
                throw new Exception("connection data is NULL!");
            }

            if (logger == null)
            {
                throw new Exception("logger is NULL!");
            }

            if (serverClientInstance != null)
            {
                throw new Exception("a working TCP client detected!");
            }

            serverClientInstance = new TcpServerClient(connData, logger);
            serverClientInstance.StartServerClient();
            return(serverClientInstance);
        }
Example #6
0
        /// <summary>
        /// Starts TCP server
        /// </summary>
        public static TcpServer RunServer(ConnectionData connData, ITcpLogger logger)
        {
            if (connData == null)
            {
                throw new Exception("connection data is NULL!");
            }

            if (logger == null)
            {
                throw new Exception("logger is NULL!");
            }

            if (serverInstance != null)
            {
                throw new Exception("A working TCP server instance detected. It should by stopped by StopServer() method first!");
            }

            serverInstance = new TcpServer(connData, logger);
            serverInstance.StartServer();
            return(serverInstance);
        }
 private TcpServerClient(ConnectionData connData, ITcpLogger logger)
 {
     this.connData = connData;
     this.logger   = logger;
 }
Example #8
0
 private TcpConnectionHandler(ITcpLogger logger, CommandHandler commandHandler)
 {
     _logger         = logger;
     _commandHandler = commandHandler;
 }