Improve: Park duplicate online connections as standby, promote on old removal
Replacing the old connection on a duplicate login made the client reconnect in a tight loop. Instead, park the new connection in a standby list keyed by clientID and promote it into the main host list only after the old connection is removed by heartbeat timeout or disconnect. Fix heartbeat attribution so a parked standby refreshes its own last-heartbeat time rather than the main connection's, otherwise the main never times out and the standby can never take over. Gate the offline notification on an actual removal with no promoted standby to avoid a spurious "host offline" when takeover happens. Skip promoting a standby already marked removed, and reuse the normal login sign/settings path when a standby is promoted. Co-Authored-By: deepseek-v4-pro
This commit is contained in:
@@ -344,6 +344,10 @@ public:
|
||||
int m_nSplitPos = 160; // 消息区高度(像素),可拖动调整
|
||||
std::vector<context*> m_HostList; // 虚拟列表数据源(全部客户端)
|
||||
std::unordered_map<uint64_t, size_t> m_ClientIndex; // clientID -> m_HostList 索引映射
|
||||
// 重复上线的替补连接:clientID -> 替补 context。
|
||||
// 网络抖动导致客户端用新连接重复上线时,不立即替换/关闭旧连接(否则会触发客户端
|
||||
// 反复重连抖动),而是把新连接暂存到这里;旧连接因心跳超时或断开被移除后,再取替补转正。
|
||||
std::unordered_map<uint64_t, CONTEXT_OBJECT*> m_StandbyHosts;
|
||||
std::vector<size_t> m_FilteredIndices; // 当前分组过滤后的索引列表
|
||||
int m_nSortColumn = -1; // 当前排序列,-1 表示未排序
|
||||
bool m_bSortAscending = true; // 排序方向(true=升序)
|
||||
@@ -366,6 +370,9 @@ public:
|
||||
context* FindHostNoLock(int port); // caller must hold m_cs lock
|
||||
context* FindHostNoLock(uint64_t id); // caller must hold m_cs lock
|
||||
bool RemoveFromHostList(context* ctx); // 从 m_HostList 中移除并更新索引
|
||||
void AddToStandbyList(CONTEXT_OBJECT* ctx); // 重复上线:暂存替补连接(替换旧替补)
|
||||
void RemoveFromStandbyList(CONTEXT_OBJECT* ctx); // 连接断开时从替补列表移除(幂等)
|
||||
bool PromoteStandby(uint64_t clientID); // 旧连接移除后,取替补转正(需持有 m_cs);返回是否真的转正
|
||||
|
||||
CStatusBar m_StatusBar; //状态条
|
||||
ULONGLONG m_ullStartTime = 0; // 程序启动时间 (GetTickCount64)
|
||||
|
||||
Reference in New Issue
Block a user