Esempio n. 1
0
        public async Task <GameState> Launch(GamespaceSpec spec)
        {
            var game = await _gamespaceStore.Load(spec.IsolationId);

            if (game == null)
            {
                var workspace = await _workspaceStore.Load(spec.WorkspaceId);

                if (workspace == null || !workspace.HasScope(Client.Scope))
                {
                    _logger.LogInformation($"No audience match for workspace {spec?.WorkspaceId}: [{workspace?.Audience}] [{Client?.Scope}]");
                    throw new InvalidOperationException();
                }

                game = new Data.Gamespace
                {
                    GlobalId  = spec.IsolationId,
                    Name      = workspace.Name,
                    Workspace = workspace,
                    Audience  = Client.Id.Untagged()
                                // ShareCode = Guid.NewGuid().ToString("N")
                };

                await _gamespaceStore.Add(game);
            }

            return(await Deploy(await _gamespaceStore.Load(game.Id), spec));
        }
Esempio n. 2
0
        public async Task <GameState> Launch(int workspaceId)
        {
            var gamespaces = await _gamespaceStore
                             .ListByProfile(User.Id)
                             .ToArrayAsync();

            var game = gamespaces
                       .Where(m => m.WorkspaceId == workspaceId)
                       .SingleOrDefault();

            if (game == null)
            {
                var workspace = await _workspaceStore.Load(workspaceId);

                if (workspace == null)
                {
                    throw new InvalidOperationException();
                }

                if (gamespaces.Length >= _options.GamespaceLimit)
                {
                    throw new GamespaceLimitReachedException();
                }

                game = new Data.Gamespace
                {
                    Name         = workspace.Name,
                    Workspace    = workspace,
                    LastActivity = DateTime.UtcNow,
                    ShareCode    = Guid.NewGuid().ToString("N"),
                    Audience     = "topomojo"
                };

                game.Players.Add(
                    new Data.Player
                {
                    PersonId   = User.Id,
                    Permission = Data.Permission.Manager
                                 // LastSeen = DateTime.UtcNow
                }
                    );

                await _gamespaceStore.Add(game);
            }

            return(await Deploy(await _gamespaceStore.Load(game.Id)));
        }
Esempio n. 3
0
        public async Task Enlist(string code, User actor)
        {
            string id = await _distCache.GetStringAsync(code);

            if (id.IsEmpty())
            {
                throw new InvalidInvitation();
            }

            var gamespace = await _store.Load(id);

            if (gamespace.Players.Any(m => m.SubjectId == actor.Id))
            {
                return;
            }

            gamespace.Players.Add(new Data.Player
            {
                SubjectId   = actor.Id,
                SubjectName = actor.Name,
            });

            await _store.Update(gamespace);
        }
Esempio n. 4
0
        public async Task <GameState> Load(int id)
        {
            var gamespace = await _gamespaceStore.Load(id);

            return(await LoadState(gamespace));
        }