Exemplo n.º 1
0
        internal void TryCreateArenaForPlayersAsync(IMatchMaker match_maker, List <Player> buffer)
        {
            if (is_disposing())
            {
                return;
            }

            Task.Run(async() =>
            {
                var attempt = new CreateArenaAttempt();
                foreach (var player in buffer)
                {
                    attempt.PlayerInfo.Add(new ArenaServer.PlayerInfo
                    {
                        AuthToken = GuidOps.ToByteString(Guid.NewGuid()),
                        BasicInfo = player.BasicPlayerInfo()
                    });
                }

                foreach (var arena in hosts)
                {
                    if (await arena.TryCreateArenaForPlayers(buffer, attempt))
                    {
                        return;
                    }
                }

                match_maker.AddPlayers(buffer);
            });
        }
Exemplo n.º 2
0
        public override async Task <QueueResult> Queue(QueueAttempt request, ServerCallContext context)
        {
            var q_result = new QueueResult
            {
                Queued = false
            };

            Player player;

            try
            {
                player = auth.GetPlayer(context);
                if (player == null)
                {
                    return(q_result);
                }
            } catch (Exception e)
            {
                Log.Exception(e);
                return(q_result);
            }

            try
            {
                return(await in_memory_worker.Schedule(() =>
                {
                    if (player.arena_state != ArenaState.NotQueued)
                    {
                        q_result.Queued = player.arena_state == ArenaState.Queued ? true : false;
                        return q_result;
                    }

                    var group = player.group;
                    if (group != null)
                    {
                        if (group.leader != player)
                        {
                            q_result.Queued = false;
                            return q_result;
                        }

                        match_maker.AddPlayers(group.players);
                        var ev = new Event
                        {
                            GroupQueueStateChanged = new Event_GroupQueueStateChanged
                            {
                                Queued = true
                                         //Matchmode is currently unused
                            }
                        };
                        foreach (var group_player in group.players)
                        {
                            if (group_player == player)
                            {
                                continue;
                            }
                            group_player.event_stream.Enqueue(ev);
                        }
                    }
                    else
                    {
                        match_maker.AddPlayer(player);
                    }

                    q_result.Queued = true;
                    return q_result;
                }));
            } catch (Exception e)
            {
                Log.Exception(e);
                return(q_result);
            }
        }