コード例 #1
0
        public static Group Find(string name)
        {
            name = name.ToLower();

            if (name == "adv")
            {
                name = "advbuilder";
            }
            if (name == "op")
            {
                name = "operator";
            }
            if (name == "super" || (name == "admin" && !Group.Exists("admin")))
            {
                name = "superop";
            }
            if (name == "noone")
            {
                name = "nobody";
            }

            foreach (Group gr in GroupList)
            {
                if (gr.name == name.ToLower())
                {
                    return(gr);
                }
            }
            return(null);
        }
コード例 #2
0
        /// <summary>
        /// the use stub
        /// </summary>
        /// <param name="p">Player</param>
        /// <param name="message">Message</param>
        public override void Use(Player p, string message)
        {
            if (message == "")
            {
                Help(p);
                return;
            }

            if (p == null)
            {
                Player.SendMessage(p, "Console can't use hackrank, that doesn't make any sense!");
                return;
            }

            string[] msg = message.Split(' ');
            if (Group.Exists(msg[0]))
            {
                Group newRank = Group.Find(msg[0]);
                ranker(p, newRank);
            }
            else
            {
                Player.SendMessage(p, "Invalid Rank!"); return;
            }
        }
コード例 #3
0
        /// <summary>
        /// Find the group with the name /name/
        /// </summary>
        /// <param name="name">The name of the group</param>
        /// <returns>The group object with that name</returns>
        public static Group Find(string name)
        {
            name = name.ToLower();

            if (name == "adv")
            {
                name = "advbuilder";
            }
            if (name == "op")
            {
                name = "operator";
            }
            if (name == "super" || (name == "admin" && !Group.Exists("admin")))
            {
                name = "superop";
            }
            if (name == "noone")
            {
                name = "nobody";
            }

            return(GroupList.FirstOrDefault(gr => gr.name == name.ToLower()));
        }
コード例 #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();
        }
コード例 #6
0
        public override void Use(Player p, string message)
        {
            try
            {
                List <groups> playerList = new List <groups>();

                foreach (Group grp in Group.GroupList)
                {
                    if (grp.name != "nobody")
                    {
                        if (String.IsNullOrEmpty(message) || !Group.Exists(message))
                        {
                            groups groups;
                            groups.group   = grp;
                            groups.players = new List <string>();
                            playerList.Add(groups);
                        }
                        else
                        {
                            Group grp2 = Group.Find(message);
                            if (grp2 != null && grp == grp2)
                            {
                                groups groups;
                                groups.group   = grp;
                                groups.players = new List <string>();
                                playerList.Add(groups);
                            }
                        }
                    }
                }

                string devs         = "";
                int    totalPlayers = 0;
                foreach (Player pl in Player.players)
                {
                    if (!pl.hidden || p == null || p.group.Permission > LevelPermission.Operator || Server.devs.Contains(p.name.ToLower()))
                    {
                        if (String.IsNullOrEmpty(message) || !Group.Exists(message) || Group.Find(message) == pl.group)
                        {
                            totalPlayers++;
                            string foundName = pl.name;

                            if (Server.afkset.Contains(pl.name))
                            {
                                foundName = pl.name + "-afk";
                            }

                            if (Server.devs.Contains(pl.name.ToLower()))
                            {
                                if (pl.voice)
                                {
                                    devs += " " + "&f+" + Server.DefaultColor + foundName + " (" + pl.level.name + "),";
                                }
                                else
                                {
                                    devs += " " + foundName + " (" + pl.level.name + "),";
                                }
                            }

                            if (pl.voice)
                            {
                                playerList.Find(grp => grp.group == pl.group).players.Add("&f+" + Server.DefaultColor + foundName + " (" + pl.level.name + ")");
                            }
                            else
                            {
                                playerList.Find(grp => grp.group == pl.group).players.Add(foundName + " (" + pl.level.name + ")");
                            }
                        }
                        else
                        {
                            Player.SendMessage(p, "There are no players of that rank online.");
                            return;
                        }
                    }
                }
                Player.SendMessage(p, "There are " + totalPlayers + " players online.");
                if (devs.Length > 0)
                {
                    Player.SendMessage(p, ":&9Developers:" + Server.DefaultColor + devs.Trim(','));
                }

                for (int i = playerList.Count - 1; i >= 0; i--)
                {
                    groups groups = playerList[i];
                    if (groups.players.Count > 0 || Server.showEmptyRanks)
                    {
                        string appendString = "";
                        foreach (string player in groups.players)
                        {
                            appendString += ", " + player;
                        }

                        if (appendString != "")
                        {
                            appendString = appendString.Remove(0, 2);
                        }
                        appendString = ":" + groups.group.color + getPlural(groups.group.trueName) + ": " + appendString;

                        Player.SendMessage(p, appendString);
                    }
                }
            }
            catch (Exception e) { Server.ErrorLog(e); }
        }