Пример #1
0
        public Server()
        {
            ICore core = new Core();

            _connectionString = core.FileManager.LoadContent("DataBaseConnection.set");

            if (string.IsNullOrEmpty(_connectionString))
            {
                throw new Exception("Connection string is empty. Please provide valid connection string and restart aplication.");
            }

            _authentication   = new Authentication(_connectionString);
            _messageProcessor = new MessageProcessor(core);

            _messageProcessor.Notification              += MessageProcessor_OnNotification;
            MessageRouter.gMessageRouter.AddedSession   += MsgRouter_OnSessionAdded;
            MessageRouter.gMessageRouter.RemovedSession += MsgRouter_OnSessionRemoved;

            _startupPath = Directory.GetCurrentDirectory();
        }
Пример #2
0
        /// <summary>
        /// Runs server as Backup server.
        /// </summary>
        public virtual void RunAsBackup()
        {
            _messageProcessor = new BackupMessageProcessor
                                    (_clusterListener, _synchronizationQueue, _problemDataSets, _activeComponents);

            if (_backupClient == null)
            {
                _backupClient = ClusterClientFactory.Factory.Create(Properties.Settings.Default.MasterAddress,
                                                                    Properties.Settings.Default.MasterPort);
            }
            if (_clusterListener == null)
            {
                _clusterListener = ClusterListenerFactory.Factory.Create(IPAddress.Any, Properties.Settings.Default.Port);
            }
            //AZBEST314
            Log.Debug("Starting backup listening mechanism.");
            _clusterListener.Start();
            _currentlyWorkingThreads.Clear();
            _isWorking = true;
            DoBackupWork();
        }
Пример #3
0
        /// <summary>
        /// Runs server as Primary server.
        /// </summary>
        public virtual void RunAsPrimary()
        {
            _messageProcessor = new PrimaryMessageProcessor
                                    (_clusterListener, _synchronizationQueue, _problemDataSets, _activeComponents);

            _backupClient = null;
            if (_clusterListener == null)
            {
                _clusterListener = ClusterListenerFactory.Factory.Create(IPAddress.Any, Properties.Settings.Default.Port);
            }
            //_backups.Clear();

            Log.Debug("Starting listening mechanism.");
            _clusterListener.Start();
            _isWorking = true;
            _currentlyWorkingThreads.Clear();
            Log.Debug("Listening mechanism has been started.");
            BackupServerStatusInterval = null;
            BackupServerId             = null;
            DoPrimaryWork();
        }
Пример #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();
        }
Пример #5
0
        static void Main(string[] args)
        {
            Debug.DefaultDebugger = new ServerConsoleDebugger();
            MessageProcessor.DefaultSerializer = new MsgPackBitSerializer();

            /*
             * LoginReqMsg msg = new LoginReqMsg {
             *  Account = "account",
             *  Password = "******",
             *  Extra = "去去去",
             * };
             *
             * //  var bytes = Serialize(msg);
             * var bytes = MessagePackSerializer.Serialize(msg);
             * var obj = MessagePackSerializer.Deserialize<LoginReqMsg>(bytes);
             * Console.WriteLine(MessagePackSerializer.ConvertToJson(bytes));
             */

            MessageProcessor messageProcessor = new MessageProcessor();

            messageProcessor.Run(TaskScheduler.Default);
            MessageProcessor.RegisterHandler <LoginReqMsg>((msg, fromLink) => {
                var rsp = new LoginRspMsg {
                    Player = new Model.Player {
                        Status = Model.Status.Online,
                        Name   = "二逼青年"
                    },
                    SeqNumber = msg.SeqNumber,
                };
                var bytes = MessageProcessor.PackageMessage(rsp);
                fromLink.SendToRemoteAsync(bytes.buffer, 0, bytes.len);
                //  Debug.LogFormat("{0}-{1}-{2}", msg.Account, msg.Password, msg.Extra);
            });

            var udpServer = new UdpServer(messageProcessor);

            udpServer.Start(IPAddress.Any, 8063);

            do
            {
                var input = Console.ReadLine();
            } while (true);

            /*
             * MessageProcessor.RegisterHandler<LoginReqMsg>((msg, remote) => {
             *  Debug.LogFormat("LoginReqMsg - {0}|{1}|{2}", msg.Account, msg.Password, msg.Extra);
             *  var loginReq = new LoginRspMsg {
             *      Player = new Model.Player {
             *          Name = "二逼青年",
             *          Status = Model.Status.Online,
             *          Mails = new System.Collections.Generic.Dictionary<int, Model.Mail> {
             *              {
             *                  234,
             *                  new Model.Mail {
             *                      Id = 234,
             *                      Title = "测试",
             *                      Content ="test"
             *                  }
             *              }
             *          },
             *      }
             *  };
             *  var loginReqBytes = MessageProcessor.DefaultSerializer.Serialize(
             *       MessageProcessor.PackageMessage(loginReq));
             *  udpServer.Send(loginReqBytes, remote);
             * });
             */
        }