コード例 #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 = Encoding.ASCII.GetString(salt),
                    Hash = Encoding.ASCII.GetString(hash)
                };

                player.Account = account;

                dc.Accounts.Add(account);
                dc.SaveChanges();
                return account;
            }
        }
コード例 #2
0
ファイル: DataModelFacade.cs プロジェクト: Dzenih/BOD-Server
 public static void SaveChanges()
 {
     using (DatabaseContainer dc = new DatabaseContainer())
     {
         dc.SaveChanges();
     }
 }
コード例 #3
0
ファイル: DataModelFacade.cs プロジェクト: RasiahT/BOD-Server
        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;
            }
        }
コード例 #4
0
ファイル: Player.Domain.cs プロジェクト: RasiahT/BOD-Server
 /// <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();
     }
 }
コード例 #5
0
 public static Player CreatePlayer(string nickname)
 {
     using (DatabaseContainer dc = new DatabaseContainer())
     {
         Player player = new Player() { Nickname = nickname }; // TODO: dynamic account.
         dc.Players.Add(player);
         dc.SaveChanges();
         return player;
     }
 }
コード例 #6
0
ファイル: Player.Domain.cs プロジェクト: Dzenih/BOD-Server
        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();
            }
        }