123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- #pragma once
- #include "SocketInterface.h"
- #include "GeneralHelper.h"
- #define USER_INFO_MSG (WM_USER + 100)
- #define MAX_LOG_RECORD_LENGTH 1000
- #define EVT_ON_SEND _T("OnSend")
- #define EVT_ON_RECEIVE _T("OnReceive")
- #define EVT_ON_CLOSE _T("OnClose")
- #define EVT_ON_ERROR _T("OnError")
- #define EVT_ON_PREPARE_CONNECT _T("OnPrepareConnect")
- #define EVT_ON_PREPARE_LISTEN _T("OnPrepareListen")
- #define EVT_ON_ACCEPT _T("OnAccept")
- #define EVT_ON_CONNECT _T("OnConnect")
- #define EVT_ON_HAND_SHAKE _T("OnHandShake")
- #define EVT_ON_SHUTDOWN _T("OnShutdown")
- #define EVT_ON_END_TEST _T("END TEST")
- #define EVT_ON_MESSAGE_BEGIN _T("OnMessageBegin")
- #define EVT_ON_REQUEST_LINE _T("OnRequestLine")
- #define EVT_ON_STATUS_LINE _T("OnStatusLine")
- #define EVT_ON_HEADER _T("OnHeader")
- #define EVT_ON_HEADERS_COMPLETE _T("OnHeadersComplete")
- #define EVT_ON_BODY _T("OnBody")
- #define EVT_ON_CHUNK_HEADER _T("OnChunkHeader")
- #define EVT_ON_CHUNK_COMPLETE _T("OnChunkComplete")
- #define EVT_ON_MESSAGE_COMPLETE _T("OnMessageComplete")
- #define EVT_ON_UPGRADE _T("OnUpgrade")
- #define EVT_ON_PARSE_ERROR _T("OnParseError")
- #define MAX_STUDIOID_LENGTH 37
- #define MAX_ACCOUNT_LENGTH 17
- #define MAX_PASSWORD_LENGTH 17
- enum EnAppState
- {
- ST_STARTING, ST_STARTED, ST_CONNECTING, ST_CONNECTED, ST_STOPPING, ST_STOPPED
- };
- enum ProtocolCmd
- {
- //----------------------------:common comand.type: 1~999----------------------------------------------------
- CMD_HEART = 1, // 心跳包;
- CMD_TOCHAT = 2, // 文字聊天;
- CMD_FILEINFO_TRANSFER = 3, // 文件传输-文件信息;
- CMD_FILECONT_TRANSFER = 4, // 文件传输-文件内容;
- CMD_UPDATA = 5, // 有升级信息(用户终端每次登录时,请求检测是否有新版本可升级的信息);
- CMD_DATABASEINFO = 6, // 向请求端返回数据库信息;
- CMD_OHTER_INFO = 999, // 其他信息;
- //------------------------C2L:consumer terminal to lyfz.service: 1000~1999------------------------------------
- C2LCMD_REQ_LOGIN = 1000, // 用户终端请求登录利亚方舟服务端(外网ip+登录信息);
- //C2LCMD_GET_DOG_DATA = 1001, // 利亚方舟获取用户终端机器加密狗数据信息;
- C2LCMD_DOGINFO = 1001, // 用户终端向利亚方舟发送加密狗信息;
- C2LCMD_GET_VAR = 1002, // 请求用户终端的版本号;
- C2LCMD_DEAL_ILLEGAL = 1003, // 处理盗版、过期用户:停止用户终端工作、启用定时关机、程序文件自动删除等等操作命令;
- C2LCMD_DEAL_SMS = 1004, // 利亚方舟服务端处理用户终端的短信发送工作;
- C2LCMD_GET_DBINFO = 1005, // 利亚方舟服务端获取用户终端电脑数据库信息;
- // .预留,若SQL数据库引擎未启用TCP/IP作为远程连接方式,需定义读写表的具体命令;(Jeff.100%的不建议使用这种方式获取数据,占用太多带宽和资源)
- // .若要使用SQL,则只允许SQL的updata、insert、delete、drop……等命令,不允许使用select来返回查询到数据;
- C2LCMD_OTHER_INFO = 1999, // 读其它信息;
- //------------------------C2C:consumer client to consumer service: 2000~2999--------------------------------
- C2CCMD_REQ_LOGIN = 2000, // 客户端请求登录服务器;
- C2CCMD_REQ_LOGOUT = 2001, // 客户端注销;
- C2CCMD_REQ_DOG_DATA = 2002, // 读软件狗数据;
- C2CCMD_AUTO_UPDATA = 2003, // 服务端向所有客户发送自动数据更新命令;
- C2CCMD_REQ_SERVER_VAR = 2004, // 请求服务端的版本号;
- C2CCMD_NEW_DEPARTMENT = 2005, // 利亚方舟服务端获取用户终端电脑数据库信息;
- C2CCMD_DEL_DEPARTMENT = 2006, // 客户端端向备份程序发送订单相片重新备份命令(导片与备份存在写备份无法锁定现象,need to Notify);
- C2CCMD_MOD_DEPARTMENT = 2007,
- C2CCMD_QRY_DEPARTMENT = 2008
- };
- enum PackageFlag
- {
- PACKAGE_ONESELF = 0, // 协议包-独立;
- PACKAGE_MULTIPLE = 1, // 协议包-多个;
- };
- enum UserLogInStatus
- {
- USER_LOGIN = 1, // 登录成功;
- USER_PW_MISTAKE = 2, // 密码错误;
- USER_HAVE_LOGIN = 3, // 用户已经登录;
- USER_NULL = 0 // 没有用户;
- };
- typedef struct __LogInUser__
- {
- TCHAR szStudioId[MAX_STUDIOID_LENGTH]; // 影楼Guid;
- TCHAR szAccount[MAX_ACCOUNT_LENGTH]; // 账号;
- TCHAR szPassword[MAX_PASSWORD_LENGTH]; // 密码;
- }LogInUser,*pLogInUser;
- #pragma pack(push,1)
- // 协议头-勿更改;
- typedef struct __THEPROPACKAGE__
- {
- byte flag; // 协议包类型标识;
- short nCmd; // 协议携带的命令标识;
- unsigned int nDataLen; // 数据长度,除了头之外的数据;
- unsigned int nSubDataLen; // 分包大小;
- TCHAR szAccount[MAX_ACCOUNT_LENGTH]; // 账号;
- DWORD dwReserve;
- BYTE byBody[2]; // 包数据;
- __THEPROPACKAGE__(){
- flag = PACKAGE_ONESELF;
- nCmd = 0;
- nDataLen = 0;
- nSubDataLen = 0;
- dwReserve = 0;
- memset(byBody, 0, 2);
- memset(szAccount, 0, sizeof(TCHAR)*MAX_ACCOUNT_LENGTH);
- }
- }TheProPackage,*pTheProPackage;
- #pragma pack(pop)
- struct info_msg
- {
- LPCTSTR name;
- CONNID connID;
- LPCTSTR evt;
- int contentLength;
- LPCTSTR content;
- static info_msg* Construct(CONNID dwConnID, LPCTSTR lpszEvent, int iContentLength = 0, LPCTSTR lpszContent = nullptr, LPCTSTR lpszName = nullptr);
- static void Destruct(info_msg* pMsg);
- private:
- info_msg(CONNID dwConnID, LPCTSTR lpszEvent, int iContentLength = 0, LPCTSTR lpszContent = nullptr, LPCTSTR lpszName = nullptr);
- ~info_msg();
- };
- struct TPkgHeader
- {
- DWORD seq;
- int body_len;
- };
- struct TPkgBody
- {
- char name[30];
- short age;
- char desc[1];
- };
- struct TPkgInfo
- {
- bool is_header;
- int length;
- TPkgInfo(bool header = true, int len = sizeof(TPkgHeader)) : is_header(header), length(len) {}
- void Reset() {is_header = true, length = sizeof(TPkgHeader);}
- ~TPkgInfo() {}
- };
- CBufferPtr* GeneratePkgBuffer(DWORD seq, LPCTSTR lpszName, short age, LPCTSTR lpszDesc);
- CBufferPtr* GeneratePkgBuffer(const TPkgHeader& header, const TPkgBody& body);
- void SetMainWnd(CWnd* pWnd);
- void SetInfoList(CListBox* pInfoList);
- void LogServerStart(LPCTSTR lpszAddress, USHORT port, LPCTSTR lpszName = nullptr);
- void LogServerStartFail(DWORD code, LPCTSTR lpszDesc, LPCTSTR lpszName = nullptr);
- void LogServerStop(LPCTSTR lpszName = nullptr);
- void LogServerStopFail(DWORD code, LPCTSTR lpszDesc, LPCTSTR lpszName = nullptr);
- void LogClientStart(LPCTSTR lpszAddress, USHORT port, LPCTSTR lpszName = nullptr);
- void LogClientStarting(LPCTSTR lpszAddress, USHORT port, LPCTSTR lpszName = nullptr);
- void LogClientStartFail(DWORD code, LPCTSTR lpszDesc, LPCTSTR lpszName = nullptr);
- void LogClientStopping(CONNID dwConnID, LPCTSTR lpszName = nullptr);
- void LogClientStopFail(DWORD code, LPCTSTR lpszDesc, LPCTSTR lpszName = nullptr);
- void LogSend(CONNID dwConnID, LPCTSTR lpszContent, LPCTSTR lpszName = nullptr);
- void LogClientSendFail(int iSequence, int iSocketIndex, DWORD code, LPCTSTR lpszDesc, LPCTSTR lpszName = nullptr);
- void LogSendFail(CONNID dwConnID, DWORD code, LPCTSTR lpszDesc, LPCTSTR lpszName = nullptr);
- void LogDisconnect(CONNID dwConnID, LPCTSTR lpszName = nullptr);
- void LogDisconnectFail(CONNID dwConnID, LPCTSTR lpszName = nullptr);
- void LogRelease(CONNID dwConnID, LPCTSTR lpszName = nullptr);
- void LogReleaseFail(CONNID dwConnID, LPCTSTR lpszName = nullptr);
- void LogDetect(CONNID dwConnID, LPCTSTR lpszName = nullptr);
- void LogDetectFail(CONNID dwConnID, LPCTSTR lpszName = nullptr);
- void LogOnConnect(CONNID dwConnID, const CString& strAddress, USHORT usPort);
- void LogOnConnect2(CONNID dwConnID, LPCTSTR lpszName = nullptr);
- void LogOnHandShake2(CONNID dwConnID, LPCTSTR lpszName = nullptr);
- void PostOnSend(CONNID dwConnID, const BYTE* pData, int iLength, LPCTSTR lpszName = nullptr);
- void PostOnReceive(CONNID dwConnID, const BYTE* pData, int iLength, LPCTSTR lpszName = nullptr);
- void PostOnReceiveCast(CONNID dwConnID, LPCTSTR lpszAddress, USHORT usPort, const BYTE* pData, int iLength, LPCTSTR lpszName = nullptr);
- void PostOnClose(CONNID dwConnID, LPCTSTR lpszName = nullptr);
- void PostOnError(CONNID dwConnID, int enOperation, int iErrorCode, LPCTSTR lpszName = nullptr);
- void PostOnAccept(CONNID dwConnID, LPCTSTR lpszAddress, USHORT usPort, BOOL bPass, LPCTSTR lpszName = nullptr);
- void PostOnAccept2(CONNID dwConnID, LPCTSTR lpszName = nullptr);
- void PostOnHandShake(CONNID dwConnID, LPCTSTR lpszName = nullptr);
- void PostOnPrepareListen(LPCTSTR lpszAddress, USHORT usPort, LPCTSTR lpszName = nullptr);
- void PostOnPrepareConnect(CONNID dwConnID, LPCTSTR lpszName = nullptr);
- void PostOnConnect(CONNID dwConnID, LPCTSTR lpszAddress, USHORT usPort, LPCTSTR lpszName = nullptr);
- void PostOnConnect2(CONNID dwConnID, LPCTSTR lpszAddress, USHORT usPort, LPCTSTR lpszName = nullptr);
- void PostOnConnect3(CONNID dwConnID, LPCTSTR lpszName = nullptr);
- void PostOnShutdown(LPCTSTR lpszName = nullptr);
- void PostServerStatics(const LONGLONG& llTotalSent, const LONGLONG& llTotalReceived, LPCTSTR lpszName = nullptr);
- void PostTimeConsuming(DWORD dwTickCount, LPCTSTR lpszName = nullptr);
- void PostOnMessageBegin(CONNID dwConnID, LPCTSTR lpszName = nullptr);
- void PostOnRequestLine(CONNID dwConnID, LPCTSTR lpszMethod, USHORT usUrlFieldSet, LPCTSTR lpszUrl, LPCTSTR lpszName = nullptr);
- void PostOnStatusLine(CONNID dwConnID, USHORT usStatusCode, LPCTSTR lpszDesc, LPCTSTR lpszName = nullptr);
- void PostOnHeader(CONNID dwConnID, LPCTSTR lpszHeaderName, LPCTSTR lpszHeaderValue, LPCTSTR lpszName = nullptr);
- void PostOnHeadersComplete(CONNID dwConnID, LPCTSTR lpszSummary, LPCTSTR lpszName = nullptr);
- void PostOnBody(CONNID dwConnID, const BYTE* pData, int iLength, LPCTSTR lpszName = nullptr);
- void PostOnChunkHeader(CONNID dwConnID, int iLength, LPCTSTR lpszName = nullptr);
- void PostOnChunkComplete(CONNID dwConnID, LPCTSTR lpszName = nullptr);
- void PostOnMessageComplete(CONNID dwConnID, LPCTSTR lpszName = nullptr);
- void PostOnUpgrade(CONNID dwConnID, EnHttpUpgradeType enUpgradeType, LPCTSTR lpszName = nullptr);
- void PostOnParseError(CONNID dwConnID, int iErrorCode, LPCTSTR lpszErrorDesc, LPCTSTR lpszName = nullptr);
- void PostInfoMsg(info_msg* msg);
- void LogInfoMsg(info_msg* pInfoMsg);
- void LogMsg(const CString& msg);
- #ifdef _SSL_SUPPORT
- extern int g_c_iVerifyMode;
- extern BOOL g_c_bNeedClientVerification;
- extern LPCTSTR g_c_lpszCAPemCertFileOrPath;
- extern LPCTSTR g_c_lpszPemCertFile;
- extern LPCTSTR g_c_lpszPemKeyFile;
- extern LPCTSTR g_c_lpszKeyPasswod;
- extern int g_s_iVerifyMode;
- extern BOOL g_s_bNeedClientVerification;
- extern LPCTSTR g_s_lpszCAPemCertFileOrPath;
- extern LPCTSTR g_s_lpszPemCertFile;
- extern LPCTSTR g_s_lpszPemKeyFile;
- extern LPCTSTR g_s_lpszKeyPasswod;
- #endif
|