示例#1
0
        private void OnMatchmakingUpdate(MatchmakingMessage obj)
        {
            if (obj == null)
            {
                Log.Warn("OnMatchmakingUpdate obj is null?");
                return;
            }
            Log.InfoFormat("OnMatchmakingUpdate {0}", obj.GetType().Name);
            _lastMatchmakingMessage = DateTime.Now;
            if (obj is MatchmakingInLineUpdateMessage)
            {
                var o = obj as MatchmakingInLineUpdateMessage;
                _awt = o.AverageWaitTime;
            }
            else if (obj is MatchmakingReadyRequest)
            {
                var o = obj as MatchmakingReadyRequest;

                _currentRequest = o;
                ShowReadyDialog = true;
                ReadyCountdown  = 100;
                //Program.LobbyClient.Matchmaking.Ready(o);
            }
            else if (obj is MatchmakingReadyFail)
            {
                var o = obj as MatchmakingReadyFail;
                _onTransition(MatchmakingTabViewEnum.InQueue);
                HideReadyDialog();
            }
        }
示例#2
0
 private void OnMatchmakingReadyRequest(MatchmakingReadyRequest obj)
 {
     if (_onMatchmakingUpdate != null)
     {
         _onMatchmakingUpdate(obj);
     }
 }
示例#3
0
        public void Ready(MatchmakingReadyRequest req)
        {
            var resp = new MatchmakingReadyResponse(_client.Config.MatchamkingBotUser.JidUser, req.QueueId);

            _messanger.Send(resp);
        }
示例#4
0
        private void Run()
        {
            Log.InfoFormat("[{0}] Queue Running", this);
            var sendStatusUpdatesBlock = new TimeBlock(TimeSpan.FromSeconds(30));
            var readyTimeout           = new TimeBlock(TimeSpan.FromSeconds(60));
            var disposeThis            = new TimeBlock(TimeSpan.FromHours(1));

            disposeThis.SetRun();
            while (_runCancelToken.IsCancellationRequested == false && Disposed == false)
            {
                lock (_users)
                {
                    try
                    {
                        if (_users.Count > 0)
                        {
                            disposeThis.SetRun();
                        }
                        if (disposeThis.IsTime)
                        {
                            Log.InfoFormat("[{0}] Dispose timer timed out", this);
                            Disposed = true;
                            this.Dispose();
                            break;
                        }
                        switch (State)
                        {
                        case MatchmakingQueueState.WaitingForUsers:
                            if (_users.Count >= MaxPlayers)
                            {
                                Log.InfoFormat("[{0}] Got enough players for ready queue.", this);
                                State = MatchmakingQueueState.WaitingForReadyUsers;
                                var readyMessage = new MatchmakingReadyRequest(null, this.QueueId);
                                foreach (var p in _users)
                                {
                                    p.IsReady        = false;
                                    p.IsInReadyQueue = false;
                                }
                                for (var i = 0; i < MaxPlayers; i++)
                                {
                                    readyMessage.To          = _users[i];
                                    _users[i].IsInReadyQueue = true;
                                    Bot.Messanger.Send(readyMessage);
                                }
                                readyTimeout.SetRun();
                            }
                            break;

                        case MatchmakingQueueState.WaitingForReadyUsers:
                            if (readyTimeout.IsTime)
                            {
                                Log.InfoFormat("[{0}] Timed out waiting for users to ready up.", this);
                                // This happens if 60 seconds has passed since ready messages were sent out.
                                // This shouldn't happen unless someone didn't respond back with a ready response.
                                foreach (var p in _users.Where(x => x.IsInReadyQueue).ToArray())
                                {
                                    // If player didn't signal ready throw them in the back of the queue.
                                    if (p.IsReady == false)
                                    {
                                        p.FailedReadyCount++;
                                        _users.Remove(p);
                                        // If they've been knocked to the back of the queue 4 or more times, kick them.
                                        if (p.FailedReadyCount < 4)
                                        {
                                            Log.InfoFormat("[{0}] {1} User failed ready 4 times, getting kicked.", this, p);
                                            _users.Add(p);
                                        }
                                    }
                                    p.IsInReadyQueue = false;
                                    p.IsReady        = false;
                                }
                            }
                            break;

                        case MatchmakingQueueState.WaitingForHostedGame:
                            if (_hostGameTimeout.IsTime)
                            {
                                Log.WarnFormat("[{0}] Timed out waiting for hosted game to be created...Oh Noes!", this);
                                State = MatchmakingQueueState.WaitingForUsers;
                                foreach (var u in _users)
                                {
                                    u.IsInReadyQueue = false;
                                    u.IsReady        = false;
                                }
                            }
                            break;
                        }

                        // Send status messages
                        if (sendStatusUpdatesBlock.IsTime)
                        {
                            var mess = new MatchmakingInLineUpdateMessage(AverageTime.Time, null, QueueId);
                            foreach (var u in _users.Where(x => x.IsInReadyQueue == false))
                            {
                                mess.To = u.JidUser;
                                mess.GenerateId();
                                Bot.Messanger.Send(mess);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Log.Error("[" + this + "] Run", e);
                    }
                }
                if (_runCancelToken.IsCancellationRequested == false && !Disposed)
                {
                    Thread.Sleep(TimeSpan.FromSeconds(1));
                }
            }
            Log.InfoFormat("[{0}] Queue done running", this);
        }