Пример #1
0
        public void YamlConfigTests_LoadSaveTest()
        {
            string      path  = Environment.CurrentDirectory + "\\TestConfig.yml";
            YamlConfig  conf  = YamlConfig.Load(Environment.CurrentDirectory + "\\TestConfig.yml");
            List <User> users = new List <User>();

            try
            {
                users.Add(new User()
                {
                    Name = "tom", Password = "******"
                });
                users.Add(new User()
                {
                    Name = "hiroki", Password = "******"
                });
                conf.Root.Add("key", "value");
                conf.Root.Add("int", 10000);
                conf.Root.Add("users", users);
                conf.Save();
            }
            catch
            {
            }
        }
Пример #2
0
        public static CrashReport ExportReport(string title, Exception cause, bool debugReport = false)
        {
            DateTime time = DateTime.Now;
            string   path = Server.ExecutePath + "/reports/crash";
            string   file = path + "/report-" + time.ToString("yyyy_M_d H_mm_ss") + ".report";

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            YamlConfig  report = YamlConfig.Load(file);
            CrashReport data   = null;

            if (debugReport)
            {
                data = new CrashReport(title, cause, time);
            }
            else
            {
                data = new CrashReport(title, cause.ToString(), time);
            }

            report.Set("reportData", data);
            report.Save();

            return(data);
        }
Пример #3
0
        private void InitConfig()
        {
            string serverPath = $"{ExecutePath}\\ServerProperties.yml";

            this.serverConfig = YamlStaticConfig.Load <ServerConfig>(serverPath);

            string minePath = $"{ExecutePath}\\MineNET.yml";

            this.mineNETConfig = YamlStaticConfig.Load <MineNETConfig>(minePath);

            LangManager.Lang = this.mineNETConfig.Language;

            string banPath = $"{ExecutePath}\\banned-players.yml";

            this.BanConfig = YamlConfig.Load(banPath);

            string banIpPath = $"{ExecutePath}\\banned-ips.yml";

            this.BanIpConfig = YamlConfig.Load(banIpPath);

            string opPath = $"{ExecutePath}\\ops.yml";

            this.OpsConfig = YamlConfig.Load(opPath);

            string whitelistPath = $"{ExecutePath}\\whitelist.yml";

            this.WhitelistConfig = YamlConfig.Load(whitelistPath);
        }
Пример #4
0
        }                                              //TODO:

        public PluginBase()
        {
            string saveFolder = this.GetPluginPath() + "/" + this.Name;
            string saveFile   = saveFolder + "/config.yml";

            if (this.Flag.HasFlag(PluginFlags.GenerateConfig))
            {
                if (!Directory.Exists(saveFolder))
                {
                    Directory.CreateDirectory(saveFolder);
                }

                this.Config = YamlConfig.Load(saveFile);
            }

            // Danger!! 黒魔術コード (クソ遅い)
            MethodInfo[] methods =
                GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
            foreach (MethodInfo method in methods)
            {
                // Attributeを探す
                Attribute att = method.GetCustomAttribute(typeof(EventHandlerAttribute));
                if (att != null)
                {
                    // パラメータから整合性をチェック
                    ParameterInfo[] parameters = method.GetParameters();
                    if (parameters.Length > 1)
                    {
                        // パラメータを取得
                        Type args = parameters[1].ParameterType;

                        // イベントマネージャーから探す
                        EventManager   eventManager = Server.Instance.Event;
                        PropertyInfo[] properties   = eventManager.GetType().GetProperties();
                        foreach (PropertyInfo property in properties)
                        {
                            // 全てのイベントを取得
                            EventInfo[] events = property.PropertyType.GetEvents();
                            foreach (EventInfo ev in events)
                            {
                                // 型情報がパラメータと一致するものを探す
                                if (ev.EventHandlerType.GenericTypeArguments.Length > 0 &&
                                    ev.EventHandlerType.GenericTypeArguments[0] == args)
                                {
                                    // イベントを動的追加
                                    ev.AddEventHandler(property.GetMethod.Invoke(eventManager, new object[0]),
                                                       Delegate.CreateDelegate(ev.EventHandlerType, this, method));
                                }
                            }
                        }
                    }
                }
            }
        }