コード例 #1
0
        public static bool Load( Economy.EcoStats p )
        {
            if ( File.Exists( "players/economy/" + p.playerName.ToLower() + "DB.txt" ) ) {
                foreach ( string line in File.ReadAllLines( "players/economy/" + p.playerName.ToLower() + "DB.txt" ) ) {
                    if ( !string.IsNullOrEmpty( line ) && !line.StartsWith( "#" ) ) {
                        string key = line.Split( '=' )[0].Trim();
                        string value = line.Split( '=' )[1].Trim();
                        string section = "nowhere yet...";

                        try {
                            switch ( key.ToLower() ) {
                                case "money":
                                p.money = int.Parse(value);
                                section = key;
                                break;
                                case "total":
                                p.totalSpent = int.Parse(value);
                                section = key;
                                break;
                                case "purchase":
                                p.purchase = value;
                                section = key;
                                break;
                                case "payment":
                                p.payment = value;
                                section = key;
                                break;
                                case "salary":
                                p.salary = value;
                                section = key;
                                break;
                                case "fine":
                                p.fine = value;
                                section = key;
                                break;
                            }
                        } catch(Exception e) {
                            Server.s.Log( "Loading " + p.playerName + "'s economy database failed at section: " + section );
                            Server.ErrorLog( e );
                        }
                    }
                }
                return true;
            } else {
                p.fine = "";
                p.money = Player.Find(p.playerName).money;
                p.payment = "";
                p.purchase = "";
                p.salary = "";
                p.totalSpent = 0;
                Save( p );
                return false;
            }
        }
コード例 #2
0
 public static void Save( Economy.EcoStats p )
 {
     StreamWriter sw = new StreamWriter( File.Create( "players/economy/" + p.playerName.ToLower() + "DB.txt" ) );
     sw.WriteLine( "Money = " + p.money);
     sw.WriteLine( "Total = " + p.totalSpent);
     sw.WriteLine( "Purchase = " + p.purchase);
     sw.WriteLine( "Payment = " + p.payment);
     sw.WriteLine( "Salary = " + p.salary);
     sw.WriteLine( "Fine = " + p.fine);
     sw.Flush();
     sw.Close();
     sw.Dispose();
 }
コード例 #3
0
        public static Economy.Settings.Rank NextRank(Player p)
        {
            Group foundGroup = p.group;
            Group nextGroup = null; bool nextOne = false;

            for (int i = 0; i < Group.GroupList.Count; i++)
            {
                Group grp = Group.GroupList[i];
                if (nextOne)
                {
                    if (grp.Permission >= LevelPermission.Nobody)
                    {
                        break;
                    }
                    nextGroup = grp;
                    break;
                }
                if (grp == foundGroup)
                {
                    nextOne = true;
                }
            }
            return(Economy.FindRank(nextGroup.name));
        }
コード例 #4
0
        public static void Load(bool loadDatabase = false)
        {
            /*if (loadDatabase) {
             * retry:
             *  if (Server.useMySQL) MySQL.executeQuery(createTable); else SQLite.executeQuery(createTable); //create database on server loading
             *  string queryP = "SELECT * FROM Players"; string queryE = "SELECT * FROM Economy";
             *  DataTable eco = Server.useMySQL ? MySQL.fillData(queryE) : SQLite.fillData(queryE);
             *  try {
             *      DataTable players = Server.useMySQL ? MySQL.fillData(queryP) : SQLite.fillData(queryP);
             *      if (players.Rows.Count == eco.Rows.Count) { } //move along, nothing to do here
             *      else if (eco.Rows.Count == 0) { //if first time, copy content from player to economy
             *          string query = "INSERT INTO Economy (player, money) SELECT Players.Name, Players.Money FROM Players";
             *          if (Server.useMySQL) MySQL.executeQuery(query); else SQLite.executeQuery(query);
             *      } else {
             *          //this will only be needed when the server shuts down while it was copying content (or some other error)
             *          if (Server.useMySQL) MySQL.executeQuery("DROP TABLE Economy"); else SQLite.executeQuery("DROP TABLE Economy");
             *          goto retry;
             *      }
             *      players.Dispose(); eco.Dispose();
             *  } catch { }
             *  return;
             * }*/

            if (!File.Exists("properties/economy.properties"))
            {
                Server.s.Log("Economy properties don't exist, creating"); File.Create("properties/economy.properties").Close(); Save();
            }
            using (StreamReader r = File.OpenText("properties/economy.properties")) {
                string line;
                while (!r.EndOfStream)
                {
                    line = r.ReadLine().ToLower().Trim();
                    string[] linear = line.ToLower().Trim().Split(':');
                    try {
                        switch (linear[0])
                        {
                        case "enabled":
                            if (linear[1] == "true")
                            {
                                Settings.Enabled = true;
                            }
                            else if (linear[1] == "false")
                            {
                                Settings.Enabled = false;
                            }
                            break;

                        case "title":
                            if (linear[1] == "price")
                            {
                                Settings.TitlePrice = int.Parse(linear[2]);
                            }
                            if (linear[1] == "enabled")
                            {
                                if (linear[2] == "true")
                                {
                                    Settings.Titles = true;
                                }
                                else if (linear[2] == "false")
                                {
                                    Settings.Titles = false;
                                }
                            }
                            break;

                        case "color":
                            if (linear[1] == "price")
                            {
                                Settings.ColorPrice = int.Parse(linear[2]);
                            }
                            if (linear[1] == "enabled")
                            {
                                if (linear[2] == "true")
                                {
                                    Settings.Colors = true;
                                }
                                else if (linear[2] == "false")
                                {
                                    Settings.Colors = false;
                                }
                            }
                            break;

                        case "titlecolor":
                            if (linear[1] == "price")
                            {
                                Settings.TColorPrice = int.Parse(linear[2]);
                            }
                            if (linear[1] == "enabled")
                            {
                                if (linear[2] == "true")
                                {
                                    Settings.TColors = true;
                                }
                                else if (linear[2] == "false")
                                {
                                    Settings.TColors = false;
                                }
                            }
                            break;

                        case "rank":
                            if (linear[1] == "price")
                            {
                                Economy.Settings.Rank rnk = new Economy.Settings.Rank();
                                rnk = Economy.FindRank(linear[2]);
                                if (rnk == null)
                                {
                                    rnk       = new Economy.Settings.Rank();
                                    rnk.group = Group.Find(linear[2]);
                                    rnk.price = int.Parse(linear[3]);
                                    Economy.Settings.RanksList.Add(rnk);
                                }
                                else
                                {
                                    Economy.Settings.RanksList.Remove(rnk);
                                    rnk.price = int.Parse(linear[3]);
                                    Economy.Settings.RanksList.Add(rnk);
                                }
                            }
                            if (linear[1] == "maxrank")
                            {
                                //Group grp = Group.Find(linear[2]);
                                //if (grp != null) { Settings.MaxRank = grp.Permission; }
                                string grpname = linear[2];
                                if (Group.Exists(grpname))
                                {
                                    Settings.MaxRank = grpname;
                                }
                            }
                            if (linear[1] == "enabled")
                            {
                                if (linear[2] == "true")
                                {
                                    Settings.Ranks = true;
                                }
                                else if (linear[2] == "false")
                                {
                                    Settings.Ranks = false;
                                }
                            }
                            break;

                        case "level":
                            if (linear[1] == "enabled")
                            {
                                if (linear[2] == "true")
                                {
                                    Settings.Levels = true;
                                }
                                else if (linear[2] == "false")
                                {
                                    Settings.Levels = false;
                                }
                            }
                            if (linear[1] == "levels")
                            {
                                Settings.Level lvl = new Settings.Level();
                                if (FindLevel(linear[2]) != null)
                                {
                                    lvl = FindLevel(linear[2]); Settings.LevelsList.Remove(lvl);
                                }
                                switch (linear[3])
                                {
                                case "name":
                                    lvl.name = linear[4];
                                    break;

                                case "price":
                                    lvl.price = int.Parse(linear[4]);
                                    break;

                                case "x":
                                    lvl.x = linear[4];
                                    break;

                                case "y":
                                    lvl.y = linear[4];
                                    break;

                                case "z":
                                    lvl.z = linear[4];
                                    break;

                                case "type":
                                    lvl.type = linear[4];
                                    break;
                                }
                                Settings.LevelsList.Add(lvl);
                            }
                            break;
                        }
                    } catch { }
                }
                r.Close();
            }
            Save();
        }
コード例 #5
0
        public static void Load(bool loadDatabase = false)
        {
            if (!File.Exists("properties/economy.properties"))
            {
                Server.s.Log("Economy properties don't exist, creating"); File.Create("properties/economy.properties").Close(); Save();
            }
            using (StreamReader r = File.OpenText("properties/economy.properties")) {
                string line;
                while (!r.EndOfStream)
                {
                    line = r.ReadLine().ToLower().Trim();
                    string[] linear = line.ToLower().Trim().Split(':');
                    try {
                        switch (linear[0])
                        {
                        case "enabled":
                            if (linear[1] == "true")
                            {
                                Settings.Enabled = true;
                            }
                            else if (linear[1] == "false")
                            {
                                Settings.Enabled = false;
                            }
                            break;

                        case "title":
                            if (linear[1] == "price")
                            {
                                Settings.TitlePrice = int.Parse(linear[2]);
                            }
                            if (linear[1] == "enabled")
                            {
                                if (linear[2] == "true")
                                {
                                    Settings.Titles = true;
                                }
                                else if (linear[2] == "false")
                                {
                                    Settings.Titles = false;
                                }
                            }
                            break;

                        case "color":
                            if (linear[1] == "price")
                            {
                                Settings.ColorPrice = int.Parse(linear[2]);
                            }
                            if (linear[1] == "enabled")
                            {
                                if (linear[2] == "true")
                                {
                                    Settings.Colors = true;
                                }
                                else if (linear[2] == "false")
                                {
                                    Settings.Colors = false;
                                }
                            }
                            break;

                        case "titlecolor":
                            if (linear[1] == "price")
                            {
                                Settings.TColorPrice = int.Parse(linear[2]);
                            }
                            if (linear[1] == "enabled")
                            {
                                if (linear[2] == "true")
                                {
                                    Settings.TColors = true;
                                }
                                else if (linear[2] == "false")
                                {
                                    Settings.TColors = false;
                                }
                            }
                            break;

                        case "rank":
                            if (linear[1] == "price")
                            {
                                Economy.Settings.Rank rnk = new Economy.Settings.Rank();
                                rnk = Economy.FindRank(linear[2]);
                                if (rnk == null)
                                {
                                    rnk       = new Economy.Settings.Rank();
                                    rnk.group = Group.Find(linear[2]);
                                    rnk.price = int.Parse(linear[3]);
                                    Economy.Settings.RanksList.Add(rnk);
                                }
                                else
                                {
                                    Economy.Settings.RanksList.Remove(rnk);
                                    rnk.price = int.Parse(linear[3]);
                                    Economy.Settings.RanksList.Add(rnk);
                                }
                            }
                            if (linear[1] == "maxrank")
                            {
                                //Group grp = Group.Find(linear[2]);
                                //if (grp != null) { Settings.MaxRank = grp.Permission; }
                                string grpname = linear[2];
                                if (Group.Exists(grpname))
                                {
                                    Settings.MaxRank = grpname;
                                }
                            }
                            if (linear[1] == "enabled")
                            {
                                if (linear[2] == "true")
                                {
                                    Settings.Ranks = true;
                                }
                                else if (linear[2] == "false")
                                {
                                    Settings.Ranks = false;
                                }
                            }
                            break;

                        case "level":
                            if (linear[1] == "enabled")
                            {
                                if (linear[2] == "true")
                                {
                                    Settings.Levels = true;
                                }
                                else if (linear[2] == "false")
                                {
                                    Settings.Levels = false;
                                }
                            }
                            if (linear[1] == "levels")
                            {
                                Settings.Level lvl = new Settings.Level();
                                if (FindLevel(linear[2]) != null)
                                {
                                    lvl = FindLevel(linear[2]); Settings.LevelsList.Remove(lvl);
                                }
                                switch (linear[3])
                                {
                                case "name":
                                    lvl.name = linear[4];
                                    break;

                                case "price":
                                    lvl.price = int.Parse(linear[4]);
                                    break;

                                case "x":
                                    lvl.x = linear[4];
                                    break;

                                case "y":
                                    lvl.y = linear[4];
                                    break;

                                case "z":
                                    lvl.z = linear[4];
                                    break;

                                case "type":
                                    lvl.type = linear[4];
                                    break;
                                }
                                Settings.LevelsList.Add(lvl);
                            }
                            break;
                        }
                    } catch { }
                }
                r.Close();
            }
            Save();
        }