コード例 #1
0
        public async Task SetStartAndFinish(string lobby, string start, string finish)
        {
            lobby = lobby.ToLowerInvariant();

            var lobbyObject = this.Database.GetLobby(lobby);
            var userObject  = this.Database.GetUser(this.Context.ConnectionId);

            if (userObject.UserName != lobbyObject.Host)
            {
                throw new Exception("You are not the lobby host!");
            }

            string startPage = "";

            if (!string.IsNullOrWhiteSpace(start))
            {
                try
                {
                    startPage = WikiCore.GetWikiPage(start, Database, Logger);
                    lobbyObject.StartArticle = start;
                }
                catch (Exception e)
                {
                    Logger.LogError(e, $"Unable to set article: {start}");
                }
            }

            if (!string.IsNullOrWhiteSpace(finish))
            {
                try
                {
                    WikiCore.GetWikiPage(finish, Database, Logger);
                    lobbyObject.FinishArticle = finish;
                }
                catch (Exception e)
                {
                    Logger.LogError(e, $"Unable to set article: {finish}");
                }
            }

            Database.SaveChanges();

            await Clients.Group(lobby).SendAsync("WikiReceive", startPage);

            await Clients.Group(lobby).SendAsync("GameState", JsonSerializer.Serialize(this.Database.GetGameState(lobby)));

            this.Logger.LogInformation($"{Context.ConnectionId} sent gamestate to all {lobby}.");
        }
コード例 #2
0
 public IActionResult GetPage(string page, string lobby, string connectionId)
 {
     try
     {
         if (this.ValidateUserAndWinningPage(page, lobby, connectionId))
         {
             var response = WikiCore.GetWikiPage(page, Database, Logger);
             return(Ok(response));
         }
         else
         {
             throw new Exception("Failed to validate user.");
         }
     }
     catch (Exception e)
     {
         this.Logger.LogError($"Error fetching page {page}", e);
         return(StatusCode(500));
     }
 }