Ejemplo n.º 1
0
        public StartMatchmakingResponse JoinMatchmakingQueue(Game game, GameMode mode, int msTimeout = 10000)
        {
            var req = new StartMatchmakingRequest(game.Id, mode.Name, game.Name, game.Version, mode.PlayerCount, typeof(MatchmakingCog).Assembly.GetName().Version, _client.Config.MatchamkingBotUser.JidUser);
            var mut = new AutoResetEvent(false);
            using (var mess = new Messanger())
            {
                mess.OnResetXmpp(_xmpp);
                StartMatchmakingResponse resp = null;
                mess.Map<StartMatchmakingResponse>(x =>
                {
                    if (x.RequestId == req.RequestId)
                        resp = x;
                    mut.Set();
                });

                mess.Send(req);
                if (!mut.WaitOne(msTimeout))
                {
                    return null;
                }
                return resp;
            }
        }
Ejemplo n.º 2
0
        private void StartMatchmakingMessage(StartMatchmakingRequest mess)
        {
            lock (_queueLock)
            {
                try
                {
                    Log.Debug("StartMatchmakingMessage");
                    var queue = Queue.FirstOrDefault(x => x.GameId == mess.GameId
                        && x.GameMode.Equals(mess.GameMode, StringComparison.InvariantCultureIgnoreCase)
                        && x.GameVersion.Major == mess.GameVersion.Major
                        && x.OctgnVersion.CompareTo(mess.OctgnVersion) == 0);
                    if (queue == null)
                    {
                        Log.Debug("Creating queue");
                        // Create queue if doesn't exist
                        queue = new MatchmakingQueue(this, mess.GameId, mess.GameName, mess.GameMode, mess.MaxPlayers, mess.GameVersion, mess.OctgnVersion);
                        Queue.Add(queue);
                        queue.Start();
                    }

                    // if User is queued, drop him/her from previous queue
                    // Don't drop them if they're in this queue
                    foreach (var q in Queue.Where(x => x != queue))
                    {
                        q.Dequeue(mess.From);
                    }

                    // Add user to queue
                    queue.Enqueue(mess.From);

                    // Send user a message
                    Messanger.Send(new StartMatchmakingResponse(mess.RequestId, mess.From, queue.QueueId));

                    // Done with it.

                }
                catch (Exception e)
                {
                    Log.Error("StartMatchmakingMessage", e);
                }
            }
        }