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();
        }
示例#2
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();
        }
示例#3
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();
        }
        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();
        }