Feature: Add remote_block_input to MCP remote control
A GUI automation run is interrupted the moment a person at the host touches the mouse, and locking the host's keyboard and mouse is the standard answer. The client already implements COMMAND_SCREEN_BLOCK_INPUT and the MFC screen window already sends it, so the tool needs no client change: it puts the same two-byte packet [COMMAND_SCREEN_BLOCK_INPUT][0|1] on the hidden screen sub-connection that remote_open established. The gate is remote_open's own - McpRemoteControl=1 and McpReadonly=0 - because the ability to lock someone out deserves exactly the same door as the ability to drive their desktop, and Linux and Android clients are refused with -32005: they have no branch for this packet at all and would silently ignore it. Locking a host out is only acceptable if every way back in is closed, so the session now carries its own lock state and three paths release it. block=false releases it directly. block=true always carries a deadline (max_block_ms, default 300000, clamped to 1000..3600000) and a watchdog thread started with the MCP server sweeps every 500ms for expired locks, sends the release and records it; the next remote_block_input reports it as auto_unblocked so the model learns that its lock lapsed instead of assuming it is still held. remote_close and the idle reclaim both send block=false before they tear the sub-connection down, because once that connection is gone the server has no channel left and a live client process stays blocked - all three release paths write an audit line, since none of them is something a person can see. The send happens outside the MCP lock, and the watchdog takes the session's busy flag while it releases, so it cannot interleave with an injection or race a close; a failed send keeps the lock marked and retries five seconds later rather than hammering a dead connection every tick, and a session that dies under the watchdog is erased the same way an injection would erase it. Verified against a real Windows client over MCP on a Debug x64 build: block then unblock, block with a 1.5-2s deadline left to expire and reported back as auto_unblocked with the watchdog audit entry at the expected second, block with a ten-minute deadline then remote_close with "(input lock forced off)" in the audit, and the five refusals (missing block, non-boolean block, max_block_ms out of range, unknown session, offline host). The smoke test gained [4d] for those refusals; 54 checks pass. Two limits are worth stating plainly. BlockInput only works when the calling process is elevated (or UIAccess), the client ignores the API's return value, so on an ordinary client the lock silently does nothing and the tool can only promise that the command was delivered - both the tool description and the server instructions say so. And the idle-reclaim release, like the two verified paths, is only exercised at a 300s idle timeout; it shares the same send helper and was reviewed rather than timed out live. Bin/settings.ini was restored byte-exact and the Release instance was left alone. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
27b5431130
commit
3d388f8e45
4 files changed
+406
-15
No files matched your search
@@ -263,6 +263,28 @@ public:
|
||||
// 屏幕子连接断开(OfflineProc 调用):擦除该子连接对应的会话 + 路由(幂等)。
|
||||
void OnScreenControlClosed(context* subCtx);
|
||||
|
||||
// ===== P10-C:键鼠锁定(remote_block_input)=====
|
||||
// 锁定状态记在会话上,报文由调用方在锁外发([COMMAND_SCREEN_BLOCK_INPUT][0|1])。
|
||||
// 必须在 BeginScreenCtrlAction 之后调用(busy 期间会话不会被并发擦除,状态才有意义)。
|
||||
// block=true 时以 maxBlockMs 为自动解锁期限。autoUnblocked 输出「上一次锁定是否因
|
||||
// 超过 maxBlockMs 被服务端自动解除」(取走后清除),供工具结果标注。
|
||||
// 返回 false = 会话已不存在(防御;正常不会发生)。
|
||||
bool ScreenCtrlSetBlock(uint64_t device_id, const std::string& sessionId, bool block,
|
||||
int maxBlockMs, bool& autoUnblocked);
|
||||
|
||||
// 该会话此刻是否锁定着对端键鼠(仅审计用:remote_close 要能说明自己强制解了锁)。
|
||||
bool IsScreenCtrlBlocked(uint64_t device_id, const std::string& sessionId);
|
||||
|
||||
// 键鼠锁定的强制解除:关闭会话 / idle 回收 / 超期自动解锁时必须先发 block=false,
|
||||
// 否则客户端进程还活着就会一直 BlockInput(人进不来)。三处实现:
|
||||
// 1) CloseScreenCtrlSession / SweepIdleScreenCtrl —— 擦会话前发(见 .cpp);
|
||||
// 2) WatchdogScreenBlock —— 每 500ms 扫描超过 blockUntil 的会话;
|
||||
// 3) OnScreenControlClosed —— 子连接已断,无从下发,只能靠客户端进程退出(既有局限)。
|
||||
// 另一个既有局限:Windows 要求调用进程有管理员权限(或 UIAccess)才允许 BlockInput,
|
||||
// 客户端忽略返回值,低权限下会静默不生效——服务端无从得知,故工具结果只承诺「已送达」。
|
||||
void BlockWatchdogLoop();
|
||||
void WatchdogScreenBlock();
|
||||
|
||||
// ===== P6:MCP 文件传输(download_file,V2 协议)=====
|
||||
// 下载走 CMD_DOWN_FILES_V2 → 客户端新开流式子连接回传 COMMAND_SEND_FILE_V2 /
|
||||
// COMMAND_FILE_COMPLETE_V2(dstClientID==0)。会话按 device_id 键控,单设备单传输;
|
||||
@@ -588,6 +610,9 @@ private:
|
||||
McpTlsProxy m_tlsProxy; // HTTPS 前端(仅在 m_httpsEnabled 时启动)
|
||||
std::thread m_thread;
|
||||
std::atomic<bool> m_running{false};
|
||||
// 键鼠锁定看门狗(P10-C):m_blockStop 置位后线程在下一次 100ms 切片退出。
|
||||
std::thread m_blockThread;
|
||||
std::atomic<bool> m_blockStop{false};
|
||||
std::string m_token;
|
||||
std::string m_bind; // Start 传入的监听地址
|
||||
int m_port = 0; // Start 传入的监听端口
|
||||
@@ -717,6 +742,11 @@ private:
|
||||
time_t lastActiveAt = 0; // idle 回收用(秒)
|
||||
int screenW = 0; // 物理捕获分辨率(来自 TOKEN_BITMAPINFO)
|
||||
int screenH = 0;
|
||||
// P10-C 键鼠锁定:inputBlocked 是服务端认为的锁定状态(唯一真相,用于强制解锁);
|
||||
// blockUntil 是自动解锁期限;blockAutoReleased 待下一次 remote_block_input 上报。
|
||||
bool inputBlocked = false;
|
||||
std::chrono::steady_clock::time_point blockUntil{};
|
||||
bool blockAutoReleased = false;
|
||||
};
|
||||
std::mutex m_ScreenCtrlMutex;
|
||||
std::map<uint64_t, ScreenCtrlSession> m_ScreenCtrlSessions; // device_id → 会话
|
||||
|
||||
Reference in new issue
Block a user