Class ServerProperties

java.lang.Object
server.ServerProperties

public class ServerProperties extends Object
  • Constructor Details

    • ServerProperties

      public ServerProperties()
  • Method Details

    • getPath

      public static String getPath()
    • loadProperties

      public static void loadProperties()
    • loadProperties

      public static void loadProperties(String s)
    • setProperty

      public static void setProperty(String prop, String newInf)
    • setProperty

      public static void setProperty(String prop, boolean newInf)
    • setProperty

      public static void setProperty(String prop, byte newInf)
    • setProperty

      public static void setProperty(String prop, short newInf)
    • setProperty

      public static void setProperty(String prop, int newInf)
    • setProperty

      public static void setProperty(String prop, long newInf)
    • removeProperty

      public static void removeProperty(String prop)
    • registerSaveHook

      public static void registerSaveHook(Runnable hook)
      註冊一個「存檔前同步」掛鉤(見 saveHooks)。

      掛鉤通常為某設定持有者的 storeSetting()(把其執行期欄位值寫回 props)。 由 saveProperties() 在寫檔前依註冊順序執行。

      Parameters:
      hook - 要在存檔前執行的同步動作(null 會被忽略)
    • loadInto

      public static void loadInto(List<ServerSetting> settings)
      依設定清單「載入」:對每個 ServerSetting,若 props 中有對應鍵就解析套用, 缺鍵則保留欄位原本的預設值(與舊式 getProperty(key, 預設=欄位現值) 行為一致)。
      Parameters:
      settings - 要載入的設定清單
    • collectFrom

      public static void collectFrom(List<ServerSetting> settings)
      依設定清單「收集」:把每個 ServerSetting 目前的執行期值寫回 props (存檔方向;實際落地由後續 saveProperties() 寫入 settings.ini)。
      Parameters:
      settings - 要收集的設定清單
    • saveProperties

      public static void saveProperties()
      將目前記憶體中的所有設定回寫到 settings.ini

      原本只有 loadProperties()(讀),本方法補上對應的「寫」:

      • ini 中既有的鍵 → 就地更新其值(只動 = 之後, 完整保留中文註解、區段標題、空行與原本的排列順序)。
      • 程式中已存在、但 ini 內尚未寫出的鍵 → 自動附加於檔尾 (即使用者「ini 沒自己新增也會生效並補上」的需求)。

      寫檔前會先執行所有 註冊的同步掛鉤,把快取於 ServerConstants 靜態欄位與各伺服器實例欄位、且可能於執行期被變更的設定 (倍率、各 log_* 開關、管理員模式…)寫回 props,因此存出的檔案會反映 目前實際生效的所有伺服器變數,而非開機當下載入的舊值。

      auth_server_channel_ip 注入的鍵(見 dbInjectedKeys)一律排除。 檔案以 UTF-8(保留 BOM)寫出,與 loadProperties() 的讀取編碼一致。

      注意:本方法會以記憶體值覆寫整份設定檔,因此伺服器執行期間若有人 手動編輯了 ini 的其他鍵,呼叫本方法會被記憶體值蓋掉。若只想持久化單一鍵、 不動其餘行,請改用 saveProperty(String, String)

    • saveProperty

      public static void saveProperty(String key, String value)
      持久化單一鍵:同時更新記憶體中的 propssettings.ini

      只會就地替換該鍵那一行的值(找不到才附加於檔尾),其餘行(含註解)原樣不動, 因此適合 GUI/指令在執行期改單一設定後立即存檔。

      Parameters:
      key - 設定鍵
      value - 新值
    • saveProperty

      public static void saveProperty(String key, boolean value)
      saveProperty(String, String) 的布林便利重載。
    • getProperty

      public static String getProperty(String s)
    • getProperty

      public static String getProperty(String s, String def)
    • getProperty

      public static boolean getProperty(String s, boolean def)
    • getProperty

      public static byte getProperty(String s, byte def)
    • getProperty

      public static short getProperty(String s, short def)
    • getProperty

      public static int getProperty(String s, int def)
    • getProperty

      public static long getProperty(String s, long def)
    • getProperty

      public static double getProperty(String s, double def)