Fix(client): refresh RES_UPTIME on every login so host popup shows the real runtime
双击 Linux 主机浮窗显示「启动信息 2026-11-14 13:33:52 + 1.3h」:日期是对的(进程确实从
11-14 06:33 起一直在跑,期间只有 TCP 重连),错的是时长——真实 6.2d,而 1.3h 正好等于当天
09:05:53 那次重连到双击时刻的间隔。
2cbed0d 加的 RES_UPTIME(登录时刻进程已运行秒数)在 Linux/macOS/Android 里跟着 LOGIN_INFOR
一起在重连循环外只构造一次、重连时原样重发,于是永远停在进程启动那一瞬的 0;服务端做
RES_UPTIME + GetAliveTime(),加出来就只剩「本次连接时长」。Windows 没有这个问题,它的
GetLoginInfo 在连接循环里每次重建。老客户端(build Oct 31 及更早)根本不发这个字段,服务端
退回 szStartTime 字符串、LNX 按北京时间比,反而正确——这就是「老版本显示正常」的原因。
改法:LOGIN_INFOR::SetReserved(index, v) 按 '|' 位置改写单个字段(末尾空槽原样保留、超长
整体放弃、越界拒绝),三个客户端把各自复制粘贴的「拆字段改 [19]」换成一行调用,并新增
RefreshLoginUptime 在每次 SendLoginInfo 前重算 [20](含 Linux 的分组变更重发路径)。
影响:只动登录包的第 21 个字段,结构体布局、字段顺序与协议不变,老主控忽略它。
已部署的旧 build 需重新下发才会恢复正常显示。
验证:SetReserved 用 MSVC 单测(21 字段位置不变、连改两次、空槽保留、补槽、超长与越界
拒绝)。三个客户端本体未编译:本机 WSL 被安全策略拦住、Docker 引擎未启动。
This commit is contained in:
1 parent
d6ea5fddea
commit
b466f568ab
4 files changed
+70
-68
No files matched your search
+16
-23
@@ -1778,30 +1778,17 @@ static void ApplySelfUpdate(const PBYTE szBuffer, ULONG ulLength)
|
||||
// 只在主线程调用(与 SendLoginInfo 同一线程),避免和接收线程抢同一个结构体。
|
||||
static void RefreshLoginTls(LOGIN_INFOR& info)
|
||||
{
|
||||
std::vector<std::string> fields;
|
||||
std::string s(info.szReserved);
|
||||
size_t pos = 0;
|
||||
for (;;) {
|
||||
size_t bar = s.find('|', pos);
|
||||
if (bar == std::string::npos) {
|
||||
fields.push_back(s.substr(pos));
|
||||
break;
|
||||
}
|
||||
fields.push_back(s.substr(pos, bar - pos));
|
||||
pos = bar + 1;
|
||||
}
|
||||
while (fields.size() <= (size_t)RES_TLS)
|
||||
fields.push_back("");
|
||||
fields[RES_TLS] = TlsEnabled() ? "1" : "0";
|
||||
info.SetReserved(RES_TLS, TlsEnabled() ? "1" : "0");
|
||||
}
|
||||
|
||||
std::string joined;
|
||||
for (size_t i = 0; i < fields.size(); ++i) {
|
||||
if (i)
|
||||
joined += '|';
|
||||
joined += fields[i];
|
||||
}
|
||||
strncpy(info.szReserved, joined.c_str(), sizeof(info.szReserved) - 1);
|
||||
info.szReserved[sizeof(info.szReserved) - 1] = '\0';
|
||||
// 登录信息 szReserved 里的 [20] RES_UPTIME 是「登录这一刻进程已经运行了多少秒」,服务端
|
||||
// 再加本次上线时长才是当前运行时长。logInfo 在重连循环外只构造一次(见 main 里的注释),
|
||||
// 不刷新的话每次重连上报的仍是进程启动那一瞬的 0,服务端算出来就只剩「本次连接时长」——
|
||||
// vps 实测:进程从 11-14 06:33 一直跑着,浮窗却只显示 1.3h(正好是当天 09:05 那次重连到
|
||||
// 双击时刻的间隔),而启动时间本身是对的。与 RefreshLoginTls 同样只在主线程登录前调用。
|
||||
static void RefreshLoginUptime(LOGIN_INFOR& info)
|
||||
{
|
||||
info.SetReserved(RES_UPTIME, std::to_string(getProcessUptimeSeconds()).c_str());
|
||||
}
|
||||
|
||||
// 能力位(moduleVersion 的 "-%04X" 后缀)里唯一依赖运行环境的是屏幕预览:
|
||||
@@ -1891,6 +1878,9 @@ int main(int argc, char* argv[])
|
||||
char hostname[256] = {};
|
||||
gethostname(hostname, sizeof(hostname));
|
||||
|
||||
// 只构造一次,每次连接复用它发登录。因此凡是「随连接变化」的字段都必须在发送前
|
||||
// 用 RefreshLoginTls / RefreshLoginUptime / RefreshLoginCaps 刷新;反过来,属于
|
||||
// 「进程启动时的事实」(szStartTime、clientID、安装时间…)就靠复用保持不变。
|
||||
LOGIN_INFOR logInfo;
|
||||
|
||||
// 读取分组名称(从配置文件或 g_SETTINGS)
|
||||
@@ -2061,6 +2051,8 @@ int main(int argc, char* argv[])
|
||||
ClientAuth::OnNewConnection();
|
||||
// 传输方式可能已被热切换(TLS 启/停),登录上报的 RES_TLS 必须反映本次连接。
|
||||
RefreshLoginTls(logInfo);
|
||||
// 同一条连接可能是几小时前断掉后重连的,RES_UPTIME 必须按「现在」重算
|
||||
RefreshLoginUptime(logInfo);
|
||||
// 屏幕预览能力取决于本机当前是否有可用桌面(daemon 启动时可能还没有 DISPLAY)
|
||||
RefreshLoginCaps(logInfo);
|
||||
ClientObject->SendLoginInfo(logInfo.Speed(clock() - c));
|
||||
@@ -2082,6 +2074,7 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
logInfo.szPCName[sizeof(logInfo.szPCName) - 1] = '\0';
|
||||
RefreshLoginTls(logInfo);
|
||||
RefreshLoginUptime(logInfo);
|
||||
RefreshLoginCaps(logInfo);
|
||||
ClientObject->SendLoginInfo(logInfo);
|
||||
Mprintf(">> Resent login info after group change\n");
|
||||
|
||||
Reference in new issue
Block a user