mirror of
https://github.com/yuanyuanxiang/SimpleRemoter.git
synced 2026-01-21 23:13:08 +08:00
Feature: Support build TestRun as windows service
This commit is contained in:
@@ -19,6 +19,17 @@
|
||||
#include "ServerServiceWrapper.h"
|
||||
#pragma comment(lib, "Dbghelp.lib")
|
||||
|
||||
BOOL ServerPair::StartServer(pfnNotifyProc NotifyProc, pfnOfflineProc OffProc, USHORT uPort)
|
||||
{
|
||||
UINT ret1 = m_tcpServer->StartServer(NotifyProc, OffProc, uPort);
|
||||
if (ret1) THIS_APP->MessageBox(CString("启动TCP服务失败: ") + std::to_string(uPort).c_str()
|
||||
+ CString("。错误码: ") + std::to_string(ret1).c_str(), "提示", MB_ICONINFORMATION);
|
||||
UINT ret2 = m_udpServer->StartServer(NotifyProc, OffProc, uPort);
|
||||
if (ret2) THIS_APP->MessageBox(CString("启动UDP服务失败: ") + std::to_string(uPort).c_str()
|
||||
+ CString("。错误码: ") + std::to_string(ret2).c_str(), "提示", MB_ICONINFORMATION);
|
||||
return (ret1 == 0 || ret2 == 0);
|
||||
}
|
||||
|
||||
CMy2015RemoteApp* GetThisApp()
|
||||
{
|
||||
return ((CMy2015RemoteApp*)AfxGetApp());
|
||||
@@ -236,8 +247,8 @@ BOOL CMy2015RemoteApp::InitInstance()
|
||||
if (ERROR_ALREADY_EXISTS == GetLastError()) {
|
||||
CloseHandle(m_Mutex);
|
||||
m_Mutex = NULL;
|
||||
MessageBoxA(NULL, "A master program is already running, please check Task Manager.",
|
||||
"Info", MB_ICONINFORMATION);
|
||||
MessageBox("一个主控程序已经在运行,请检查任务管理器。",
|
||||
"提示", MB_ICONINFORMATION);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,16 +35,7 @@ public:
|
||||
SAFE_DELETE(m_udpServer);
|
||||
}
|
||||
|
||||
BOOL StartServer(pfnNotifyProc NotifyProc, pfnOfflineProc OffProc, USHORT uPort)
|
||||
{
|
||||
UINT ret1 = m_tcpServer->StartServer(NotifyProc, OffProc, uPort);
|
||||
if (ret1) MessageBox(NULL, CString("启动TCP服务失败: ") + std::to_string(uPort).c_str()
|
||||
+ CString("。错误码: ") + std::to_string(ret1).c_str(), "提示", MB_ICONINFORMATION);
|
||||
UINT ret2 = m_udpServer->StartServer(NotifyProc, OffProc, uPort);
|
||||
if (ret2) MessageBox(NULL, CString("启动UDP服务失败: ") + std::to_string(uPort).c_str()
|
||||
+ CString("。错误码: ") + std::to_string(ret2).c_str(), "提示", MB_ICONINFORMATION);
|
||||
return (ret1 == 0 || ret2 == 0);
|
||||
}
|
||||
BOOL StartServer(pfnNotifyProc NotifyProc, pfnOfflineProc OffProc, USHORT uPort);
|
||||
|
||||
void UpdateMaxConnection(int maxConn)
|
||||
{
|
||||
@@ -65,7 +56,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class CSplashDlg; // 前向声明
|
||||
#include "SplashDlg.h"
|
||||
|
||||
class CMy2015RemoteApp : public CWinApp
|
||||
{
|
||||
@@ -102,6 +93,11 @@ public:
|
||||
return m_iniFile;
|
||||
}
|
||||
|
||||
int MessageBox(const CString& strText, const CString& strCaption = NULL, UINT nType = 0)
|
||||
{
|
||||
return m_pSplash ? m_pSplash->SafeMessageBox(strText, strCaption, nType) : ::MessageBox(NULL, strText, strCaption, nType);
|
||||
}
|
||||
|
||||
// 启动多个服务端,成功返回0
|
||||
// nPort示例: 6543;7543
|
||||
UINT StartServer(pfnNotifyProc NotifyProc, pfnOfflineProc OffProc, const std::string& uPort, int maxConn, const std::string& method)
|
||||
|
||||
@@ -489,6 +489,7 @@ BEGIN_MESSAGE_MAP(CMy2015RemoteDlg, CDialogEx)
|
||||
ON_MESSAGE(WM_SHARE_CLIENT, ShareClient)
|
||||
ON_MESSAGE(WM_ASSIGN_CLIENT, AssignClient)
|
||||
ON_MESSAGE(WM_ASSIGN_ALLCLIENT, AssignAllClient)
|
||||
ON_MESSAGE(WM_UPDATE_ACTIVEWND, UpdateUserEvent)
|
||||
ON_WM_HELPINFO()
|
||||
ON_COMMAND(ID_ONLINE_SHARE, &CMy2015RemoteDlg::OnOnlineShare)
|
||||
ON_COMMAND(ID_TOOL_AUTH, &CMy2015RemoteDlg::OnToolAuth)
|
||||
@@ -813,7 +814,8 @@ VOID CMy2015RemoteDlg::ShowMessage(CString strType, CString strMsg)
|
||||
LeaveCriticalSection(&m_cs);
|
||||
|
||||
strStatusMsg.Format("有%d个主机在线",m_iCount);
|
||||
m_StatusBar.SetPaneText(0,strStatusMsg); //在状态条上显示文字
|
||||
if (m_StatusBar.GetSafeHwnd())
|
||||
m_StatusBar.SetPaneText(0,strStatusMsg); //在状态条上显示文字
|
||||
}
|
||||
|
||||
LRESULT CMy2015RemoteDlg::OnShowErrMessage(WPARAM wParam, LPARAM lParam)
|
||||
@@ -1176,7 +1178,7 @@ BOOL CMy2015RemoteDlg::OnInitDialog()
|
||||
m_CList_Online.SetColumn(ONLINELIST_VIDEO, &lvColumn);
|
||||
timeBeginPeriod(1);
|
||||
if (IsFunctionReallyHooked("user32.dll","SetTimer") || IsFunctionReallyHooked("user32.dll", "KillTimer")) {
|
||||
MessageBoxA("FUCK!!! 请勿HOOK此程序!", "提示", MB_ICONERROR);
|
||||
THIS_APP->MessageBox("FUCK!!! 请勿HOOK此程序!", "提示", MB_ICONERROR);
|
||||
ExitProcess(-1);
|
||||
return FALSE;
|
||||
}
|
||||
@@ -2055,7 +2057,7 @@ BOOL CMy2015RemoteDlg::Activate(const std::string& nPort,int nMaxConnection, con
|
||||
if (!pids.empty()) {
|
||||
pids.back() = '?';
|
||||
}
|
||||
if (IDYES == MessageBox("调用函数StartServer失败! 错误代码:" + CString(std::to_string(ret).c_str()) +
|
||||
if (IDYES == THIS_APP->MessageBox("调用函数StartServer失败! 错误代码:" + CString(std::to_string(ret).c_str()) +
|
||||
"\r\n是否关闭以下进程重试: " + pids.c_str(), "提示", MB_YESNO)) {
|
||||
for (const auto& line : lines) {
|
||||
auto cmd = std::string("taskkill /f /pid ") + line;
|
||||
@@ -2064,7 +2066,7 @@ BOOL CMy2015RemoteDlg::Activate(const std::string& nPort,int nMaxConnection, con
|
||||
return Activate(nPort, nMaxConnection, method);
|
||||
}
|
||||
} else
|
||||
MessageBox("调用函数StartServer失败! 错误代码:" + CString(std::to_string(ret).c_str()));
|
||||
THIS_APP->MessageBox("调用函数StartServer失败! 错误代码:" + CString(std::to_string(ret).c_str()));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -2312,7 +2314,7 @@ VOID CMy2015RemoteDlg::MessageHandle(CONTEXT_OBJECT* ContextObject)
|
||||
}
|
||||
case TOKEN_HEARTBEAT:
|
||||
case 137: // 心跳【L】
|
||||
UpdateActiveWindow(ContextObject);
|
||||
g_2015RemoteDlg->SendMessage(WM_UPDATE_ACTIVEWND, 0, (LPARAM)ContextObject);
|
||||
break;
|
||||
case SOCKET_DLLLOADER: {// 请求DLL【L】
|
||||
auto len = ContextObject->InDeCompressedBuffer.GetBufferLength();
|
||||
@@ -2472,7 +2474,7 @@ LRESULT CMy2015RemoteDlg::OnUserToOnlineList(WPARAM wParam, LPARAM lParam)
|
||||
delete LoginInfor;
|
||||
return S_OK;
|
||||
} catch(...) {
|
||||
Mprintf("[ERROR] OnUserToOnlineList catch an error \n");
|
||||
Mprintf("[ERROR] OnUserToOnlineList catch an error: %s\n", ContextObject->GetPeerName().c_str());
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -2510,6 +2512,13 @@ LRESULT CMy2015RemoteDlg::OnUserOfflineMsg(WPARAM wParam, LPARAM lParam)
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
LRESULT CMy2015RemoteDlg::UpdateUserEvent(WPARAM wParam, LPARAM lParam) {
|
||||
CONTEXT_OBJECT* ctx = (CONTEXT_OBJECT*)lParam;
|
||||
UpdateActiveWindow(ctx);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void CMy2015RemoteDlg::UpdateActiveWindow(CONTEXT_OBJECT* ctx)
|
||||
{
|
||||
Heartbeat hb;
|
||||
@@ -2537,6 +2546,11 @@ void CMy2015RemoteDlg::UpdateActiveWindow(CONTEXT_OBJECT* ctx)
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (auto i = m_HostList.begin(); i != m_HostList.end(); ++i) {
|
||||
if (ctx->IsEqual(*i)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
ctx->CancelIO();
|
||||
Mprintf("UpdateActiveWindow failed: %s \n", ctx->GetPeerName().c_str());
|
||||
}
|
||||
|
||||
@@ -307,6 +307,7 @@ public:
|
||||
LRESULT assignFunction(WPARAM wParam, LPARAM lParam, BOOL all);
|
||||
afx_msg LRESULT AssignClient(WPARAM wParam, LPARAM lParam);
|
||||
afx_msg LRESULT AssignAllClient(WPARAM wParam, LPARAM lParam);
|
||||
afx_msg LRESULT UpdateUserEvent(WPARAM wParam, LPARAM lParam);
|
||||
afx_msg BOOL OnHelpInfo(HELPINFO* pHelpInfo);
|
||||
virtual BOOL PreTranslateMessage(MSG* pMsg);
|
||||
afx_msg void OnOnlineShare();
|
||||
|
||||
@@ -19,6 +19,7 @@ enum Index {
|
||||
IndexServerDll,
|
||||
IndexTinyRun,
|
||||
IndexGhostMsc,
|
||||
IndexTestRunMsc,
|
||||
OTHER_ITEM
|
||||
};
|
||||
|
||||
@@ -196,9 +197,15 @@ void CBuildDlg::OnBnClickedOk()
|
||||
case IndexGhostMsc:
|
||||
file = "ghost.exe";
|
||||
typ = CLIENT_TYPE_ONE;
|
||||
startup = Startup_GhostMsc,
|
||||
startup = Startup_GhostMsc;
|
||||
szBuffer = ReadResource(is64bit ? IDR_GHOST_X64 : IDR_GHOST_X86, dwFileSize);
|
||||
break;
|
||||
case IndexTestRunMsc:
|
||||
file = "TestRun.exe";
|
||||
typ = CLIENT_TYPE_MEMDLL;
|
||||
startup = Startup_TestRunMsc;
|
||||
szBuffer = ReadResource(is64bit ? IDR_TESTRUN_X64 : IDR_TESTRUN_X86, dwFileSize);
|
||||
break;
|
||||
case IndexServerDll:
|
||||
file = "ServerDll.dll";
|
||||
typ = CLIENT_TYPE_DLL;
|
||||
@@ -381,6 +388,7 @@ BOOL CBuildDlg::OnInitDialog()
|
||||
m_ComboExe.InsertString(IndexServerDll, "ServerDll.dll");
|
||||
m_ComboExe.InsertString(IndexTinyRun, "TinyRun.dll");
|
||||
m_ComboExe.InsertString(IndexGhostMsc, "ghost.exe - Windows <20><><EFBFBD><EFBFBD>");
|
||||
m_ComboExe.InsertString(IndexTestRunMsc, "TestRun - Windows <20><><EFBFBD><EFBFBD>");
|
||||
m_ComboExe.InsertString(OTHER_ITEM, CString("ѡ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>"));
|
||||
m_ComboExe.SetCurSel(IndexTestRun_MemDLL);
|
||||
|
||||
|
||||
@@ -25,6 +25,17 @@ CSplashDlg::~CSplashDlg()
|
||||
m_fontStatus.DeleteObject();
|
||||
}
|
||||
|
||||
int CSplashDlg::SafeMessageBox(LPCTSTR lpszText, LPCTSTR lpszCaption, UINT nType)
|
||||
{
|
||||
SetWindowPos(&wndNoTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
|
||||
|
||||
int result = MessageBox(lpszText, lpszCaption, nType);
|
||||
|
||||
SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
BOOL CSplashDlg::Create(CWnd* pParent)
|
||||
{
|
||||
// 注册窗口类
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <afxwin.h>
|
||||
|
||||
// 启动画面对话框 - 显示加载进度
|
||||
class CSplashDlg : public CWnd
|
||||
{
|
||||
@@ -12,6 +10,8 @@ public:
|
||||
// 创建并显示启动画面
|
||||
BOOL Create(CWnd* pParent = NULL);
|
||||
|
||||
int SafeMessageBox(LPCTSTR lpszText, LPCTSTR lpszCaption, UINT nType);
|
||||
|
||||
// 更新进度 (0-100) - 通过消息队列(用于跨线程)
|
||||
void SetProgress(int nPercent);
|
||||
|
||||
|
||||
@@ -90,6 +90,7 @@
|
||||
#define WM_ASSIGN_CLIENT WM_USER+3027
|
||||
#define WM_ASSIGN_ALLCLIENT WM_USER+3028
|
||||
#define WM_ANTI_BLACKSCREEN WM_USER+3029
|
||||
#define WM_UPDATE_ACTIVEWND WM_USER+3030
|
||||
|
||||
#ifdef _UNICODE
|
||||
#if defined _M_IX86
|
||||
|
||||
Reference in New Issue
Block a user