public async Task <SporeServerAggregator> AddAsync(SporeServerUser author, string name, string description, SporeServerAsset[] assets) { try { var aggregator = new SporeServerAggregator() { Name = name, Description = description, Timestamp = DateTime.Now, Author = author, Assets = assets }; // add aggregator to database await _context.Aggregators.AddAsync(aggregator); await _context.SaveChangesAsync(); _logger.LogInformation($"AddAsync: Added Aggregator {aggregator.AggregatorId} For User {aggregator.Author.Id}"); return(aggregator); } catch (Exception e) { _logger.LogError($"AddAsync: Failed To Add Aggregator: {e}"); return(null); } }
public async Task <bool> ReserveAsync(SporeServerUser user) { try { // create new empty asset var asset = new SporeServerAsset() { Used = false, Author = user }; // add it to assets await _context.Assets.AddAsync(asset); await _context.SaveChangesAsync(); // update user user.NextAssetId = asset.AssetId; await _userManager.UpdateAsync(user); _logger.LogInformation($"ReserveAsync: Reserved Asset {asset.AssetId} For User {user.Id}"); return(true); } catch (Exception e) { _logger.LogError($"ReserveAsync: Failed To Reserve Asset For User {user.Id}: {e}"); return(false); } }
public async Task <bool> AddAsync(SporeServerAsset adventureAsset, SporeServerAsset captainAsset, Int32 percentageCompleted, Int32 timeInMilliseconds, SporeServerUser author) { try { var entry = new SporeServerLeaderboardEntry() { Asset = adventureAsset, Author = author, Timestamp = DateTime.Now, PercentageCompleted = percentageCompleted, TimeInMilliseconds = timeInMilliseconds, Captain = captainAsset }; await _context.LeaderboardEntries.AddAsync(entry); await _context.SaveChangesAsync(); _logger.LogInformation($"AddAsync: Added Leaderboard Entry {entry.EntryId} For {entry.AuthorId}"); return(true); } catch (Exception e) { _logger.LogError($"AddAsync: Failed To Add Leaderboard Entry: {e}"); return(false); } }
public async Task <bool> AddAsync(SporeServerAsset asset, SporeServerUser author, string comment) { try { var assetComment = new SporeServerAssetComment() { Author = author, Asset = asset, // comments on your own creations are automatically approved Approved = (author.Id == asset.AuthorId), Timestamp = DateTime.Now, Comment = comment }; await _context.AssetComments.AddAsync(assetComment); await _context.SaveChangesAsync(); _logger.LogInformation($"AddAsync: Added Comment {assetComment.CommentId}"); return(true); } catch (Exception e) { _logger.LogError($"AddAsync: Failed To Add Comment For {asset.AssetId}: {e}"); return(false); } }
public async Task <bool> AddAsync(SporeServerUser author, SporeServerAsset asset, bool rating) { try { var assetRating = new SporeServerRating() { Author = author, Asset = asset, Timestamp = DateTime.Now, Rating = rating }; await _context.AssetRatings.AddAsync(assetRating); await _context.SaveChangesAsync(); // update asset rating await UpdateAssetRatingAsync(asset); _logger.LogInformation($"AddAsync: Added Rating {assetRating.RatingId}"); return(true); } catch (Exception e) { _logger.LogError($"AddAsync: Failed To Add Rating For {asset.AssetId}: {e}"); return(false); } }
public UserTemplate(SporeServerUser author, SporeServerAsset[] assets) { // <feed /> // var document = AtomFeedBuilder.CreateDocument("feed"); // <id /> AtomFeedBuilder.AddCustomElement(document, "id", $"tag:spore.com,2006:user/{author.Id}"); // <title /> AtomFeedBuilder.AddCustomElement(document, "title", $"{author.UserName}"); // <updated /> // TODO AtomFeedBuilder.AddCustomElement(document, "updated", $"{XmlConvert.ToString(DateTime.Now, XmlDateTimeSerializationMode.Utc)}"); // <author /> AtomFeedBuilder.AddAuthorElement(document, $"{author.UserName}", $"{author.Id}"); // <subcount /> // TODO? AtomFeedBuilder.AddCustomElement(document, "subcount", "0"); // <link /> AtomFeedBuilder.AddLinkElement(document, "self", $"https://pollinator.spore.com/pollinator/atom/user/{author.Id}", null, null); // add assets to feed SporeAtomFeedHelper.AddAssetsToFeed(document, assets); // save xml _xml = document.OuterXml; }
public async Task <Int32> GetCountByAuthorAsync(SporeServerUser author) { try { return(await _context.Assets .Where(a => a.AuthorId == author.Id) .CountAsync()); } catch (Exception e) { _logger.LogError($"GetCountByAuthor: Failed To Get Count For {author.Id}: {e}"); return(0); } }
public async Task <int> GetCountByUserAsync(SporeServerUser user) { try { return(await _context.UserSubscriptions .Where(s => s.UserId == user.Id) .CountAsync()); } catch (Exception e) { _logger.LogError($"GetCountByUserAsync: Failed To Get Count Of Subscriptions For {user.Id}: {e}"); return(0); } }
public async Task <SporeServerUserSubscription> FindAsync(SporeServerUser author, SporeServerUser user) { try { return(await _context.UserSubscriptions .Where(s => s.AuthorId == author.Id && s.UserId == user.Id) .FirstOrDefaultAsync()); } catch (Exception e) { _logger.LogError($"FindAsync: Failed To Find Subscription: {e}"); return(null); } }
public async Task <SporeServerUserSubscription[]> FindAllByAuthorAsync(SporeServerUser author) { try { return(await _context.UserSubscriptions .Include(s => s.User) .Where(s => s.AuthorId == author.Id) .ToArrayAsync()); } catch (Exception e) { _logger.LogError($"FindAllByAuthorAsync: Failed To Find By Author {author.Id}: {e}"); return(null); } }
public async Task <Int64[]> FindAllByAuthorAsync(SporeServerUser author) { try { return(await _context.UnlockedAchievements .Where(u => u.AuthorId == author.Id) .OrderBy(u => u.Timestamp) .Select(u => u.AchievementId) .ToArrayAsync()); } catch (Exception e) { _logger.LogError($"Failed To Find All Unlocked Achievements For {author.Id}: {e}"); return(null); } }
public async Task <SporeServerAggregator[]> FindByAuthorAsync(SporeServerUser author) { try { return(await _context.Aggregators .Include(a => a.Assets) .Include(a => a.Author) .Where(a => a.AuthorId == author.Id) .ToArrayAsync()); } catch (Exception e) { _logger.LogError($"FindByAuthorAsync: Failed To Find Aggregators For Author {author.Id}: {e}"); return(null); } }
public async Task <SporeServerRating> FindAsync(SporeServerUser author, SporeServerAsset asset) { try { return(await _context.AssetRatings .Include(r => r.Asset) .Where(r => r.AuthorId == author.Id && r.AssetId == asset.AssetId) .FirstOrDefaultAsync()); } catch (Exception e) { _logger.LogError($"FindAsync: Failed To Find Rating For {asset.AssetId}: {e}"); return(null); } }
public async Task <SporeServerAssetComment[]> FindAllByAssetAuthorAsync(SporeServerUser author) { try { return(await _context.AssetComments .Include(c => c.Asset) .Where(c => c.Asset.AuthorId == author.Id ) .OrderByDescending(c => c.Timestamp) .Take(10) .ToArrayAsync()); } catch (Exception e) { _logger.LogError($"FindAllByAssetAuthorAsync: Failed To Find Unapproved Comments For {author.Id}: {e}"); return(null); } }
public async Task Invoke(HttpContext context, UserManager <SporeServerUser> userManager, SignInManager <SporeServerUser> signInManager) { string email, password; // we don't need to do anything if // * we're already authenticated // * the header doesn't contain Spore-User (or it's empty) // * the header doesn't contain Spore-Password (or it's empty) if (context.User.Identity.IsAuthenticated || !context.Request.Headers.ContainsKey("Spore-User") || String.IsNullOrEmpty(email = context.Request.Headers["Spore-User"]) || !context.Request.Headers.ContainsKey("Spore-Password") || String.IsNullOrEmpty((password = context.Request.Headers["Spore-Password"]))) { await _next(context); return; } // decode email & password email = WebUtility.UrlDecode(email); password = WebUtility.UrlDecode(password); // attempt to find the user SporeServerUser user = await userManager.FindByEmailAsync(email); if (user != null) { // attempt to login using password SignInResult result = await signInManager.PasswordSignInAsync(user, password, false, true); if (result == SignInResult.Success) { // authenticate current context aswell context.User = await signInManager.CreateUserPrincipalAsync(user); } } await _next(context); }
public async Task <bool> UnlockAsync(Int64 achievementId, SporeServerUser author) { try { // make sure the achievement id is valid if (!SporeAchievements.Achievements.Select(a => a.Id).Contains(achievementId)) { throw new Exception($"Achivement Id {achievementId} is invalid!"); } // make sure achievement isn't already unlocked var achievements = await FindAllByAuthorAsync(author); if (achievements.Contains(achievementId)) { return(true); } var achievement = new SporeServerUnlockedAchievement() { Author = author, Timestamp = DateTime.Now, AchievementId = achievementId }; // add to the database await _context.UnlockedAchievements.AddAsync(achievement); await _context.SaveChangesAsync(); _logger.LogInformation($"Unlocked Achievement {achievementId} For User {author.Id}"); return(true); } catch (Exception e) { _logger.LogError($"Failed To Unlock Achivement For {author.Id}: {e}"); return(false); } }
public async Task <bool> AddAsync(SporeServerUser author, SporeServerUser user) { try { var subscription = new SporeServerUserSubscription() { Author = author, User = user }; // add subscription to database await _context.UserSubscriptions.AddAsync(subscription); await _context.SaveChangesAsync(); _logger.LogInformation($"AddAsync: Added Subscription {subscription.SubscriptionId} For User {author.Id}"); return(true); } catch (Exception e) { _logger.LogError($"AddAsync: Failed To Add Subscription: {e}"); return(false); } }
/// <summary> /// returns Asset Count of given user /// </summary> /// <param name="user"></param> /// <returns></returns> public async Task <Int32> GetAssetCountByUserAsync(SporeServerUser user) { return(await _assetManager.GetCountByAuthorAsync(user)); }
public async Task <bool> AddAsync(Stream eventStream, SporeServerUser author) { try { var events = await EventsModel.SerializeAsync(eventStream); foreach (var eventsEvent in events.Events) { switch (eventsEvent.Verb) { // Unlocked Achievement case (Int64)SporeEventType.AchievementUnlocked: await _achievementManager.UnlockAsync(eventsEvent.Args[0], author); break; // Befriended Creature case (Int64)SporeEventType.CreatureBefriended: break; // Extincted Creature case (Int64)SporeEventType.CreatureExtinction: break; // Adventure Won case (Int64)SporeEventType.AdventureWon: { var adventureAssetId = eventsEvent.AssetId; var percentageCompleted = (Int32)eventsEvent.Args[0]; var timeInMs = (Int32)eventsEvent.Args[1]; // Args[2] contains the amount of captain points earned // maybe a thing to track in the future? // seems to be unrequired for anything ingame though var captainAssetId = eventsEvent.Args[3]; var adventureAsset = await _assetManager.FindByIdAsync(adventureAssetId); var captainAsset = await _assetManager.FindByIdAsync(captainAssetId); // make sure we can find the needed assets if (adventureAsset == null || captainAsset == null) { break; } await _leaderboardManager.AddAsync(adventureAsset, captainAsset, percentageCompleted, timeInMs, author); } break; // Adventure Lost case (Int64)SporeEventType.AdventureLost: break; // Adventure Captain Stats case (Int64)SporeEventType.AdventureCaptainStats: break; // Adventure Captain Name case (Int64)SporeEventType.AdventureCaptainName: break; // Adventure Captain Unlocked Parts case (Int64)SporeEventType.AdventureCaptainUnlockedParts: break; // Unsupported default: _logger.LogWarning($"Invalid Event Verb 0x{eventsEvent.Verb:x}"); break; } } return(true); } catch (Exception e) { _logger.LogError($"Failed To Add Event For {author.Id}: {e}"); return(false); } }
public HandshakeTemplate(SporeServerUser user, SporeServerAggregator[] aggregators, Int32[] aggregatorSubscriptionCounts, SporeServerUserSubscription[] userSubscriptions, SporeServerAggregatorSubscription[] aggregatorSubscriptions) { // <handshake /> // var document = AtomFeedBuilder.CreateDocument("handshake"); // <user-id /> AtomFeedBuilder.AddCustomElement(document, "user-id", $"{user.Id}"); // <screen-name /> AtomFeedBuilder.AddCustomElement(document, "screen-name", $"{user.UserName}"); // <next-id /> AtomFeedBuilder.AddCustomElement(document, "next-id", $"{user.NextAssetId}"); // <refresh-rate /> AtomFeedBuilder.AddCustomElement(document, "refresh-rate", "120"); // <maxis-feeds /> // AtomFeedBuilder.AddCustomElement(document, "maxis-feeds"); /* We can remove this because * the official server returns an empty feed at the url anyways * maybe allow custom sporecasts here in the future? * AtomFeedBuilder.AddFeedEntry(document, maxisFeeds, * id: "tag:spore.com,2006:maxis/adventures/en_US", * title: "Maxis Adventures", * updated: DateTime.Now, * subtitle: "Free creations from Maxis.", * authorName: null, * authorUri: null, * subCount: 0, * link: "https://pollinator.spore.com/pollinator/atom/maxis/adventures/en_US"); */ // <my-feeds /> // var myFeeds = AtomFeedBuilder.AddCustomElement(document, "my-feeds"); for (int i = 0; i < aggregators.Length; i++) { var aggregator = aggregators[i]; var aggregatorSubscriptionCount = aggregatorSubscriptionCounts[i]; AtomFeedBuilder.AddFeedEntry(document, myFeeds, id: $"tag:spore.com,2006:aggregator/{aggregator.AggregatorId}", title: $"{aggregator.Name}", updated: DateTime.Now, subtitle: null, authorName: $"{aggregator.Author.UserName}", authorUri: $"{aggregator.AuthorId}", subCount: aggregatorSubscriptionCount, link: $"https://pollinator.spore.com/pollinator/atom/aggregator/{aggregator.AggregatorId}"); } AtomFeedBuilder.AddFeedEntry(document, myFeeds, id: $"tag:spore.com,2006:user/{user.Id}", title: $"{user.UserName}", updated: DateTime.Now, subtitle: null, authorName: $"{user.UserName}", authorUri: $"{user.Id}", subCount: 0, link: $"https://pollinator.spore.com/pollinator/atom/user/{user.Id}"); // <subscriptions /> // var subscriptionsFeed = AtomFeedBuilder.AddCustomElement(document, "subscriptions"); foreach (var subscription in userSubscriptions) { AtomFeedBuilder.AddFeedEntry(document, subscriptionsFeed, id: $"tag:spore.com,2006:user/{subscription.UserId}", title: $"{subscription.User.UserName}", updated: DateTime.Now, subtitle: null, authorName: $"{subscription.User.UserName}", authorUri: $"{subscription.UserId}", subCount: 0, link: $"https://pollinator.spore.com/pollinator/atom/user/{subscription.UserId}"); } foreach (var subscription in aggregatorSubscriptions) { AtomFeedBuilder.AddFeedEntry(document, subscriptionsFeed, id: $"tag:spore.com,2006:aggregator/{subscription.AggregatorId}", title: $"{subscription.Aggregator.Name}", updated: subscription.Aggregator.Timestamp, subtitle: $"{subscription.Aggregator.Description}", authorName: $"{subscription.Aggregator.Author.UserName}", authorUri: $"{subscription.Aggregator.AuthorId}", subCount: 0, link: $"https://pollinator.spore.com/pollinator/atom/aggregator/{subscription.AggregatorId}"); } // <invisible-feeds /> // var invisibleFeed = AtomFeedBuilder.AddCustomElement(document, "invisible-feeds"); AtomFeedBuilder.AddFeedEntry(document, invisibleFeed, id: "tag:spore.com,2006:downloadQueue", title: $"{user.UserName}", updated: DateTime.Now, subtitle: null, authorName: $"{user.UserName}", authorUri: $"{user.Id}", subCount: 0, link: "https://pollinator.spore.com/pollinator/atom/downloadQueue"); // save xml _xml = document.OuterXml; }