Class ChatLogService
java.lang.Object
server.chat.ChatLogService
玩家聊天記錄服務(單例):把所有頻道的對話非同步寫入
chatlog 資料表,並每日清除超過保留期的舊記錄。
非同步設計:各聊天 handler 只呼叫 record(MapleClient, ChatLogType, String) 把訊息丟進
有界佇列(O(1)、不阻塞 Netty 執行緒);背景由 Timer.EtcTimer 每 3000L 毫秒批次
多列 INSERT,避免在聊天熱路徑上做 DB I/O,且批次插入遠比逐列高效。
清除:Timer.EtcTimer 每 24 小時跑一次 DELETE ... WHERE date_created < NOW()-INTERVAL N DAY
(開服後約 1 分鐘先跑一次,確保每次開機都會清)。保留天數由 settings.ini 的 chatlog_retention_days
控制;整個功能由 chatlog_enabled 總開關控制。
連線契約:flush() 取用 DatabaseConnection 的 ThreadLocal 共用連線,
try-with-resources 只涵蓋 PreparedStatement,絕不關閉共用 Connection。
-
Method Summary
Modifier and TypeMethodDescriptionstatic ChatLogService取得單例。static boolean判斷一段文字是否為指令(首字為!或@)。voidrecord(MapleClient c, ChatLogType type, String content) 記錄一則玩家對話(非阻塞)。voidstart()啟動背景的批次寫入與每日清除任務(由server.Start.run()在Timer.EtcTimer啟動後呼叫一次)。
-
Method Details
-
getInstance
取得單例。 -
record
記錄一則玩家對話(非阻塞)。功能停用、缺少玩家或內容為空時直接略過。- Parameters:
c- 發話者的連線(取 accId 與 charId)type- 頻道型別content- 發話內容(超過 255 字截斷)
-
start
public void start()啟動背景的批次寫入與每日清除任務(由server.Start.run()在Timer.EtcTimer啟動後呼叫一次)。 功能停用時不註冊任何任務。 -
isCommand
判斷一段文字是否為指令(首字為!或@)。- Parameters:
s- 待判斷文字- Returns:
- 是指令回
true
-