Beispiel #1
0
        public static bool Load(Player p)
        {
            if (File.Exists("players/" + p.name.ToLower() + "DB.txt"))
            {
                foreach (string line in File.ReadAllLines("players/" + p.name.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 "title":
                                p.title = value;
                                section = key;
                                break;

                            case "titlecolor":
                                p.titlecolor = value;
                                section      = key;
                                break;

                            case "color":
                                p.color = value;
                                section = key;
                                break;

                            case "money":
                                p.money = int.Parse(value);
                                section = key;
                                break;

                            case "timespent":
                                p.time  = value;
                                section = key;
                                break;

                            case "firstlogin":
                                p.firstLogin = DateTime.Parse(value);
                                section      = key;
                                break;

                            case "lastlogin":
                                p.lastlogin = DateTime.Parse(value);
                                section     = key;
                                break;

                            case "totallogins":
                                p.totalLogins = int.Parse(value) + 1;
                                section       = key;
                                break;

                            case "totalkicked":
                                p.totalKicked = int.Parse(value);
                                section       = key;
                                break;

                            case "overalldeath":
                                p.overallDeath = int.Parse(value);
                                section        = key;
                                break;

                            case "overallblocks":
                                p.overallBlocks = int.Parse(value);
                                section         = key;
                                break;

                            case "nick":
                                p.DisplayName = value;
                                section       = key;
                                break;
                            }

                            EXPLevel currLevel = null;
                            foreach (EXPLevel lvl in EXPLevel.levels)
                            {
                                if (lvl.requiredEXP <= p.points)
                                {
                                    currLevel = lvl;
                                }
                            }

                            if (currLevel != null)
                            {
                                p.explevel = currLevel;
                            }
                            else
                            {
                                p.explevel = EXPLevel.levels[0];
                            }
                        } catch (Exception e) {
                            Server.s.Log("Loading " + p.name + "'s database failed at section: " + section);
                            Server.ErrorLog(e);
                        }

                        p.timeLogged = DateTime.Now;
                    }
                }
                return(true);
            }
            else
            {
                p.title         = "";
                p.titlecolor    = "";
                p.color         = p.group.color;
                p.money         = 0;
                p.firstLogin    = DateTime.Now;
                p.lastlogin     = DateTime.Now;
                p.totalLogins   = 1;
                p.totalKicked   = 0;
                p.overallDeath  = 0;
                p.overallBlocks = 0;
                p.points        = 0;
                p.time          = "0 0 0 1";
                p.timeLogged    = DateTime.Now;
                p.explevel      = EXPLevel.levels[0];
                Save(p);
                return(false);
            }
        }
 public static void Call(Level l)
 {
     events.ForEach(delegate(OnLevelLoadedEvent p1)
     {
         try
         {
             p1.method(l);
         }
         catch (Exception e) { Server.s.Log("The plugin " + p1.plugin.name + " errored when calling the LevelUnload Event!"); Server.ErrorLog(e); }
     });
 }
Beispiel #3
0
 public static void Call(Player p, string message)
 {
     events.ForEach(delegate(OnMessageRecieveEvent p1)
     {
         try
         {
             p1.method(p, message);
         }
         catch (Exception e) { Server.s.Log("The plugin " + p1.plugin.name + " errored when calling the MessageRecieve Event!"); Server.ErrorLog(e); }
     });
 }
Beispiel #4
0
        public MapSettings LoadMapSettings(string name)
        {
            MapSettings settings = new MapSettings(name);

            if (!Directory.Exists(propsPath))
            {
                Directory.CreateDirectory(propsPath);
            }
            if (!File.Exists(propsPath + name + ".properties"))
            {
                SaveMapSettings(settings);
                return(settings);
            }

            foreach (string line in File.ReadAllLines(propsPath + name + ".properties"))
            {
                try
                {
                    if (line[0] != '#')
                    {
                        string[] sp;
                        string   value = line.Substring(line.IndexOf(" = ") + 3);
                        switch (line.Substring(0, line.IndexOf(" = ")).ToLower())
                        {
                        case "fast-chance":
                            settings.fast = (byte)MathHelper.Clamp(decimal.Parse(value), 0, 100);
                            break;

                        case "killer-chance":
                            settings.killer = (byte)MathHelper.Clamp(decimal.Parse(value), 0, 100);
                            break;

                        case "destroy-chance":
                            settings.destroy = (byte)MathHelper.Clamp(decimal.Parse(value), 0, 100);
                            break;

                        case "water-chance":
                            settings.water = (byte)MathHelper.Clamp(decimal.Parse(value), 0, 100);
                            break;

                        case "layer-chance":
                            settings.layer = (byte)MathHelper.Clamp(decimal.Parse(value), 0, 100);
                            break;

                        case "layer-height":
                            settings.layerHeight = int.Parse(value);
                            break;

                        case "layer-count":
                            settings.layerCount = int.Parse(value);
                            break;

                        case "layer-interval":
                            settings.layerInterval = double.Parse(value);
                            break;

                        case "round-time":
                            settings.roundTime = double.Parse(value);
                            break;

                        case "flood-time":
                            settings.floodTime = double.Parse(value);
                            break;

                        case "block-flood":
                            sp = value.Split(',');
                            settings.blockFlood = new Pos(ushort.Parse(sp[0]), ushort.Parse(sp[1]), ushort.Parse(sp[2]));
                            break;

                        case "block-layer":
                            sp = value.Split(',');
                            settings.blockLayer = new Pos(ushort.Parse(sp[0]), ushort.Parse(sp[1]), ushort.Parse(sp[2]));
                            break;

                        case "safe-zone":
                            sp = value.Split('-');
                            string[] p1 = sp[0].Split(','), p2 = sp[1].Split(',');
                            settings.safeZone = new Pos[] { new Pos(ushort.Parse(p1[0]), ushort.Parse(p1[1]), ushort.Parse(p1[2])), new Pos(ushort.Parse(p2[0]), ushort.Parse(p2[1]), ushort.Parse(p2[2])) };
                            break;
                        }
                    }
                }
                catch (Exception e) { Server.ErrorLog(e); }
            }
            return(settings);
        }
Beispiel #5
0
        public void AddExtension(string Extension, int version)
        {
            lock (this)
            {
                switch (Extension.Trim())
                {
                case "ClickDistance":
                    ClickDistance = version;
                    break;

                case "CustomBlocks":
                    CustomBlocks = version;
                    if (version == 1)
                    {
                        SendCustomBlockSupportLevel(1);
                    }
                    break;

                case "HeldBlock":
                    HeldBlock = version;
                    break;

                case "TextHotKey":
                    TextHotKey = version;
                    break;

                case "ExtPlayerList":
                    ExtPlayerList = version;
                    spawned       = true;
                    if (version > 0)
                    {
                        Player.players.ForEach(delegate(Player p)
                        {
                            if (p.HasExtension("ExtPlayerList", 2))
                            {
                                p.SendExtAddPlayerName(id, name, group, color + name);
                            }
                            if (HasExtension("ExtPlayerList", 2))
                            {
                                SendExtAddPlayerName(p.id, p.name, p.group, p.color + p.name);
                            }
                        });
                    }

                    try
                    {
                        ushort x = (ushort)((0.5 + level.spawnx) * 32);
                        ushort y = (ushort)((1 + level.spawny) * 32);
                        ushort z = (ushort)((0.5 + level.spawnz) * 32);
                        pos = new ushort[3] {
                            x, y, z
                        }; rot = new byte[2] {
                            level.rotx, level.roty
                        };

                        GlobalSpawn(this, x, y, z, rot[0], rot[1], true);
                        foreach (Player p in players)
                        {
                            if (p.level == level && p != this && !p.hidden)
                            {
                                SendSpawn(p.id, p.color + p.name, p.pos[0], p.pos[1], p.pos[2], p.rot[0], p.rot[1], p.DisplayName, p.SkinName);
                            }
                            if (HasExtension("ChangeModel"))
                            {
                                if (p == this)
                                {
                                    unchecked { SendChangeModel((byte)-1, model); }
                                }
                                else
                                {
                                    SendChangeModel(p.id, p.model);
                                }
                            }
                        }
                        foreach (PlayerBot pB in PlayerBot.playerbots)
                        {
                            if (pB.level == level)
                            {
                                SendSpawn(pB.id, pB.color + pB.name, pB.pos[0], pB.pos[1], pB.pos[2], pB.rot[0], pB.rot[1], pB.name, pB.name);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Server.ErrorLog(e);
                        Server.s.Log("Error spawning player \"" + name + "\"");
                    }
                    break;

                case "EnvColors":
                    EnvColors = version;
                    break;

                case "SelectionCuboid":
                    SelectionCuboid = version;
                    break;

                case "BlockPermissions":
                    BlockPermissions = version;
                    break;

                case "ChangeModel":
                    ChangeModel = version;
                    break;

                case "EnvMapAppearance":
                    EnvMapAppearance = version;
                    break;

                case "EnvWeatherType":
                    EnvWeatherType = version;
                    break;

                case "HackControl":
                    HackControl = version;
                    break;

                case "EmoteFix":
                    EmoteFix = version;
                    break;

                case "MessageTypes":
                    MessageTypes = version;
                    break;
                }
            }
        }
 public static void Call(Player p, Group newrank)
 {
     events.ForEach(delegate(OnPlayerRankSetEvent p1)
     {
         try
         {
             p1.method(p, newrank);
         }
         catch (Exception e) { Server.s.Log("The plugin " + p1.plugin.name + " errored when calling the LevelUnload Event!"); Server.ErrorLog(e); }
     });
 }
        /// <summary>
        /// Load a plugin
        /// </summary>
        /// <param name="pluginname">The file path of the dll file</param>
        /// <param name="startup">Is this startup?</param>
        public static void Load(string pluginname, bool startup)
        {
            String creator = "";

            try
            {
                object   instance = null;
                Assembly lib      = null;
                using (FileStream fs = File.Open(pluginname, FileMode.Open))
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        byte[] buffer = new byte[1024];
                        int    read   = 0;
                        while ((read = fs.Read(buffer, 0, 1024)) > 0)
                        {
                            ms.Write(buffer, 0, read);
                        }
                        lib = Assembly.Load(ms.ToArray());
                        ms.Close();
                        ms.Dispose();
                    }
                    fs.Close();
                    fs.Dispose();
                }
                try
                {
                    foreach (Type t in lib.GetTypes())
                    {
                        if (t.BaseType == typeof(Plugin))
                        {
                            instance = Activator.CreateInstance(t);
                            break;
                        }
                    }
                }
                catch { }
                if (instance == null)
                {
                    Server.s.Log("The plugin " + pluginname + " couldn't be loaded!");
                    return;
                }
                String plugin_version = ((Plugin)instance).MCForge_Version;
                if (!String.IsNullOrEmpty(plugin_version) && new Version(plugin_version) > Server.Version)
                {
                    Server.s.Log("This plugin (" + ((Plugin)instance).name + ") isn't compatible with this version of MCForge!");
                    Thread.Sleep(1000);
                    if (Server.unsafe_plugin)
                    {
                        Server.s.Log("Will attempt to load!");
                        goto here;
                    }
                    else
                    {
                        return;
                    }
                }
here:
                Plugin.all.Add((Plugin)instance);
                creator = ((Plugin)instance).creator;
                if (((Plugin)instance).LoadAtStartup)
                {
                    ((Plugin)instance).Load(startup);
                    Server.s.Log("Plugin: " + ((Plugin)instance).name + " loaded...build: " + ((Plugin)instance).build);
                }
                else
                {
                    Server.s.Log("Plugin: " + ((Plugin)instance).name + " was not loaded, you can load it with /pload");
                }
                Server.s.Log(((Plugin)instance).welcome);
                return;
            }
            catch (FileNotFoundException)
            {
                Plugin_Simple.Load(pluginname, startup);
            }
            catch (BadImageFormatException)
            {
                Plugin_Simple.Load(pluginname, startup);
            }
            catch (PathTooLongException)
            {
            }
            catch (FileLoadException)
            {
                Plugin_Simple.Load(pluginname, startup);
            }
            catch (Exception e)
            {
                try { Server.s.Log("Attempting a simple plugin!"); if (Plugin_Simple.Load(pluginname, startup))
                      {
                          return;
                      }
                }
                catch { }
                Server.ErrorLog(e);
                Server.s.Log("The plugin " + pluginname + " failed to load!");
                if (creator != "")
                {
                    Server.s.Log("You can go bug " + creator + " about it.");
                }
                Thread.Sleep(1000);
            }
        }
 public static void Call(Player p, byte[] rot)
 {
     events.ForEach(delegate(PlayerRotateEvent p1)
     {
         try
         {
             p1.method(p, rot);
         }
         catch (Exception e) { Server.s.Log("The plugin " + p1.plugin.name + " errored when calling the PlayerRotate Event!"); Server.ErrorLog(e); }
     });
 }
Beispiel #9
0
 public override void Use(Player p, string message)
 { // TODO
     try
     {
         if (message != "")
         {
             Help(p); return;
         }
         message = "";
         string message2 = "";
         bool   Once     = false;
         Server.levels.ForEach(delegate(Level level)
         {
             if (p != null && level.permissionvisit <= p.group.Permission)
             {
                 if (Group.findPerm(level.permissionbuild) != null)
                 {
                     message += ", " + Group.findPerm(level.permissionbuild).color + level.name + " &b[" + level.physics + "]";
                 }
                 else
                 {
                     message += ", " + level.name + " &b[" + level.physics + "]";
                 }
             }
             else
             {
                 if (!Once)
                 {
                     Once = true;
                     if (Group.findPerm(level.permissionvisit) != null)
                     {
                         message2 += Group.findPerm(level.permissionvisit).color + level.name + " &b[" + level.physics + "]";
                     }
                     else
                     {
                         message2 += level.name + " &b[" + level.physics + "]";
                     }
                 }
                 else
                 {
                     if (Group.findPerm(level.permissionvisit) != null)
                     {
                         message2 += ", " + Group.findPerm(level.permissionvisit).color + level.name + " &b[" + level.physics + "]";
                     }
                     else
                     {
                         message2 += ", " + level.name + " &b[" + level.physics + "]";
                     }
                 }
             }
         });
         Player.SendMessage(p, "Loaded: " + message.Remove(0, 2));
         if (message2 != "")
         {
             Player.SendMessage(p, "Can't Goto: " + message2);
         }
         Player.SendMessage(p, "Use &4/unloaded for unloaded levels.");
     }
     catch (Exception e)
     {
         Server.ErrorLog(e);
     }
 }
Beispiel #10
0
        public override void Use(Player p, string message)
        {
            try
            {
                message.ToLower();
                switch (message)
                {
                case "":
                    if (Server.oldHelp)
                    {
                        goto case "old";
                    }
                    else
                    {
                        Player.SendMessage(p, "Use &b/help ranks" + Server.DefaultColor + " for a list of ranks.");
                        Player.SendMessage(p, "Use &b/help build" + Server.DefaultColor + " for a list of building commands.");
                        Player.SendMessage(p, "Use &b/help mod" + Server.DefaultColor + " for a list of moderation commands.");
                        Player.SendMessage(p, "Use &b/help information" + Server.DefaultColor + " for a list of information commands.");
                        Player.SendMessage(p, "Use &b/help games" + Server.DefaultColor + " for a list of game commands.");
                        Player.SendMessage(p, "Use &b/help other" + Server.DefaultColor + " for a list of other commands.");
                        Player.SendMessage(p, "Use &b/help colors" + Server.DefaultColor + " to view the color codes.");
                        Player.SendMessage(p, "Use &b/help short" + Server.DefaultColor + " for a list of shortcuts.");
                        Player.SendMessage(p, "Use &b/help old" + Server.DefaultColor + " to view the Old help menu.");
                        Player.SendMessage(p, "Use &b/help [command] or /help [block] " + Server.DefaultColor + "to view more info.");
                    } break;

                case "ranks":
                    message = "";
                    foreach (Group grp in Group.GroupList)
                    {
                        if (grp.name != "nobody")     // Note that -1 means max undo.  Undo anything and everything.
                        {
                            Player.SendMessage(p, grp.color + grp.name + " - &bCmd: " + grp.maxBlocks + " - &2Undo: " + ((grp.maxUndo != -1) ? grp.maxUndo.ToString() : "max") + " - &cPerm: " + (int)grp.Permission);
                        }
                    }
                    break;

                case "build":
                    message = "";
                    foreach (Command comm in Command.all.commands)
                    {
                        if (p == null || p.group.commands.All().Contains(comm))
                        {
                            if (comm.type.Contains("build"))
                            {
                                message += ", " + getColor(comm.name) + comm.name;
                            }
                        }
                    }

                    if (message == "")
                    {
                        Player.SendMessage(p, "No commands of this type are available to you."); break;
                    }
                    Player.SendMessage(p, "Building commands you may use:");
                    Player.SendMessage(p, message.Remove(0, 2) + ".");
                    break;

                case "mod":
                case "moderation":
                    message = "";
                    foreach (Command comm in Command.all.commands)
                    {
                        if (p == null || p.group.commands.All().Contains(comm))
                        {
                            if (comm.type.Contains("mod"))
                            {
                                message += ", " + getColor(comm.name) + comm.name;
                            }
                        }
                    }

                    if (message == "")
                    {
                        Player.SendMessage(p, "No commands of this type are available to you."); break;
                    }
                    Player.SendMessage(p, "Moderation commands you may use:");
                    Player.SendMessage(p, message.Remove(0, 2) + ".");
                    break;

                case "information":
                    message = "";
                    foreach (Command comm in Command.all.commands)
                    {
                        if (p == null || p.group.commands.All().Contains(comm))
                        {
                            if (comm.type.Contains("info"))
                            {
                                message += ", " + getColor(comm.name) + comm.name;
                            }
                        }
                    }

                    if (message == "")
                    {
                        Player.SendMessage(p, "No commands of this type are available to you."); break;
                    }
                    Player.SendMessage(p, "Information commands you may use:");
                    Player.SendMessage(p, message.Remove(0, 2) + ".");
                    break;

                case "games":
                case "game":
                    message = "";
                    foreach (Command comm in Command.all.commands)
                    {
                        if (p == null || p.group.commands.All().Contains(comm))
                        {
                            if (comm.type.Contains("game"))
                            {
                                message += ", " + getColor(comm.name) + comm.name;
                            }
                        }
                    }

                    if (message == "")
                    {
                        Player.SendMessage(p, "No commands of this type are available to you."); break;
                    }
                    Player.SendMessage(p, "Game commands you may use:");
                    Player.SendMessage(p, message.Remove(0, 2) + ".");
                    break;

                case "other":
                    message = "";
                    foreach (Command comm in Command.all.commands)
                    {
                        if (p == null || p.group.commands.All().Contains(comm))
                        {
                            if (comm.type.Contains("other"))
                            {
                                message += ", " + getColor(comm.name) + comm.name;
                            }
                        }
                    }

                    if (message == "")
                    {
                        Player.SendMessage(p, "No commands of this type are available to you."); break;
                    }
                    Player.SendMessage(p, "Other commands you may use:");
                    Player.SendMessage(p, message.Remove(0, 2) + ".");
                    break;

                case "short":
                    message = "";
                    foreach (Command comm in Command.all.commands)
                    {
                        if (p == null || p.group.commands.All().Contains(comm))
                        {
                            if (comm.shortcut != "")
                            {
                                message += ", &b" + comm.shortcut + " " + Server.DefaultColor + "[" + comm.name + "]";
                            }
                        }
                    }
                    Player.SendMessage(p, "Available shortcuts:");
                    Player.SendMessage(p, message.Remove(0, 2) + ".");
                    break;

                case "colours":
                case "colors":
                    Player.SendMessage(p, "&fTo use a color simply put a '%' sign symbol before you put the color code.");
                    Player.SendMessage(p, "Colors Available:");
                    Player.SendMessage(p, "0 - &0Black " + Server.DefaultColor + "| 8 - &8Gray");
                    Player.SendMessage(p, "1 - &1Navy " + Server.DefaultColor + "| 9 - &9Blue");
                    Player.SendMessage(p, "2 - &2Green " + Server.DefaultColor + "| a - &aLime");
                    Player.SendMessage(p, "3 - &3Teal " + Server.DefaultColor + "| b - &bAqua");
                    Player.SendMessage(p, "4 - &4Maroon " + Server.DefaultColor + "| c - &cRed");
                    Player.SendMessage(p, "5 - &5Purple " + Server.DefaultColor + "| d - &dPink");
                    Player.SendMessage(p, "6 - &6Gold " + Server.DefaultColor + "| e - &eYellow");
                    Player.SendMessage(p, "7 - &7Silver " + Server.DefaultColor + "| f - &fWhite");
                    break;

                case "old":
                    string commandsFound = "";
                    foreach (Command comm in Command.all.commands)
                    {
                        if (p == null || p.group.commands.All().Contains(comm))
                        {
                            try { commandsFound += ", " + comm.name; } catch { }
                        }
                    }
                    Player.SendMessage(p, "Available commands:");
                    Player.SendMessage(p, commandsFound.Remove(0, 2));
                    Player.SendMessage(p, "Type \"/help <command>\" for more help.");
                    Player.SendMessage(p, "Type \"/help shortcuts\" for shortcuts.");
                    break;

                default:
                    Command cmd = Command.all.Find(message);
                    if (cmd != null)
                    {
                        cmd.Help(p);
                        string foundRank = Level.PermissionToName(GrpCommands.allowedCommands.Find(grpComm => grpComm.commandName == cmd.name).lowestRank);
                        Player.SendMessage(p, "Rank needed: " + getColor(cmd.name) + foundRank);
                        return;
                    }
                    byte b = Block.Byte(message);
                    if (b != Block.Zero)
                    {
                        Player.SendMessage(p, "Block \"" + message + "\" appears as &b" + Block.Name(Block.Convert(b)));
                        Group foundRank = Group.findPerm(Block.BlockList.Find(bs => bs.type == b).lowestRank);
                        Player.SendMessage(p, "Rank needed: " + foundRank.color + foundRank.name);
                        return;
                    }
                    Plugin plugin = null;
                    foreach (Plugin p1 in Plugin.all)
                    {
                        if (p1.name.ToLower() == message.ToLower())
                        {
                            plugin = p1;
                            break;
                        }
                    }
                    if (plugin != null)
                    {
                        plugin.Help(p);
                    }
                    Player.SendMessage(p, "Could not find command, plugin or block specified.");
                    break;
                }
            }
            catch (Exception e) { Server.ErrorLog(e); Player.SendMessage(p, "An error occured"); }
        }
Beispiel #11
0
        public override void Use(Player p, string message)
        {
            string path;

            if (message.Split(' ').Length == 1)
            {
                path = "levels/" + message + ".lvl";
            }
            else if (message.Split(' ').Length == 2)
            {
                try { path = @Server.backupLocation + "/" + message.Split(' ')[0] + "/" + int.Parse(message.Split(' ')[1]) + "/" + message.Split(' ')[0] + ".lvl"; }
                catch { Help(p); return; }
            }
            else
            {
                Help(p); return;
            }

            if (File.Exists(path))
            {
                FileStream fs = File.OpenRead(path);
                try
                {
                    GZipStream gs  = new GZipStream(fs, CompressionMode.Decompress);
                    byte[]     ver = new byte[2];
                    gs.Read(ver, 0, ver.Length);
                    ushort version = BitConverter.ToUInt16(ver, 0);
                    Level  level;
                    if (version == 1874)
                    {
                        byte[] header = new byte[16]; gs.Read(header, 0, header.Length);
                        ushort width  = BitConverter.ToUInt16(header, 0);
                        ushort height = BitConverter.ToUInt16(header, 2);
                        ushort depth  = BitConverter.ToUInt16(header, 4);
                        level        = new Level(name, width, depth, height, "empty");
                        level.spawnx = BitConverter.ToUInt16(header, 6);
                        level.spawnz = BitConverter.ToUInt16(header, 8);
                        level.spawny = BitConverter.ToUInt16(header, 10);
                        level.rotx   = header[12]; level.roty = header[13];
                    }
                    else
                    {
                        byte[] header = new byte[12]; gs.Read(header, 0, header.Length);
                        ushort width  = version;
                        ushort height = BitConverter.ToUInt16(header, 0);
                        ushort depth  = BitConverter.ToUInt16(header, 2);
                        level        = new Level(name, width, depth, height, "grass");
                        level.spawnx = BitConverter.ToUInt16(header, 4);
                        level.spawnz = BitConverter.ToUInt16(header, 6);
                        level.spawny = BitConverter.ToUInt16(header, 8);
                        level.rotx   = header[10]; level.roty = header[11];
                    }

                    level.setPhysics(0);

                    byte[] blocks = new byte[level.width * level.height * level.depth];
                    gs.Read(blocks, 0, blocks.Length);
                    level.blocks = blocks;
                    gs.Close();

                    level.backedup        = true;
                    level.permissionbuild = LevelPermission.Admin;

                    level.jailx    = (ushort)(level.spawnx * 32); level.jaily = (ushort)(level.spawny * 32); level.jailz = (ushort)(level.spawnz * 32);
                    level.jailrotx = level.rotx; level.jailroty = level.roty;

                    p.Loading = true;
                    foreach (Player pl in Player.players)
                    {
                        if (p.level == pl.level && p != pl)
                        {
                            p.SendDie(pl.id);
                        }
                    }
                    foreach (PlayerBot b in PlayerBot.playerbots)
                    {
                        if (p.level == b.level)
                        {
                            p.SendDie(b.id);
                        }
                    }

                    Player.GlobalDie(p, true);

                    p.level = level;
                    p.SendMotd();

                    p.SendRaw(2);
                    byte[] buffer = new byte[level.blocks.Length + 4];
                    BitConverter.GetBytes(IPAddress.HostToNetworkOrder(level.blocks.Length)).CopyTo(buffer, 0);
                    //ushort xx; ushort yy; ushort zz;

                    for (int i = 0; i < level.blocks.Length; ++i)
                    {
                        buffer[4 + i] = Block.Convert(level.blocks[i]);
                    }

                    buffer = buffer.GZip();
                    int number = (int)Math.Ceiling(((double)buffer.Length) / 1024);
                    for (int i = 1; buffer.Length > 0; ++i)
                    {
                        short  length = (short)Math.Min(buffer.Length, 1024);
                        byte[] send   = new byte[1027];
                        Player.HTNO(length).CopyTo(send, 0);
                        Buffer.BlockCopy(buffer, 0, send, 2, length);
                        byte[] tempbuffer = new byte[buffer.Length - length];
                        Buffer.BlockCopy(buffer, length, tempbuffer, 0, buffer.Length - length);
                        buffer     = tempbuffer;
                        send[1026] = (byte)(i * 100 / number);
                        p.SendRaw(3, send);
                        Thread.Sleep(10);
                    }
                    buffer = new byte[6];
                    Player.HTNO((short)level.width).CopyTo(buffer, 0);
                    Player.HTNO((short)level.depth).CopyTo(buffer, 2);
                    Player.HTNO((short)level.height).CopyTo(buffer, 4);
                    p.SendRaw(4, buffer);

                    ushort x = (ushort)((0.5 + level.spawnx) * 32);
                    ushort y = (ushort)((1 + level.spawny) * 32);
                    ushort z = (ushort)((0.5 + level.spawnz) * 32);

                    p.aiming = false;
                    Player.GlobalSpawn(p, x, y, z, level.rotx, level.roty, true);
                    p.ClearBlockchange();
                    p.Loading = false;

                    if (message.IndexOf(' ') == -1)
                    {
                        level.name = "&cMuseum " + Server.DefaultColor + "(" + message.Split(' ')[0] + ")";
                    }
                    else
                    {
                        level.name = "&cMuseum " + Server.DefaultColor + "(" + message.Split(' ')[0] + " " + message.Split(' ')[1] + ")";
                    }

                    if (!p.hidden)
                    {
                        Player.GlobalChat(null, p.color + p.prefix + p.name + Server.DefaultColor + " went to the " + level.name, false);
                    }

                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                }
                catch (Exception ex) { Player.SendMessage(p, "Error loading level."); Server.ErrorLog(ex); return; }
                finally { fs.Close(); }
            }
            else
            {
                Player.SendMessage(p, "Level or backup could not be found."); return;
            }
        }
Beispiel #12
0
        public override void Use(Player p, string message)
        {
            if (message == "")
            {
                Help(p); return;
            }
            bool success = false;

            string[] param = message.Split(' ');
            string   name  = param[0];

            if (param.Length == 1)
            {
                if (File.Exists("extra/commands/source/Cmd" + message + ".cs"))
                {
                    try
                    {
                        success = Scripting.Compile(message);
                    }
                    catch (Exception e)
                    {
                        Server.ErrorLog(e);
                        Player.SendMessage(p, "An exception was thrown during compilation.");
                        return;
                    }
                    if (success)
                    {
                        Player.SendMessage(p, "Compiled successfully.");
                    }
                    else
                    {
                        Player.SendMessage(p, "Compilation error.  Please check compile.log for more information.");
                    }
                    return;
                }
                else
                {
                    Player.SendMessage(p, "file &9Cmd" + message + ".cs " + Server.DefaultColor + "not found!");
                }
            }
            if (param[1] == "vb")
            {
                message = message.Remove(message.Length - 3, 3);
                if (File.Exists("extra/commands/source/Cmd" + message + ".vb"))
                {
                    try
                    {
                        success = ScriptingVB.Compile(name);
                    }
                    catch (Exception e)
                    {
                        Server.ErrorLog(e);
                        Player.SendMessage(p, "An exception was thrown during compilation.");
                        return;
                    }
                    if (success)
                    {
                        Player.SendMessage(p, "Compiled successfully.");
                    }
                    else
                    {
                        Player.SendMessage(p, "Compilation error.  Please check compile.log for more information.");
                    }
                    return;
                }
                else
                {
                    Player.SendMessage(p, "file &9Cmd" + message + ".vb " + Server.DefaultColor + "not found!");
                }
            }
        }
Beispiel #13
0
        public override void Use(Player p, string message)
        {
            if (message == "")
            {
                Help(p); return;
            }

            try
            {
                Level foundLevel = Level.Find(message);
                if (foundLevel != null)
                {
                    Level startLevel = p.level;

                    GC.Collect();

                    if (p.level == foundLevel)
                    {
                        Player.SendMessage(p, "You are already in \"" + foundLevel.name + "\"."); return;
                    }
                    if (!p.ignorePermission)
                    {
                        if (p.group.Permission < foundLevel.permissionvisit)
                        {
                            Player.SendMessage(p, "You're not allowed to go to " + foundLevel.name + "."); return;
                        }
                    }
                    {
                        if (!File.Exists("text/lockdown/map/" + message + ""))
                        {
                            p.Loading = true;
                            foreach (Player pl in Player.players)
                            {
                                if (p.level == pl.level && p != pl)
                                {
                                    p.SendDie(pl.id);
                                }
                            }
                            foreach (PlayerBot b in PlayerBot.playerbots)
                            {
                                if (p.level == b.level)
                                {
                                    p.SendDie(b.id);
                                }
                            }

                            Player.GlobalDie(p, true);
                            p.level = foundLevel; p.SendUserMOTD(); p.SendMap();

                            GC.Collect();

                            ushort x = (ushort)((0.5 + foundLevel.spawnx) * 32);
                            ushort y = (ushort)((1 + foundLevel.spawny) * 32);
                            ushort z = (ushort)((0.5 + foundLevel.spawnz) * 32);

                            if (!p.hidden)
                            {
                                Player.GlobalSpawn(p, x, y, z, foundLevel.rotx, foundLevel.roty, true, "");
                            }
                            else
                            {
                                unchecked { p.SendPos((byte)-1, x, y, z, foundLevel.rotx, foundLevel.roty); }
                            }

                            foreach (Player pl in Player.players)
                            {
                                if (pl.level == p.level && p != pl && !pl.hidden)
                                {
                                    p.SendSpawn(pl.id, pl.color + pl.name, pl.pos[0], pl.pos[1], pl.pos[2], pl.rot[0], pl.rot[1]);
                                }
                            }

                            foreach (PlayerBot b in PlayerBot.playerbots)
                            {
                                if (b.level == p.level)
                                {
                                    p.SendSpawn(b.id, b.color + b.name, b.pos[0], b.pos[1], b.pos[2], b.rot[0], b.rot[1]);
                                }
                            }

                            if (!p.hidden)
                            {
                                Player.GlobalChat(p, p.color + "*" + p.name + Server.DefaultColor + " went to &b" + foundLevel.name, false);
                            }

                            p.Loading = false;

                            bool skipUnload = false;
                            if (startLevel.unload && !startLevel.name.Contains("&cMuseum "))
                            {
                                foreach (Player pl in Player.players)
                                {
                                    if (pl.level == startLevel)
                                    {
                                        skipUnload = true;
                                    }
                                }
                                if (!skipUnload && Server.AutoLoad)
                                {
                                    startLevel.Unload();
                                }
                            }
                        }
                        else
                        {
                            Player.SendMessage(p, "The level " + message + " is locked.");
                        }
                    }
                }
                else if (Server.AutoLoad)
                {
                    Command.all.Find("load").Use(p, message);
                    foundLevel = Level.Find(message);
                    if (foundLevel != null)
                    {
                        Use(p, message);
                    }
                }
                else
                {
                    Player.SendMessage(p, "There is no level \"" + message + "\" loaded.");
                }

                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            catch (Exception e) { Server.ErrorLog(e); }
        }
Beispiel #14
0
        public override void Use(Player p, string message)
        {
            if (message == "")
            {
                if (p != null)
                {
                    message = p.level.name + " 30";
                }
                else
                {
                    message = Server.mainLevel + " 30";
                }
            }
            int foundNum = 0; Level foundLevel;

            if (message.IndexOf(' ') == -1)
            {
                try
                {
                    foundNum = int.Parse(message);
                    if (p != null)
                    {
                        foundLevel = p.level;
                    }
                    else
                    {
                        foundLevel = Server.mainLevel;
                    }
                }
                catch
                {
                    foundNum   = 30;
                    foundLevel = Level.Find(message);
                }
            }
            else
            {
                try
                {
                    foundNum   = int.Parse(message.Split(' ')[1]);
                    foundLevel = Level.Find(message.Split(' ')[0]);
                }
                catch
                {
                    Player.SendMessage(p, "Invalid input");
                    return;
                }
            }

            if (foundLevel == null)
            {
                Player.SendMessage(p, "Could not find entered level.");
                return;
            }

            try
            {
                if (foundLevel.physPause)
                {
                    foundLevel.physThread.Resume();
                    foundLevel.physResume = DateTime.Now;
                    foundLevel.physPause  = false;
                    Player.GlobalMessage("Physics on " + foundLevel.name + " were re-enabled.");
                }
                else
                {
                    foundLevel.physThread.Suspend();
                    foundLevel.physResume = DateTime.Now.AddSeconds(foundNum);
                    foundLevel.physPause  = true;
                    Player.GlobalMessage("Physics on " + foundLevel.name + " were temporarily disabled.");

                    foundLevel.physTimer.Elapsed += delegate
                    {
                        if (DateTime.Now > foundLevel.physResume)
                        {
                            foundLevel.physPause = false;
                            try
                            {
                                foundLevel.physThread.Resume();
                            }
                            catch (Exception e) { Server.ErrorLog(e); }
                            Player.GlobalMessage("Physics on " + foundLevel.name + " were re-enabled.");
                            foundLevel.physTimer.Stop();
                            foundLevel.physTimer.Dispose();
                        }
                    };
                    foundLevel.physTimer.Start();
                }
            }
            catch (Exception e)
            {
                Server.ErrorLog(e);
            }
        }
Beispiel #15
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")
                    {
                        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.group.Permission > LevelPermission.AdvBuilder || Server.devs.Contains(p.name.ToLower()))
                    {
                        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 + "),";
                            }
                        }
                        else
                        {
                            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 + ")");
                            }
                        }
                    }
                }
                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];
                    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); }
        }
        public static Level Load(Stream lvlStream, string fileName)
        {
            byte[] temp = new byte[8];
            using (Level lvl = new Level(fileName, 0, 0, 0, "empty"))
            {
                byte[] data;
                int    length;
                try
                {
                    lvlStream.Seek(-4, SeekOrigin.End);
                    lvlStream.Read(temp, 0, sizeof(int));
                    lvlStream.Seek(0, SeekOrigin.Begin);
                    length = BitConverter.ToInt32(temp, 0);
                    data   = new byte[length];
                    using (GZipStream reader = new GZipStream(lvlStream, CompressionMode.Decompress, true))
                    {
                        reader.Read(data, 0, length);
                    }

                    for (int i = 0; i < length - 1; i++)
                    {
                        if (data[i] == 0xAC && data[i + 1] == 0xED)
                        {
                            // bypassing the header crap
                            int pointer = i + 6;
                            Array.Copy(data, pointer, temp, 0, sizeof(short));
                            pointer += IPAddress.HostToNetworkOrder(BitConverter.ToInt16(temp, 0));
                            pointer += 13;

                            int headerEnd = 0;
                            // find the end of serialization listing
                            for (headerEnd = pointer; headerEnd < data.Length - 1; headerEnd++)
                            {
                                if (data[headerEnd] == 0x78 && data[headerEnd + 1] == 0x70)
                                {
                                    headerEnd += 2;
                                    break;
                                }
                            }

                            // start parsing serialization listing
                            int offset = 0;
                            while (pointer < headerEnd)
                            {
                                if (data[pointer] == 'Z')
                                {
                                    offset++;
                                }
                                else if (data[pointer] == 'I' || data[pointer] == 'F')
                                {
                                    offset += 4;
                                }
                                else if (data[pointer] == 'J')
                                {
                                    offset += 8;
                                }

                                pointer += 1;
                                Array.Copy(data, pointer, temp, 0, sizeof(short));
                                short skip = IPAddress.HostToNetworkOrder(BitConverter.ToInt16(temp, 0));
                                pointer += 2;

                                // look for relevant variables
                                Array.Copy(data, headerEnd + offset - 4, temp, 0, sizeof(int));
                                if (MemCmp(data, pointer, "width"))
                                {
                                    lvl.width = (ushort)IPAddress.HostToNetworkOrder(BitConverter.ToInt32(temp, 0));
                                }
                                else if (MemCmp(data, pointer, "depth"))
                                {
                                    lvl.depth = (ushort)IPAddress.HostToNetworkOrder(BitConverter.ToInt32(temp, 0));
                                }
                                else if (MemCmp(data, pointer, "height"))
                                {
                                    lvl.height = (ushort)IPAddress.HostToNetworkOrder(BitConverter.ToInt32(temp, 0));
                                }

                                pointer += skip;
                            }

                            lvl.spawnx = (ushort)(lvl.width / 1.3);
                            lvl.spawny = (ushort)(lvl.depth / 1.3);
                            lvl.spawnz = (ushort)(lvl.height / 1.3);

                            // find the start of the block array
                            bool foundBlockArray = false;
                            offset = Array.IndexOf <byte>(data, 0x00, headerEnd);
                            while (offset != -1 && offset < data.Length - 2)
                            {
                                if (data[offset] == 0x00 && data[offset + 1] == 0x78 && data[offset + 2] == 0x70)
                                {
                                    foundBlockArray = true;
                                    pointer         = offset + 7;
                                }
                                offset = Array.IndexOf <byte>(data, 0x00, offset + 1);
                            }

                            // copy the block array... or fail
                            if (foundBlockArray)
                            {
                                lvl.CopyBlocks(data, pointer);
                                lvl.Save(true);
                            }
                            else
                            {
                                throw new Exception("Could not locate block array.");
                            }
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Server.s.Log("Conversion failed");
                    Server.ErrorLog(ex);
                    return(null);
                }

                return(lvl);
            }
        }
Beispiel #17
0
 public static void Call(ushort x, ushort y, ushort z, byte time, string extra, Level l)
 {
     events.ForEach(delegate(OnPhysicsUpdateEvent p1)
     {
         try
         {
             p1.method(x, y, z, time, extra, l);
         }
         catch (Exception e) { Server.s.Log("The plugin " + p1.plugin.name + " errored when calling the LevelUnload Event!"); Server.ErrorLog(e); }
     });
 }
Beispiel #18
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);
        }
Beispiel #19
0
        public override void Use(Player p, string message)
        {
            try
            {
                if (message == "")
                {
                    Help(p); return;
                }
                bool stealth = false; bool totalBan = false;
                if (message[0] == '#')
                {
                    if (p == null)
                    {
                        message = message.Remove(0, 1).Trim();
                        stealth = true;
                        Server.s.Log("Stealth Ban Attempted by Console");
                    }
                    else
                    {
                        message = message.Remove(0, 1).Trim();
                        stealth = true;
                        Server.s.Log("Stealth Ban Attempted by " + p.name);
                    }
                }
                else if (message[0] == '@')
                {
                    if (p == null)
                    {
                        message = message.Remove(0, 1).Trim();
                        stealth = true;
                        Server.s.Log("Total Ban Attempted by Console");
                    }
                    else
                    {
                        totalBan = true;
                        message  = message.Remove(0, 1).Trim();
                        Server.s.Log("Total Ban Attempted by " + p.name);
                    }
                }
                string reason = "-";
                if (message.Split(' ').Length > 1)
                {
                    reason = message;
                    string newreason  = reason.Remove(0, reason.Split(' ')[0].Length + 1);
                    int    removetrim = newreason.Length + 1;
                    string newmessage = message.Remove(message.Length - removetrim, removetrim);
                    reason  = newreason;
                    message = newmessage;
                }
                if (reason == "-")
                {
                    reason = "&c-";
                }
                reason = reason.Replace(" ", "%20");
                Player who = Player.Find(message);

                if (who == null)
                {
                    if (!Player.ValidName(message))
                    {
                        Player.SendMessage(p, "Invalid name \"" + message + "\".");
                        return;
                    }
                    if (Server.devs.Contains(message.ToLower()))
                    {
                        Player.SendMessage(p, "You can't ban a MCForge Developer!");
                        if (p != null)
                        {
                            Player.GlobalMessage(p.color + p.name + Server.DefaultColor + " attempted to ban a MCForge Developer!");
                        }
                        else
                        {
                            Player.GlobalMessage(Server.DefaultColor + "The Console attempted to ban a MCForge Developer!");
                        }
                        return;
                    }
                    Group foundGroup = Group.findPlayerGroup(message);

                    if ((int)foundGroup.Permission >= CommandOtherPerms.GetPerm(this))
                    {
                        Player.SendMessage(p, "You can't ban a " + foundGroup.name + "!");
                        return;
                    }
                    if (foundGroup.Permission == LevelPermission.Banned)
                    {
                        Player.SendMessage(p, message + " is already banned.");
                        return;
                    }
                    if (p != null && foundGroup.Permission >= p.group.Permission)
                    {
                        Player.SendMessage(p, "You cannot ban a person ranked equal or higher than you.");
                        return;
                    }
                    string oldgroup = foundGroup.name.ToString();
                    foundGroup.playerList.Remove(message);
                    foundGroup.playerList.Save();
                    if (p != null)
                    {
                        Player.GlobalMessage(message + " &f(offline)" + Server.DefaultColor + " was &8banned" + Server.DefaultColor + " by " + p.color + p.name + Server.DefaultColor + ".");
                    }
                    else
                    {
                        Player.GlobalMessage(message + " &f(offline)" + Server.DefaultColor + " was &8banned" + Server.DefaultColor + " by console.");
                    }
                    Group.findPerm(LevelPermission.Banned).playerList.Add(message);
                    Ban.Banplayer(p, message, reason, stealth, oldgroup);
                }
                else
                {
                    if (!Player.ValidName(who.name))
                    {
                        Player.SendMessage(p, "Invalid name \"" + who.name + "\".");
                        return;
                    }
                    if (Server.devs.Contains(who.name.ToLower()))
                    {
                        Player.SendMessage(p, "You can't ban an MCForge Developer!");
                        if (p != null)
                        {
                            Player.GlobalMessage(p.color + p.name + Server.DefaultColor + " attempted to ban an MCForge Developer!");
                        }
                        else
                        {
                            Player.GlobalMessage(Server.DefaultColor + "The Console attempted to ban an MCForge Developer!");
                        }
                        return;
                    }
                    if ((int)who.group.Permission >= CommandOtherPerms.GetPerm(this))
                    {
                        Player.SendMessage(p, "You can't ban a " + who.group.name + "!");
                        return;
                    }
                    if (who.group.Permission == LevelPermission.Banned)
                    {
                        Player.SendMessage(p, message + " is already banned.");
                        return;
                    }
                    if (p != null && who.group.Permission >= p.group.Permission)
                    {
                        Player.SendMessage(p, "You cannot ban a person ranked equal or higher than you.");
                        return;
                    }
                    string oldgroup = who.group.name.ToString();
                    who.group.playerList.Remove(message);
                    who.group.playerList.Save();

                    if (p != null)
                    {
                        if (stealth)
                        {
                            Player.GlobalMessageOps(who.color + who.name + Server.DefaultColor + " was STEALTH &8banned" + Server.DefaultColor + " by " + p.color + p.name + Server.DefaultColor + "!");
                        }
                        else
                        {
                            Player.GlobalMessage(who.color + who.name + Server.DefaultColor + " was &8banned" + Server.DefaultColor + " by " + p.color + p.name + Server.DefaultColor + "!");
                        }
                    }
                    else
                    {
                        if (stealth)
                        {
                            Player.GlobalMessageOps(who.color + who.name + Server.DefaultColor + " was STEALTH &8banned" + Server.DefaultColor + " by console.");
                        }
                        else
                        {
                            Player.GlobalMessage(who.color + who.name + Server.DefaultColor + " was &8banned" + Server.DefaultColor + " by console.");
                        }
                    }
                    who.group = Group.findPerm(LevelPermission.Banned);
                    who.color = who.group.color;
                    Player.GlobalDie(who, false);
                    Player.GlobalSpawn(who, who.pos[0], who.pos[1], who.pos[2], who.rot[0], who.rot[1], false);
                    Group.findPerm(LevelPermission.Banned).playerList.Add(who.name);
                    Ban.Banplayer(p, who.name, reason, stealth, oldgroup);
                }
                Group.findPerm(LevelPermission.Banned).playerList.Save();

                if (p != null)
                {
                    Server.IRC.Say(message + " was banned by " + p.name + ".");
                    Server.s.Log("BANNED: " + message.ToLower() + " by " + p.name);
                }
                else
                {
                    Server.IRC.Say(message + " was banned by console.");
                    Server.s.Log("BANNED: " + message.ToLower() + " by console.");
                }

                if (totalBan == true)
                {
                    Command.all.Find("undo").Use(p, message + " 0");
                    Command.all.Find("banip").Use(p, "@ " + message);
                }
            }
            catch (Exception e) { Server.ErrorLog(e); }
        }
        public static bool Pump(Beat type)
        {
            if (staticVars == null)
            {
                Init();
            }
            // default information to send
            string postVars = staticVars;

            string url = "http://www.classicube.net/heartbeat.jsp";

            try
            {
                int hidden = 0;
                // append additional information as needed
                switch (type)
                {
                case Beat.ClassiCube:
                    postVars += "&salt=" + Server.salt2;
                    goto default;

                case Beat.Minecraft:
                    url       = "https://minecraft.net/heartbeat.jsp";
                    postVars += "&salt=" + Server.salt;
                    goto default;

                default:
                    postVars += "&users=" + (Player.number - hidden);
                    break;
                }

                request             = (HttpWebRequest)WebRequest.Create(new Uri(url + "?" + postVars));
                request.Method      = "POST";
                request.ContentType = "application/x-www-form-urlencoded";
                request.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);
                byte[] formData = Encoding.ASCII.GetBytes(postVars);
                request.ContentLength = formData.Length;
                request.Timeout       = 15000;
                try
                {
                    using (Stream requestStream = request.GetRequestStream())
                    {
                        requestStream.Write(formData, 0, formData.Length);
                        requestStream.Close();
                    }
                }
                catch (WebException e)
                {
                    if (e.Status == WebExceptionStatus.Timeout)
                    {
                        throw new WebException("Failed during request.GetRequestStream()", e.InnerException, e.Status, e.Response);
                    }
                }

                if (hash == null)
                {
                    using (WebResponse response = request.GetResponse())
                    {
                        using (StreamReader responseReader = new StreamReader(response.GetResponseStream()))
                        {
                            string line = responseReader.ReadLine();
                            hash      = line.Substring(line.LastIndexOf('=') + 1);
                            serverURL = line;

                            Server.s.UpdateUrl(serverURL);
                            Server.s.Log("URL saved to text/externalurl.txt...");
                            File.WriteAllText("text/externalurl.txt", serverURL);
                        }
                    }
                }
            }
            catch (WebException e)
            {
                if (e.Status == WebExceptionStatus.Timeout)
                {
                    Server.s.Log(string.Format("Timeout: {0}", type));
                }
                Server.ErrorLog(e);
            }
            catch (Exception e)
            {
                Server.s.Log(string.Format("Error reporting to {0}", type));
                Server.ErrorLog(e);
                return(false);
            }
            finally
            {
                request.Abort();
            }
            return(true);
        }
Beispiel #21
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); }
            }
        }
        /// <summary>
        /// Loads a command for use on the server.
        /// </summary>
        /// <param name="command">Name of the command to be loaded (make sure it's prefixed by Cmd before bringing it in here or you'll have problems).</param>
        /// <returns>Error string on failure, null on success.</returns>
        public static string Load(string command)
        {
            if (command.Length < 3 || command.Substring(0, 3).ToLower() != "cmd")
            {
                return("Invalid command name specified.");
            }
            try
            {
                //Allows unloading and deleting dlls without server restart
                object   instance = null;
                Assembly lib      = null;
                using (FileStream fs = File.Open("extra/commands/dll/" + command + ".dll", FileMode.Open))
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        byte[] buffer = new byte[1024];
                        int    read   = 0;
                        while ((read = fs.Read(buffer, 0, 1024)) > 0)
                        {
                            ms.Write(buffer, 0, read);
                        }
                        lib = Assembly.Load(ms.ToArray());
                        ms.Close();
                        ms.Dispose();
                    }
                    fs.Close();
                    fs.Dispose();
                }
                try
                {
                    foreach (Type t in lib.GetTypes())
                    {
                        if (t.BaseType == typeof(Command))
                        {
                            instance = Activator.CreateInstance(t);
                            Command.all.Add((Command)instance);
                        }
                    }
                }
                catch { }
                if (instance == null)
                {
                    Server.s.Log("The command " + command + " couldnt be loaded!");
                    throw new BadImageFormatException();
                }

                /*Assembly asm = Assembly.LoadFrom("extra/commands/dll/" + command + ".dll");
                 * Type[] types = asm.GetTypes();
                 * foreach(var type in types)
                 * {
                 *  if(type.BaseType == typeof(Command))
                 *  {
                 *      object instance = Activator.CreateInstance(type);
                 *      Command.all.Add((Command)instance);
                 *  }
                 * }
                 * //Type type = asm.GetTypes()[0];*/
            }
            catch (FileNotFoundException e)
            {
                Server.ErrorLog(e);
                return(command + ".dll does not exist in the DLL folder, or is missing a dependency.  Details in the error log.");
            }
            catch (BadImageFormatException e)
            {
                Server.ErrorLog(e);
                return(command + ".dll is not a valid assembly, or has an invalid dependency.  Details in the error log.");
            }
            catch (PathTooLongException)
            {
                return("Class name is too long.");
            }
            catch (FileLoadException e)
            {
                Server.ErrorLog(e);
                return(command + ".dll or one of its dependencies could not be loaded.  Details in the error log.");
            }
            catch (Exception e)
            {
                Server.ErrorLog(e);
                return("An unknown error occured and has been logged.");
            }
            return(null);
        }
Beispiel #23
0
        public override void Use(Player p, string message)
        {
            try
            {
                if (message == "")
                {
                    Help(p); return;
                }

                if (message.IndexOf(' ') == -1)
                {
                    if (File.Exists("extra/copy/" + message + ".copy"))
                    {
                        Player.SendMessage(p, "File: &f" + message + Server.DefaultColor + " already exists.  Delete first");
                        return;
                    }
                    else
                    {
                        Player.SendMessage(p, "Storing: " + message);
                        StreamWriter sW = new StreamWriter(File.Create("extra/copy/" + message + ".copy"));
                        sW.WriteLine("Saved by: " + p.name + " at " + DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss "));
                        for (int k = 0; k < p.CopyBuffer.Count; k++)
                        {
                            sW.WriteLine(p.CopyBuffer[k].x + " " + p.CopyBuffer[k].y + " " + p.CopyBuffer[k].z + " " + p.CopyBuffer[k].type);
                        }
                        sW.Flush();
                        sW.Close();

                        sW = File.AppendText("extra/copy/index.copydb");
                        sW.WriteLine(message + " " + p.name);
                        sW.Flush();
                        sW.Close();
                    }
                }
                else
                {
                    if (message.Split(' ')[0] == "delete")
                    {
                        message = message.Split(' ')[1];
                        list.Clear();
                        foreach (string s in File.ReadAllLines("extra/copy/index.copydb"))
                        {
                            CopyOwner cO = new CopyOwner();
                            cO.file = s.Split(' ')[0];
                            cO.name = s.Split(' ')[1];
                            list.Add(cO);
                        }
                        CopyOwner result = list.Find(
                            delegate(CopyOwner cO) {
                            return(cO.file == message);
                        }
                            );

                        if (p.group.Permission >= LevelPermission.Operator || result.name == p.name)
                        {
                            if (File.Exists("extra/copy/" + message + ".copy"))
                            {
                                try
                                {
                                    if (File.Exists("extra/copyBackup/" + message + ".copy"))
                                    {
                                        File.Delete("extra/copyBackup/" + message + ".copy");
                                    }
                                    File.Move("extra/copy/" + message + ".copy", "extra/copyBackup/" + message + ".copy");
                                }
                                catch { }
                                Player.SendMessage(p, "File &f" + message + Server.DefaultColor + " has been deleted.");
                                list.Remove(result);
                                File.Delete("extra/copy/index.copydb");
                                StreamWriter sW = new StreamWriter(File.Create("extra/copy/index.copydb"));
                                foreach (CopyOwner cO in list)
                                {
                                    sW.WriteLine(cO.file + " " + cO.name);
                                }
                                sW.Flush();
                                sW.Close();
                            }
                            else
                            {
                                Player.SendMessage(p, "File does not exist.");
                            }
                        }
                        else
                        {
                            Player.SendMessage(p, "You must be an operator or file owner to delete a save.");
                            return;
                        }
                    }
                    else
                    {
                        Help(p); return;
                    }
                }
            }
            catch (Exception e) { Server.ErrorLog(e); }
        }
Beispiel #24
0
        public override void Use(Player p, string message)
        {
            if (!Directory.Exists("extra/text/"))
            {
                Directory.CreateDirectory("extra/text");
            }
            if (message == "")
            {
                DirectoryInfo di       = new DirectoryInfo("extra/text/");
                string        allFiles = "";
                foreach (FileInfo fi in di.GetFiles("*.txt"))
                {
                    try
                    {
                        string firstLine = File.ReadAllLines("extra/text/" + fi.Name.Substring(0, fi.Name.Length - fi.Extension.Length) + ".txt")[0];
                        if (firstLine[0] == '#')
                        {
                            if (Group.Find(firstLine.Substring(1)).Permission <= p.group.Permission)
                            {
                                allFiles += ", " + fi.Name.Substring(0, fi.Name.Length - fi.Extension.Length);
                            }
                        }
                        else
                        {
                            allFiles += ", " + fi.Name;
                        }
                    } catch (Exception e) { Server.ErrorLog(e); Player.SendMessage(p, "Error"); }
                }

                if (allFiles == "")
                {
                    Player.SendMessage(p, "No files are viewable by you");
                }
                else
                {
                    Player.SendMessage(p, "Available files:");
                    Player.SendMessage(p, allFiles.Remove(0, 2));
                }
            }
            else
            {
                Player who = null;
                if (message.IndexOf(' ') != -1)
                {
                    who = Player.Find(message.Split(' ')[message.Split(' ').Length - 1]);
                    if (who != null)
                    {
                        message = message.Substring(0, message.LastIndexOf(' '));
                    }
                }
                if (who == null)
                {
                    who = p;
                }

                if (File.Exists("extra/text/" + message + ".txt"))
                {
                    try
                    {
                        string[] allLines = File.ReadAllLines("extra/text/" + message + ".txt");
                        if (allLines[0][0] == '#')
                        {
                            if (Group.Find(allLines[0].Substring(1)).Permission <= p.group.Permission)
                            {
                                for (int i = 1; i < allLines.Length; i++)
                                {
                                    Player.SendMessage(who, allLines[i]);
                                }
                            }
                            else
                            {
                                Player.SendMessage(p, "You cannot view this file");
                            }
                        }
                        else
                        {
                            for (int i = 1; i < allLines.Length; i++)
                            {
                                Player.SendMessage(who, allLines[i]);
                            }
                        }
                    } catch { Player.SendMessage(p, "An error occurred when retrieving the file"); }
                }
                else
                {
                    Player.SendMessage(p, "File specified doesn't exist");
                }
            }
        }
Beispiel #25
0
 public static void Call(Player p, ushort x, ushort y, ushort z)
 {
     events.ForEach(delegate(PlayerMoveEvent p1)
     {
         try
         {
             p1.method(p, x, y, z);
         }
         catch (Exception e) { Server.s.Log("The plugin " + p1.plugin.name + " errored when calling the PlayerMove Event!"); Server.ErrorLog(e); }
     });
 }
 public static void Call(string cmd, string message)
 {
     events.ForEach(delegate(OnConsoleCommandEvent p1)
     {
         try
         {
             p1.method(cmd, message);
         }
         catch (Exception e) { Server.s.Log("The plugin " + p1.plugin.name + " errored when calling the LevelUnload Event!"); Server.ErrorLog(e); }
     });
 }
Beispiel #27
0
 internal static void Call(Player p, string mysqlcommand)
 {
     events.ForEach(delegate(OnMySQLSaveEvent p1)
     {
         try
         {
             p1.method(p, mysqlcommand);
         }
         catch (Exception e) { Server.s.Log("The plugin " + p1.plugin.name + " errored when calling the MySQLSave Event!"); Server.ErrorLog(e); }
     });
 }
Beispiel #28
0
 internal static void Call(string cmd, Player p, string message)
 {
     events.ForEach(delegate(OnPlayerCommandEvent p1)
     {
         try
         {
             p1.method(cmd, p, message);
         }
         catch (Exception e) { Server.s.Log("The plugin " + p1.plugin.name + " errored when calling the PlayerCommand Event!"); Server.ErrorLog(e); }
     });
 }
Beispiel #29
0
 internal static void Call(Player p)
 {
     events.ForEach(delegate(OnPlayerAFKEvent p1)
     {
         try
         {
             p1.method(p);
         }
         catch (Exception e) { Server.s.Log("The plugin " + p1.plugin.name + " errored when calling the OnAFK Event!"); Server.ErrorLog(e); }
     });
 }
 internal static void Call(Player p, ushort x, ushort y, ushort z, byte type)
 {
     events.ForEach(delegate(OnBlockChangeEvent p1)
     {
         try
         {
             p1.method(p, x, y, z, type);
         }
         catch (Exception e) { Server.s.Log("The plugin " + p1.plugin.name + " errored when calling the PlayerBlockChange Event!"); Server.ErrorLog(e); }
     });
 }