feature: Support listening on multiple ports simultaneously
This commit is contained in:
@@ -11,18 +11,52 @@
|
||||
#include "resource.h" // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#include "common/iniFile.h"
|
||||
#include "IOCPServer.h"
|
||||
#include "IOCPUDPServer.h"
|
||||
|
||||
// CMy2015RemoteApp:
|
||||
// <20>йش<D0B9><D8B4><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>֣<EFBFBD><D6A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2015Remote.cpp
|
||||
//
|
||||
|
||||
// ServerPair:
|
||||
// һ<><D2BB>SOCKET<45><54><EFBFBD><EFBFBD><EFBFBD>ˣ<EFBFBD><CBA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD>: ͬʱ<CDAC><CAB1><EFBFBD><EFBFBD>TCP<43><50>UDP.
|
||||
class ServerPair
|
||||
{
|
||||
private:
|
||||
Server* m_tcpServer;
|
||||
Server* m_udpServer;
|
||||
public:
|
||||
ServerPair() : m_tcpServer(new IOCPServer), m_udpServer(new IOCPUDPServer) {}
|
||||
virtual ~ServerPair() { SAFE_DELETE(m_tcpServer); SAFE_DELETE(m_udpServer); }
|
||||
|
||||
BOOL StartServer(pfnNotifyProc NotifyProc, pfnOfflineProc OffProc, USHORT uPort) {
|
||||
UINT ret1 = m_tcpServer->StartServer(NotifyProc, OffProc, uPort);
|
||||
UINT ret2 = m_udpServer->StartServer(NotifyProc, OffProc, uPort);
|
||||
return (ret1 == 0 || ret2 == 0);
|
||||
}
|
||||
|
||||
void UpdateMaxConnection(int maxConn) {
|
||||
if (m_tcpServer) m_tcpServer->UpdateMaxConnection(maxConn);
|
||||
if (m_udpServer) m_udpServer->UpdateMaxConnection(maxConn);
|
||||
}
|
||||
|
||||
void Destroy() {
|
||||
if (m_tcpServer) m_tcpServer->Destroy();
|
||||
if (m_udpServer) m_udpServer->Destroy();
|
||||
}
|
||||
|
||||
void Disconnect(CONTEXT_OBJECT* ctx) {
|
||||
if (m_tcpServer) m_tcpServer->Disconnect(ctx);
|
||||
if (m_udpServer) m_udpServer->Disconnect(ctx);
|
||||
}
|
||||
};
|
||||
|
||||
class CMy2015RemoteApp : public CWinApp
|
||||
{
|
||||
private:
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>ȡ<EFBFBD><C8A1>
|
||||
config* m_iniFile = nullptr;
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
|
||||
std::vector<Server*> m_iocpServer;
|
||||
std::vector<ServerPair*> m_iocpServer;
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
HANDLE m_Mutex = nullptr;
|
||||
|
||||
@@ -38,16 +72,25 @@ public:
|
||||
return m_iniFile;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˣ<EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0
|
||||
UINT StartServer(pfnNotifyProc NotifyProc, pfnOfflineProc OffProc, USHORT uPort) {
|
||||
auto svr = new IOCPServer();
|
||||
UINT ret = svr->StartServer(NotifyProc, OffProc, uPort);
|
||||
if (ret != 0) {
|
||||
SAFE_DELETE(svr);
|
||||
return ret;
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˣ<EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0
|
||||
// nPortʾ<74><CABE>: 6543;7543
|
||||
UINT StartServer(pfnNotifyProc NotifyProc, pfnOfflineProc OffProc, const std::string& uPort) {
|
||||
bool succeed = false;
|
||||
auto list = StringToVector(uPort, ';');
|
||||
for (int i=0; i<list.size(); ++i)
|
||||
{
|
||||
int port = std::atoi(list[i].c_str());
|
||||
auto svr = new ServerPair();
|
||||
BOOL ret = svr->StartServer(NotifyProc, OffProc, port);
|
||||
if (ret == FALSE) {
|
||||
SAFE_DELETE(svr);
|
||||
continue;
|
||||
}
|
||||
succeed = true;
|
||||
m_iocpServer.push_back(svr);
|
||||
}
|
||||
m_iocpServer.push_back(svr);
|
||||
return 0;
|
||||
|
||||
return succeed ? 0 : -1;
|
||||
}
|
||||
|
||||
// <20>ͷŷ<CDB7><C5B7><EFBFBD><EFBFBD><EFBFBD> SOCKET
|
||||
|
||||
Binary file not shown.
@@ -774,8 +774,8 @@ BOOL CMy2015RemoteDlg::OnInitDialog()
|
||||
}
|
||||
// 主控程序公网IP
|
||||
std::string ip = THIS_CFG.GetStr("settings", "master", "");
|
||||
std::string port = THIS_CFG.GetStr("settings", "ghost", "6543");
|
||||
std::string master = ip.empty() ? "" : ip + ":" + port;
|
||||
int port = THIS_CFG.Get1Int("settings", "ghost", ';', 6543);
|
||||
std::string master = ip.empty() ? "" : ip + ":" + std::to_string(port);
|
||||
const Validation* v = GetValidation();
|
||||
if (!(strlen(v->Admin) && v->Port > 0)) {
|
||||
// IMPORTANT: For authorization only.
|
||||
@@ -1422,7 +1422,7 @@ void CMy2015RemoteDlg::OnOnlineBuildClient()
|
||||
// TODO: 在此添加命令处理程序代码
|
||||
CBuildDlg Dlg;
|
||||
Dlg.m_strIP = THIS_CFG.GetStr("settings", "master", "").c_str();
|
||||
int Port = THIS_CFG.GetInt("settings", "ghost");
|
||||
int Port = THIS_CFG.Get1Int("settings", "ghost", ';', 6543);
|
||||
Dlg.m_strIP = Dlg.m_strIP.IsEmpty() ? "127.0.0.1" : Dlg.m_strIP;
|
||||
Dlg.m_strPort = Port <= 0 ? "6543" : std::to_string(Port).c_str();
|
||||
Dlg.DoModal();
|
||||
@@ -1508,12 +1508,11 @@ void CMy2015RemoteDlg::OnMainExit()
|
||||
|
||||
BOOL CMy2015RemoteDlg::ListenPort()
|
||||
{
|
||||
int nPort = THIS_CFG.GetInt("settings", "ghost");
|
||||
std::string nPort = THIS_CFG.GetStr("settings", "ghost", "6543");
|
||||
//读取ini 文件中的监听端口
|
||||
int nMaxConnection = THIS_CFG.GetInt("settings", "MaxConnection");
|
||||
//读取最大连接数
|
||||
if (nPort<=0 || nPort>65535)
|
||||
nPort = 6543;
|
||||
|
||||
if (nMaxConnection <= 0)
|
||||
nMaxConnection = 10000;
|
||||
return Activate(nPort,nMaxConnection); //开始监听
|
||||
@@ -1586,14 +1585,14 @@ std::vector<std::string> splitByNewline(const std::string& input) {
|
||||
return lines;
|
||||
}
|
||||
|
||||
BOOL CMy2015RemoteDlg::Activate(int nPort,int nMaxConnection)
|
||||
BOOL CMy2015RemoteDlg::Activate(const std::string& nPort,int nMaxConnection)
|
||||
{
|
||||
UINT ret = 0;
|
||||
if ( (ret = THIS_APP->StartServer(NotifyProc, OfflineProc, nPort)) !=0 )
|
||||
{
|
||||
Mprintf("======> StartServer Failed \n");
|
||||
char cmd[200];
|
||||
sprintf_s(cmd, "for /f \"tokens=5\" %%i in ('netstat -ano ^| findstr \":%d \"') do @echo %%i", nPort);
|
||||
sprintf_s(cmd, "for /f \"tokens=5\" %%i in ('netstat -ano ^| findstr \":%s \"') do @echo %%i", nPort.c_str());
|
||||
std::string output = exec(cmd);
|
||||
output.erase(std::remove(output.begin(), output.end(), '\r'), output.end());
|
||||
if (!output.empty())
|
||||
@@ -1625,7 +1624,7 @@ BOOL CMy2015RemoteDlg::Activate(int nPort,int nMaxConnection)
|
||||
|
||||
ShowMessage("使用提示", "严禁用于非法侵入、控制、监听他人设备等违法行为");
|
||||
CString strTemp;
|
||||
strTemp.Format("监听端口: %d成功", nPort);
|
||||
strTemp.Format("监听端口: %s成功", nPort.c_str());
|
||||
ShowMessage("操作成功",strTemp);
|
||||
return TRUE;
|
||||
}
|
||||
@@ -2466,7 +2465,7 @@ void CMy2015RemoteDlg::OnToolGenMaster()
|
||||
return;
|
||||
}
|
||||
}
|
||||
int port = THIS_CFG.GetInt("settings", "ghost");
|
||||
int port = THIS_CFG.Get1Int("settings", "ghost", ';', 6543);
|
||||
std::string id = genHMAC(pwdHash, m_superPass);
|
||||
Validation verify(atof(days.m_str), master.c_str(), port<=0 ? 6543 : port, id.c_str());
|
||||
if (!WritePwdHash(curEXE + iOffset, pwdHash, verify)) {
|
||||
|
||||
@@ -169,7 +169,7 @@ public:
|
||||
VOID CreateNotifyBar();
|
||||
VOID CreateSolidMenu();
|
||||
BOOL ListenPort();
|
||||
BOOL Activate(int nPort,int nMaxConnection);
|
||||
BOOL Activate(const std::string& nPort,int nMaxConnection);
|
||||
void UpdateActiveWindow(CONTEXT_OBJECT* ctx);
|
||||
void SendMasterSettings(CONTEXT_OBJECT* ctx);
|
||||
VOID SendServerDll(CONTEXT_OBJECT* ContextObject, bool isDLL, bool is64Bit);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "common/commands.h"
|
||||
#include "common/header.h"
|
||||
#include "common/encrypt.h"
|
||||
|
||||
@@ -14,7 +14,7 @@ IMPLEMENT_DYNAMIC(CSettingDlg, CDialog)
|
||||
|
||||
CSettingDlg::CSettingDlg(CWnd* pParent)
|
||||
: CDialog(CSettingDlg::IDD, pParent)
|
||||
, m_nListenPort(0)
|
||||
, m_nListenPort("6543")
|
||||
, m_nMax_Connect(0)
|
||||
, m_sScreenCapture(_T("GDI"))
|
||||
, m_sScreenCompress(_T("<EFBFBD><EFBFBD>Ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>㷨"))
|
||||
@@ -32,6 +32,7 @@ void CSettingDlg::DoDataExchange(CDataExchange* pDX)
|
||||
{
|
||||
CDialog::DoDataExchange(pDX);
|
||||
DDX_Text(pDX, IDC_EDIT_PORT, m_nListenPort);
|
||||
DDV_MaxChars(pDX, m_nListenPort, 32);
|
||||
DDX_Text(pDX, IDC_EDIT_MAX, m_nMax_Connect);
|
||||
DDX_Control(pDX, IDC_BUTTON_SETTINGAPPLY, m_ApplyButton);
|
||||
DDX_Control(pDX, IDC_COMBO_SCREEN_CAPTURE, m_ComboScreenCapture);
|
||||
@@ -66,7 +67,7 @@ BOOL CSettingDlg::OnInitDialog()
|
||||
IPConverter cvt;
|
||||
m_sPublicIP = THIS_CFG.GetStr("settings", "master", "").c_str();
|
||||
m_sPublicIP = m_sPublicIP.IsEmpty() ? cvt.getPublicIP().c_str() : m_sPublicIP;
|
||||
int nPort = THIS_CFG.GetInt("settings", "ghost");
|
||||
std::string nPort = THIS_CFG.GetStr("settings", "ghost", "6543");
|
||||
//<2F><>ȡini <20>ļ<EFBFBD><C4BC>еļ<D0B5><C4BC><EFBFBD><EFBFBD>˿<EFBFBD>
|
||||
int nMaxConnection = THIS_CFG.GetInt("settings", "MaxConnection");
|
||||
|
||||
@@ -74,7 +75,7 @@ BOOL CSettingDlg::OnInitDialog()
|
||||
|
||||
CString algo = THIS_CFG.GetStr("settings", "ScreenCompress", "").c_str();
|
||||
|
||||
m_nListenPort = (nPort<=0 || nPort>65535) ? 6543 : nPort;
|
||||
m_nListenPort = nPort.c_str();
|
||||
m_nMax_Connect = nMaxConnection<=0 ? 10000 : nMaxConnection;
|
||||
|
||||
int n = algo.IsEmpty() ? ALGORITHM_DIFF : atoi(algo.GetString());
|
||||
@@ -129,7 +130,7 @@ void CSettingDlg::OnBnClickedButtonSettingapply()
|
||||
{
|
||||
UpdateData(TRUE);
|
||||
THIS_CFG.SetStr("settings", "master", m_sPublicIP.GetBuffer());
|
||||
THIS_CFG.SetInt("settings", "ghost", m_nListenPort);
|
||||
THIS_CFG.SetStr("settings", "ghost", m_nListenPort.GetString());
|
||||
//<2F><>ini<6E>ļ<EFBFBD><C4BC><EFBFBD>д<EFBFBD><D0B4>ֵ
|
||||
THIS_CFG.SetInt("settings", "MaxConnection", m_nMax_Connect);
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ protected:
|
||||
|
||||
DECLARE_MESSAGE_MAP()
|
||||
public:
|
||||
UINT m_nListenPort;
|
||||
CString m_nListenPort;
|
||||
UINT m_nMax_Connect;
|
||||
virtual BOOL OnInitDialog();
|
||||
afx_msg void OnBnClickedButtonSettingapply();
|
||||
|
||||
Reference in New Issue
Block a user