using System; using System.Net; using BrewMonster; using CSNetwork; using CSNetwork.GPDataType; using BrewMonster.Common; using BrewMonster.UI; using UnityEngine; // Account login info struct public struct AccountLoginInfo { public uint login_time; public uint login_ip; public uint current_ip; public void Reset() { login_time = 0; login_ip = 0; current_ip = 0; } } // Game runtime partial class partial class CECGameRun { public AccountLoginInfo m_AccountLoginInfo = new AccountLoginInfo(); public bool m_bAccountLoginInfoShown = false; public byte m_accountInfoFlag = 0; public bool m_bAccountInfoShown = false; public void ResetAccountLoginInfo() { m_AccountLoginInfo.Reset(); m_bAccountLoginInfoShown = true; } /// /// Hiển thị thông tin đăng nhập của tài khoản (thời gian & IP). /// Hàm này được gọi khi người chơi vào thế giới game. /// Thông báo chỉ hiển thị một lần duy nhất theo phiên chơi nhờ biến m_bAccountLoginInfoShown. /// public void ShowAccountLoginInfo() { //Debug.Log("[Cuong] ShowAccountLoginInfo"); // Kiểm tra cờ xem đã hiển thị thông tin đăng nhập chưa để tránh in lặp lại nhiều lần. if (!m_bAccountLoginInfoShown) { var pGameUI = CECUIManager.Instance?.GetInGameUIMan(); if (pGameUI != null) { m_bAccountLoginInfoShown = true; // (Trong C++ gốc: CECUIConfig::Instance().GetGameUI().bEnableShowIP) // Hiện tại mặc định bật cờ hiển thị IP đăng nhập. bool bEnableShowIP = true; if (bEnableShowIP) { // 1. Tính toán và hiển thị thời gian đăng nhập lần trước (Last login time). DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); DateTime t = epoch.AddSeconds(m_AccountLoginInfo.login_time).ToLocalTime(); // Table 8010: chuỗi dạng "%d-%d-%d %d:%d" hoặc tương tự string timeStr = AUIDialog.FormatPrintf(pGameUI.GetStringFromTable(8010), t.Year, t.Month, t.Day, t.Hour, t.Minute); // Table 9343: chuỗi dạng "Thời gian đăng nhập trước: %s" string textTime = AUIDialog.FormatPrintf(pGameUI.GetStringFromTable(9343), timeStr); EventBus.Publish(new GameSession.ChatMessageEvent { context = textTime, channel = (byte)ChatChannel.GP_CHAT_SYSTEM }); BMLogger.Log($"[Cuong] ShowAccountLoginInfo {textTime}"); // 2. Định dạng và hiển thị IP đăng nhập lần trước (Last login IP). // Table 9344: chuỗi dạng "IP đăng nhập trước: %s" string ipStr = new IPAddress((long)m_AccountLoginInfo.login_ip).ToString(); string textIp = AUIDialog.FormatPrintf(pGameUI.GetStringFromTable(9344), ipStr); EventBus.Publish(new GameSession.ChatMessageEvent { context = textIp, channel = (byte)ChatChannel.GP_CHAT_SYSTEM }); BMLogger.Log($"[Cuong] ShowAccountLoginInfo {textIp}"); // 3. Định dạng và hiển thị IP đăng nhập hiện tại (Current login IP). // Table 9345: chuỗi dạng "IP đăng nhập hiện tại: %s" string curIpStr = new IPAddress((long)m_AccountLoginInfo.current_ip).ToString(); string textCurIp = AUIDialog.FormatPrintf(pGameUI.GetStringFromTable(9345), curIpStr); EventBus.Publish(new GameSession.ChatMessageEvent { context = textCurIp, channel = (byte)ChatChannel.GP_CHAT_SYSTEM }); BMLogger.Log($"[Cuong] ShowAccountLoginInfo {textCurIp}"); } } } } public void SetAccountInfoFlag(byte accountinfo_flag) { m_accountInfoFlag = accountinfo_flag; m_bAccountInfoShown = false; } public void ShowAccountInfo() { if (!m_bAccountInfoShown) { m_bAccountInfoShown = true; bool bEnableCompleteAccount = true; if (bEnableCompleteAccount && ((m_accountInfoFlag & 0x03) != 0)) { string text = "Hoàn tất thông tin tài khoản..."; // 9347 EventBus.Publish(new GameSession.ChatMessageEvent { context = text, channel = (byte)ChatChannel.GP_CHAT_SYSTEM }); } } } /// /// Seconds between chat reminders (default 10). Change at runtime or in code as needed. /// public float healthPlaytimeChatReminderIntervalSeconds = 600f; private uint _healthPlaytimeChatReminderAccumMs; private bool _healthPlaytimeChatReminderDidImmediateThisSession; private const string HealthPlaytimeChatReminderText = "Chơi game quá 180 phút có hại cho sức khoẻ"; private static void PublishHealthPlaytimeChatReminder() { string redMsg = "" + HealthPlaytimeChatReminderText + ""; EventBus.Publish(new GameSession.ChatMessageEvent(redMsg, (byte)ChatChannel.GP_CHAT_SYSTEM)); } private void TickHealthPlaytimeChatReminder(uint dwDeltaMs) { if (GetGameState() != (int)GameState.GS_GAME) { _healthPlaytimeChatReminderAccumMs = 0; _healthPlaytimeChatReminderDidImmediateThisSession = false; return; } if (!_healthPlaytimeChatReminderDidImmediateThisSession) { _healthPlaytimeChatReminderDidImmediateThisSession = true; _healthPlaytimeChatReminderAccumMs = 0; PublishHealthPlaytimeChatReminder(); } float intervalSec = Mathf.Max(0.1f, healthPlaytimeChatReminderIntervalSeconds); uint intervalMs = (uint)(intervalSec * 1000f); if (intervalMs < 1) intervalMs = 1; _healthPlaytimeChatReminderAccumMs += dwDeltaMs; while (_healthPlaytimeChatReminderAccumMs >= intervalMs) { _healthPlaytimeChatReminderAccumMs -= intervalMs; PublishHealthPlaytimeChatReminder(); } } }