mirror of
https://github.com/yuanyuanxiang/SimpleRemoter.git
synced 2026-01-21 23:13:08 +08:00
Fix: Check time to make reassigned client restore immediately
This commit is contained in:
@@ -472,14 +472,20 @@ DWORD WINAPI StartClient(LPVOID lParam)
|
||||
Mprintf("StartClient begin\n");
|
||||
ClientApp& app(*(ClientApp*)lParam);
|
||||
CONNECT_ADDRESS& settings(*(app.g_Connection));
|
||||
BOOL assigned = FALSE;
|
||||
double valid_to = 0;
|
||||
std::string ip = settings.ServerIP();
|
||||
int port = settings.ServerPort();
|
||||
if (!app.m_bShared) {
|
||||
iniFile cfg(CLIENT_PATH);
|
||||
auto now = time(0);
|
||||
auto valid_to = atof(cfg.GetStr("settings", "valid_to").c_str());
|
||||
if (now <= valid_to) {
|
||||
valid_to = atof(cfg.GetStr("settings", "valid_to").c_str());
|
||||
if (assigned = now <= valid_to) {
|
||||
auto saved_ip = cfg.GetStr("settings", "master");
|
||||
auto saved_port = cfg.GetInt("settings", "port");
|
||||
settings.SetServer(saved_ip.c_str(), saved_port);
|
||||
Mprintf("[StartClient] Client is assigned to %s:%d- %ds left.\n", saved_ip.c_str(), saved_port,
|
||||
int(valid_to-now));
|
||||
}
|
||||
}
|
||||
auto list = app.GetSharedMasterList();
|
||||
@@ -532,6 +538,11 @@ DWORD WINAPI StartClient(LPVOID lParam)
|
||||
do {
|
||||
Manager->SendHeartbeat();
|
||||
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED);
|
||||
if (assigned && time(0) > valid_to) {
|
||||
app.SetProcessState(S_CLIENT_UPDATE);
|
||||
settings.SetServer(ip.c_str(), port);
|
||||
Mprintf("[StartClient] Client is restored to %s:%d\n", ip.c_str(), port);
|
||||
}
|
||||
} while (ClientObject->IsRunning() && ClientObject->IsConnected() && app.m_bIsRunning(&app));
|
||||
while (GetTickCount64() - dwTickCount < 5000 && app.m_bIsRunning(&app))
|
||||
Sleep(200);
|
||||
|
||||
Binary file not shown.
@@ -573,6 +573,10 @@ BEGIN_MESSAGE_MAP(CMy2015RemoteDlg, CDialogEx)
|
||||
ON_COMMAND(ID_HOOK_WIN, &CMy2015RemoteDlg::OnHookWin)
|
||||
ON_COMMAND(ID_RUNAS_SERVICE, &CMy2015RemoteDlg::OnRunasService)
|
||||
ON_COMMAND(ID_HISTORY_CLIENTS, &CMy2015RemoteDlg::OnHistoryClients)
|
||||
ON_COMMAND(ID_BACKUP_DATA, &CMy2015RemoteDlg::OnBackupData)
|
||||
ON_COMMAND(ID_PLUGIN_REQUEST, &CMy2015RemoteDlg::OnPluginRequest)
|
||||
ON_COMMAND(ID_CHANGE_LANG, &CMy2015RemoteDlg::OnChangeLang)
|
||||
ON_COMMAND(ID_IMPORT_DATA, &CMy2015RemoteDlg::OnImportData)
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
|
||||
@@ -4784,3 +4788,44 @@ void CMy2015RemoteDlg::OnHistoryClients()
|
||||
m_pClientListDlg->ShowWindow(SW_SHOW);
|
||||
}
|
||||
}
|
||||
|
||||
void CMy2015RemoteDlg::OnBackupData()
|
||||
{
|
||||
MessageBoxA("如果更换主控IP,必须将主机迁移到新的主控IP名下。注意,更换主控程序的机器可能导致授权失效!"
|
||||
"请将数据库文件拷贝到目标机器,否则将丢失全部备注信息。", "提示");
|
||||
std::filesystem::path path = GetDbPath();
|
||||
std::filesystem::path dir = path.parent_path();
|
||||
ShellExecuteW(NULL, L"open", dir.c_str(), NULL, NULL, SW_SHOWNORMAL);
|
||||
}
|
||||
|
||||
void CMy2015RemoteDlg::OnPluginRequest()
|
||||
{
|
||||
TODO_NOTICE;
|
||||
}
|
||||
|
||||
void CMy2015RemoteDlg::OnChangeLang()
|
||||
{
|
||||
TODO_NOTICE;
|
||||
}
|
||||
|
||||
void CMy2015RemoteDlg::OnImportData()
|
||||
{
|
||||
if (IDOK!=MessageBoxA("导入主控程序的历史主机记录。此操作会覆盖本机的历史记录,请仅在迁移主控程序时进行操作。"
|
||||
"数据库文件仅用于恢复主机备注信息。是否继续?", "提示",IDOK)) return;
|
||||
CFileDialog fileDlg(TRUE, NULL, "YAMA.db", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
|
||||
_T("YAMA DB (*.db)|*.db|All Files (*.*)|*.*||"), AfxGetMainWnd());
|
||||
int ret = 0;
|
||||
try {
|
||||
ret = fileDlg.DoModal();
|
||||
}
|
||||
catch (...) {
|
||||
AfxMessageBox("文件对话框未成功打开! 请稍后再试。", MB_ICONWARNING);
|
||||
return;
|
||||
}
|
||||
if (ret == IDOK) {
|
||||
CString name = fileDlg.GetPathName();
|
||||
auto backup = GetDbPath() + "." + ToPekingDateTime(0);
|
||||
CopyFileA(GetDbPath().c_str(), backup.c_str(), FALSE);
|
||||
m_ClientMap->LoadFromFile(name.GetString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,4 +313,8 @@ public:
|
||||
afx_msg void OnHookWin();
|
||||
afx_msg void OnRunasService();
|
||||
afx_msg void OnHistoryClients();
|
||||
afx_msg void OnBackupData();
|
||||
afx_msg void OnPluginRequest();
|
||||
afx_msg void OnChangeLang();
|
||||
afx_msg void OnImportData();
|
||||
};
|
||||
|
||||
@@ -629,6 +629,14 @@
|
||||
#define ID_DOWNLOAD_SERVERPORT 32996
|
||||
#define ID_32997 32997
|
||||
#define ID_HISTORY_CLIENTS 32998
|
||||
#define ID_32999 32999
|
||||
#define ID_BACKUP_DATA 33000
|
||||
#define ID_33001 33001
|
||||
#define ID_PLUGIN_REQUEST 33002
|
||||
#define ID_33003 33003
|
||||
#define ID_CHANGE_LANG 33004
|
||||
#define ID_33005 33005
|
||||
#define ID_IMPORT_DATA 33006
|
||||
#define ID_EXIT_FULLSCREEN 40001
|
||||
|
||||
// Next default values for new objects
|
||||
@@ -636,7 +644,7 @@
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 326
|
||||
#define _APS_NEXT_COMMAND_VALUE 32999
|
||||
#define _APS_NEXT_COMMAND_VALUE 33007
|
||||
#define _APS_NEXT_CONTROL_VALUE 2228
|
||||
#define _APS_NEXT_SYMED_VALUE 105
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user