Esempio n. 1
0
 //Used in a situation where the player has already logged in when the game starts. (Once logged in, you log out only if log out button is pressed manually.)
 public void SetDataIfLogin(string playerName)
 {
     LoginSuccess = true;
     playerList   = playerCollection.Find(new BsonDocument()).ToList();
     foreach (var playerObject in playerList)
     {
         if (playerObject.Name.Equals(playerName))
         {
             player       = playerObject;
             hsCollection = player.ScoreCollection;
         }
     }
 }
Esempio n. 2
0
    //Insert new player object to the database, if the username was valid after trying to sign up.
    public async void RegisterNewPlayer(string playerName, string pw)
    {
        try
        {
            player.Name     = playerName;
            player.Password = PasswordHandler.Encrypt(pw, player.Name);
            await playerCollection.InsertOneAsync(player);

            hsCollection = player.ScoreCollection;
        }
        catch (Exception e)
        {
            Debug.LogWarning(e);
        }
    }
Esempio n. 3
0
    //Search player's highscore on certain map and update it.
    public HighScoresCollection UpdateCollectionItem(HighScoresCollection highScoresCollection, HighScore highScore)
    {
        var obj = highScoresCollection.Hiscores.FirstOrDefault(x => x.MapId == highScore.MapId);

        if (obj != null)
        {
            obj.Score        = highScore.Score;
            obj.HighestCombo = highScore.HighestCombo;
            obj.MaxCombo     = highScore.MaxCombo;
            obj.Perfects     = highScore.Perfects;
            obj.Normals      = highScore.Normals;
            obj.Poors        = highScore.Poors;
            obj.Misses       = highScore.Misses;
        }
        else
        {
            highScoresCollection.Hiscores.Add(new HighScore(highScore.MapId, highScore.Score, highScore.HighestCombo, highScore.MaxCombo, highScore.Perfects, highScore.Normals, highScore.Poors, highScore.Misses));
        }
        return(highScoresCollection);
    }
Esempio n. 4
0
 //Verify if user put the correct credentials on login menu and return a playerobject matching those credentials from the database if he did.
 public PlayerRef GetPlayerByCredentials(string playerName, string pw)
 {
     playerList = playerCollection.Find(new BsonDocument()).ToList();
     foreach (var playerObject in playerList)
     {
         if (playerObject.Name.Equals(playerName))
         {
             var decrypted = PasswordHandler.Decrypt(playerObject.Password, playerObject.Name);
             if (decrypted.Equals(pw))
             {
                 LoginSuccess = true;
                 player       = playerObject;
                 hsCollection = playerObject.ScoreCollection;
             }
             else
             {
                 LoginSuccess = false;
             }
         }
     }
     return(player);
 }
Esempio n. 5
0
 public PlayerRef()
 {
     ScoreCollection = new HighScoresCollection();
 }