Exemplo n.º 1
0
        private void TryCreateMatch()
        {
            if (Settings.HasFlag(ServerOperationMode.DisableCreateInstance))
            {
                return;
            }

            if (WaitingQueue.Count >= Settings.PlayersPerGameInstance && PortManager.HasFreePorts())
            {
                Port port = PortManager.AquirePort();
                InstanceManager.StartInstance(port, CreateArgs(port.PortNum, 20000, 3600000));

                WaitingQueueItem[] players = new WaitingQueueItem[Settings.PlayersPerGameInstance];

                for (int i = 0; i < Settings.PlayersPerGameInstance; i++)
                {
                    players[i] = WaitingQueue[i];
                    RemoveList.Add(WaitingQueue[i]);
                }

                Thread t = new Thread(() =>
                {
                    Thread.Sleep(Settings.PlayersMatchFoundNotifyDelay);
                    for (int i = 0; i < players.Length; i++)
                    {
                        Logger.DefaultLogger("Notifying Player: " + players[i].Identifier);
                        players[i].SendMatchFound(port.PortNum);
                    }

                    Thread.Sleep(1000);

                    for (int i = 0; i < players.Length; i++)
                    {
                        RemoveQueueItem(players[i]);
                    }
                });

                t.Start();
            }
        }