2025-11-29 14:13:34 +01:00
|
|
|
|
|
|
|
|
|
|
// 2015Remote.h : PROJECT_NAME 应用程序的主头文件
|
2019-01-05 20:21:43 +08:00
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef __AFXWIN_H__
|
2025-11-29 14:13:34 +01:00
|
|
|
|
#error "在包含此文件之前包含“stdafx.h”以生成 PCH 文件"
|
2019-01-05 20:21:43 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
|
2025-11-29 14:13:34 +01:00
|
|
|
|
#include "resource.h" // 主符号
|
2025-06-18 04:22:48 +08:00
|
|
|
|
#include "common/iniFile.h"
|
2025-04-07 18:18:36 +08:00
|
|
|
|
#include "IOCPServer.h"
|
2025-07-01 04:01:10 +08:00
|
|
|
|
#include "IOCPUDPServer.h"
|
2025-07-20 04:42:29 +08:00
|
|
|
|
#include "IOCPKCPServer.h"
|
2019-01-05 20:21:43 +08:00
|
|
|
|
|
|
|
|
|
|
// CMy2015RemoteApp:
|
2025-11-29 14:13:34 +01:00
|
|
|
|
// 有关此类的实现,请参阅 2015Remote.cpp
|
2019-01-05 20:21:43 +08:00
|
|
|
|
//
|
|
|
|
|
|
|
2025-10-15 04:32:59 +08:00
|
|
|
|
// ServerPair:
|
2025-11-29 14:13:34 +01:00
|
|
|
|
// 一对SOCKET服务端,监听端口: 同时监听TCP和UDP.
|
2025-07-01 04:01:10 +08:00
|
|
|
|
class ServerPair
|
|
|
|
|
|
{
|
|
|
|
|
|
private:
|
2025-10-15 04:32:59 +08:00
|
|
|
|
Server* m_tcpServer;
|
|
|
|
|
|
Server* m_udpServer;
|
2025-07-01 04:01:10 +08:00
|
|
|
|
public:
|
2025-10-15 04:32:59 +08:00
|
|
|
|
ServerPair(int method=0) :
|
|
|
|
|
|
m_tcpServer(new IOCPServer),
|
|
|
|
|
|
m_udpServer(method ? (Server*)new IOCPKCPServer : new IOCPUDPServer) {}
|
|
|
|
|
|
virtual ~ServerPair()
|
|
|
|
|
|
{
|
|
|
|
|
|
SAFE_DELETE(m_tcpServer);
|
|
|
|
|
|
SAFE_DELETE(m_udpServer);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-02 21:45:43 +01:00
|
|
|
|
BOOL StartServer(pfnNotifyProc NotifyProc, pfnOfflineProc OffProc, USHORT uPort);
|
2025-10-15 04:32:59 +08:00
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
2025-07-01 04:01:10 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2025-12-02 21:45:43 +01:00
|
|
|
|
#include "SplashDlg.h"
|
2025-11-29 14:13:34 +01:00
|
|
|
|
|
2019-01-05 20:21:43 +08:00
|
|
|
|
class CMy2015RemoteApp : public CWinApp
|
|
|
|
|
|
{
|
2025-06-30 04:35:38 +08:00
|
|
|
|
private:
|
2025-11-29 14:13:34 +01:00
|
|
|
|
// 配置文件读取器
|
2025-10-15 04:32:59 +08:00
|
|
|
|
config* m_iniFile = nullptr;
|
2025-11-29 14:13:34 +01:00
|
|
|
|
// 服务端对象列表
|
2025-10-15 04:32:59 +08:00
|
|
|
|
std::vector<ServerPair*> m_iocpServer;
|
2025-11-29 14:13:34 +01:00
|
|
|
|
// 互斥量
|
2025-10-15 04:32:59 +08:00
|
|
|
|
HANDLE m_Mutex = nullptr;
|
2025-11-29 14:13:34 +01:00
|
|
|
|
// 启动画面
|
|
|
|
|
|
CSplashDlg* m_pSplash = nullptr;
|
2025-06-30 04:35:38 +08:00
|
|
|
|
|
2019-01-05 20:21:43 +08:00
|
|
|
|
public:
|
2025-10-15 04:32:59 +08:00
|
|
|
|
CMy2015RemoteApp();
|
|
|
|
|
|
|
2025-11-29 14:13:34 +01:00
|
|
|
|
CImageList m_pImageList_Large; // 系统大图标
|
|
|
|
|
|
CImageList m_pImageList_Small; // 系统小图标
|
|
|
|
|
|
|
|
|
|
|
|
// 获取启动画面指针
|
2025-11-29 23:22:55 +01:00
|
|
|
|
CSplashDlg* GetSplash() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_pSplash;
|
|
|
|
|
|
}
|
|
|
|
|
|
void SetSplash(CSplashDlg* pSplash)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pSplash = pSplash;
|
|
|
|
|
|
}
|
2025-10-15 04:32:59 +08:00
|
|
|
|
|
|
|
|
|
|
virtual BOOL InitInstance();
|
|
|
|
|
|
|
|
|
|
|
|
config* GetCfg() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_iniFile;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-02 21:45:43 +01:00
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-29 14:13:34 +01:00
|
|
|
|
// 启动多个服务端,成功返回0
|
|
|
|
|
|
// nPort示例: 6543;7543
|
2025-10-15 04:32:59 +08:00
|
|
|
|
UINT StartServer(pfnNotifyProc NotifyProc, pfnOfflineProc OffProc, const std::string& uPort, int maxConn, const std::string& method)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool succeed = false;
|
|
|
|
|
|
auto list = StringToVector(uPort, ';');
|
|
|
|
|
|
auto methods = StringToVector(method, ';', list.size());
|
|
|
|
|
|
for (int i=0; i<list.size(); ++i) {
|
|
|
|
|
|
int port = std::atoi(list[i].c_str());
|
|
|
|
|
|
auto svr = new ServerPair(atoi(methods[i].c_str()));
|
|
|
|
|
|
BOOL ret = svr->StartServer(NotifyProc, OffProc, port);
|
|
|
|
|
|
if (ret == FALSE) {
|
|
|
|
|
|
SAFE_DELETE(svr);
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
svr->UpdateMaxConnection(maxConn);
|
|
|
|
|
|
succeed = true;
|
|
|
|
|
|
m_iocpServer.push_back(svr);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return succeed ? 0 : -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-29 14:13:34 +01:00
|
|
|
|
// 释放服务端 SOCKET
|
2025-10-15 04:32:59 +08:00
|
|
|
|
void Destroy()
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int i=0; i<m_iocpServer.size(); ++i) {
|
|
|
|
|
|
m_iocpServer[i]->Destroy();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-29 14:13:34 +01:00
|
|
|
|
// 释放服务端指针
|
2025-10-15 04:32:59 +08:00
|
|
|
|
void Delete()
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int i = 0; i < m_iocpServer.size(); ++i) {
|
|
|
|
|
|
SAFE_DELETE(m_iocpServer[i]);
|
|
|
|
|
|
}
|
|
|
|
|
|
m_iocpServer.clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-29 14:13:34 +01:00
|
|
|
|
// 更新最大连接数
|
2025-10-15 04:32:59 +08:00
|
|
|
|
void UpdateMaxConnection(int maxConn)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int i = 0; i < m_iocpServer.size(); ++i) {
|
|
|
|
|
|
m_iocpServer[i]->UpdateMaxConnection(maxConn);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DECLARE_MESSAGE_MAP()
|
|
|
|
|
|
virtual int ExitInstance();
|
2019-01-05 20:21:43 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2025-06-18 04:22:48 +08:00
|
|
|
|
extern CMy2015RemoteApp theApp;
|
|
|
|
|
|
|
|
|
|
|
|
CMy2015RemoteApp* GetThisApp();
|
|
|
|
|
|
|
|
|
|
|
|
config& GetThisCfg();
|
|
|
|
|
|
|
2025-07-13 04:37:14 +08:00
|
|
|
|
std::string GetMasterHash();
|
|
|
|
|
|
|
2025-06-18 04:22:48 +08:00
|
|
|
|
#define THIS_APP GetThisApp()
|
|
|
|
|
|
|
|
|
|
|
|
#define THIS_CFG GetThisCfg()
|