Files
SimpleRemoter/server/2015Remote/TriggerSettingsDlg.h
T
yuanyuanxianganddeepseek-v4-pro d80d8f21da Feature: Add auth-failed trigger type (授权失败触发)
Add a second trigger type TRIGGER_AUTH_FAILED alongside the existing
TRIGGER_HOST_ONLINE. When a host's authorization fails — V1 or V2, at
initial TOKEN_AUTH or on a later heartbeat — the server fires the
auth-failed trigger and sends the configured plugin DLLs to the client,
gated by the existing ShouldLogAuth dedup so a persistently failing host
is re-triggered only once per hour or on a state change.

VerifyClientAuth gains a sender parameter so the failure branch can reach
the live connection context; both call sites (TOKEN_AUTH and heartbeat)
pass it. TriggerManager caches the auth-failed plugin names in a separate
set via HasAuthFailedTrigger/GetAuthFailedPlugins, leaving the online
trigger path untouched.

Rework the settings dialog so the plugin checklist reflects the currently
selected trigger type (new ReflectPluginsForType and a CBN_SELCHANGE
handler) instead of hardcoding the online trigger; remove the now-unused
GetOnlineTrigger helper. Add "授权失败" translations to en_US, zh_TW and
de_DE.

Co-Authored-By: deepseek-v4-pro
2026-10-06 17:50:30 +02:00

109 lines
3.1 KiB
C++

#pragma once
#include "resource.h"
#include "LangManager.h"
#include <vector>
#include <string>
#include <set>
// 前向声明
struct DllInfo;
// 触发器类型
enum TriggerType {
TRIGGER_HOST_ONLINE = 0, // 主机上线
TRIGGER_AUTH_FAILED = 1, // 授权失败
// 后续可扩展更多类型
};
// 触发器配置
struct TriggerConfig {
TriggerType Type; // 触发类型
std::vector<std::string> PluginNames; // 要执行的插件名称列表
TriggerConfig() : Type(TRIGGER_HOST_ONLINE) {}
};
// 触发器管理器(单例,线程安全,缓存配置)
class TriggerManager {
public:
static TriggerManager& Instance() {
static TriggerManager instance;
return instance;
}
// 获取主机上线触发器的插件名称集合(高性能查询)
std::set<std::string> GetOnlinePlugins();
// 获取授权失败触发器的插件名称集合(高性能查询)
std::set<std::string> GetAuthFailedPlugins();
// 重新加载配置(保存后调用)
void Reload();
// 检查是否有上线触发器
bool HasOnlineTrigger();
// 检查是否有授权失败触发器
bool HasAuthFailedTrigger();
private:
TriggerManager();
~TriggerManager();
TriggerManager(const TriggerManager&) = delete;
TriggerManager& operator=(const TriggerManager&) = delete;
void LoadFromDisk();
CRITICAL_SECTION m_cs;
std::set<std::string> m_OnlinePlugins; // 缓存的上线触发器插件名称
std::set<std::string> m_AuthFailedPlugins; // 缓存的授权失败触发器插件名称
bool m_bLoaded;
};
// 触发器设置对话框
class CTriggerSettingsDlg : public CDialogLangEx
{
public:
CTriggerSettingsDlg(std::vector<DllInfo*>& dllList, CWnd* pParent = nullptr);
virtual ~CTriggerSettingsDlg();
enum { IDD = IDD_DIALOG_TRIGGER_SETTINGS };
// 静态方法:加载触发器配置
static std::vector<TriggerConfig> LoadTriggerConfigs();
// 静态方法:保存触发器配置
static void SaveTriggerConfigs(const std::vector<TriggerConfig>& configs);
// 静态方法:获取配置文件路径
static std::string GetTriggerConfigPath();
protected:
virtual void DoDataExchange(CDataExchange* pDX);
virtual BOOL OnInitDialog();
DECLARE_MESSAGE_MAP()
afx_msg void OnBnClickedBtnSave();
afx_msg void OnBnClickedBtnTriggerAdd();
afx_msg void OnBnClickedBtnTriggerRemove();
afx_msg void OnLvnItemchangedListTriggers(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnCbnSelchangeComboTriggerType();
private:
void InitControls();
void LoadPluginsToList();
void LoadTriggersToList();
void UpdateTriggerDisplay();
// 回显指定触发类型已勾选的插件(取消其他勾选)
void ReflectPluginsForType(TriggerType type);
private:
std::vector<DllInfo*>& m_DllList; // 引用主对话框的 DLL 列表
std::vector<TriggerConfig> m_Configs; // 触发器配置列表
// 控件变量
CComboBox m_comboTriggerType;
CListCtrl m_listPlugins;
CListCtrl m_listTriggers;
};