Beispiel #1
0
        internal void Init()
        {
            if (!Directory.Exists(FileUtils.DllsPath + "/gui"))
            {
                Directory.CreateDirectory(FileUtils.DllsPath + "/gui");
            }

            foreach (var info in Directory.GetFiles(FileUtils.DllsPath + "/gui", "*.dll"))
            {
                var _assem = LoadAllDlls.LoadFile(info);
                foreach (var type in _assem.GetTypes())
                {
                    if (type.IsAbstract || !type.IsPublic)
                    {
                        continue;
                    }

                    var guiType = type.GetInterface("MCForgeGui", true);

                    if (guiType == null)
                    {
                        continue;
                    }

                    MCForgeGui mGui = (MCForgeGui)Activator.CreateInstance(_assem.GetType(type.ToString()));
                    _guiElements.Add(mGui);
                }
            }
        }
        /// <summary>
        /// Check the args that were passed on program startup
        /// </summary>
        /// <param name="args">The args</param>
        /// <returns>If returns false, run normal setup. If returns true, cancel normal setup. In this case something has already started the server.</returns>
        static bool CheckArgs(string[] args)
        {
            if (args.Length == 0)
            {
                return(false);
            }
            string name = args[0];

            switch (name)
            {
            case "load-plugin":
                if (args.Length == 1)
                {
                    return(false);
                }
                string   plugin = args[1];
                string[] pargs  = new string[] { "-force" };
                for (int i = 1; i < args.Length; i++)
                {
                    pargs[i] = args[i];
                }
                LoadAllDlls.LoadDLL(plugin, pargs);
                break;

            case "debug":
                Server.DebugMode = true;
                return(false);

            case "abort-setup":
                return(true);
            }
            return(args[args.Length - 1] == "abort-setup");
        }
 private static void ReloadCommands()
 {
     Logger.Log("Reloading Plugins and Commands", LogType.Debug);
     Plugin.unloadAll();
     Command.Commands.Clear();
     LoadAllDlls.InitCommandsAndPlugins();
     new MCForge.Interface.Command.CmdReloadCmds().Initialize();
 }
 public void Use(Player p, string[] args)
 {
     Player.UniversalChat("Reloading the Command system, please wait.");
     Plugin.Plugin.unloadAll();
     Command.Commands.Clear();
     LoadAllDlls.InitCommandsAndPlugins();
     Initialize();
 }
        public override void Action()
        {
            object   instance = null;
            Assembly a        = LoadAllDlls.LoadFile("temp.dll");

            foreach (Type ClassType in a.GetTypes())
            {
                if (ClassType.IsPublic)
                {
                    if (ClassType.BaseType == typeof(IAction))
                    {
                        instance = Activator.CreateInstance(ClassType);
                        break;
                    }
                }
            }
            if (instance == null)
            {
                return;
            }
            IAction.actions.Add((IAction)instance);
            File.Delete("temp.dll");
        }
Beispiel #6
0
        /// <summary>
        /// Inits this instance.
        /// </summary>
        public static void Init()
        {
            Running = true;

            Logger.WriteLog("--------- Server Started at " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + " ---------");
            Logger.Log("Debug mode started", LogType.Debug);
            //TODO Add debug messages
            //TODO load the level if it exists
            Block.InIt();
            Logger.Log("Starting update timer", LogType.Debug);
            UpdateTimer = new System.Threading.Timer((e) => Update(), null, 0, 100);
            Logger.Log("Log timer started", LogType.Debug);
            Logger.Log("Loading DLL's", LogType.Debug);
            LoadAllDlls.Init();
            Logger.Log("Finished loading DLL's", LogType.Debug);
            Logger.Log("Sending Heartbeat..", LogType.Debug);
            Logger.Log("Auto-Updater Starting..", LogType.Debug);
            Updater.InIt();
            HeartThread = new Thread(new ThreadStart(Heartbeat.ActivateHeartBeat));
            HeartThread.Start();
            Logger.Log("Starting Physics Tick..", LogType.Debug);
            PhysicsBlock.InIt();
            CmdReloadCmds reload = new CmdReloadCmds();

            reload.Initialize();

            Groups.PlayerGroup.Load();
            VerifyGroup = Groups.PlayerGroup.Find(ServerSettings.GetSetting("VerifyGroup"));
            Mainlevel   = Level.LoadLevel(ServerSettings.GetSetting("Main-Level"));
            if (Mainlevel == null)
            {
                Mainlevel = Level.CreateLevel(new Vector3S(256, 128, 64), Level.LevelTypes.Flat);
                ServerSettings.SetSetting("Main-Level", null, "main");
            }
            Level.Levels.Add(Mainlevel);
            if (ServerSettings.GetSettingBoolean("LoadAllLevels"))
            {
                Level.LoadAllLevels();
            }
            BlockQueue.Start();
            Backup.StartBackup();

            Database.Init();

            CreateCoreFiles();

            InternetUtils = new InetUtils();
            InetUtils.InternetAvailable = InetUtils.CanConnectToInternet();

            Logger.Log("Loading Bans", LogType.Debug);
            Logger.Log("IPBANS", LogType.Debug);
            IPBans = new List <string>(File.ReadAllLines("bans/IPBans.txt"));
            Logger.Log("IPBANS", LogType.Debug);
            UsernameBans = new List <string>(File.ReadAllLines("bans/NameBans.txt"));
            StartListening();
            Started = true;

            if (OnServerFinishSetup != null)
            {
                OnServerFinishSetup();
            }
            blockThread = new Thread(new ThreadStart(delegate
            {
                while (true)
                {
                    Thread.Sleep(60000);
                    Level.Levels.ForEach(delegate(Level l)
                    {
                        try
                        {
                            l.SaveToBinary();
                        }
                        catch (Exception e)
                        {
                            Logger.LogError(e);
                        }
                    });
                }
            }));
            blockThread.Start();
            Logger.Log("[Important]: Server Started.", Color.Black, Color.White);
            if (!ServerSettings.GetSettingBoolean("VerifyNames"))
            {
                Logger.Log("[Important]: The server is running with verify names off! This could lead to bad things! Please turn on verify names if you dont know the risk and dont want these bad things to happen!", LogType.Critical);
            }

            if (ServerSettings.GetSettingBoolean("IRC-Enabled"))
            {
                try
                {
                    IRC = new ServerChat();
                    IRC.Connect();
                }
                catch (Exception e)
                {
                    Logger.LogError(e);
                }
            }

            if (ServerSettings.GetSettingBoolean("GC-Enabled"))
            {
                GC = new GlobalChat();
                try
                {
                    GC.Connect();
                }
                catch (Exception e)
                {
                    Logger.LogError(e);
                }
            }

            try
            {
                RC = new ConsoleListener();
                RC.Start();
            }
            catch { }

            PlayerConnectionTimeoutChecker = new Thread(() => {
                int sleep = ServerSettings.GetSettingInt("AutoTimeout");
                if (sleep < 0)
                {
                    sleep = 30;
                }
                if (sleep != 0)
                {
                    while (Running)
                    {
                        for (int i = 0; i < sleep && Running; i++)
                        {
                            Thread.Sleep(1000);
                        }
                        if (!Running)
                        {
                            break;
                        }
                        foreach (Player p in Players)
                        {
                            if (p.lastReceived.AddSeconds(sleep) < DateTime.Now)
                            {
#if !DEBUG
                                p.Kick("The connection timed out");
#endif
                            }
                        }
                    }
                }
            });
            PlayerConnectionTimeoutChecker.Start();
        }
        //UNDONE Windows needs to update
        private static object Tick()
        {
            using (WebClient wc = new WebClient()) {
                if (checkmisc)
                {
                    bool updated = false;
                    if (!cmdupdate)
                    {
                        //Check commands first
                        Logger.Log("Checking Commands for updates", LogType.Debug);
                        Version cmdv     = LoadAllDlls.LoadFile("Plugins.dll").GetName().Version;
                        Version clastest = new Version(wc.DownloadString("http://update.mcforge.net/cmdv.txt"));
                        if (clastest > cmdv)
                        {
                            updated = true;
                            Logger.Log("Updates found, updating", LogType.Debug);
                            if (silentupdate)
                            {
                                wc.DownloadFile("http://update.mcforge.net/DLL/Commands.dll", "Commands.dll");
                            }
                            else if (autoupdate)
                            {
                                Player.UniversalChatOps("&2[Updater] " + Server.DefaultColor + "An update for the Core Commands are available!");
                                Player.UniversalChatOps("&2[Updater] " + Server.DefaultColor + "Downloading update..");
                                wc.DownloadFile("http://update.mcforge.net/DLL/Commands.dll", "Commands.dll");
                            }
                            else if (askbeforemisc)
                            {
                                cmdupdate = true;
                                Player.UniversalChatOps("&2[Updater] " + Server.DefaultColor + "An update for the Core Commands are available!");
                                Player.UniversalChatOps("&2[Updater] " + Server.DefaultColor + "To update, type /update");
                            }
                        }
                    }
                    if (!plugupdate)
                    {
                        //Check plugin system
                        Logger.Log("Checking Plugins for updates", LogType.Debug);
                        Version plugv    = LoadAllDlls.LoadFile("Plugins.dll").GetName().Version;
                        Version plastest = new Version(wc.DownloadString("http://update.mcforge.net/plugv.txt"));
                        if (plastest > plugv)
                        {
                            updated = true;
                            Logger.Log("Updates found, updating", LogType.Debug);
                            if (silentupdate)
                            {
                                wc.DownloadFile("http://update.mcforge.net/DLL/Plugins.dll", "Plugins.dll");
                            }
                            else if (autoupdate)
                            {
                                Player.UniversalChatOps("&2[Updater] " + Server.DefaultColor + "An update for the Core Plugins are available!");
                                Player.UniversalChatOps("&2[Updater] " + Server.DefaultColor + "Downloading update..");
                                wc.DownloadFile("http://update.mcforge.net/DLL/Commands.dll", "Plugins.dll");
                            }
                            else if (askbeforemisc)
                            {
                                plugupdate = true;
                                Player.UniversalChatOps("&2[Updater] " + Server.DefaultColor + "An update for the Core Plugins are available!");
                                Player.UniversalChatOps("&2[Updater] " + Server.DefaultColor + "To update, type /update");
                            }
                        }
                    }

                    //Reload the system if new updates were installed
                    if ((silentupdate || autoupdate) && updated)
                    {
                        ReloadCommands();
                    }
                }

                if (checkcore && !coreupdated)
                {
                    Logger.Log("Checking Core for updates", LogType.Debug);
                    //Check core
                    if (coreupdate && silentcoreupdate)
                    {
                        if (Server.PlayerCount < (int)((double)(ServerSettings.GetSettingInt("MaxPlayers") / 4)))
                        {
                            if (Server.OnMono)
                            {
                                string args = wc.DownloadString("http://update.mcforge.net/Patch/args.txt");
                                if (allowpatch && args != "")
                                {
                                    Process process = new Process();
                                    process.StartInfo.FileName  = "Updater.exe";
                                    process.StartInfo.Arguments = args;
                                    process.Start();
                                    System.Environment.Exit(0);
                                }
                                else
                                {
                                    wc.DownloadFile("http://update.mcforge.net/DLL/Core.dll", "MCForge.dll");
                                }
                            }
                            else
                            {
                                string args = "";
                                if (allowpatch)
                                {
                                    args = wc.DownloadString("http://update.mcforge.net/Patch/args.txt");
                                }
                                Process process = new Process();
                                process.StartInfo.FileName  = "Updater.exe";
                                process.StartInfo.Arguments = args;
                                process.Start();
                                System.Environment.Exit(0);
                            }
                        }
                    }
                    Version corel = new Version(wc.DownloadString("http://update.mcforge.net/corev.txt"));
                    if (corel > Version)
                    {
                        Logger.Log("Updates found, updating", LogType.Debug);
                        coreupdate = true;
                        if (silentcoreupdate)
                        {
                            if (Server.PlayerCount < (int)((double)(ServerSettings.GetSettingInt("MaxPlayers") / 4)))
                            {
                                if (Server.OnMono)
                                {
                                    string args = wc.DownloadString("http://update.mcforge.net/Patch/args.txt");
                                    if (allowpatch && args != "")
                                    {
                                        Process process = new Process();
                                        process.StartInfo.FileName  = "Updater.exe";
                                        process.StartInfo.Arguments = args;
                                        process.Start();
                                        System.Environment.Exit(0);
                                    }
                                    else
                                    {
                                        wc.DownloadFile("http://update.mcforge.net/DLL/Core.dll", "MCForge.dll");
                                    }
                                }
                                else
                                {
                                    string args = "";
                                    if (allowpatch)
                                    {
                                        args = wc.DownloadString("http://update.mcforge.net/Patch/args.txt");
                                    }
                                    Process process = new Process();
                                    process.StartInfo.FileName  = "Updater.exe";
                                    process.StartInfo.Arguments = args;
                                    process.Start();
                                    System.Environment.Exit(0);
                                }
                            }
                        }
                        else if (autoupdate)
                        {
                            Player.UniversalChatOps("&2[Updater] " + Server.DefaultColor + "An update for the Core is available!");
                            Player.UniversalChatOps("&2[Updater] " + Server.DefaultColor + "Downloading update..");
                            if (Server.OnMono)
                            {
                                string args = wc.DownloadString("http://update.mcforge.net/Patch/args.txt");
                                if (allowpatch && args != "")
                                {
                                    Process process = new Process();
                                    process.StartInfo.FileName  = "Updater.exe";
                                    process.StartInfo.Arguments = args;
                                    process.Start();
                                    System.Environment.Exit(0);
                                }
                                else
                                {
                                    wc.DownloadFile("http://update.mcforge.net/DLL/Core.dll", "MCForge.dll");
                                    Player.UniversalChatOps("&2[Updater] " + Server.DefaultColor + "MCForge has been updated!");
                                    Player.UniversalChatOps("&2[Updater] " + Server.DefaultColor + "Updates will be applied next restart.");
                                    Logger.Log("MCForge has been updated!", LogType.Critical);
                                    Logger.Log("Updates will be applied next restart.", LogType.Critical);
                                    coreupdated = true;
                                }
                            }
                            else
                            {
                                string args = "";
                                if (allowpatch)
                                {
                                    args = wc.DownloadString("http://update.mcforge.net/Patch/args.txt");
                                }
                                Process process = new Process();
                                process.StartInfo.FileName  = "Updater.exe";
                                process.StartInfo.Arguments = args;
                                process.Start();
                                System.Environment.Exit(0);
                            }
                        }
                        else
                        {
                            Player.UniversalChatOps("&2[Updater] " + Server.DefaultColor + "An update for the Core is available!");
                            Player.UniversalChatOps("&2[Updater] " + Server.DefaultColor + "To update, type /update");
                        }
                    }
                }
            }
            return(null);
        }
Beispiel #8
0
        /// <summary>
        /// Reload one or all unloaded plugins.
        /// </summary>
        /// <param name="name">The name of the plugin to load, or an empty string to load all plugins</param>
        /// <param name="ignoreCase">Whether the case of the name gets ignored or not</param>
        /// <returns></returns>
        public static int reload(string name = "", bool ignoreCase = true)
        {
            foreach (IPlugin p in Plugins.ToArray())
            {
                if (name != "")
                {
                    if (ignoreCase)
                    {
                        if (p.Name.ToLower() == name.ToLower())
                        {
                            unload(name);
                            break;
                        }
                    }
                    else
                    if (p.Name == name)
                    {
                        unload(name);
                        break;
                    }
                }
                else
                {
                    unload(p.Name);
                    Logger.Log("[Plugin] Unloaded " + p.Name);
                }
            }

            int    ret  = 0;
            string path = Directory.GetCurrentDirectory();

            string[] DLLFiles = Directory.GetFiles(path, "*.dll");
            foreach (string s in DLLFiles)
            {
                ret++;
                if (name == "")
                {
                    LoadAllDlls.LoadDLL(s, new string[] { "-normal" }, typeof(IPlugin));
                }
                else if (ignoreCase)
                {
                    if (s.ToLower() == name.ToLower())
                    {
                        LoadAllDlls.LoadDLL(s, new string[] { "-normal" }, typeof(IPlugin));
                    }
                }
                else
                if (s == name)
                {
                    LoadAllDlls.LoadDLL(s, new string[] { "-normal" }, typeof(IPlugin));
                }
            }
            if (ServerSettings.HasKey("PluginsPath"))
            {
                string pluginspath = ServerSettings.GetSetting("PluginsPath");
                if (Directory.Exists(pluginspath))
                {
                    DLLFiles = Directory.GetFiles(pluginspath, "*.dll");
                    foreach (string s in DLLFiles)
                    {
                        if (name == "")
                        {
                            LoadAllDlls.LoadDLL(s, new string[] { "-normal" }, typeof(IPlugin));
                        }
                        else if (ignoreCase)
                        {
                            if (s.ToLower() == name.ToLower())
                            {
                                LoadAllDlls.LoadDLL(s, new string[] { "-normal" }, typeof(IPlugin));
                            }
                        }
                        else
                        if (s == name)
                        {
                            LoadAllDlls.LoadDLL(s, new string[] { "-normal" }, typeof(IPlugin));
                        }
                        ret++;
                    }
                }
            }
            return(ret);
        }