Exemplo n.º 1
0
        private static void Load()
        {
            string filePath = Path.Combine("Saves/Accounts", "accounts.xml");

            if (!File.Exists(filePath))
            {
                return;
            }

            XmlDocument doc = new XmlDocument();

            doc.Load(filePath);

            XmlElement root = doc["accounts"];

            foreach (XmlElement accountXmlElement in root.GetElementsByTagName("account"))
            {
                try
                {
                    Account acct = new Account(accountXmlElement);

                    Accounts.AddAccount(acct);
                }
                catch
                {
                    Console.WriteLine("Warning: Account instance load failed");
                }
            }
        }
Exemplo n.º 2
0
        public static void CreateAccountsFromDB( )
        {
            //Console.WriteLine( "Getting New Accounts..." );
            try
            {
                ArrayList      ToCreateFromDB = new ArrayList( );
                OdbcConnection Connection     = new OdbcConnection(ConnectionString);

                Connection.Open( );
                OdbcCommand Command = Connection.CreateCommand( );

                Command.CommandText = string.Format("SELECT name,password,email FROM {0} WHERE state='{1}'", DatabaseTable, ( int )Status.Pending);
                OdbcDataReader reader = Command.ExecuteReader( );

                QueryCount += 1;

                while (reader.Read( ))
                {
                    string username = reader.GetString(0);
                    string password = reader.GetString(1);
                    string email    = reader.GetString(2);

                    if (Accounts.GetAccount(username) == null)
                    {
                        ToCreateFromDB.Add(Accounts.AddAccount(username, password, email));
                    }
                }
                reader.Close( );

                //Console.WriteLine( "Updating Database..." );
                foreach (Account a in ToCreateFromDB)
                {
                    int ALevel = 0;

                    if (a.AccessLevel == AccessLevel.Player)
                    {
                        ALevel = 1;
                    }
                    else if (a.AccessLevel == AccessLevel.Counselor)
                    {
                        ALevel = 2;
                    }
                    else if (a.AccessLevel == AccessLevel.GameMaster)
                    {
                        ALevel = 3;
                    }
                    else if (a.AccessLevel == AccessLevel.Seer)
                    {
                        ALevel = 4;
                    }
                    else if (a.AccessLevel == AccessLevel.Administrator)
                    {
                        ALevel = 6;
                    }

                    QueryCount += 1;

                    Command.CommandText = string.Format("UPDATE {0} SET email='{1}',password='******',state='{3}',access='{4}' WHERE name='{5}'", DatabaseTable, a.Email, a.CryptPassword, ( int )Status.Active, ALevel, a.Username);
                    Command.ExecuteNonQuery( );
                }

                Connection.Close( );

                Console.WriteLine("[{0} In-Game Accounts Created] ", ToCreateFromDB.Count);
            }
            catch (Exception e)
            {
                Console.WriteLine("[In-Game Account Create] Error...");
                Console.WriteLine(e);
            }
        }