예제 #1
0
 /// <summary>
 /// Create object of LANMatch/OnlineMatch. This function is called by UI Event.
 /// </summary>
 public void SetServerTypeLocal(bool isLocalServer)
 {
     if (isLocalServer)
     {
         match = LANMatch.GetMatchCreator(networkDiscovery);
     }
     else
     {
         match = OnlineMatch.GetMatchCreator();
     }
 }
예제 #2
0
    public void Update()
    {
        // Vérifier le nombre de joueurs en queue. S'il est égal ou supérieur à "PlayersPerMatch", créer un match et l'ajouter à un
        // Updater.

        int[] matchMakingQueue = PlayersManager.GetMatchmakingQueue();

        if (matchMakingQueue.Length >= PlayersPerMatch)
        {
            List <int> players = new List <int>();
            for (int i = 0; i < PlayersPerMatch; i++)
            {
                players.Add(matchMakingQueue[i]);
                PlayersManager.RemovePlayerFromMatchmakingQueue(matchMakingQueue[i]);
            }
            Match newMatch          = MatchCreator.CreateMatch(players.ToArray());
            int   matchesPerUpdater = 0;
            int   currentUpdaterID  = 0;
            while (matchesPerUpdater >= 0) // Cherche le meilleur "Updater" de façon à ce que la charge des matchs soit bien
            {                              // Répartie entre les Threads.
                if (currentUpdaterID < Updaters.Length)
                {
                    if (Updaters[currentUpdaterID].GetNumberOfMatches() <= matchesPerUpdater)
                    {
                        Updaters[currentUpdaterID].AddMatch(newMatch);
                        BloodAndBileEngine.Debugger.Log("Création d'un match !");
                        matchesPerUpdater = -1;
                    }
                    else
                    {
                        currentUpdaterID++;
                    }
                }
                else
                {
                    currentUpdaterID = 0;
                    matchesPerUpdater++;
                }
            }
        }

        foreach (MatchUpdater updater in Updaters)
        {
            updater.UpdateDisconnects();
        }
    }
        public async Task <BaseResponse> Handle(CreateMatchCommand request, CancellationToken cancellationToken)
        {
            request.Host = await _ctx.UserInformation
                           .FirstAsync(x => x.Id == request.UserId, cancellationToken);

            try
            {
                var match = MatchCreator.CreateMatch(request);
                _ctx.Matches.Add(match);
            }
            catch (Exception e)
            {
                return(new BaseResponse(e.Message, false));
            }

            await _ctx.SaveChangesAsync(cancellationToken);

            return(new BaseResponse("Match Created", true));
        }
예제 #4
0
        public async Task <BaseResponse> Handle(CreateMatchCommand request, CancellationToken cancellationToken)
        {
            request.Host = await _ctx.UserInformation
                           .FirstAsync(x => x.Id == request.UserId, cancellationToken);

            try
            {
                var match = MatchCreator.CreateMatch(request);
                _ctx.Matches.Add(match);
            }
            catch (Exception e)
            {
                return(BaseResponse.Fail(e.Message));
            }

            await _ctx.SaveChangesAsync(cancellationToken);

            return(BaseResponse.Ok(await _translator.GetTranslation("Match", "Created")));
        }
 public MatchModelMessageHandler(MatchCreator matchCreator, MatchStorage matchStorage)
 {
     this.matchCreator   = matchCreator;
     matchModelValidator = new MatchModelValidator(matchStorage);
 }
예제 #6
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();
        }
예제 #7
0
        public async Task <IActionResult> GetMatch([FromForm] IEnumerable <Guid> userIds, [FromForm] string deviation, [FromServices] MatchCreator creator)
        {
            var dev = double.Parse(deviation, CultureInfo.InvariantCulture);

            return(new OkObjectResult(await creator.MakeMatchAsync(userIds, 2, dev)));
        }
예제 #8
0
 public static Match CreateMatch(this MatchSettings settings) =>
 MatchCreator.CreateMatch(settings);