Skip to content

Commit

Permalink
Merge pull request #150 from mongodb-developer/main
Browse files Browse the repository at this point in the history
email masking and readme with arch diagram
  • Loading branch information
snarvaez authored Jul 31, 2024
2 parents f15a41c + 2d8893a commit 4ef6fe6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# Leafsteroids

This repository contains the MongoDB `Leafsteroids` demo.
This repository contains the MongoDB `Leafsteroids` demo. A game developed by the MongoDB team, featuring a 2D arcade-style space shooter. Built with Unity3D and .NET, it includes a game client, an ASP.NET Web API, and a website using Blazor pages. Players aim to destroy bricks (asteroids) and achieve the highest score within 60 seconds by collecting power-ups and destroying targets quickly, while competing against each other within the concept of an event (tournament). The backend uses MongoDB Atlas for data storage, including Atlas Vector Search to match players based on gameplay style, score, and speed. The game is playable on tablets, mobiles, and desktop/laptop, with real-time scoreboards for competitive play.

Follow the instructions in this README to run a clone of your own to get your MongoDB development jump started.

You can also register and create your own event to share with your friends and play live anywhere [here](https://leafsteroids.net/).

## Architecture

![Leafsteroids Architecture](./arch_diagram.png)

The demo and repository consist of the following parts:

- Game Client (Unity3D, .NET, C#)
Expand Down
Binary file added arch_diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 6 additions & 5 deletions rest_service/Controllers/PlayersController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Xml.Linq;
using System.Xml.Linq;
using Microsoft.AspNetCore.Mvc;
using MongoDB.Bson;
using MongoDB.Bson.Serialization;
Expand Down Expand Up @@ -59,11 +59,11 @@ public async Task<List<PlayerResponse>> GetPlayers([FromQuery] PlayerRequest pla
filter &= Builders<Player>.Filter.Eq(x => x.Location, playerUnique.Location);
}

var players = await _playersCollection.FindAsync(filter, new FindOptions<Player,Player>() { Limit = 10 });
var players = await _playersCollection.FindAsync(filter, new FindOptions<Player, Player>() { Limit = 10 });

var playersResponse =
players.ToList().Select(player => new PlayerResponse(player)).ToList();

return playersResponse;
}

Expand Down Expand Up @@ -156,7 +156,7 @@ public async Task<ActionResult<PlayerResponse>> CreatePlayer(PlayerRequest playe
try
{
await _playersCollection.InsertOneAsync(session, player);

await _playersUniqueCollection.InsertOneAsync(session, playerUnique);

if (session.IsInTransaction)
Expand Down Expand Up @@ -205,7 +205,8 @@ public async Task<List<string>> PlayerAutoComplete([FromQuery] string Name)
return arrMatches.GetElement("matches").Value.AsBsonArray
.Select(x => x.ToString())
.ToList();
} catch (Exception e)
}
catch (Exception e)
{
Logger.LogError("GetPlayerAutoComplete did not find matches");
Logger.LogError(e.Message);
Expand Down
21 changes: 20 additions & 1 deletion rest_service/Dtos/ResponseObjects/PlayerResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,27 @@ public PlayerResponse(Player player)
{
Id = player.Id.ToString();
Name = player.Name;
Email = player.Email;
Email = MaskEmail(player.Email ?? string.Empty);
Team = player.Team;
Location = player.Location;
}

public string MaskEmail(string email)
{
if (string.IsNullOrEmpty(email) || !email.Contains("@"))
return email;

string[] emailArr = email.Split('@');
string domainExt = Path.GetExtension(email);

string maskedEmail = string.Format("{0}****{1}@{2}****{3}{4}",
emailArr[0][0],
emailArr[0].Substring(emailArr[0].Length - 1),
emailArr[1][0],
emailArr[1].Substring(emailArr[1].Length - domainExt.Length - 1, 1),
domainExt
);

return maskedEmail;
}
}

0 comments on commit 4ef6fe6

Please sign in to comment.