Ejemplo n.º 1
0
        public static void Load()
        {
            if (!File.Exists("SSC/config.json"))
            {
                ServerSideCharacter2.Config = ConfigData.DefaultConfig();
            }
            else
            {
                try
                {
                    string data;
                    using (var reader = new StreamReader(defaultName, Encoding.UTF8))
                    {
                        data = reader.ReadToEnd();
                    }

                    ServerSideCharacter2.Config = JsonConvert.DeserializeObject <ConfigData>(data);
                    QQAuth.ConnectionStr        = $"server={ServerSideCharacter2.Config.ServerAddr};User Id={ServerSideCharacter2.Config.ServerUserID};Password={ServerSideCharacter2.Config.ServerPassword};" +
                                                  $"Database={ServerSideCharacter2.Config.DatabaseName};port={ServerSideCharacter2.Config.ServerPort}";
                }
                catch (Exception ex)
                {
                    CommandBoardcast.ConsoleError("读取配置文件出错,重置为默认配置");
                    CommandBoardcast.ConsoleError(ex);
                    ServerSideCharacter2.Config = ConfigData.DefaultConfig();
                }
            }
            CommandBoardcast.ConsoleMessage("配置文件已经加载");
            CommandBoardcast.ConsoleMessage(
                $"当前配置  自动保存: {(ServerSideCharacter2.Config.AutoSave ? "开" : "关")},自动保存间隔:{ServerSideCharacter2.Config.SaveInterval / 60f}s");

            GroupConfigManager            = new GroupConfig();
            UnionDataManager              = new Unions.UnionConfig();
            RegionConfig                  = new RegionConfig();
            ServerSideCharacter2.RankData = RankData.Load();

            Save();
        }
Ejemplo n.º 2
0
 public DataConfig()
 {
     ConfigExist = File.Exists(Path);
     if (!ConfigExist)
     {
         _data = new ConfigData();
         SetDefaults(_data);
         var data = JsonConvert.SerializeObject(_data, Formatting.Indented, converter);
         using (var sw = new StreamWriter(Path))
         {
             sw.Write(data);
         }
         CommandBoardcast.ConsoleMessage(Message);
     }
     else
     {
         using (var sr = new StreamReader(Path))
         {
             var data = sr.ReadToEnd();
             _data = JsonConvert.DeserializeObject <ConfigData>(data, converter);
         }
         Receive(_data.Data);
     }
 }