示例#1
0
        public static Account CreateAccount(string username, string nickname, int playerId, byte[] salt, byte[] hash)
        {
            using (DatabaseContainer dc = new DatabaseContainer())
            {
                if (dc.Accounts.FirstOrDefault(a => a.Username == username) != null)
                {
                    throw new ArgumentException($"Username: {username} is already taken");
                }

                Player player = dc.Players.FirstOrDefault(p => p.Id == playerId) ?? CreatePlayer(nickname);
                Account account = new Account()
                {
                    Username = username,
                    Player = player,
                    Salt = Convert.ToBase64String(salt),
                    Hash = Convert.ToBase64String(hash)
                };

                player.Account = account;
                dc.Accounts.Add(account);
                dc.Entry(player).State = EntityState.Modified; // Avoid making duplicate players.

                dc.SaveChanges();
                return account;
            }
        }
示例#2
0
 /// <summary>
 /// Adds gold to the player.
 /// </summary>
 /// <param name="observable"></param>
 /// <param name="data"></param>
 private void AddGold(Observable observable, object data)
 {
     Gold += 10;
     using (DatabaseContainer dc = new DatabaseContainer())
     {
         dc.Entry(this).State = EntityState.Modified;
         dc.SaveChanges();
     }
 }
示例#3
0
        private void DestroyEvent(Observable observable, object data)
        {
            if (CurrentCharacter.HighScore > this.HighScore)
            {
                this.HighScore = CurrentCharacter.HighScore;
            }

            using (DatabaseContainer dc = new DatabaseContainer())
            {
                dc.Entry(this).State = EntityState.Modified;
                dc.SaveChanges();
            }
        }