public RedisClient(IRedisSocket socket, EndPoint endpoint, int asyncConcurrency, int asyncBufferSize)
        {
            _connector    = new RedisConnector(endpoint, socket, asyncConcurrency, asyncBufferSize);
            _transaction  = new RedisTransaction(_connector);
            _subscription = new SubscriptionListener(_connector);
            _monitor      = new MonitorListener(_connector);

            _subscription.MessageReceived  += OnSubscriptionReceived;
            _subscription.Changed          += OnSubscriptionChanged;
            _monitor.MonitorReceived       += OnMonitorReceived;
            _connector.Connected           += OnConnectionConnected;
            _transaction.TransactionQueued += OnTransactionQueued;
        }
Exemple #2
0
        internal RedisClient(IRedisSocket socket, EndPoint endpoint, int asyncConcurrency, int asyncBufferSize)
        {
            // use invariant culture - we have to set it explicitly for every thread we create to
            // prevent any floating-point problems (mostly because of number formats in non en-US cultures).
            //CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture; 这行会影响 string.Compare 结果

            _connector    = new RedisConnector(endpoint, socket, asyncConcurrency, asyncBufferSize);
            _transaction  = new RedisTransaction(_connector);
            _subscription = new SubscriptionListener(_connector);
            _monitor      = new MonitorListener(_connector);

            _subscription.MessageReceived  += OnSubscriptionReceived;
            _subscription.Changed          += OnSubscriptionChanged;
            _monitor.MonitorReceived       += OnMonitorReceived;
            _connector.Connected           += OnConnectionConnected;
            _transaction.TransactionQueued += OnTransactionQueued;
        }
Exemple #3
0
        internal RedisClient(IRedisConnector connector)
        {
            // use invariant culture - we have to set it explicitly for every thread we create to
            // prevent any floating-point problems (mostly because of number formats in non en-US cultures).
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            _connector    = connector;
            _transaction  = new RedisTransaction(_connector);
            _subscription = new SubscriptionListener(_connector);
            _monitor      = new MonitorListener(_connector);

            _subscription.MessageReceived  += OnSubscriptionReceived;
            _subscription.Changed          += OnSubscriptionChanged;
            _monitor.MonitorReceived       += OnMonitorReceived;
            _connector.Connected           += OnConnectionConnected;
            _transaction.TransactionQueued += OnTransactionQueued;
        }
Exemple #4
0
        public void Run()
        {
            if (matchmakerListenerCts != null)
            {
                throw new Exception("Сервер уже запущен");
            }

            //Старт уведомления матчмейкера о смертях игроков и окончании матчей
            MatchmakerNotifier notifier = new MatchmakerNotifier();

            matchmakerNotifierCts = notifier.StartThread();

            //Создание структур данных для матчей
            matchStorage = new MatchStorage();


            MessageIdFactory messageIdFactory = new MessageIdFactory();
            MessageFactory   messageFactory   = new MessageFactory(messageIdFactory);

            InputEntitiesCreator inputEntitiesCreator = new InputEntitiesCreator(matchStorage);
            ExitEntitiesCreator  exitEntitiesCreator  = new ExitEntitiesCreator(matchStorage);

            ByteArrayRudpStorage byteArrayRudpStorage = new ByteArrayRudpStorage();

            shittyUdpMediator = new ShittyUdpMediator();

            MessagesPackIdFactory   messagesPackIdFactory   = new MessagesPackIdFactory();
            IpAddressesStorage      ipAddressesStorage      = new IpAddressesStorage();
            SimpleMessagesPacker    simpleMessagesPacker    = new SimpleMessagesPacker(PackingHelper.Mtu, shittyUdpMediator, messagesPackIdFactory);
            OutgoingMessagesStorage outgoingMessagesStorage = new OutgoingMessagesStorage(simpleMessagesPacker, ipAddressesStorage);
            UdpSendUtils            udpSendUtils            = new UdpSendUtils(byteArrayRudpStorage, outgoingMessagesStorage, messageFactory);
            MessageProcessor        messageProcessor        = new MessageProcessor(inputEntitiesCreator, exitEntitiesCreator,
                                                                                   byteArrayRudpStorage,
                                                                                   // udpSendUtils,
                                                                                   ipAddressesStorage);

            shittyUdpMediator.SetProcessor(messageProcessor);

            matchRemover = new MatchRemover(matchStorage, byteArrayRudpStorage, udpSendUtils, notifier, ipAddressesStorage, messageIdFactory, messagesPackIdFactory);
            MatchFactory          matchFactory          = new MatchFactory(matchRemover, udpSendUtils, notifier, ipAddressesStorage, messageIdFactory, messagesPackIdFactory);
            MatchCreator          matchCreator          = new MatchCreator(matchFactory);
            MatchLifeCycleManager matchLifeCycleManager =
                new MatchLifeCycleManager(matchStorage, matchCreator, matchRemover);

            //Старт прослушки матчмейкера
            MatchModelMessageHandler matchModelMessageHandler = new MatchModelMessageHandler(matchCreator, matchStorage);
            MatchmakerListener       matchmakerListener       = new MatchmakerListener(matchModelMessageHandler, HttpPort);
            MonitorListener          monitorListener          = new MonitorListener(HttpPort);

            monitorListenerCts    = monitorListener.StartThread();
            matchmakerListenerCts = matchmakerListener.StartThread();


            //Старт прослушки игроков
            shittyUdpMediator
            .SetupConnection(UdpPort)
            .StartReceiveThread();

            RudpMessagesSender rudpMessagesSender = new RudpMessagesSender(byteArrayRudpStorage, matchStorage, udpSendUtils, ipAddressesStorage);
            GameEngineTicker   gameEngineTicker   = new GameEngineTicker(matchStorage, matchLifeCycleManager,
                                                                         inputEntitiesCreator, exitEntitiesCreator, rudpMessagesSender, outgoingMessagesStorage);

            //Старт тиков
            Chronometer chronometer = ChronometerFactory.Create(gameEngineTicker.Tick);

            chronometer.StartEndlessLoop();
        }