Esempio n. 1
0
        private async Task <TopoMojo.Api.Data.Gamespace> _Register(GamespaceRegistration request, User actor)
        {
            string playerId = request.Players.FirstOrDefault()?.SubjectId ?? actor.Id;

            var gamespace = await _store.LoadActiveByContext(
                request.ResourceId,
                playerId
                );

            if (gamespace is Data.Gamespace)
            {
                return(gamespace);
            }

            if (!await _store.IsBelowGamespaceLimit(actor.Id, actor.GamespaceLimit))
            {
                throw new ClientGamespaceLimitReached();
            }

            string lockKey = $"{playerId}{request.ResourceId}";

            var ctx = await LoadContext(request);

            if (!await _locker.Lock(lockKey))
            {
                throw new ResourceIsLocked();
            }

            try
            {
                await Create(ctx, actor);
            }
            finally
            {
                await _locker.Unlock(lockKey);
            }

            return(ctx.Gamespace);
        }