BOOL KLogClient::Init() { BOOL bResult = false; BOOL bRetCode = false; IIniFile* piIniFile = NULL; piIniFile = g_OpenIniFile(GS_SETTINGS_FILENAME); KGLOG_PROCESS_ERROR(piIniFile); bRetCode = piIniFile->GetString(LOG_SERVER_SECTION_GAMESERVER, "IP", "127.0.0.1", m_szLogServerAddr, sizeof(m_szLogServerAddr)); KGLOG_PROCESS_ERROR(bRetCode); bRetCode = piIniFile->GetInteger(LOG_SERVER_SECTION_GAMESERVER, "Port", 5004, &m_nRelayPort); KGLOG_PROCESS_ERROR(bRetCode); bRetCode = piIniFile->GetInteger(LOG_SERVER_SECTION_GAMESERVER, "PingCycle", 20, &m_nPingCycle); KGLOG_PROCESS_ERROR(bRetCode); m_bRunFlag = true; bRetCode = m_WorkThread.Create(WorkThreadFunction, this); KGLOG_PROCESS_ERROR(bRetCode); bResult = true; Exit0: if (!bResult) { KG_COM_RELEASE(m_piSocketStream); } KG_COM_RELEASE(piIniFile); return bResult; }
int KGFileManager::CompareFileByDataStream(const char cszFileName_1[], const char cszFileName_2[]) { int nResult = false; int nRetCode = false; IFile* pFile_1 = NULL; IFile* pFile_2 = NULL; BYTE byData_1[SIZE_READ_BUFFER] = {0}; BYTE byData_2[SIZE_READ_BUFFER] = {0}; char szResult[2 * MAX_PATH] = {0}; pFile_1 = g_OpenFile(cszFileName_1); KGLOG_PROCESS_ERROR(pFile_1); pFile_2 = g_OpenFile(cszFileName_2); KGLOG_PROCESS_ERROR(pFile_2); if (pFile_1->Size() != pFile_2->Size()) { nRetCode = _snprintf_s( szResult, sizeof(szResult), sizeof(szResult) - 1, "Size Differ. File_1=%s File_2=%s", cszFileName_1, cszFileName_2 ); KGLOG_PROCESS_ERROR(nRetCode > 0); KGLogPrintf(KGLOG_ERR, szResult); KGLOG_PROCESS_ERROR(false); } for (ULONG i = 0; i < pFile_1->Size(); i += SIZE_READ_BUFFER) { pFile_1->Read(byData_1, SIZE_READ_BUFFER); pFile_2->Read(byData_2, SIZE_READ_BUFFER); nRetCode = memcmp(byData_1, byData_2, SIZE_READ_BUFFER); if (nRetCode != 0) { nRetCode = _snprintf_s( szResult, sizeof(szResult), sizeof(szResult) - 1, "File Data Differ. File_1=%s File_2=%s", cszFileName_1, cszFileName_2 ); KGLOG_PROCESS_ERROR(nRetCode > 0); KGLogPrintf(KGLOG_ERR, szResult); KGLOG_PROCESS_ERROR(false); } } nResult = true; Exit0: KG_COM_RELEASE(pFile_1); KG_COM_RELEASE(pFile_2); return nResult; }
KG3DAnimationTagContainer* KG3DAnimationTagContainerTable::LoadTag(LPCSTR strFileName) { HRESULT hrResult = E_FAIL; HRESULT hrRetCode = E_FAIL; DWORD dwID = 0; KG3DAnimationTagContainer* pHoldTag = NULL; KG3DAnimationTagContainer* pNewTag = NULL; TAG_MAP::iterator it; TAG_MAP::_Pairib Pair; pNewTag = new KG3DAnimationTagContainer(); KGLOG_PROCESS_ERROR(pNewTag); dwID = g_FileNameHash(strFileName); it = m_mapTagCache.find(dwID); if (it == m_mapTagCache.end()) { pHoldTag = new KG3DAnimationTagContainer(); KGLOG_PROCESS_ERROR(pHoldTag); hrRetCode = pHoldTag->Load(strFileName); KGLOG_COM_PROCESS_ERROR(hrRetCode); Pair = m_mapTagCache.insert(make_pair(dwID, pHoldTag)); KGLOG_PROCESS_ERROR(Pair.second); Pair.first->second->AddRef(); } else { pHoldTag = it->second; pHoldTag->AddRef(); } if (pHoldTag->IsLoaded()) { hrRetCode = pNewTag->Clone(pHoldTag); KGLOG_COM_PROCESS_ERROR(hrRetCode); } else { hrRetCode = pNewTag->Load(strFileName); KGLOG_COM_PROCESS_ERROR(hrRetCode); } hrResult = S_OK; Exit0: if (FAILED(hrResult)) KG_COM_RELEASE(pNewTag); KG_COM_RELEASE(pHoldTag); return pNewTag; }
BOOL KLogClient::Connect() { BOOL bResult = false; BOOL bRetCode = false; KG_SocketConnector Connector; struct timeval TimeVal; IKG_SocketStream* piSocketStream = NULL; IKG_Buffer* piPackage = NULL; G2L_HANDSHAKE_REQUEST* pHandshake = NULL; piSocketStream = Connector.Connect(m_szLogServerAddr, m_nRelayPort); KG_PROCESS_ERROR(piSocketStream); TimeVal.tv_sec = 0; TimeVal.tv_usec = 10000; bRetCode = piSocketStream->SetTimeout(&TimeVal); KGLOG_PROCESS_ERROR(bRetCode); m_bSocketError = false; //m_nWorldIndex = 0; m_nLastSendPacketTime = g_pSO3World->m_nCurrentTime; // 初始化的一些操作,注意多线程 piPackage = KG_MemoryCreateBuffer((unsigned)sizeof(G2L_HANDSHAKE_REQUEST)); KGLOG_PROCESS_ERROR(piPackage); pHandshake = (G2L_HANDSHAKE_REQUEST*)piPackage->GetData(); KGLOG_PROCESS_ERROR(pHandshake); pHandshake->wProtocolID = g2l_handshake_request; pHandshake->nServerTime = (int)time(NULL); pHandshake->nServerIndexInGC = g_pSO3World->m_nServerIndexInGC; bRetCode = piSocketStream->Send(piPackage); KGLOG_PROCESS_ERROR(bRetCode == 1); // 小心: 这里不能写成 "m_piSocket = piSocket; m_piSocket->AddRef(); ", 那样会导致线程安全隐患 piSocketStream->AddRef(); m_piSocketStream = piSocketStream; KGLogPrintf( KGLOG_INFO, "Connect to log server %s:%d ... ... [OK]", m_szLogServerAddr, m_nRelayPort ); bResult = true; Exit0: KG_COM_RELEASE(piPackage); KG_COM_RELEASE(piSocketStream); return bResult; }
BOOL KLogServerAgency::LoginServer(const char cszIP[], int nPort, const char cszIdentity[]) { BOOL bResult = false; BOOL bRetCode = false; IKG_Buffer* piSendBuffer = NULL; KGCSLogServerLogin* pLogin = NULL; KG_SocketConnector Connector; struct timeval TimeVal; assert(m_piSocket == NULL); m_piSocket = Connector.Connect(cszIP, nPort); KG_PROCESS_ERROR(m_piSocket); TimeVal.tv_sec = 2; TimeVal.tv_usec = 0; bRetCode = m_piSocket->SetTimeout(&TimeVal); KGLOG_PROCESS_ERROR(bRetCode); piSendBuffer = KG_MemoryCreateBuffer((unsigned)sizeof(KGCSLogServerLogin)); KGLOG_PROCESS_ERROR(piSendBuffer); pLogin = (KGCSLogServerLogin*)piSendBuffer->GetData(); KGLOG_PROCESS_ERROR(pLogin); pLogin->ProtocolType = LOGC2S_LOG_LOGIN; pLogin->ulIdentity = 0; strncpy(pLogin->szGatewayName, cszIdentity, sizeof(pLogin->szGatewayName)); pLogin->szGatewayName[sizeof(pLogin->szGatewayName) - 1] = '\0'; bRetCode = Send(piSendBuffer); KGLOG_PROCESS_ERROR(bRetCode); bResult = true; Exit0: KGLogPrintf( KGLOG_INFO, "Connect to log server %s:%d ... ... [%s]", cszIP, nPort, bResult ? "OK" : "Failed" ); if (!bResult) { KG_COM_RELEASE(m_piSocket); } KG_COM_RELEASE(piSendBuffer); return bResult; }
BOOL KApexProxy::Connect(const char szIP[], int nPort) { BOOL bResult = false; BOOL bRetCode = false; timeval TimeoutValue = {0, 0}; KG_SocketConnector Connector; assert(m_piSocketStream == NULL); m_piSocketStream = Connector.Connect(szIP, nPort); KG_PROCESS_ERROR(m_piSocketStream); bRetCode = m_piSocketStream->SetTimeout(&TimeoutValue); KGLOG_PROCESS_ERROR(bRetCode); m_bSendErrorFlag = false; bResult = true; Exit0: if (!bResult) { KG_COM_RELEASE(m_piSocketStream); } KGLogPrintf( KGLOG_INFO, "[ApexProxy] Connect to %s : %d ... ... [%s]", szIP, nPort, bResult ? "Ok" : "Failed" ); return bResult; }
IKIDSequence* CreateIDSequence( const char cszDBAddr[], const char cszDBName[], const char cszUserName[], const char cszPassword[] ) { IKIDSequence* piResult = NULL; KIDSequence* pIDSequence = NULL; BOOL bRetCode = false; assert(cszDBAddr); assert(cszDBName); assert(cszUserName); assert(cszPassword); pIDSequence = new KIDSequence; KGLOG_PROCESS_ERROR(pIDSequence); bRetCode = pIDSequence->Create(cszDBAddr, cszDBName, cszUserName, cszPassword); KGLOG_PROCESS_ERROR(bRetCode); piResult = pIDSequence; Exit0: if (!piResult) { KG_COM_RELEASE(pIDSequence); } return piResult; }
BOOL KLogClient::DoPingSignal() { BOOL bResult = false; BOOL bRetCode = false; DWORD dwNowTime = 0; IKG_Buffer* piSendBuffer = NULL; G2L_PING_SIGNAL* pPingSingal = NULL; dwNowTime = KG_GetTickCount(); KG_PROCESS_ERROR(dwNowTime >= m_dwNextPingTime); m_dwNextPingTime = dwNowTime + 1000 * m_nPingCycle; piSendBuffer = KG_MemoryCreateBuffer(sizeof(G2L_PING_SIGNAL)); KGLOG_PROCESS_ERROR(piSendBuffer); pPingSingal = (G2L_PING_SIGNAL*)piSendBuffer->GetData(); KGLOG_PROCESS_ERROR(pPingSingal); pPingSingal->wProtocolID = g2l_ping_signal; bRetCode = Send(piSendBuffer); KGLOG_PROCESS_ERROR(bRetCode); bResult = true; Exit0: KG_COM_RELEASE(piSendBuffer); return bResult; }
void KG3DFontTexture::LoadAlphaAdjustTable(LPCSTR szFontName, INT nFontSize) { BOOL bAdjust = FALSE; char szFileName[MAX_PATH]; LPSTR szSep = NULL; int nLen = _countof(szFileName) - 16; strncpy(szFileName, szFontName, nLen); szFileName[nLen - 1] = '\0'; szSep = strrchr(szFileName, '.'); if (szSep) { sprintf(szSep, "%d.prf", nFontSize); if (g_IsFileExist(szFileName)) { IFile* pFile = g_OpenFile(szFileName); if (pFile) { unsigned int nCount = pFile->Read(m_uchAdjustBuffer, sizeof(m_uchAdjustBuffer)); if (nCount == sizeof(m_uchAdjustBuffer)) bAdjust = TRUE; KG_COM_RELEASE(pFile); } } } if (!bAdjust) { for (size_t nIndex = 0; nIndex < _countof(m_uchAdjustBuffer); ++nIndex) { m_uchAdjustBuffer[nIndex] = (UCHAR)nIndex; } } }
void KGT_g_OpenIniFileFromArgumentsTest::Test_g_OpenFileFromArguments_09() { int nResult = false; int nRetCode = false; IIniFile *piIniFile = NULL; char *szArgv[] = { "KG_GoddessD.exe", "--Database.password="******"value的长度为0", ""); piIniFile = g_OpenIniFileFromArguments(nArgc, szArgv); KG_PROCESS_ERROR(piIniFile); nRetCode = piIniFile->GetSectionCount(); KG_PROCESS_ERROR(nRetCode == 1); nRetCode = piIniFile->GetString("Database", "password", "root", szRetValue, sizeof(szRetValue) / sizeof(szRetValue[0])); KG_PROCESS_ERROR(nRetCode); KG_PROCESS_ERROR(szRetValue[0] == '\0'); nResult = true; Exit0: KG_COM_RELEASE(piIniFile); CPPUNIT_ASSERT(nResult); }
BOOL KLogClient::Init() { BOOL bResult = false; BOOL bRetCode = false; IIniFile* piIniFile = NULL; int nPort = 0; char szIP[16]; piIniFile = g_OpenIniFile(GS_SETTINGS_FILENAME); KGLOG_PROCESS_ERROR(piIniFile); bRetCode = piIniFile->GetString("LogServer", "IP", "127.0.0.1", szIP, sizeof(szIP)); KGLOG_PROCESS_ERROR(bRetCode); bRetCode = piIniFile->GetInteger("LogServer", "Port", 5005, &nPort); KGLOG_PROCESS_ERROR(bRetCode); bRetCode = piIniFile->GetInteger("LogServer", "PingCycle", 30, &m_nPingCycle); KGLOG_PROCESS_ERROR(bRetCode); KGLOG_PROCESS_ERROR(m_nPingCycle > 0); bRetCode = piIniFile->GetString("LogServer", "Identity", "", m_szIdentity, sizeof(m_szIdentity)); KGLOG_PROCESS_ERROR(bRetCode); m_szIdentity[sizeof(m_szIdentity) - 1] = '\0'; // 无论连上与否,均视为成功 LoginServer(szIP, nPort, m_szIdentity); bResult = true; Exit0: KG_COM_RELEASE(piIniFile); return bResult; }
int KSimulateRelay::DoFreezeCoinRequest() { BOOL bResult = false; BOOL bRetCode = false; IKG_Buffer* piBuffer = NULL; R2G_FREEZE_COIN_REQUEST* pRequest = NULL; const char* pszAccountName = "0000"; DWORD dwRoleID = 3333; assert(pszAccountName); piBuffer = KG_MemoryCreateBuffer((unsigned)sizeof(R2G_FREEZE_COIN_REQUEST)); KGLOG_PROCESS_ERROR(piBuffer); pRequest = (R2G_FREEZE_COIN_REQUEST*)piBuffer->GetData(); KGLOG_PROCESS_ERROR(pRequest); pRequest->byProtocol = r2g_freeze_coin_request; strncpy(pRequest->szAccount, pszAccountName, sizeof(pRequest->szAccount)); pRequest->szAccount[sizeof(pRequest->szAccount) - 1] = '\0'; pRequest->dwRequestID = dwRoleID; bRetCode = m_piSocket->Send(piBuffer); KGLOG_PROCESS_ERROR(bRetCode); KGLogPrintf(KGLOG_INFO, "Relay, DoFreezeCoinRequest\n"); bResult = true; Exit0: KG_COM_RELEASE(piBuffer); return bResult; }
int KSimulateRelay::DoPingRespond() { int nResult = false; int nRetCode = false; IKG_Buffer* piSendBuffer = NULL; BYTE* pbySendBuffer = NULL; tagProtocolHeader* ptagProtocolHeader = NULL; KGLOG_PROCESS_ERROR(m_piSocket); piSendBuffer = KG_MemoryCreateBuffer((unsigned)(sizeof(R2G_PING_SIGNAL))); KGLOG_PROCESS_ERROR(piSendBuffer); pbySendBuffer = (BYTE*)piSendBuffer->GetData(); KGLOG_PROCESS_ERROR(pbySendBuffer); ptagProtocolHeader = (tagProtocolHeader*)pbySendBuffer; ptagProtocolHeader->cProtocol = r2g_ping_signal; nRetCode = m_piSocket->Send(piSendBuffer); KGLOG_PROCESS_ERROR(nRetCode); nResult = true; Exit0: KG_COM_RELEASE(piSendBuffer); return nResult; }
int KSimulateRelay::OnQueryAccountState(BYTE* pbyData, size_t uDataLen) { int nResult = false; int nRetCode = false; IKG_Buffer* piSendBuffer = NULL; G2R_QUERY_ACCOUNT_STATE* pQueryAccountState = (G2R_QUERY_ACCOUNT_STATE*)pbyData; R2G_SYNC_ACCOUNT_STATE* pSyncAccountState = NULL; pQueryAccountState->szAccount[sizeof(pQueryAccountState->szAccount) - 1] = '\0'; piSendBuffer = KG_MemoryCreateBuffer(sizeof(R2G_SYNC_ACCOUNT_STATE)); KGLOG_PROCESS_ERROR(piSendBuffer); pSyncAccountState = (R2G_SYNC_ACCOUNT_STATE*)piSendBuffer->GetData(); KGLOG_PROCESS_ERROR(pSyncAccountState); pSyncAccountState->byProtocol = r2g_sync_account_state; pSyncAccountState->nPlayerIndex = pQueryAccountState->nPlayerIndex; pSyncAccountState->bOnline = m_RelayConfig.nUserOnlineResult; nRetCode = m_piSocket->Send(piSendBuffer); KGLOG_PROCESS_ERROR(nRetCode == 1); nResult = true; Exit0: KG_COM_RELEASE(piSendBuffer); return nResult; }
int KSimulateRelay::DoDeleteRoleRespond(DWORD dwPacketIdentity, int nRespondCode) { int nResult = false; int nRetCode = false; IKG_Buffer* piSendBuffer = false; size_t uSendBufferSize = 0; R2G_DELETE_ROLE_RESPOND* pRespond = NULL; KGLOG_PROCESS_ERROR(m_piSocket); uSendBufferSize = sizeof(R2G_DELETE_ROLE_RESPOND); piSendBuffer = KG_MemoryCreateBuffer((unsigned)uSendBufferSize); KGLOG_PROCESS_ERROR(piSendBuffer); pRespond = (R2G_DELETE_ROLE_RESPOND*)piSendBuffer->GetData(); KGLOG_PROCESS_ERROR(pRespond); pRespond->byProtocol = r2g_delete_role_respond; pRespond->nPlayerIndex = dwPacketIdentity; pRespond->byCode = nRespondCode; pRespond->dwRoleID = 0; nRetCode = m_piSocket->Send(piSendBuffer); KGLOG_PROCESS_ERROR(nRetCode == 1); nResult = true; Exit0: KG_COM_RELEASE(piSendBuffer); return nResult; }
int KSimulateRelay::DoSetProtocolVersion(int nLowerVersion, int nUpperVersion) { int nResult = false; int nRetCode = false; IKG_Buffer* piSendBuffer = false; size_t uSendBufferSize = 0; R2G_SET_GAME_WORLD_VERSION* pRespond = NULL; KG_PROCESS_ERROR(m_piSocket); uSendBufferSize = sizeof(R2G_SET_GAME_WORLD_VERSION); piSendBuffer = KG_MemoryCreateBuffer((unsigned)uSendBufferSize); KGLOG_PROCESS_ERROR(piSendBuffer); pRespond = (R2G_SET_GAME_WORLD_VERSION*)piSendBuffer->GetData(); KGLOG_PROCESS_ERROR(pRespond); pRespond->byProtocol = r2g_set_game_world_version; pRespond->nLowerVersion = nLowerVersion; pRespond->nUpperVersion = nUpperVersion; nRetCode = m_piSocket->Send(piSendBuffer); KGLOG_PROCESS_ERROR(nRetCode == 1); nResult = true; Exit0: KG_COM_RELEASE(piSendBuffer); return nResult; }
int KSimulateRelay::DoAccountExchangeRequest() { BOOL bResult = false; BOOL bRetCode = false; IKG_Buffer* piBuffer = NULL; R2G_ACCOUNT_EXCHANGE_REQUEST* pRequest = NULL; const char* pszAccountName = "0000"; // DWORD dwRoleID = 3333; assert(pszAccountName); piBuffer = KG_MemoryCreateBuffer((unsigned)sizeof(R2G_ACCOUNT_EXCHANGE_REQUEST)); KGLOG_PROCESS_ERROR(piBuffer); pRequest = (R2G_ACCOUNT_EXCHANGE_REQUEST*)piBuffer->GetData(); KGLOG_PROCESS_ERROR(pRequest); pRequest->byProtocol = r2g_account_exchange_request; bRetCode = m_piSocket->Send(piBuffer); KGLOG_PROCESS_ERROR(bRetCode); KGLogPrintf(KGLOG_INFO, "Relay, DoAccountExchangeRequest\n"); bResult = true; Exit0: KG_COM_RELEASE(piBuffer); return bResult; }
BOOL KApexProxy::DoRoleLogout(DWORD dwRoleID) { BOOL bResult = false; APEX_ROLE_LOGOUT* pRoleLogout = NULL; IKG_Buffer* piBuffer = NULL; KRole* pRole = NULL; size_t nNameLen = 0; pRole = g_pSO3GameCenter->m_RoleManager.GetRole(dwRoleID); KGLOG_PROCESS_ERROR(pRole); piBuffer = KG_MemoryCreateBuffer((unsigned)sizeof(APEX_ROLE_LOGOUT)); KGLOG_PROCESS_ERROR(piBuffer); pRoleLogout = (APEX_ROLE_LOGOUT*)piBuffer->GetData(); KGLOG_PROCESS_ERROR(pRoleLogout); pRoleLogout->cMsgId = 'G'; pRoleLogout->nSendId = (int)dwRoleID; strncpy(pRoleLogout->szName, pRole->m_szName, sizeof(pRoleLogout->szName)); pRoleLogout->szName[sizeof(pRoleLogout->szName) - 1] = '\0'; Send(piBuffer); bResult = true; Exit0: KG_COM_RELEASE(piBuffer); return bResult; }
BOOL KGMInfoList::Init() { BOOL bResult = false; int nRetCode = false; ITabFile* piTabFile = NULL; char szFilePath[MAX_PATH]; snprintf(szFilePath, sizeof(szFilePath), "%s/%s", SETTING_DIR, GMACCOUNT_LIST_FILE_NAME); szFilePath[sizeof(szFilePath) - 1] = '\0'; piTabFile = g_OpenTabFile(szFilePath); KGLOG_PROCESS_ERROR(piTabFile); for (int nRowIndex = 2; nRowIndex <= piTabFile->GetHeight(); nRowIndex++) { GMAccountInfo NewGMAccount; piTabFile->GetString(nRowIndex, "szAccount", "", NewGMAccount.szGMAccount, sizeof(NewGMAccount.szGMAccount)); NewGMAccount.szGMAccount[countof(NewGMAccount.szGMAccount) - 1] = '\0'; KGLOG_PROCESS_ERROR(NewGMAccount.szGMAccount != '\0'); m_GMAccountInfoList.push_back(NewGMAccount); } bResult = true; Exit0: KG_COM_RELEASE(piTabFile); return bResult; }
BOOL KAIManager::Init() { BOOL bResult = false; BOOL bRetCode = false; IIniFile* piIniFile = NULL; RegisterActionFunctions(); KGLogPrintf(KGLOG_INFO, "[AI] loading ... ..."); bRetCode = LoadAITabFile(); KGLOG_PROCESS_ERROR(bRetCode); KGLogPrintf(KGLOG_INFO, "[AI] %u AI loaded !", m_AITable.size()); memset(m_ActionRunTimeStatisticsArray, 0, sizeof(m_ActionRunTimeStatisticsArray)); m_NpcAIRunTimeStatisticsMap.clear(); m_bLogAIRuntimeStat = 0; piIniFile = g_OpenIniFile(GS_SETTINGS_FILENAME); KGLOG_PROCESS_ERROR(piIniFile); bRetCode = piIniFile->GetInteger("AI", "LogAIRuntimeStat", 0, &m_bLogAIRuntimeStat); //KGLOG_PROCESS_ERROR(bRetCode); bResult = true; Exit0: KG_COM_RELEASE(piIniFile); return bResult; }
void KGT_GetNextSectionTest::TestGetNextSection_11() { int nResult = false; int nRetCode = false; IIniFile *piIniFile = NULL; char *szArgv[] = { "KG_GoddessD.exe" }; int nArgc = sizeof(szArgv) / sizeof(szArgv[0]); char *pszSection = "Version"; char szNextSection[IIniFile::INI_MAX_SUPPORT_SECTION_AND_KEY_SIZE]; szNextSection[0] = '\0'; KG_CASE_INFO("非空值下一个section", "KG_Ini_SectionMap没有记录"); piIniFile = g_OpenIniFileFromArguments(nArgc, szArgv); KG_PROCESS_ERROR(piIniFile); nRetCode = piIniFile->GetNextSection(pszSection, szNextSection); KG_PROCESS_ERROR(!nRetCode); szNextSection[sizeof(szNextSection) - 1] = '\0'; KG_PROCESS_ERROR(szNextSection[0] == '\0'); nResult = true; Exit0: KG_COM_RELEASE(piIniFile); CPPUNIT_ASSERT(nResult); }
int LoadConfig(BOOL *pnIsClient, char *pszDir, unsigned uSize) { int nResult = false; int nRetCode = false; const char CONFIGFILE[] = "KG_BoneChecker.ini"; IIniFile *piFile = NULL; *pnIsClient = false; piFile = g_OpenIniFile(CONFIGFILE); KGLOG_PROCESS_ERROR(piFile); nRetCode = piFile->GetString("BoneChecker", "SO3ClientDir", "", pszDir, uSize); KGLOG_PROCESS_ERROR(nRetCode); if (strcmp(pszDir, "")) { *pnIsClient = true; KG_PROCESS_SUCCESS(true); } nRetCode = piFile->GetString("BoneChecker", "bipdir", "", pszDir, uSize); KGLOG_PROCESS_ERROR(nRetCode); Exit1: nResult = true; Exit0: if (!nResult) puts("!!!Read Config File Failed."); KG_COM_RELEASE(piFile); return nResult; }
void KGT_GetNextSectionTest::TestGetNextSection_06() { int nResult = false; int nRetCode = false; IIniFile *piIniFile = NULL; char *szArgv[] = { "KG_GoddessD.exe", "--AVersion.version=2", "--BDatabase.user=root", "--CNameServer.user=root", "--DLogServer.user=root" }; int nArgc = sizeof(szArgv) / sizeof(szArgv[0]); char *pszSection = "EGoddessServer"; char szNextSection[IIniFile::INI_MAX_SUPPORT_SECTION_AND_KEY_SIZE]; szNextSection[0] = '\0'; KG_CASE_INFO("不存在的记录的下一个section", "KG_Ini_SectionMap有多条记录"); piIniFile = g_OpenIniFileFromArguments(nArgc, szArgv); KG_PROCESS_ERROR(piIniFile); nRetCode = piIniFile->GetNextSection(pszSection, szNextSection); KG_PROCESS_ERROR(!nRetCode); szNextSection[sizeof(szNextSection) - 1] = '\0'; KG_PROCESS_ERROR(szNextSection[0] == '\0'); //szNextSection保持不变 nResult = true; Exit0: KG_COM_RELEASE(piIniFile); CPPUNIT_ASSERT(nResult); }
BOOL KLogServerAgency::Ping() { BOOL bResult = false; BOOL bRetCode = false; IKG_Buffer* piSendBuffer = NULL; tagProtocolHeader2* pPing = NULL; KG_PROCESS_ERROR(g_pSO3GameCenter->m_nTimeNow >= m_nNextPingTime); m_nNextPingTime = g_pSO3GameCenter->m_nTimeNow + m_nPingCycle; piSendBuffer = KG_MemoryCreateBuffer((unsigned)sizeof(tagProtocolHeader2)); KGLOG_PROCESS_ERROR(piSendBuffer); pPing = (tagProtocolHeader2*)piSendBuffer->GetData(); KGLOG_PROCESS_ERROR(pPing); pPing->ProtocolType = LOGC2S_PING; pPing->ulIdentity = 0; bRetCode = Send(piSendBuffer); KG_PROCESS_ERROR(bRetCode); bResult = true; Exit0: KG_COM_RELEASE(piSendBuffer); return bResult; }
BOOL KMapCopy::Load(BYTE* pbyData, size_t uDataLen) { BOOL bResult = false; BOOL bRetCode = false; BYTE* pbyOffset = pbyData; size_t uLeftSize = uDataLen; DWORD dwPlayerCount = 0; DWORD dwSceneDataLen = 0; IKG_Buffer* piSceneData = NULL; BYTE* pbySceneData = NULL; KGLOG_PROCESS_ERROR(uLeftSize >= sizeof(DWORD)); dwPlayerCount = *(DWORD*)pbyOffset; pbyOffset += sizeof(DWORD); uLeftSize -= sizeof(DWORD); for (DWORD i = 0; i < dwPlayerCount; i++) { KGLOG_PROCESS_ERROR(uLeftSize >= sizeof(DWORD)); m_PlayerList.insert(*(DWORD*)pbyOffset); pbyOffset += sizeof(DWORD); uLeftSize -= sizeof(DWORD); } KGLOG_PROCESS_ERROR(uLeftSize >= sizeof(DWORD)); dwSceneDataLen = *(DWORD*)pbyOffset; pbyOffset += sizeof(DWORD); uLeftSize -= sizeof(DWORD); KGLOG_PROCESS_ERROR(uLeftSize >= dwSceneDataLen); if (dwSceneDataLen > 0) { piSceneData = KG_MemoryCreateBuffer((unsigned)dwSceneDataLen); KGLOG_PROCESS_ERROR(piSceneData); pbySceneData = (BYTE*)piSceneData->GetData(); KGLOG_PROCESS_ERROR(pbySceneData); memcpy(pbySceneData, pbyOffset, dwSceneDataLen); assert(m_piSceneData == NULL); m_piSceneData = piSceneData; m_piSceneData->AddRef(); } pbyOffset += dwSceneDataLen; uLeftSize -= dwSceneDataLen; KGLOG_PROCESS_ERROR(uLeftSize == 0); bResult = true; Exit0: KG_COM_RELEASE(piSceneData); return bResult; }
BOOL KQuestInfoList::LoadRandomQuestGroup() { BOOL bResult = false; int nRetCode = false; int nHeight = 0; ITabFile* piTabFile = NULL; DWORD dwTemplateID = 0; DWORD dwQuestID = 0; KQuestInfo* pQuestInfo = NULL; char szFilePath[MAX_PATH]; char szColName[64]; std::set<DWORD>::iterator setIt; int nID = 0; nRetCode = (int)snprintf(szFilePath, sizeof(szFilePath), "%s/%s", SETTING_DIR, RANDOM_QUEST_FILE_NAME); KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)sizeof(szFilePath)); piTabFile = g_OpenTabFile(szFilePath); KGLOG_PROCESS_ERROR(piTabFile); nHeight = piTabFile->GetHeight(); if (nHeight >= 2) { for (int i = 2; i <= nHeight; ++i) { KQUEST_GROUP QuestGroupInfo; nRetCode = piTabFile->GetInteger(i, "ID", 0, &nID); KGLOG_PROCESS_ERROR(nRetCode > 0); for (int j = 0; j < RANDOM_QUEST_COUNT_PER_GROUP; ++j) { snprintf(szColName, sizeof(szColName), "Quest%d", j + 1); szColName[sizeof(szColName) - 1] = '\0'; nRetCode = piTabFile->GetInteger(i, szColName, 0, (int*)&dwQuestID); if (dwQuestID == 0) break; pQuestInfo = GetQuestInfo(dwQuestID); KGLOG_PROCESS_ERROR(pQuestInfo); KGLOG_PROCESS_ERROR(pQuestInfo->bAccept); KGLOG_PROCESS_ERROR(pQuestInfo->bRepeat); QuestGroupInfo.push_back(dwQuestID); } m_RandomQuestGroup[nID] = QuestGroupInfo; } } Exit1: bResult = true; Exit0: KG_COM_RELEASE(piTabFile); return bResult; }
BOOL KEntryList::Init() { BOOL bResult = false; int nRetCode = false; ITabFile* piTabFile = NULL; int nTabHeight = 0; char szFileName[PATH_MAX]; snprintf(szFileName, sizeof(szFileName), "%s/EntryList.tab", SETTING_DIR); szFileName[sizeof(szFileName) - 1] = '\0'; piTabFile = g_OpenTabFile(szFileName); if (!piTabFile) { KGLogPrintf(KGLOG_ERR, "[EntryList] Failed to open entry list file : %s\n", szFileName); goto Exit0; } nTabHeight = piTabFile->GetHeight(); for (int nLine = 2; nLine <= nTabHeight; nLine++) { __int64 nKey = 0; int nMapID = 0; int nIndex = 0; KMapEntry EntryInfo; nRetCode = piTabFile->GetInteger(nLine, "Map", 0, &nMapID); KGLOG_PROCESS_ERROR(nRetCode == 1); nRetCode = piTabFile->GetInteger(nLine, "Index", 0, &nIndex); KGLOG_PROCESS_ERROR(nRetCode == 1); nRetCode = piTabFile->GetInteger(nLine, "PosX", 0, &EntryInfo.nPosX); KGLOG_PROCESS_ERROR(nRetCode == 1); nRetCode = piTabFile->GetInteger(nLine, "PosY", 0, &EntryInfo.nPosY); KGLOG_PROCESS_ERROR(nRetCode == 1); nRetCode = piTabFile->GetInteger(nLine, "PosZ", 0, &EntryInfo.nPosZ); KGLOG_PROCESS_ERROR(nRetCode == 1); nRetCode = piTabFile->GetInteger(nLine, "Direction", 0, &EntryInfo.nDirection); KGLOG_PROCESS_ERROR(nRetCode == 1); nKey = MAKE_INT64(nMapID, nIndex); m_EntryList[nKey] = EntryInfo; } bResult = true; Exit0: KG_COM_RELEASE(piTabFile); if (!bResult) { m_EntryList.clear(); } return bResult; }
BOOL KSkillManager::LoadSkillBinaryData(KMAP_SKILL_DATA& allBinarySkillData) { BOOL bResult = false; BOOL bRetCode = false; IFile* piFile = NULL; BYTE* pBuffer = NULL; size_t uBufferSize = 0; uint64_t uSkillKey = 0; KSkillBinaryData* pBinaryData = NULL; KAnchor* pAnchor = NULL; KSkillSegmentInfo* pSegmentInfo = NULL; KSkillLogicInfo* pLogicData = NULL; unsigned int uEnd = 0; BYTE* pBufferEnd = NULL; piFile = g_OpenFile(SETTING_DIR"/SkillAction.skilllogic"); KGLOG_PROCESS_ERROR(piFile); pBuffer = (BYTE*)piFile->GetBuffer(); KGLOG_PROCESS_ERROR(pBuffer); uBufferSize = piFile->Size(); KGLOG_PROCESS_ERROR(uBufferSize); bRetCode = g_DoBufferSkip(pBuffer, uBufferSize, sizeof(KSkillLogicFileHeader)); KG_PROCESS_ERROR(bRetCode); while (uBufferSize) { bRetCode = g_ReadFromBufferTo(pBuffer, uBufferSize, uEnd); KGLOG_PROCESS_ERROR(bRetCode); pBufferEnd = pBuffer + uEnd; bRetCode = g_ReadFromBufferAs(pBuffer, uBufferSize, pLogicData); KGLOG_PROCESS_ERROR(bRetCode); uSkillKey = MAKE_INT64(pLogicData->skillID, pLogicData->skillStep); pBinaryData = &allBinarySkillData[uSkillKey]; pBinaryData->dwID = pLogicData->skillID; pBinaryData->dwStep = pLogicData->skillStep; pBinaryData->nTotalFrame = pLogicData->frameCount; bRetCode = LoadAnchors(pBuffer, uBufferSize, pBinaryData->Anchors); KGLOG_PROCESS_ERROR(bRetCode); bRetCode = LoadSegments(pBuffer, uBufferSize, pBinaryData->Segments); KGLOG_PROCESS_ERROR(bRetCode); KGLOG_PROCESS_ERROR(pBufferEnd == pBuffer); } bResult = true; Exit0: KG_COM_RELEASE(piFile); return bResult; }
void KPlayerServer::ProcessNetwork(void) { int nRetCode = false; while (true) { int nEventCount = 0; KG_SOCKET_EVENT* pSocketEvent = NULL; KG_SOCKET_EVENT* pSocketEventEnd = NULL; nRetCode = m_SocketServerAcceptor.Wait(m_nSocketEventCount, m_pSocketEventArray, &nEventCount); KGLOG_PROCESS_ERROR(nRetCode); if (nEventCount == 0) break; pSocketEventEnd = m_pSocketEventArray + nEventCount; for (pSocketEvent = m_pSocketEventArray; pSocketEvent < pSocketEventEnd; pSocketEvent++) { // Process new connection accept // KG_SOCKET_EVENT_ACCEPT event must be processed before any other event, // because Maybe uEventFlag = KG_SOCKET_EVENT_ACCEPT | KG_SOCKET_EVENT_IN. if (pSocketEvent->uEventFlag & KG_SOCKET_EVENT_ACCEPT) { ProcessNewConnection(pSocketEvent->piSocket); KG_COM_RELEASE(pSocketEvent->piSocket); continue; } if (!(pSocketEvent->uEventFlag & KG_SOCKET_EVENT_IN)) { KGLogPrintf(KGLOG_DEBUG, "Unexpected socket event: %u", pSocketEvent->uEventFlag); KG_COM_RELEASE(pSocketEvent->piSocket); continue; } ProcessPackage(pSocketEvent->piSocket); KG_COM_RELEASE(pSocketEvent->piSocket); } } Exit0: return; }
void KLogServerAgency::Activate() { int nRetCode = false; BOOL bConnectionLost = false; IKG_Buffer* piBuffer = NULL; while (m_piSocket) { const struct timeval TimeVal = {0, 0}; tagProtocolHeader2* pHeader = NULL; nRetCode = m_piSocket->CheckCanRecv(&TimeVal); if (nRetCode == -1) { bConnectionLost = true; break; } if (nRetCode == 0) { break; } KG_COM_RELEASE(piBuffer); nRetCode = m_piSocket->Recv(&piBuffer); if (nRetCode != 1) { bConnectionLost = true; break; } } if (bConnectionLost) { KGLogPrintf(KGLOG_ERR, "Log server connection lost !\n"); KG_COM_RELEASE(m_piSocket); goto Exit0; } Ping(); Exit0: KG_COM_RELEASE(piBuffer); }