Пример #1
0
		private void SaveNewHighscore(Player player, int score, bool hadHighScoreAlready)
		{
			if (hadHighScoreAlready)
				highscores.Update(new QueryDocument("PlayerId", player.Id),
					new UpdateDocument { { "$set", new BsonDocument("Score", score) } });
			else
				highscores.Insert(new HighScore
				{
					PlayerId = player.Id,
					Score = score,
					PositionInRanking = 0
				});
			var all = highscores.FindAll().OrderByDescending(hs => hs.Score);
			int rank = 1;
			foreach (var hs in all)
				highscores.Update(new QueryDocument("PlayerId", hs.PlayerId),
					new UpdateDocument { { "$set", new BsonDocument("PositionInRanking", rank++) } });
		}
Пример #2
0
		private void UpdateLastLogin(Player player)
		{
			players.Update(new QueryDocument("Username", player.Username),
				new UpdateDocument { { "$set", new BsonDocument("LastLogin", DateTime.UtcNow) } });
		}