예제 #1
0
        public TCPServer(TCPServerSettings settings)
        {
            _settings = settings;

            _clients                = new ClientToken[_settings.MaxConnections];
            _bufferManager          = new BufferManager(_settings.BufferSize, _settings.MaxConnections * 2);
            _poolOfDataEventArgs    = new Pool <ClientToken>(_settings.MaxConnections, false);
            _poolOfAcceptEventArgs  = new Pool <SocketAsyncEventArgs>(_settings.MaxAcceptOps, false);
            _maxConnectionsEnforcer = new Semaphore(_settings.MaxConnections, _settings.MaxConnections);
        }
예제 #2
0
        public TCPServer(TCPServerSettings settings)
        {
            _settings = settings;

            _clients = new ClientToken[_settings.MaxConnections];
            _bufferManager = new BufferManager(_settings.BufferSize, _settings.MaxConnections*2);
            _poolOfDataEventArgs = new Pool<ClientToken>(_settings.MaxConnections, false);
            _poolOfAcceptEventArgs = new Pool<SocketAsyncEventArgs>(_settings.MaxAcceptOps, false);
            _maxConnectionsEnforcer = new Semaphore(_settings.MaxConnections, _settings.MaxConnections);
        }
예제 #3
0
        public GameHost()
        {
            World = new GameWorld();
            World.LoadMap();

            TCPServerSettings setting = new TCPServerSettings(
                NET_MAX_CONNECTIONS, NET_SOCKET_BACKLOG, NET_MAX_ACCEPT_OPS, 
                NET_BUFFER_SIZE, NET_PORT);

            _netServer = new TCPServer(setting);
            _netServer.ClientConnected += TCPClientConnected;
            _netServer.ClientDisonnected += TCPClientDisonnected;
            _netServer.ClientDataReceived += TCPClientDataReceived;
            _netServer.ClientDataReceiveError += TCPClientDataReceiveError;
            _netServer.ClientDataSent += TCPClientDataSent;
            _netServer.ClientDataSendError += NetServerOnClientDataSendError;
            _netServer.Start();

            _loggedPlayers = new Dictionary<int, int>();
            _tcpClients = new Dictionary<int, int>();
            _playerClients = new Dictionary<int, int>();

            _responses = new List<Pair<int, BaseResponse>>();

            _actions = new Dictionary<PacketType, OnAcceptPacket<BasePacket>>
            {
                {PacketType.UserLogin, Login},
                {PacketType.UserEnter, Enter},
                {PacketType.UserLogout, Logout},

                {PacketType.PlayerRotate, PlayerRotate},
                {PacketType.PlayerMove, PlayerMove},

                {PacketType.MapData, MapData}
            };

            _validators = new ValidatorList
            {
                (_vCheckPosition = new VCheckPosition(this))
            };

            _responsesPool = new Pool<Pair<int, BaseResponse>>(1000, true);

            _threadSendResponses = new Thread(SendResponsesProc);
            _threadSendResponses.Priority = ThreadPriority.AboveNormal;
            _threadSendResponses.IsBackground = true;
            _threadSendResponses.Start();
        }