Esempio n. 1
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();
        }
Esempio n. 2
0
        /// <summary>
        /// Load up all server groups
        /// </summary>
        public static void InitAll()
        {
            GroupList = new List <Group>();

            if (File.Exists("properties/ranks.properties"))
            {
                string[] lines = File.ReadAllLines("properties/ranks.properties");

                Group thisGroup = new Group();
                int   gots = 0, version = 1;
                if (lines.Length > 0 && lines[0].StartsWith("#Version "))
                {
                    try { version = int.Parse(lines[0].Remove(0, 9)); } catch { Server.s.Log("The ranks.properties version header is invalid! Ranks may fail to load!"); }
                }

                foreach (string s in lines)
                {
                    try {
                        if (s == "" || s[0] == '#')
                        {
                            continue;
                        }
                        if (s.Split('=').Length == 2)
                        {
                            string property = s.Split('=')[0].Trim();
                            string value    = s.Split('=')[1].Trim();

                            if (thisGroup.name == "" && property.ToLower() != "rankname")
                            {
                                Server.s.Log("Hitting an error at " + s + " of ranks.properties");
                            }
                            else
                            {
                                switch (property.ToLower())
                                {
                                case "rankname":
                                    gots      = 0;
                                    thisGroup = new Group();

                                    if (value.ToLower() == "adv" || value.ToLower() == "op" || value.ToLower() == "super" || value.ToLower() == "nobody" || value.ToLower() == "noone")
                                    {
                                        Server.s.Log("Cannot have a rank named \"" + value.ToLower() + "\", this rank is hard-coded.");
                                    }
                                    else if (GroupList.Find(grp => grp.name == value.ToLower()) == null)
                                    {
                                        thisGroup.trueName = value;
                                    }
                                    else
                                    {
                                        Server.s.Log("Cannot add the rank " + value + " twice");
                                    }
                                    break;

                                case "permission":
                                    int foundPermission;

                                    try {
                                        foundPermission = int.Parse(value);
                                    } catch { Server.s.Log("Invalid permission on " + s); break; }

                                    if (thisGroup.Permission != LevelPermission.Null)
                                    {
                                        Server.s.Log("Setting permission again on " + s);
                                        gots--;
                                    }

                                    bool allowed = GroupList.Find(grp => grp.Permission == (LevelPermission)foundPermission) == null;

                                    if (foundPermission > 119 || foundPermission < -50)
                                    {
                                        Server.s.Log("Permission must be between -50 and 119 for ranks");
                                        break;
                                    }

                                    if (allowed)
                                    {
                                        gots++;
                                        thisGroup.Permission = (LevelPermission)foundPermission;
                                    }
                                    else
                                    {
                                        Server.s.Log("Cannot have 2 ranks set at permission level " + value);
                                    }
                                    break;

                                case "limit":
                                    int foundLimit;

                                    try {
                                        foundLimit = int.Parse(value);
                                    } catch { Server.s.Log("Invalid limit on " + s); break; }

                                    gots++;
                                    thisGroup.maxBlocks = foundLimit;
                                    break;

                                case "maxundo":
                                    int foundMax;

                                    try {
                                        foundMax = int.Parse(value);
                                    } catch { Server.s.Log("Invalid maximum on " + s); break; }

                                    gots++;
                                    thisGroup.maxUndo = foundMax;
                                    break;

                                case "color":
                                    char foundChar;

                                    try {
                                        foundChar = char.Parse(value);
                                    } catch { Server.s.Log("Incorrect color on " + s); break; }

                                    if ((foundChar >= '0' && foundChar <= '9') || (foundChar >= 'a' && foundChar <= 'f'))
                                    {
                                        gots++;
                                        thisGroup.color = foundChar.ToString(CultureInfo.InvariantCulture);
                                    }
                                    else
                                    {
                                        Server.s.Log("Invalid color code at " + s);
                                    }
                                    break;

                                case "filename":
                                    if (value.Contains("\\") || value.Contains("/"))
                                    {
                                        Server.s.Log("Invalid filename on " + s);
                                        break;
                                    }

                                    gots++;
                                    thisGroup.fileName = value;
                                    break;

                                case "motd":
                                    if (!String.IsNullOrEmpty(value))
                                    {
                                        thisGroup.MOTD = value;
                                    }
                                    gots++;
                                    break;
                                }

                                if ((gots >= 4 && version < 2) || (gots >= 5 && version < 3) || gots >= 6)
                                {
                                    if (version < 2)
                                    {
                                        if ((int)thisGroup.Permission >= 100)
                                        {
                                            thisGroup.maxUndo = int.MaxValue;
                                        }
                                        else if ((int)thisGroup.Permission >= 80)
                                        {
                                            thisGroup.maxUndo = 5400;
                                        }
                                    }

                                    GroupList.Add(new Group(thisGroup.Permission, thisGroup.maxBlocks, thisGroup.maxUndo, thisGroup.trueName, thisGroup.color[0], thisGroup.MOTD, thisGroup.fileName));
                                }
                            }
                        }
                        else
                        {
                            Server.s.Log("In ranks.properties, the line " + s + " is wrongly formatted");
                        }
                    } catch (Exception e) { Server.s.Log("Encountered an error at line \"" + s + "\" in ranks.properties"); Server.ErrorLog(e); }
                }
            }

            if (GroupList.Find(grp => grp.Permission == LevelPermission.Banned) == null)
            {
                GroupList.Add(new Group(LevelPermission.Banned, 1, 1, "Banned", '8', String.Empty, "banned.txt"));
            }
            if (GroupList.Find(grp => grp.Permission == LevelPermission.Guest) == null)
            {
                GroupList.Add(new Group(LevelPermission.Guest, 1, 120, "Guest", '7', String.Empty, "guest.txt"));
            }
            if (GroupList.Find(grp => grp.Permission == LevelPermission.Builder) == null)
            {
                GroupList.Add(new Group(LevelPermission.Builder, 400, 300, "Builder", '2', String.Empty, "builders.txt"));
            }
            if (GroupList.Find(grp => grp.Permission == LevelPermission.AdvBuilder) == null)
            {
                GroupList.Add(new Group(LevelPermission.AdvBuilder, 1200, 900, "AdvBuilder", '3', String.Empty, "advbuilders.txt"));
            }
            if (GroupList.Find(grp => grp.Permission == LevelPermission.Operator) == null)
            {
                GroupList.Add(new Group(LevelPermission.Operator, 2500, 5400, "Operator", 'c', String.Empty, "operators.txt"));
            }
            if (GroupList.Find(grp => grp.Permission == LevelPermission.Admin) == null)
            {
                GroupList.Add(new Group(LevelPermission.Admin, 65536, int.MaxValue, "SuperOP", 'e', String.Empty, "uberOps.txt"));
            }
            GroupList.Add(new Group(LevelPermission.Nobody, 65536, -1, "Nobody", '0', String.Empty, "nobody.txt"));

            bool swap = true; Group storedGroup;

            while (swap)
            {
                swap = false;
                for (int i = 0; i < GroupList.Count - 1; i++)
                {
                    if (GroupList[i].Permission > GroupList[i + 1].Permission)
                    {
                        swap             = true;
                        storedGroup      = GroupList[i];
                        GroupList[i]     = GroupList[i + 1];
                        GroupList[i + 1] = storedGroup;
                    }
                }
            }

            if (Group.Find(Server.defaultRank) != null)
            {
                standard = Group.Find(Server.defaultRank);
            }
            else
            {
                standard = Group.findPerm(LevelPermission.Guest);
            }

            foreach (Player pl in Player.players)
            {
                pl.group = GroupList.Find(g => g.name == pl.group.name);
            }
            if (OnGroupLoad != null)
            {
                OnGroupLoad();
            }
            OnGroupLoadEvent.Call();
            saveGroups(GroupList);
        }
Esempio n. 3
0
        public void LoadSettings()
        {
            if (!File.Exists("properties/lavasurvival.properties"))
            {
                SaveSettings();
                return;
            }

            foreach (string line in File.ReadAllLines("properties/lavasurvival.properties"))
            {
                try
                {
                    if (line[0] != '#')
                    {
                        string value = line.Substring(line.IndexOf(" = ") + 3);
                        switch (line.Substring(0, line.IndexOf(" = ")).ToLower())
                        {
                        case "start-on-startup":
                            startOnStartup = bool.Parse(value);
                            break;

                        case "send-afk-to-main":
                            sendAfkMain = bool.Parse(value);
                            break;

                        case "vote-count":
                            voteCount = (byte)MathHelper.Clamp(decimal.Parse(value), 2, 10);
                            break;

                        case "vote-time":
                            voteTime = double.Parse(value);
                            break;

                        case "lives":
                            lifeNum = int.Parse(value);
                            break;

                        case "setup-rank":
                            if (Group.Find(value.ToLower()) != null)
                            {
                                setupRank = Group.Find(value.ToLower()).Permission;
                            }
                            break;

                        case "control-rank":
                            if (Group.Find(value.ToLower()) != null)
                            {
                                controlRank = Group.Find(value.ToLower()).Permission;
                            }
                            break;

                        case "maps":
                            foreach (string mapname in value.Split(','))
                            {
                                if (!String.IsNullOrEmpty(mapname) && !maps.Contains(mapname))
                                {
                                    maps.Add(mapname);
                                }
                            }
                            break;
                        }
                    }
                }
                catch (Exception e) { Server.ErrorLog(e); }
            }
        }
Esempio n. 4
0
        //During Game Main Methods
        public void Start()
        {
            GameStatus = TntWarsGameStatus.AboutToStart;
            //Checking Backups & physics etc.
            {
                BackupNumber = lvl.Backup(true);
                if (BackupNumber <= 0)
                {
                    SendAllPlayersMessage(c.red + "Backing up Level for TNT Wars failed, Stopping game");
                    Player.GlobalMessageOps(c.red + "Backing up Level for TNT Wars failed, Stopping game");
                    GameStatus = TntWarsGameStatus.Finished;
                    return;
                }
                Server.s.Log("Backed up " + lvl.name + " (" + BackupNumber.ToString() + ") for TNT Wars");
            }
            //Map stuff
            lvl.setPhysics(3);
            lvl.permissionbuild = Group.Find(Server.defaultRank).Permission;
            lvl.permissionvisit = Group.Find(Server.defaultRank).Permission;
            lvl.Killer          = true;
            //Seting Up Some Player stuff
            {
                foreach (player p in Players)
                {
                    p.p.PlayingTntWars       = true;
                    p.p.CurrentAmountOfTnt   = 0;
                    p.p.CurrentTntGameNumber = GameNumber;
                    if (GameDifficulty == TntWarsDifficulty.Easy || GameDifficulty == TntWarsDifficulty.Normal)
                    {
                        p.p.TntWarsHealth = 2;
                    }
                    else
                    {
                        p.p.TntWarsHealth = 1;
                    }
                    p.p.HarmedBy = null;
                    if (GracePeriod)
                    {
                        p.p.canBuild = false;
                    }
                    if (p.spec)
                    {
                        p.p.canBuild = false;
                        Player.SendMessage(p.p, "TNT Wars: Disabled building because you are a spectator!");
                    }
                    p.p.TntWarsKillStreak              = 0;
                    p.p.TntWarsScoreMultiplier         = 1f;
                    p.p.TNTWarsLastKillStreakAnnounced = 0;
                    SetTitlesAndColor(p);
                }
                if (GracePeriod)
                {
                    SendAllPlayersMessage("TNT Wars: Disabled building during Grace Period!");
                }
            }
            //Spawn them (And if needed, move them to the correct level!)
            {
                foreach (player p in Players.Where(p => p.p.level != lvl))
                {
                    Command.all.Find("goto").Use(p.p, lvl.name);
                    while (p.p.Loading)
                    {
                        Thread.Sleep(250);
                    }
                    p.p.inTNTwarsMap = true;
                }
                if (GameMode == TntWarsGameMode.TDM)
                {
                    Command.all.Find("reveal").Use(null, "all " + lvl.name);
                }                                                                                                //So peoples names apear above their heads in the right color!
                foreach (player p in Players)
                {
                    Command.all.Find("spawn").Use(p.p, ""); //This has to be after reveal so that they spawn in the correct place!!
                    Thread.Sleep(250);
                }
            }
            //Announcing Etc.
            string Gamemode = "Free For All";

            if (GameMode == TntWarsGameMode.TDM)
            {
                Gamemode = "Team Deathmatch";
            }
            string Difficulty    = "Normal";
            string HitsToDie     = "2";
            string explosiontime = "medium";
            string explosionsize = "normal";

            switch (GameDifficulty)
            {
            case TntWarsDifficulty.Easy:
                Difficulty    = "Easy";
                explosiontime = "long";
                break;

            case TntWarsDifficulty.Normal:
                Difficulty = "Normal";
                break;

            case TntWarsDifficulty.Hard:
                HitsToDie  = "1";
                Difficulty = "Hard";
                break;

            case TntWarsDifficulty.Extreme:
                HitsToDie     = "1";
                explosiontime = "short";
                explosionsize = "big";
                Difficulty    = "Extreme";
                break;
            }
            string teamkillling = "Disabled";

            if (TeamKills)
            {
                teamkillling = "Enabled";
            }
            Player.GlobalMessage(c.red + "TNT Wars " + Server.DefaultColor + "on '" + lvl.name + "' has started " + c.teal + Gamemode + Server.DefaultColor + " with a difficulty of " + c.teal + Difficulty + Server.DefaultColor + " (" + c.teal + HitsToDie + Server.DefaultColor + " hits to die, a " + c.teal + explosiontime + Server.DefaultColor + " explosion delay and with a " + c.teal + explosionsize + Server.DefaultColor + " explosion size)" + ", team killing is " + c.teal + teamkillling + Server.DefaultColor + " and you can place " + c.teal + TntPerPlayerAtATime.ToString() + Server.DefaultColor + " TNT at a time and there is a score limit of " + c.teal + ScoreLimit.ToString() + Server.DefaultColor + "!!");
            if (GameMode == TntWarsGameMode.TDM)
            {
                SendAllPlayersMessage("TNT Wars: Start your message with ':' to send it as a team chat!");
            }
            //GracePeriod
            if (GracePeriod) //Check This Grace Stuff
            {
                GameStatus = TntWarsGameStatus.GracePeriod;
                int GracePeriodSecsRemaining = GracePeriodSecs;
                SendAllPlayersMessage("TNT Wars: Grace Period of " + c.lime + GracePeriodSecsRemaining.ToString() + Server.DefaultColor + " seconds");
                while (GracePeriodSecsRemaining > 0)
                {
                    switch (GracePeriodSecsRemaining)
                    {
                    case 300:
                        SendAllPlayersMessage("TNT Wars: " + c.teal + "5" + Server.DefaultColor + " minutes remaining!");
                        break;

                    case 240:
                        SendAllPlayersMessage("TNT Wars: " + c.teal + "4" + Server.DefaultColor + " minutes remaining!");
                        break;

                    case 180:
                        SendAllPlayersMessage("TNT Wars: " + c.teal + "3" + Server.DefaultColor + " minutes remaining!");
                        break;

                    case 120:
                        SendAllPlayersMessage("TNT Wars: " + c.teal + "2" + Server.DefaultColor + " minutes remaining!");
                        break;

                    case 90:
                        SendAllPlayersMessage("TNT Wars: " + c.teal + "1" + Server.DefaultColor + " minute and " + c.teal + "30" + Server.DefaultColor + " seconds remaining!");
                        break;

                    case 60:
                        SendAllPlayersMessage("TNT Wars: " + c.teal + "1" + Server.DefaultColor + " minute remaining!");
                        break;

                    case 45:
                        SendAllPlayersMessage("TNT Wars: " + c.teal + "45" + Server.DefaultColor + " seconds remaining!");
                        break;

                    case 30:
                        SendAllPlayersMessage("TNT Wars: " + c.teal + "30" + Server.DefaultColor + " seconds remaining!");
                        break;

                    case 15:
                        SendAllPlayersMessage("TNT Wars: " + c.teal + "15" + Server.DefaultColor + " seconds remaining!");
                        break;

                    case 10:
                        SendAllPlayersMessage("TNT Wars: " + c.teal + "10" + Server.DefaultColor + " seconds remaining!");
                        break;

                    case 9:
                        SendAllPlayersMessage("TNT Wars: " + c.teal + "9" + Server.DefaultColor + " seconds remaining!");
                        break;

                    case 8:
                        SendAllPlayersMessage("TNT Wars: " + c.teal + "8" + Server.DefaultColor + " seconds remaining!");
                        break;

                    case 7:
                        SendAllPlayersMessage("TNT Wars: " + c.teal + "7" + Server.DefaultColor + " seconds remaining!");
                        break;

                    case 6:
                        SendAllPlayersMessage("TNT Wars: " + c.teal + "6" + Server.DefaultColor + " seconds remaining!");
                        break;

                    case 5:
                        SendAllPlayersMessage("TNT Wars: " + c.teal + "5" + Server.DefaultColor + " seconds remaining!");
                        break;

                    case 4:
                        SendAllPlayersMessage("TNT Wars: " + c.teal + "4" + Server.DefaultColor + " seconds remaining!");
                        break;

                    case 3:
                        SendAllPlayersMessage("TNT Wars: " + c.teal + "3" + Server.DefaultColor + " seconds remaining!");
                        break;

                    case 2:
                        SendAllPlayersMessage("TNT Wars: " + c.teal + "2" + Server.DefaultColor + " seconds remaining!");
                        break;

                    case 1:
                        SendAllPlayersMessage("TNT Wars: " + c.teal + "1" + Server.DefaultColor + " second remaining!");
                        break;
                    }

                    Thread.Sleep(1000);
                    GracePeriodSecsRemaining -= 1;
                }
                SendAllPlayersMessage("TNT Wars: Grace Period is over!!!!!");
                SendAllPlayersMessage("TNT Wars: You may now place " + c.red + "TNT");
            }
            SendAllPlayersMessage("TNT Wars: " + c.white + "The Game Has Started!!!!!");
            GameStatus = TntWarsGameStatus.InProgress;
            foreach (player p in Players)
            {
                if (p.spec == false)
                {
                    p.p.canBuild = true;
                }
            }
            if (GracePeriod)
            {
                SendAllPlayersMessage("TNT Wars: You can now build!!");
            }
            //MainLoop
            while (!Finished())
            {
                int i = 1; //For making a top 5 (or whatever) players announcement every 3 loops (if TDM)
                Thread.Sleep(3 * 1000); if (Finished())
                {
                    break;                                      //--\\
                }
                Thread.Sleep(3 * 1000); if (Finished())
                {
                    break;                                      //----\
                }
                Thread.Sleep(3 * 1000); if (Finished())
                {
                    break;                                      //-----> So that if it finsihes, we don't have to wait like 10 secs for the announcement!!
                }
                Thread.Sleep(3 * 1000); if (Finished())
                {
                    break;                                      //----/
                }
                Thread.Sleep(3 * 1000); if (Finished())
                {
                    break;                                      //--//
                }
                if (GameMode == TntWarsGameMode.TDM)
                {
                    if (i < 3)
                    {
                        SendAllPlayersScore(true, true);
                    }
                    if (i >= 3)
                    {
                        SendAllPlayersScore(true, true, true);
                        i = 0;
                    }
                    i++;
                }
                else if (GameMode == TntWarsGameMode.FFA)
                {
                    SendAllPlayersScore(false, true, true);
                }
            }
            END();
        }