⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cusemoney.cpp

📁 Agent in c++ for DragonRaja
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		return 1;
	}	

	m_vtUser.push_back( stUser );
	return 1;//葛滴 吝汗 立加矫 乐绰蜡历 肺弊酒眶窍霸
}

void CAsyncClient::DisconnectUser( USERINFOPAY& stUser )
{
	//版快
	//1.沥惑利牢 蜡历辆丰
	//2.辑滚促款(沥惑)
	//3.辑滚促款(农贰浆)
	//4.辑滚促款(哪腔磐俊矾)
	//5.拌沥肯丰 -> 1,2锅栏肺 贸府

	//SendMsgToPayServer( int nType , USERINFO& stUser );
}


list<USERINFOPAY>::iterator CAsyncClient::FindUserIterator( const char* szUserName )
{
	LISTUSERIT itFind = find_if(m_vtUser.begin(), m_vtUser.end(), bind2nd( IsUserHere(), szUserName ) );
	if( itFind != m_vtUser.end() )
	{
		return itFind;
	}

	return NULL;
}

//030703 YGI
void CAsyncClient::CheckAliveUser()
{
	for( LISTUSERIT it = m_vtUser.begin(); it != m_vtUser.end(); it++ )
	{
		it->nAliveTime++;
		if( it->nAliveTime >= 10 )
		{
			it->nAliveTime = 0;
			SendAliveMessage( *it );
		}
	}
}

void CAsyncClient::SendAliveMessage( USERINFOPAY& userInfo )
{
	char szMsgLogOut[128];
	sprintf( szMsgLogOut, "%s\t1\035%d\t%s\t%s\t%s\t\0", m_szGumHeader, GUM_MSG_ALIVE_USER, 
			userInfo.szGameId, userInfo.szUserId, userInfo.szUserType);
	SendPayFormatMessage( szMsgLogOut );
}
//

USERINFO* CAsyncClient::FindPayUser( const char* szUserId)
{
	USERINFO *pUser = g_pUserTable->GetUserInfo( szUserId );	
	return pUser;
}

bool CAsyncClient::DeletePayUser( USERINFOPAY& stUser )
{	
	//秦寸蜡历甫 茫酒 昏力茄促.
	LISTUSERIT it = FindUserIterator( stUser.szUserId );
	if( it == NULL )
	{
		return false;
				
	}

	//EnterCriticalSection( &this->m_cs);
	m_vtUser.erase( it );
	//LeaveCriticalSection( &this->m_cs);

	return true;
}

void CAsyncClient::SendMsgToPayServer( int nType , USERINFOPAY& stUser)
{
	//Ser
}

int CAsyncClient::SendPayFormatMessage( char* strMsg )
{

	int nLen = strlen( strMsg );
	if( 0 >= nLen ) 
	{
		return 0;
	}
	//MyLog( 0, strMsg );

	nLen++;
	int nRet, nIdx=0;
__try{ // 030502  烙拌康开 棺  try 巩 火涝
	//EnterCriticalSection( &this->m_cs);
	while( nLen > 0 )
	{
		nRet = send( m_sSocket, &strMsg[nIdx], nLen, 0 );
		if( SOCKET_ERROR == nRet )
		{
			
			if( 1 == ::GetPrivateProfileInt( "PayInfo", "LOG_SendPayFormatMessage", 0, "./agentserver.ini" ) )
			{
				MyLog( 0, "ERROR IN CAsyncClient::SendPayFormatMessage = %d ", WSAGetLastError()); // 030701 kyo 
			}
			break;
			//Error
		}
		nLen -= nRet;
		nIdx += nRet;
	}
	//	LeaveCriticalSection( &this->m_cs); 
}__except( EXCEPTION_EXECUTE_HANDLER )
{
	MyLog( 0, "ERROR IN RecvResponsMessage" );
}


	return nIdx;
	//send( m_sSocket, "test", 5, 0);
}

void CAsyncClient::SendKeepaliveMsg()
{
	if( IsRunning() )
	{
		if( NULL != m_szKeepaliveMsg )
		{
			SendPayFormatMessage( m_szKeepaliveMsg );
			CheckAliveUser();	//030703 YGI
		}
	}
}

void CAsyncClient::RecvResponsMessage( SOCKET socket , char* szBuf)
{
	int	nRet=0;
	int nIdx=0;
	
	while( nIdx < MAX_RECV_BUF_SIZE )
	{
		if( nRet > 100|| nIdx > 100 ) 
		{
			nIdx = 0;
			break;
		}
		nRet = recv( socket, (char*)(&szBuf[nIdx]), 1, 0 );
		if( SOCKET_ERROR == nRet || 0 > nRet)
		{
			if( 1 == ::GetPrivateProfileInt( "PayInfo", "LOG_RecvResponsMessage", 0, "./agentserver.ini" ) )
			{
				MyLog( 0, "ERROR IN CAsyncClient::RecvResponsMessage = %d ", WSAGetLastError()); // 030701 kyo 
			}
			break;
		}
		if( szBuf[nIdx] == '\0')
		{
			break;
		}
		nIdx+=nRet;			
	}	

	if( nIdx < 0)
	{
		nIdx = 0;
	}
	szBuf[nIdx] = '\0';

	return;
}

void CAsyncClient::LoginUser( const int nCn, const char* szUserId, const char* szUserPass , const char* szGameId, const char* szUserType, const char* szUserRealIp, const char* szUserVrIp)
{
	USERINFOPAY userInfo;
	SetUserInfo( userInfo, nCn, szUserId, szUserPass, szGameId, szUserType );//GAME_ID, USER_TYPE );
	//扁粮抛捞喉俊 蜡历啊 乐栏搁 弊 蜡历甫 昏力窍绊 泅力 蜡历甫 火涝茄促.
	int nReConnect = AddPayUser( userInfo );	//蜡历甫 秦寸 抛捞喉俊 历厘茄促.
	/* 030502 kyo
	int nReConnect = 0;
	USERINFO *pUser = g_pUserTable->GetUserInfo( szUserId );
	( NULL == pUser)
	{
		nReConnect = 0;
	}
	else
		nReConnect = 1;
*/
	SendUserLogin( userInfo, szUserRealIp, szUserVrIp, nReConnect );
	
	//SendUserLogin( userInfo, szUserRealIp, szUserVrIp, 0);
}

void CAsyncClient::LogoutUser( const int nCn, const char* szUserName )
{
/*
	USERINFO *pUser = FindPayUser( szUserName );
	if( pUser == NULL )
	{
		return;
	}

	if( nCn != pUser->dwConnectionIndex )
	{
		return;
	}
*/
	if( NULL == szUserName ) // 030701 kyo
	{
		return;
	}

	LISTUSERIT it = FindUserIterator( szUserName );
	if( it == NULL ) 
	{
		return;
	}

	USERINFOPAY userinfo;
	SetUserInfo( userinfo, (*it).dwConnectionIndex, (*it).szUserId, "", CAsyncClient::GAME_ID, CAsyncClient::USER_TYPE);
	
	SendUserLogout( userinfo);
}

void CAsyncClient::LogoutUser( USERINFO *pUser )
{
	if( pUser == NULL )
	{
		return;
	}

	USERINFOPAY userinfo;
	SetUserInfo( userinfo, pUser->dwConnectionIndex, pUser->szName, "", CAsyncClient::GAME_ID, CAsyncClient::USER_TYPE);
	//MyLog( 0, "[PayClient] UserLogout    cn: %d, name = %s" , pUser->dwConnectionIndex, pUser->szName );
	SendUserLogout( userinfo);
}

void CAsyncClient::LogoutAllUser()
{
	
	if( m_vtUser.empty() )
	{
		return;
	}
	//copy( m_vtUser.begin(), m_vtUser.end(), SendUserLogout );	//努贰胶窃荐 静扁 拱绢杭帛.
	
	for( LISTUSERIT it = m_vtUser.begin() ; it != m_vtUser.end(); it++ )
	{
		SendUserLogout( (*it) );
		KickOffUser( (*it).szUserId ); // 030716 kyo kickoff all user
	}
	
	MyLog(LOG_NORMAL, "~CAsyncClient :: LogoutAllUser" ); // 030619 kyo
}

void CAsyncClient::SetUserInfo( USERINFOPAY& info, const int nCn, const char* szUserId, const char* szUserPass, const char* szGameId, const char* szUserType ) 
{
	info.dwConnectionIndex	= nCn;
	
	//strupr( info.szUserId ); // 030430 葛电 蜡历捞抚阑 措巩磊肺 贸府茄促.
	
	//strcpy( info.szUserId, szUserId );
	//strcpy( info.szUserPass, szUserPass ); 
	//strcpy( info.szGameId, szGameId );
	//strcpy( info.szUserType, szUserType );

	strncpy( info.szUserPass, szUserPass,32 ); 
	strncpy( info.szGameId, szGameId ,32 );	
	strncpy( info.szUserType, szUserType ,32 );
	strncpy( info.szUserId, szUserId, 32 ); 
	CharUpper(info.szUserId);
	info.nAliveTime = 0;	// 030703 YGI
}

void CAsyncClient::SendUserLogin( USERINFOPAY& userInfo, const char* szRIP, const char* szVIP , const int nReConnect)
{
	char szMsgLogin[0xff];
	sprintf( szMsgLogin, "%s\t1\035%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t\0", m_szGumHeader, GUM_MSG_LOGIN_ACCESS, nReConnect,
			userInfo.szGameId, userInfo.szUserId, userInfo.szUserType, userInfo.szUserPass, szRIP, szVIP );
	LeaveLogInText( szMsgLogin ); // 030701 kyo // leave log "send to GUMP"
	SendPayFormatMessage( szMsgLogin );
}

void CAsyncClient::SendUserLogout( USERINFOPAY& userInfo )
{
	char szMsgLogOut[0xff];
	sprintf( szMsgLogOut, "%s\t1\035%d\t%s\t%s\t%s\t\0", m_szGumHeader, GUM_MSG_LOGOUT_ACCESS, 
			userInfo.szGameId, userInfo.szUserId, userInfo.szUserType);
	LeaveLogInText( szMsgLogOut ); // 030701 kyo // leave log "send to GUMP"
	SendPayFormatMessage( szMsgLogOut );
}

void CAsyncClient::RecvUserLogin( USERINFOPAY& userInfo)
{ //唱狼 蜡历府胶飘俊辑 茫绰促. 
	LISTUSERIT it = FindUserIterator( userInfo.szUserId );
	if( it == NULL ) 
	{
		return;
	}
	SendUser2Client( (*it).dwConnectionIndex, (*it).szUserId, 100);

	/*
	USERINFO *pUser = FindPayUser( userInfo.szUserId );
	if( pUser == NULL )
	{
		return;
	}
	SendUser2Client( pUser->dwConnectionIndex, pUser->szName, 100);
	*/
	//::SendCMD_CONNECT_AGENT_SERVER_CONFORM( pUser->dwConnectionIndex, pUser->szName, 100);	
	//::SendCMD_CONNECT_AGENT_SERVER_CONFORM( (*it).dwConnectionIndex, (*it).szUserId, 100);

}

void CAsyncClient::RecvUserLogout( USERINFOPAY& userInfo)
{
	//蜡历啊 酒流巢酒  乐绰瘤 犬牢辑 犬角洒 谗绢 滚赴促. 
	// -> 030422 kyo 辆丰措扁蜡历老瘤档隔福葱唱 快急 措扁茄促. 
	// 030502 俊捞傈飘啊 胶胶肺 蜡历甫 肋福霸 出滴绊 快府绰 府胶飘俊辑父 昏力茄促.

	
	//g_pINet->CompulsiveDisconnectUser( userInfo.dwConnectionIndex ); // 030422 kyo
	DeletePayUser( userInfo );
	/*
	USERINFO *pUser = FindPayUser( userInfo.szUserId );
	if( pUser == NULL )
	{
		return;
	}
	*/
	//::MyLog( 0, "AboutPAY :: User didn't LogOut!! userId = %s", userInfo.szUserId);
	
	//碍力肺弊酒眶
	//g_pINet->CompulsiveDisconnectUser( pUser->dwConnectionIndex ); // 030422 kyo
}

void CAsyncClient::RecvUserLoginFail( USERINFOPAY& userInfo, int nType)
{	
	LISTUSERIT it = FindUserIterator( userInfo.szUserId );
	if( it == NULL ) 
	{
		return;
	}
	SendUser2Client( (*it).dwConnectionIndex, (*it).szUserId, nType );
	DeletePayUser( userInfo );
	
	/*
	USERINFO *pUser = FindPayUser( userInfo.szUserId );
	if( pUser == NULL )
	{
		return;
	}
	
	SendUser2Client( pUser->dwConnectionIndex, pUser->szName, nType );
	*/
}

void CAsyncClient::RecvUserLogoutFail( USERINFOPAY& userInfo )
{// 苞陛辑滚俊 肺弊牢 茄 利捞 绝绰 蜡历甫 肺弊酒眶茄 版快..
	DeletePayUser( userInfo);
	//Leave Log
	//::MyLog( 0, "AboutPAY :: FAIL LogOut    userId = %s", userInfo.szUserId);
}

void CAsyncClient::SendUserLoginSuccess2DB( const DWORD dwConnectionIndex, const char* szUserId )
{
	//db俊霸 秦寸 蜡历啊 立加俊 己傍沁澜阑 舅赴促. 
	//捞镑 眠啊夸噶
}

void CAsyncClient::SendUser2Client( const DWORD dwConnectionIndex, const char* szUserId, const int nType)
{
	//client俊霸 秦寸 蜡历狼 立加捞 角菩寝澜阑 舅赴促. 
	//捞镑 眠啊夸噶	
	::SendCMD_CONNECT_AGENT_SERVER_CONFORM( dwConnectionIndex, szUserId, nType);
}

void CAsyncClient::RecvUserAlert( USERINFOPAY& userInfo, int nTime)
{
	//Cliet俊霸 蜡历 立加矫埃捞 倔付 救 巢疽澜阑 舅赴促.
	//捞镑 眠啊夸噶	

	LISTUSERIT it = FindUserIterator( userInfo.szUserId );
	if( it == NULL ) 
	{
		return;
	}
	SendUser2Client( (*it).dwConnectionIndex, (*it).szUserId, -nTime );
	/*
	USERINFO *pUser = FindPayUser( userInfo.szUserId );
	if( pUser == NULL )
	{
		return;
	}
	//矫埃篮 澜荐肺 焊辰促. 
	SendUser2Client( pUser->dwConnectionIndex, pUser->szName, -nTime );
	*/
}

void CAsyncClient::RecvUserDisconnect( USERINFOPAY& userInfo, int nMsgType)
{
	//client狼 立加阑 秦力茄促. 
	LISTUSERIT it = FindUserIterator( userInfo.szUserId );
	if( it == NULL ) 
	{
		return;
	}
	SendUser2Client( (*it).dwConnectionIndex, (*it).szUserId, nMsgType);
/*
	USERINFO *pUser = FindPayUser( userInfo.szUserId );
	if( pUser == NULL )
	{
		return;
	}

	SendUser2Client( pUser->dwConnectionIndex, pUser->szName, nMsgType );
	*/

	g_pINet->CompulsiveDisconnectUser( (*it).dwConnectionIndex ); //快急 林籍贸府
}



void CAsyncClient::ShowError( int nError )
{
	nError;
}

bool CAsyncClient::IsRightType( int nType )
{
	
	switch( nType )
	{

	case GUM_MSG_INITALIZED:
	case GUM_MSG_INIT_FAIL:
	case GUM_MSG_MESSAGEFORM_WRONG:
	case GUM_MSG_RESPONS_INITALIZED:	
	case GUM_MSG_LOGIN_ACCESS:
	case GUM_MSG_LOGIN_SUCCESS:
	case GUM_MSG_WRONG_PASS:		
	case GUM_MSG_HAVENO_AUTHORITY:
	case GUM_MSG_END_OF_DATE	:		
	case GUM_MSG_ALREADY_LOGIN	:	
	case GUM_MSG_ALL_SPEND_IP	:	
	case GUM_MSG_DISCONNECT_USER:
	case GUM_MSG_END_OF_DATE_1DAY:	
	case GUM_MSG_END_OF_DATE_1DAY2:	
	case GUM_MSG_LOGOUT_ACCESS	:	
	case GUM_MSG_LOGOUT_SUCCESS	:	
	case GUM_MSG_LOGOUT_FAIL:
	case GUM_MSG_USER_TIMEOVER	:	
	case GUM_MSG_USER_TIMEOVER_1DAY	:
	case GUM_MSG_USER_TIMEOVER_1DAY2:	
	case GUM_MSG_USER_DIS_TIMEOVER	:
	case GUM_MSG_USER_DIS_TIMEOV_1D	:
	case GUM_MSG_USER_DIS_TIMEOV_1D2:
	case GUM_MSG_USER_DIS_OUSER_REQ	:
		return true;
		
	}
	return false;
	
}

void CAsyncClient::CloseConnection()
{
	closesocket( m_sSocket );
}
/*
int CAsyncClient::GetUserCN( USERINFO *pUser, const char* szName )
{
	return 0;

	DWORD index = info->dwID%m_wMaxBucketNum;
	
	if (!m_ppInfoTable[index])
	{
		m_ppInfoTable[index] = info;
		info->pNextUserInfo = NULL;
		info->pPrvUserInfo = NULL;
		return;
	}

	int nBucket = g_pUserTable->GetBucketNum();
	for( int i=0 ; i< nBucket; i++)
	{
		
	}
	USERINFO* cur = m_ppInfoTable[index];
	USERINFO* prv = NULL;

	while (cur)
	{
		prv = cur;
		cur = cur->pNextUserInfo;
	}

}
*/

BOOL DumpException(LPEXCEPTION_POINTERS lpExcep,char* szOutMsg, void *pData, int nSize )
{// 030620 thailand kyo _ copy dbdemon 
	if (!lpExcep)
		return FALSE;

	BOOL		result = TRUE;
	SYSTEMTIME time;
	FILE*		fp = NULL;

	const DWORD		dwExceptionAddress = (DWORD)lpExcep->ExceptionRecord->ExceptionAddress;
	const DWORD		dwExceptionCode = lpExcep->ExceptionRecord->ExceptionCode;
	const DWORD		dwExceptionFlags = lpExcep->ExceptionRecord->ExceptionFlags;
	const DWORD		dwNumberParameters = lpExcep->ExceptionRecord->NumberParameters;
	const DWORD		dwDr0 = lpExcep->ContextRecord->Dr0;
	const DWORD		dwDr1 = lpExcep->ContextRecord->Dr1;
	const DWORD		dwDr2 = lpExcep->ContextRecord->Dr2;
	const DWORD		dwDr3 = lpExcep->ContextRecord->Dr3;
	const DWORD		dwDr6 = lpExcep->ContextRecord->Dr6;
	const DWORD		dwDr7 = lpExcep->ContextRecord->Dr7;
	
	const DWORD		dwSegCs = lpExcep->ContextRecord->SegCs;
	const DWORD		dwSegGs = lpExcep->ContextRecord->SegGs;
	const DWORD		dwSegFs = lpExcep->ContextRecord->SegFs;
	const DWORD		dwSegEs = lpExcep->ContextRecord->SegEs;
	const DWORD		dwEFlags = lpExcep->ContextRecord->EFlags;

	const DWORD		dwEsi = lpExcep->ContextRecord->Esi;
	const DWORD		dwEdi = lpExcep->ContextRecord->Edi;
	const DWORD		dwEbp = lpExcep->ContextRecord->Ebp;
	const DWORD		dwEsp = lpExcep->ContextRecord->Esp;
	const DWORD		dwEip = lpExcep->ContextRecord->Eip;

	const DWORD		dwEax = lpExcep->ContextRecord->Eax;
	const DWORD		dwEbx = lpExcep->ContextRecord->Ebx;
	const DWORD		dwEcx = lpExcep->ContextRecord->Ecx;
	const DWORD		dwEdx = lpExcep->ContextRecord->Edx;
	
	__try
	{
		char szFileName[256+1];
		GetLocalTime(&time);

		sprintf( szFileName, "Agent_%d_%d_%d_%d_%d_%d.log", time.wYear,time.wMonth,time.wDay,time.wHour, time.wMinute,time.wSecond );
		fp = fopen( szFileName, "w");

		fprintf(fp,"%d year, %d month, %d day,%d hour, %d minute, %d second\n",
			time.wYear,time.wMonth,time.wDay,time.wHour, time.wMinute,time.wSecond); 
		
		fprintf(fp,"Crashed address %xh \n",dwExceptionAddress);
		fprintf(fp,"Crashed Map Address %04X:%08X",
			dwSegCs,
			dwExceptionAddress);


		fprintf(fp,"Exception Code %u \n",dwExceptionCode);
		fprintf(fp,"Exception Flag %xh \n",dwExceptionFlags);
		fprintf(fp,"NumberParameters %d \n",dwNumberParameters);
		fprintf(fp,"Dr0 %xh \n",dwDr0);
		fprintf(fp,"Dr1 %xh \n",dwDr1);
		fprintf(fp,"Dr2 %xh \n",dwDr2);
		fprintf(fp,"Dr3 %xh \n",dwDr3);
		fprintf(fp,"Dr6 %xh \n",dwDr6);
		fprintf(fp,"Dr7 %xh \n",dwDr7);
		
		fprintf(fp,"SegGs %xh \n",dwSegGs);
		fprintf(fp,"SegFs %xh \n",dwSegFs);
		fprintf(fp,"SegEs %xh \n",dwSegEs);
		fprintf(fp,"EFlags %xh \n",dwEFlags);
		
		fprintf(fp,"Esi %xh \n",dwEsi);
		fprintf(fp,"Edi %xh \n",dwEdi);
		fprintf(fp,"Ebp %xh \n",dwEbp);
		fprintf(fp,"Esp %xh \n",dwEsp);
		fprintf(fp,"Eip %xh \n",dwEip);
		

		fprintf(fp,"Eax %xh \n",dwEax);
		fprintf(fp,"Ebx %xh \n",dwEbx);
		fprintf(fp,"Ecx %xh \n",dwEcx);
		fprintf(fp,"Edx %xh \n",dwEdx);

		if( pData )	fprintf(fp,"info : packet_type(PTCL_) =  %d \n",*((char*)pData));
	
		fprintf(fp,"\n\n");

		fclose(fp);
		fp = NULL;

		if( pData )
		{
			sprintf( szFileName, "Agent_info_%d_%d_%d_%d_%d_%d.bin", time.wYear,time.wMonth,time.wDay,time.wMinute,time.wSecond );
			fp = fopen( szFileName, "w");
			fwrite( &nSize, 4, 1, fp );
			fwrite( pData, 1, nSize, fp );
			fclose( fp );
			fp = NULL;
		}
	}
	__except (GetExceptionCode())
	{
		MyLog(LOG_NORMAL, "ERROR :: Write in DumpException" ); 
		if (fp)
			fclose(fp);
	
		result = FALSE;
	}

	return result;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -