String EncryptPassword(const String& str) { Int32 lLen = str.GetCStringLen(STRINGENCODING_8BIT); if (lLen <= 0) return str; Int32 lCryptLen = (lLen + 256) / 256; lCryptLen *= 256; Int32 i; Random rnd; rnd.Init(97355832); Int32 plKey[30]; char ch[3]; String strCrypt; GeCipher256 c; char* pchPassword = NewMemClear(Char,lCryptLen); if (!pchPassword) return str; str.GetCString(pchPassword, lLen + 1, STRINGENCODING_8BIT); pchPassword[lLen] = 0; for (i = 0; i < lCryptLen; i++) { rnd.Get01(); pchPassword[i] ^= (rnd.GetSeed() & 0xff); } rnd.Init(956612571); for (i = 0; i < 30; i++) { rnd.Get01(); plKey[i] = rnd.GetSeed(); lIntel(&(plKey[i])); } if (!c.Open((UChar*)plKey, sizeof(plKey), true)) { DeleteMem(pchPassword); return str; } for (i = 0; i < lCryptLen; i += 256) c.Encrypt((UChar*)&pchPassword[i], 256); for (i = 0; i < lCryptLen; i++) { sprintf_safe(ch, sizeof(ch), "%02x", ((int)pchPassword[i]) & 0xff); DebugAssert(ch[2] == 0); strCrypt += ch; } DeleteMem(pchPassword); return strCrypt; }
void CConsolePromissions::Init(const char* pFileName) { CXmlOpeation m_ConcoleConfig; //初始化队列 Close(); m_objHashCommandList.Init(MAX_COMSOLE_COMMAND_COUNT); if (false == m_ConcoleConfig.Init(pFileName)) { OUR_DEBUG((LM_INFO, "[CConsolePromissions::Init]File Read Error = %s.\n", pFileName)); return; } TiXmlElement* pNextTiXmlCommandName = NULL; TiXmlElement* pNextTiXmlUser = NULL; while (true) { char* pCommandNameData = NULL; char* pUserData = NULL; _Console_Command_Info* pConsole_Command_Info = new _Console_Command_Info(); pCommandNameData = m_ConcoleConfig.GetData("CommandInfo", "CommandName", pNextTiXmlCommandName); pUserData = m_ConcoleConfig.GetData("CommandInfo", "User", pNextTiXmlUser); if (NULL == pCommandNameData || NULL == pUserData) { SAFE_DELETE(pConsole_Command_Info); break; } sprintf_safe(pConsole_Command_Info->m_szCommand, MAX_BUFF_50, "%s", pCommandNameData); sprintf_safe(pConsole_Command_Info->m_szUser, MAX_BUFF_200, "%s", pUserData); if (-1 == m_objHashCommandList.Add_Hash_Data(pConsole_Command_Info->m_szCommand, pConsole_Command_Info)) { SAFE_DELETE(pConsole_Command_Info); OUR_DEBUG((LM_INFO, "[CConsolePromissions::Init](%s)Add error.\n", pConsole_Command_Info->m_szCommand)); } } }
bool Server_Manager_Common_FrameLogging(Frame_Logging_Strategy*& pFrameLoggingStrategy) { if (GetXmlConfigAttribute(xmlAceDebug)->TrunOn == 1) { pFrameLoggingStrategy = new Frame_Logging_Strategy(); //是否打开ACE_DEBUG文件存储 Logging_Config_Param objParam; sprintf_safe(objParam.m_strLogFile, 256, "%s", GetXmlConfigAttribute(xmlAceDebug)->DebugName.c_str()); objParam.m_iChkInterval = GetXmlConfigAttribute(xmlAceDebug)->ChkInterval; objParam.m_iLogFileMaxCnt = GetXmlConfigAttribute(xmlAceDebug)->LogFileMaxCnt; objParam.m_iLogFileMaxSize = GetXmlConfigAttribute(xmlAceDebug)->LogFileMaxSize; sprintf_safe(objParam.m_strLogLevel, 128, "%s", GetXmlConfigAttribute(xmlAceDebug)->Level.c_str()); pFrameLoggingStrategy->InitLogStrategy(objParam); } return true; }
void CStatsAndAchievements::DrawInventory( RECT &rect, SteamItemInstanceID_t itemid ) { const CSpaceWarItem *pItem = SpaceWarLocalInventory()->GetItem( itemid ); if ( !pItem ) return; // todo: divide up so can draw image char rgchBuffer[256]; sprintf_safe( rgchBuffer, "%s", pItem->GetLocalizedName().c_str() ); m_pGameEngine->BDrawString( m_hDisplayFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), TEXTPOS_LEFT|TEXTPOS_VCENTER, rgchBuffer ); }
CConsolePacketParse::CConsolePacketParse(void) { //如果是包头模式,这里需要设置包头的长度 m_u4PacketHead = PACKET_HEAD; //这里修改属于你的包解析版本号 sprintf_safe(m_szPacketVersion, MAX_BUFF_20, "0.92"); //这里设置你的包模式 m_u1PacketMode = PACKET_WITHHEAD; }
bool CForbiddenIP::Init(const char* szConfigPath) { char* pData = NULL; OUR_DEBUG((LM_INFO, "[CForbiddenIP::Init]Filename = %s.\n", szConfigPath)); if(!m_ForbiddenData.Init(szConfigPath)) { OUR_DEBUG((LM_INFO, "[CForbiddenIP::Init]Read Filename = %s error.\n", szConfigPath)); return false; } m_VecForeverForbiddenIP.clear(); m_VecTempForbiddenIP.clear(); ACE_TString strValue; _ForbiddenIP ForbiddenIP; TiXmlElement* pNextTiXmlElementIP = NULL; TiXmlElement* pNextTiXmlElementType = NULL; while(true) { pData = m_ForbiddenData.GetData("ForbiddenIP", "ip", pNextTiXmlElementIP); if(pData != NULL) { sprintf_safe(ForbiddenIP.m_szClientIP, MAX_BUFF_20, "%s", pData); } else { break; } pData = m_ForbiddenData.GetData("ForbiddenIP", "type", pNextTiXmlElementType); if(pData != NULL) { if(ACE_OS::strcmp(pData, "TCP") == 0) { ForbiddenIP.m_u1Type = PACKET_TCP; } else { ForbiddenIP.m_u1Type = PACKET_UDP; } } else { break; } m_VecForeverForbiddenIP.push_back(ForbiddenIP); } return true; }
bool CForbiddenIP::AddTempIP(const char* pIP, uint32 u4Second, uint8 u1ConnectType) { _ForbiddenIP ForbiddenIP; sprintf_safe(ForbiddenIP.m_szClientIP, MAX_IP_SIZE, "%s", pIP); ForbiddenIP.m_u1Type = 1; ForbiddenIP.m_tvBegin = ACE_OS::gettimeofday(); ForbiddenIP.m_u4Second = u4Second; ForbiddenIP.m_u1ConnectType = u1ConnectType; m_VecTempForbiddenIP.push_back(ForbiddenIP); return true; }
int CProactorUDPHandler::OpenAddress(const ACE_INET_Addr& AddrLocal, ACE_Proactor* pProactor) { if(m_skRemote.open(AddrLocal) == -1) { OUR_DEBUG((LM_ERROR, "[CProactorUDPHandler::OpenAddress]Open error(%d).\n", errno)); return -1; } sprintf_safe(m_szCompletionkey, MAX_BUFF_20, "CompUDP"); sprintf_safe(m_szAct, MAX_BUFF_20, "ActUDP"); if(m_Read.open(*this, m_skRemote.get_handle(), m_szCompletionkey, pProactor) == -1) { OUR_DEBUG((LM_ERROR, "[CProactorUDPHandler::OpenAddress]m_Read error.\n")); return -1; } if(m_Write.open(*this, m_skRemote.get_handle(), m_szCompletionkey, pProactor) == -1) { OUR_DEBUG((LM_ERROR, "[CProactorUDPHandler::OpenAddress]m_Write error.\n")); return -1; } ACE_Message_Block* pMBBuff = App_MessageBlockManager::instance()->Create(MAX_UDP_PACKET_LEN); if(NULL == pMBBuff) { OUR_DEBUG((LM_ERROR, "[CProactorUDPHandler::OpenAddress]pMBBuff is NULL.\n")); return -1; } //初始化检查器 m_TimeConnectInfo.Init(App_MainConfig::instance()->GetValid(), App_MainConfig::instance()->GetValidPacketCount(), App_MainConfig::instance()->GetValidRecvSize()); m_pPacketParse = App_PacketParsePool::instance()->Create(); size_t stRecvLen = MAX_UDP_PACKET_LEN; //OUR_DEBUG((LM_INFO, "[CProactorUDPHandler::OpenAddress]pMBBuff=0x%08x.\n", pMBBuff)); int nRecvSize = m_Read.recv(pMBBuff, stRecvLen, 0, PF_INET, m_szAct); return nRecvSize; }
bool CBuffPacket::Init(int nSize) { //lock try { m_szError[0] = '\0'; if(nSize >= MAX_PACKET_SIZE) { //OUR_DEBUG((LM_ERROR, "[CBuffPacket::Init] nSize [%d] is more than MAX_PACKET_SIZE.\n", nSize)); char szError[MAX_BUFF_500] = {'\0'}; sprintf_safe(szError, MAX_BUFF_500, "[CBuffPacket::Init] nSize [%d] is more than MAX_PACKET_SIZE.", nSize); throw szError; } //初始化包数据结构 m_u4ReadPtr = 0; m_u4WritePtr = 0; m_u4PacketCount = 0; m_u4PacketLen = ((int)ceil((double)nSize/(double)DEFINE_PACKET_ADD))*DEFINE_PACKET_ADD;//ceil返回大于或者等于指定表达式的最小整数 m_szData = new char[m_u4PacketLen];//TODO 应该改为在共享内存中申请 //OUR_DEBUG((LM_ERROR, "[CBuffPacket::Init] nSize [%d], m_szData=[0x%08x].\n", m_u4PacketLen, m_szData)); if(NULL == m_szData) { //OUR_DEBUG((LM_ERROR, "[CBuffPacket::Init] nSize [%d] is new error.\n", m_u4PacketLen)); char szError[MAX_BUFF_500] = {'\0'}; sprintf_safe(szError, MAX_BUFF_500, "[CBuffPacket::Init] nSize [%d] is new error..", m_u4PacketLen); throw szError; } return true; } catch(const char* szError) { sprintf_safe(m_szError, MAX_BUFF_500, "%s", szError); return false; } }
void ClistManager::Add_LG_Info(uint32 u4ConnectID, uint32 u4LGID, const char* pIP, uint32 u4Port, const char* pMD5, const char* pSession, uint16 u2Version) { ACE_Guard<ACE_Recursive_Thread_Mutex> WGuard(m_ThreadLock); _LG_Info* pInfo = Get_LG_Info_By_LGID(u4LGID); if(NULL == pInfo) { _LG_Info objNewInfo; objNewInfo.m_u4ConnectID = u4ConnectID; objNewInfo.m_u4LGID = u4LGID; objNewInfo.m_u4Port = u4Port; sprintf_safe(objNewInfo.m_szIP, 50, "%s", pIP); sprintf_safe(objNewInfo.m_szMD5, 33, "%s", pMD5); sprintf_safe(objNewInfo.m_szSession, 33, "%s", pSession); m_vecLGInfo.push_back(objNewInfo); objNewInfo.m_u2Version = u2Version; } else { pInfo->m_u4ConnectID = u4ConnectID; pInfo->m_u4LGID = u4LGID; pInfo->m_u4Port = u4Port; sprintf_safe(pInfo->m_szIP, 50, "%s", pIP); sprintf_safe(pInfo->m_szMD5, 33, "%s", pMD5); sprintf_safe(pInfo->m_szSession, 33, "%s", pSession); pInfo->m_u2Version = u2Version; } Compare_MD5(); Check_LG_Target(u4ConnectID, u4LGID, pIP, u4Port); }
//----------------------------------------------------------------------------- // Purpose: An achievement was stored //----------------------------------------------------------------------------- void CStatsAndAchievements::OnAchievementStored( UserAchievementStored_t *pCallback ) { // we may get callbacks for other games' stats arriving, ignore them if ( m_GameID.ToUint64() == pCallback->m_nGameID ) { if ( 0 == pCallback->m_nMaxProgress ) { char buffer[128]; sprintf_safe( buffer, "Achievement '%s' unlocked!", pCallback->m_rgchAchievementName ); buffer[ sizeof(buffer) - 1 ] = 0; OutputDebugString( buffer ); } else { char buffer[128]; sprintf_safe( buffer, "Achievement '%s' progress callback, (%d,%d)\n", pCallback->m_rgchAchievementName, pCallback->m_nCurProgress, pCallback->m_nMaxProgress ); buffer[ sizeof(buffer) - 1 ] = 0; OutputDebugString( buffer ); } } }
bool CClientReConnectManager::GetServerIPInfo( int nServerID, _ClientIPInfo& objServerIPInfo ) { ACE_Guard<ACE_Recursive_Thread_Mutex> guard(m_ThreadWritrLock); char szServerID[10] = {'\0'}; sprintf_safe(szServerID, 10, "%d", nServerID); CReactorClientInfo* pClientInfo = m_objClientTCPList.Get_Hash_Box_Data(szServerID); if (NULL == pClientInfo) { //如果这个链接不存在,则不创建新的链接 OUR_DEBUG((LM_ERROR, "[CClientReConnectManager::Close]nServerID =(%d) is not exist.\n", nServerID)); return false; } else { ACE_INET_Addr remote_addr = pClientInfo->GetServerAddr(); sprintf_safe(objServerIPInfo.m_szClientIP, MAX_BUFF_50, remote_addr.get_host_addr()); objServerIPInfo.m_nPort = remote_addr.get_port_number(); return true; } }
CLSServerManager::CLSServerManager() { m_u4ServerID = 0; m_szServerIP[0] = '\0'; m_u4Port = 0; m_pServerObject = NULL; m_szLGIP[0] = '\0'; m_u4LGPort = 0; m_u4LGID = 0; sprintf_safe(m_szSessionKey, 32, "%s", SESSION_KEY); }
void StringReplace::Init(const String &strBuildVersion) { DateTime dt; BaseContainer bc; char ch[100]; GetDateTimeNow(dt); sprintf_safe(ch, sizeof(ch), "%4d%02d%02d", (int)dt.year, (int)dt.month, (int)dt.day); m_strDate = ch; sprintf_safe(ch, sizeof(ch), "%02d%02d%02d", (int)dt.hour, (int)dt.minute, (int)dt.second); m_strTime = ch; m_strDateTime = m_strDate + "_" + m_strTime; Int32 lVersion = GetC4DVersion(); sprintf_safe(ch, sizeof(ch), "%.3f", ((Float32)lVersion) / 1000.0f); m_strCurrentVersion = ch; m_strStartupPath = GeGetStartupPath().GetString(); m_strPluginPath = GeGetPluginPath().GetString(); m_strBuildVersion = strBuildVersion; bc = GetMachineFeatures(); m_strReleaseLine = bc.GetString(1000001); m_strBuildID = bc.GetString(1000002); }
bool CLoadModule::LoadModule(const char* szModulePath, const char* szResourceName) { vector<string> vecModuleName; string strModuleName; //将字符串数组解析成单一的模块名称 ParseModule(szResourceName, vecModuleName); sprintf_safe(m_szModulePath, MAX_BUFF_200, "%s", szModulePath); for(uint16 i = 0; i < (uint16)vecModuleName.size(); i++) { strModuleName = vecModuleName[i]; OUR_DEBUG((LM_ERROR, "[CLoadModule::LoadMoudle] Begin Load ModuleName[%s]!\n", strModuleName.c_str())); //确定这个模块是否被注册过 _ModuleInfo* pCurr = m_mapModuleInfo.SearchMapData(strModuleName); if(NULL != pCurr) { //如果被注册过,先卸载现有的,再重新装载 UnLoadModule(strModuleName.c_str()); } _ModuleInfo* pModuleInfo = new _ModuleInfo(); if(NULL == pModuleInfo) { OUR_DEBUG((LM_ERROR, "[CLoadModule::LoadMoudle] new _ModuleInfo is error!\n")); return false; } //开始注册模块 if(false == LoadModuleInfo(strModuleName, pModuleInfo)) { SAFE_DELETE(pModuleInfo); return false; } //将注册成功的模块,加入到map中 if(false == m_mapModuleInfo.AddMapData(pModuleInfo->GetName(), pModuleInfo)) { OUR_DEBUG((LM_ERROR, "[CLoadModule::LoadMoudle] m_mapModuleInfo.AddMapData error!\n")); SAFE_DELETE(pModuleInfo); return false; } OUR_DEBUG((LM_ERROR, "[CLoadModule::LoadMoudle] Begin Load ModuleName[%s] OK!\n", strModuleName.c_str())); } return true; }
uint32 CControlListen::GetListenCount() { m_vecListenList.clear(); if (0 == App_ConnectAcceptorManager::instance()->GetCount()) { //监控尚未启动,需要从配置文件中获取 int nServerPortCount = (int)GetXmlConfigAttribute(xmlTCPServerIPs)->vec.size(); for (int i = 0; i < nServerPortCount; i++) { _ControlInfo objInfo; sprintf_safe(objInfo.m_szListenIP, MAX_BUFF_20, "%s", GetXmlConfigAttribute(xmlTCPServerIPs)->vec[i].ip.c_str()); objInfo.m_u4Port = GetXmlConfigAttribute(xmlTCPServerIPs)->vec[i].port; m_vecListenList.push_back(objInfo); } } else { for (int i = 0; i < App_ConnectAcceptorManager::instance()->GetCount(); i++) { ConnectAcceptor* pConnectAcceptor = App_ConnectAcceptorManager::instance()->GetConnectAcceptor(i); if (NULL != pConnectAcceptor) { _ControlInfo objInfo; sprintf_safe(objInfo.m_szListenIP, MAX_BUFF_20, "%s", pConnectAcceptor->GetListenIP()); objInfo.m_u4Port = pConnectAcceptor->GetListenPort(); m_vecListenList.push_back(objInfo); } } } return (uint32)m_vecListenList.size(); }
SMHandle OpenShareMemory(SMKey Key, int nSize) { #ifdef _WIN32 char szKey[MAX_SHAREMEMORY_64] = {'\0'}; sprintf_safe(szKey, MAX_SHAREMEMORY_64, "%d", Key); return OpenFileMapping(FILE_MAP_ALL_ACCESS, TRUE, szKey); #endif #ifdef __LINUX__ return shmget(Key, nSize, 0); #endif return SMHandle(-1); }
SMHandle CreateShareMemory(SMKey Key, int nSize) { #ifdef _WIN32 char szKey[MAX_SHAREMEMORY_64] = {'\0'}; sprintf_safe(szKey, MAX_SHAREMEMORY_64, "%d", Key); return CreateFileMapping((HANDLE )INIT_HANDLE, NULL, PAGE_READWRITE, 0, nSize, szKey); #endif #ifdef __LINUX__ return shmget(Key, nSize, IPC_CREAT|IPC_EXCL|0666); #endif return SMHandle(-1); }
//----------------------------------------------------------------------------- // Purpose: An achievement was stored //----------------------------------------------------------------------------- void CStatsAndAchievements::OnPS3TrophiesInstalled( PS3TrophiesInstalled_t *pCallback ) { // we may get callbacks for other games' stats arriving, ignore them if ( m_GameID.ToUint64() == pCallback->m_nGameID ) { if ( pCallback->m_eResult != k_EResultOK ) { // this is a fatal error. Usually the PS3 would have already displayed a fatal error to the user and forced the game to exit. If the system // could not display that error, you should display the appropriate message to the user then exit. char buffer[256]; if ( pCallback->m_eResult == k_EResultDiskFull ) sprintf_safe( buffer, "Failed to install PS3 trophies because the HD is full (required space=%llu)\n", pCallback->m_ulRequiredDiskSpace ); else sprintf_safe( buffer, "Failed to install PS3 trophies (%d)", pCallback->m_eResult ); buffer[ sizeof(buffer) - 1 ] = 0; OutputDebugString( buffer ); exit( 1 ); } m_bInstalledPS3Trophies = true; } }
void CBaseCommand::InitUserList() { //初始化允许的用户名和密码 m_mapUserList.clear(); string strUserName; _UserInfo* pUserInfo = new _UserInfo(); //添加一个可以允许的账号 strUserName = "******"; sprintf_safe(pUserInfo->m_szUserPass, MAX_BUFF_100, "1234"); m_mapUserList.insert(mapUserList::value_type(strUserName, pUserInfo)); }
void CMessageService::Init(uint32 u4ThreadID, uint32 u4MaxQueue, uint32 u4LowMask, uint32 u4HighMask) { m_u4MaxQueue = u4MaxQueue; m_u4HighMask = u4HighMask; m_u4LowMask = u4LowMask; //OUR_DEBUG((LM_INFO, "[CMessageService::Init]ID=%d,m_u4State=%d.\n", m_u4ThreadID = u4ThreadID, m_ThreadInfo.m_u4State)); //添加线程信息 m_u4ThreadID = u4ThreadID; m_ThreadInfo.m_u4ThreadID = u4ThreadID; m_u4WorkQueuePutTime = App_MainConfig::instance()->GetWorkQueuePutTime() * 1000; //初始化线程AI m_WorkThreadAI.Init(App_MainConfig::instance()->GetWTAI(), App_MainConfig::instance()->GetPacketTimeOut(), App_MainConfig::instance()->GetWTCheckTime(), App_MainConfig::instance()->GetWTTimeoutCount(), App_MainConfig::instance()->GetWTStopTime(), App_MainConfig::instance()->GetWTReturnDataType(), App_MainConfig::instance()->GetWTReturnData()); //按照线程初始化统计模块的名字 char szName[MAX_BUFF_50] = {'\0'}; sprintf_safe(szName, MAX_BUFF_50, "工作线程(%d)", u4ThreadID); m_CommandAccount.InitName(szName); //初始化统计模块功能 m_CommandAccount.Init(App_MainConfig::instance()->GetCommandAccount(), App_MainConfig::instance()->GetCommandFlow(), App_MainConfig::instance()->GetPacketTimeOut()); //初始化CommandID告警阀值相关 for(int i = 0; i < (int)App_MainConfig::instance()->GetCommandAlertCount(); i++) { _CommandAlert* pCommandAlert = App_MainConfig::instance()->GetCommandAlert(i); if(NULL != pCommandAlert) { m_CommandAccount.AddCommandAlert(pCommandAlert->m_u2CommandID, pCommandAlert->m_u4CommandCount, pCommandAlert->m_u4MailID); } } //设置消息池 m_MessagePool.Init(MAX_MESSAGE_POOL); }
_Packet_Parse_Info* CLoadPacketParse::GetPacketParseInfo(uint32 u4PacketParseID) { char szPacketID[10] = { '\0' }; sprintf_safe(szPacketID, 10, "%d", u4PacketParseID); _Packet_Parse_Info* pPacketParseInfo = m_objPacketParseList.Get_Hash_Box_Data(szPacketID); if(NULL == pPacketParseInfo) { //这里打印输出错误 OUR_DEBUG((LM_INFO, "[CLoadPacketParse::GetPacketParseInfo]can't find u4PacketParseID(%d).\n", u4PacketParseID)); } return pPacketParseInfo; }
bool MMatchServer::OnAdminExecute(MAdminArgvInfo* pAI, char* szOut, int maxlen) { szOut[0] = 0; if (pAI->cargc <= 0) return false; // wall if (!_stricmp(pAI->cargv[0], "wall")) { if (pAI->cargc < 3) { sprintf_safe(szOut, maxlen, "인자가 부족합니다."); return true; } char szMsg[256]; int nMsgType = 0; strcpy_safe(szMsg, pAI->cargv[1]); nMsgType = atoi(pAI->cargv[2]); MCommand* pCmd = CreateCommand(MC_ADMIN_ANNOUNCE, MUID(0,0)); pCmd->AddParameter(new MCmdParamUID(MUID(0,0))); pCmd->AddParameter(new MCmdParamStr(szMsg)); pCmd->AddParameter(new MCmdParamUInt(nMsgType)); RouteToAllClient(pCmd); } else { sprintf_safe(szOut, maxlen, "%s: no such command", pAI->cargv[0]); } return true; }
uint32 CClientReConnectManager::GetPacketParseID(int nServerID) { ACE_Guard<ACE_Recursive_Thread_Mutex> guard(m_ThreadWritrLock); char szServerID[10] = { '\0' }; sprintf_safe(szServerID, 10, "%d", nServerID); CReactorClientInfo* pClientInfo = m_objClientTCPList.Get_Hash_Box_Data(szServerID); if (NULL != pClientInfo) { return pClientInfo->GetPacketParseID(); } return 0; }
void CProControlListen::ShowListen(vecControlInfo& objProControlInfo) { objProControlInfo.clear(); for(int i = 0; i < App_ProConnectAcceptManager::instance()->GetCount(); i++) { ProConnectAcceptor* pProConnectAcceptor = App_ProConnectAcceptManager::instance()->GetConnectAcceptor(i); if(NULL != pProConnectAcceptor) { _ControlInfo objInfo; sprintf_safe(objInfo.m_szListenIP, MAX_BUFF_20, "%s", pProConnectAcceptor->GetListenIP()); objInfo.m_u4Port = pProConnectAcceptor->GetListenPort(); objProControlInfo.push_back(objInfo); } } }
bool CClientReConnectManager::SendData(int nServerID, char*& pData, int nSize, bool blIsDelete) { ACE_Guard<ACE_Recursive_Thread_Mutex> guard(m_ThreadWritrLock); //查找已有连接 char szServerID[10] = {'\0'}; sprintf_safe(szServerID, 10, "%d", nServerID); CReactorClientInfo* pClientInfo = m_objClientTCPList.Get_Hash_Box_Data(szServerID); if (NULL == pClientInfo) { //如果这个链接已经存在,则不创建新的链接 OUR_DEBUG((LM_ERROR, "[CProConnectManager::SendData]nServerID =(%d) is not exist.\n", nServerID)); if (true == blIsDelete) { SAFE_DELETE_ARRAY(pData); } return false; } ACE_Message_Block* pmblk = App_MessageBlockManager::instance()->Create(nSize); if (NULL == pmblk) { OUR_DEBUG((LM_ERROR, "[CClientReConnectManager::SendData]nServerID =(%d) pmblk is NULL.\n", nServerID)); if (true == blIsDelete) { SAFE_DELETE_ARRAY(pData); } return false; } memcpy_safe((char* )pData, (uint32)nSize, pmblk->wr_ptr(), (uint32)nSize); pmblk->wr_ptr(nSize); if (true == blIsDelete) { SAFE_DELETE_ARRAY(pData); } //发送数据 return pClientInfo->SendData(pmblk); }
bool CClientReConnectManager::CloseByClient(int nServerID) { //如果是因为远程连接断开,则只删除ProConnectClient的指针 ACE_Guard<ACE_Recursive_Thread_Mutex> guard(m_ThreadWritrLock); char szServerID[10] = {'\0'}; sprintf_safe(szServerID, 10, "%d", nServerID); CReactorClientInfo* pClientInfo = m_objClientTCPList.Get_Hash_Box_Data(szServerID); if (NULL != pClientInfo) { pClientInfo->SetConnectClient(NULL); pClientInfo->SetServerConnectState(SERVER_CONNECT_FAIL); } return true; }
EM_Server_Connect_State CClientReConnectManager::GetConnectState( int nServerID ) { ACE_Guard<ACE_Recursive_Thread_Mutex> guard(m_ThreadWritrLock); char szServerID[10] = {'\0'}; sprintf_safe(szServerID, 10, "%d", nServerID); CReactorClientInfo* pClientInfo = m_objClientTCPList.Get_Hash_Box_Data(szServerID); if (NULL == pClientInfo) { //如果这个链接已经存在,则不创建新的链接 OUR_DEBUG((LM_ERROR, "[CClientReConnectManager::GetConnectState]nServerID =(%d) is not exist.\n", nServerID)); return SERVER_CONNECT_FAIL; } return pClientInfo->GetServerConnectState(); }
void FrameProfiler::dump_output(SCP_stringstream& out, uint64_t /*start_profile_time*/, uint64_t /*end_profile_time*/, SCP_vector<profile_sample>& samples) { out << " Avg : Min : Max : # : Profile Name\n"; out << "----------------------------------------\n"; for (int i = 0; i < (int) samples.size(); i++) { uint64_t sample_time; uint64_t avg_micro_seconds, min_micro_seconds, max_micro_seconds; Assert(samples[i].open_profiles == 0); sample_time = samples[i].accumulator - samples[i].children_sample_time; avg_micro_seconds = min_micro_seconds = max_micro_seconds = sample_time; // add new measurement into the history and get avg, min, and max store_profile_in_history(samples[i].name, sample_time); get_profile_from_history(samples[i].name, &avg_micro_seconds, &min_micro_seconds, &max_micro_seconds); // format the data char avg[64], min[64], max[64], num[64]; sprintf(avg, "%3.1fms", i2fl(avg_micro_seconds) * 0.000001f); sprintf(min, "%3.1fms", i2fl(min_micro_seconds) * 0.000001f); sprintf(max, "%3.1fms", i2fl(max_micro_seconds) * 0.000001f); sprintf(num, "%3d", samples[i].profile_instances); SCP_string indented_name; for (uint indent = 0; indent < samples[i].num_parents; indent++) { indented_name += ">"; } indented_name += samples[i].name; char line[256]; sprintf_safe(line, "%5s : %5s : %5s : %3s : ", avg, min, max, num); out << line + indented_name + "\n"; } }
int ConnectAcceptor::open2(ACE_INET_Addr& local_addr, ACE_Reactor* reactor, int flags, int backlog) { ACE_TRACE("ACE_Acceptor<SVC_HANDLER, PEER_ACCEPTOR>::open"); this->flags_ = flags; this->use_select_ = 1; this->reuse_addr_ = 1; this->peer_acceptor_addr_ = local_addr; //添加记录监听服务器的IP和端口地址 sprintf_safe(m_szListenIP, MAX_BUFF_20, "%s", local_addr.get_host_addr()); m_u4Port = (uint32)local_addr.get_port_number(); if (reactor == 0) { errno = EINVAL; return -1; } // Open the underlying PEER_ACCEPTOR. if (this->peer_acceptor_.open(local_addr, 1, 0, backlog) == -1) { return -1; } // Set the peer acceptor's handle into non-blocking mode. This is a // safe-guard against the race condition that can otherwise occur // between the time when <select> indicates that a passive-mode // socket handle is "ready" and when we call <accept>. During this // interval, the client can shutdown the connection, in which case, // the <accept> call can hang! (void) this->peer_acceptor_.enable(ACE_NONBLOCK); int const result = reactor->register_handler(this, ACE_Event_Handler::ACCEPT_MASK); if (result != -1) { this->reactor(reactor); } else { this->peer_acceptor_.close(); } return result; }