Esempio n. 1
0
        internal void ArenaShutdown(SingleArena arena)
        {
            if (is_disposing())
            {
                return;
            }

            bool did_remove;

            lock (arenas)
                did_remove = arenas.Remove(arena);
            if (!did_remove)
            {
                Log.Warning("ArenaShutdown was with an arena which is not part of this host.");
                return;
            }

            ++suggested_arena_instances_left;
        }
Esempio n. 2
0
        internal async Task <bool> TryCreateArenaForPlayers(List <Player> buffer, CreateArenaAttempt attempt)
        {
            if (is_disposing())
            {
                return(false);
            }

            if (channel.State != ChannelState.Ready)
            {
                return(false);
            }

            if (buffer.Count != attempt.PlayerInfo.Count)
            {
                Log.Fatal("Parameter buffer is expected to have same size and attempt.PlayerInfo");
                return(false);
            }

            if (suggested_arena_instances_left == 0)
            {
                return(false);
            }

            CreateArenaResult result;

            try
            {
                result = await client.CreateArenaAsync(attempt);

                if (!result.Success)
                {
                    return(false);
                }
            } catch (RpcException)
            {
                Log.Msg(string.Format("Could not speak to arena host with connection string: {0}", connection_str));
                try_connect();
                return(false);
            } catch (Exception e)
            {
                Log.Exception(e);
                return(false);
            }

            suggested_arena_instances_left = result.FreeArenaCount;

            var arena = new SingleArena(this, buffer, result);

            lock (arenas)
                arenas.Add(arena);

            for (var i = 0; i < buffer.Count; ++i)
            {
                var player = buffer[i];
                var info   = attempt.PlayerInfo[i];

                player.arena       = arena;
                player.arena_state = ArenaState.InArena;

                var ev = new Event
                {
                    QueuePopped = new Event_QueuePopped
                    {
                        AuthToken     = info.AuthToken,
                        ConnectionStr = result.PublicConnectionStr
                    }
                };

                player.event_stream.Enqueue(ev);
            }

            return(true);
        }