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;
}
Beispiel #2
0
int KG_GameDatabase::_GetRoleEquipmentPoint(const KG_RoleInfo &crRoleInfo, float *pfRetLevel)
{
	int nResult  = false;
	int nRetCode = false;
    int nEmptyFlag = false;
    int nTypeID = 0;
    int nItemID = 0;
    KG_EQUIPMENT_TYPE_MAP::iterator itType;
    KG_EQUIPMENT_POINT_MAP *pEquipmentPointMap = NULL;
    KG_EQUIPMENT_POINT_MAP::iterator itPoint;
    const int ARMED_BOX_ID = 0;
    const int EQUIPMENT_ID_ARRAY[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 22};

    // 装备身上所对应的BoxID为0
    // 统计身上的装备:   近战武器 远程武器 上装 帽子 项链 左手戒指 右手戒指 腰带 腰坠 下装 鞋子 护手 暗器
    // 对应的Position ID:0        1        2    3    4    5        6        7    8     9   10   11   22

    ASSERT(pfRetLevel);
    *pfRetLevel = 0;

    for (int i = 0; i < sizeof(EQUIPMENT_ID_ARRAY) / sizeof(EQUIPMENT_ID_ARRAY[0]); i++)
    {
        nRetCode = crRoleInfo.GetItemInfo(
            ARMED_BOX_ID, EQUIPMENT_ID_ARRAY[i], &nEmptyFlag, &nTypeID, &nItemID
        );
        KGLOG_PROCESS_ERROR(nRetCode && "crRoleInfo.GetItemInfo()");

        if (nEmptyFlag)
            continue;

        itType = m_EquipmentTypeMap.find(nTypeID);
        if (itType == m_EquipmentTypeMap.end())
        {
            printf("Failed to find the item, Type ID: %d, Item ID: %d\n", nTypeID, nItemID);
            KGLogPrintf(
                KGLOG_DEBUG, "Failed to find the item, Type ID: %d, Item ID: %d", nTypeID, nItemID
            );
            continue;
        }

        pEquipmentPointMap = &(itType->second);

        itPoint = pEquipmentPointMap->find(nItemID);
        if (itPoint == pEquipmentPointMap->end())
        {
            printf("Failed to find the item, Type ID: %d, Item ID: %d\n", nTypeID, nItemID);
            KGLogPrintf(
                KGLOG_DEBUG, "Failed to find the item, Type ID: %d, Item ID: %d", nTypeID, nItemID
            );
            continue;
        }

        *pfRetLevel += itPoint->second;        
    }   

	nResult = true;
Exit0:
	return nResult;
}
Beispiel #3
0
BOOL KScriptManager::LoadScripts(ILuaScriptEx* piScript, const char cszDir[])
{
    BOOL            bResult     = false;
	BOOL			bRetCode    = false;
    HANDLE          hFind       = INVALID_HANDLE_VALUE;
    WIN32_FIND_DATA FindFileData;
    char            szPath[MAX_PATH];

    snprintf(szPath, sizeof(szPath), "%s\\*", cszDir);
    szPath[sizeof(szPath) - 1] = '\0';

    hFind = FindFirstFile(szPath, &FindFileData);
    KGLOG_PROCESS_ERROR(hFind != INVALID_HANDLE_VALUE);
	if (hFind == INVALID_HANDLE_VALUE)
	{
		KGLogPrintf(KGLOG_ERR, "[Lua] Failed to file file: %s\n", szPath);
	}
	

    do 
    {
        if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
        {
            if (strcmp(FindFileData.cFileName, ".") != 0 && strcmp(FindFileData.cFileName, "..") != 0)
            {
                snprintf(szPath, sizeof(szPath), "%s\\%s", cszDir, FindFileData.cFileName);
                szPath[sizeof(szPath) - 1] = '\0';

                LoadScripts(piScript, szPath);
            }
        }
        else
        {
            snprintf(szPath, sizeof(szPath), "%s\\%s", cszDir, FindFileData.cFileName);
            szPath[sizeof(szPath) - 1] = '\0';

            bRetCode = IsLuaScriptFile(szPath);
            if (bRetCode)
            {
                bRetCode = piScript->LoadFromFile(szPath);
                if (!bRetCode)
                {
                    KGLogPrintf(KGLOG_ERR, "[Lua] Failed to load file: %s\n", szPath);
                }
            }
        }

    } while (FindNextFile(hFind, &FindFileData));

    bResult = true;
Exit0:
    if (hFind != INVALID_HANDLE_VALUE)
    {
        FindClose(hFind);
        hFind = INVALID_HANDLE_VALUE;
    }
    return bResult;
}
Beispiel #4
0
int main(int argc, char* argv[])
{
    int         nResult      = false;
    int         nRetCode     = false;  
    int         nLogInitFlag = false;
    int         nRdbFlag     = false;
    KGLOG_PARAM LogParam;  

    KSO3RoleDBUpdater* pKSO3RoleDBUpdater = NULL;

#ifdef WIN32
    SetConsoleInfo();
#endif
    setlocale(LC_ALL, "");
    g_SetRootPath(NULL);

    strncpy(LogParam.szPath, "logs", sizeof(LogParam.szPath));
    LogParam.szPath[sizeof(LogParam.szPath) - 1] = '\0';
    strncpy(LogParam.szIdent, "SO3RoleDBUpdaterTest", sizeof(LogParam.szIdent));
    LogParam.szIdent[sizeof(LogParam.szIdent) - 1] = '\0';
    LogParam.Options = (KGLOG_OPTIONS)(KGLOG_OPTION_FILE | KGLOG_OPTION_CONSOLE);
    LogParam.nMaxLineEachFile = 160000;

    nRetCode = KGLogInit(LogParam, NULL);
    KGLOG_PROCESS_ERROR(nRetCode);
    nLogInitFlag = true;  

    pKSO3RoleDBUpdater = new KSO3RoleDBUpdater();
    KGLOG_PROCESS_ERROR(pKSO3RoleDBUpdater);

    nRetCode = pKSO3RoleDBUpdater->Init();
    KGLOG_PROCESS_ERROR(nRetCode);
    nRdbFlag = true;
    KGLogPrintf(KGLOG_INFO, "SO3RoleDBUpdaterTest had started up ... ...");

    nRetCode = pKSO3RoleDBUpdater->Run();
    KGLOG_PROCESS_ERROR(nRetCode);

    KGLogPrintf(KGLOG_INFO, "SO3RoleDB UpdateTest Complete...");

    nResult = true;
Exit0:
    if (nRdbFlag)
    {
        pKSO3RoleDBUpdater->UnInit();
        nRdbFlag = false;
    }

    KG_DELETE(pKSO3RoleDBUpdater);

    if (nLogInitFlag)
    {
        KGLogUnInit(NULL);
        nLogInitFlag = false;
    }
    
    return nResult ? 0 : 1;
}
Beispiel #5
0
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;
}
Beispiel #6
0
int KHttpFile::Download()
{
    int nRetCode    = false;
    int nResult     = false;
    int nRetryCount = 0;

    nRetCode = GetFileInfo();
    KGLOG_PROCESS_ERROR(nRetCode);

    while (nRetryCount <= 5)
    {
        if (m_nFileSize == m_nDownloadedSize)
        {
            m_nErrorCode = dec_err_success;
            goto Exit1;
        }

        nRetCode = m_Downloader.Download(m_strUrl.c_str(), m_strFile.c_str());
        switch(nRetCode)
        {
        case HTTP_RESULT_SUCCESS:
        case HTTP_RESULT_SAMEAS:
            m_nErrorCode = dec_err_success;
            goto Exit1;
            break;

        case HTTP_RESULT_STOP:
            m_nErrorCode = dec_err_stop;
            goto Exit0;
            break;

        case HTTP_RESULT_FAIL:
            m_nErrorCode = dec_err_disconnection;
            KGLogPrintf(KGLOG_INFO, "disconnection retry %d", nRetryCount++);
            Sleep(5000);
            break;

        case HTTP_RESULT_REDIRECT_FTP:
        case HTTP_RESULT_REDIRECT_HTTP:
            m_nErrorCode = dec_err_cannotconnect;
            KGLogPrintf(KGLOG_INFO, "cannotconnect retry %d", nRetryCount++);
            Sleep(5000);
            break;

        default:
            m_nErrorCode = dec_err_cannotconnect;
            KGLOG_PROCESS_ERROR(false && "unknow result");
            break;
        }
    }

Exit1:
    nResult = true;
Exit0:
    KGLogPrintf(KGLOG_INFO, "download result= %d, filename = %s", m_nErrorCode, m_strFile.c_str());
    return nResult;
}
int KAILogic::LuaNewAction(Lua_State* L)
{
    int         nResult     = 0;
    int         nRetCode    = 0;
    int         nActionID   = KAI_ACTION_ID_NONE;
    int         nActionKey  = eakInvalid;
    KAIAction*  pActionData = NULL;
    std::pair<KAI_ACTION_TABLE::iterator, bool> RetPair;

    nRetCode = Lua_GetTopIndex(L);
    KGLOG_PROCESS_ERROR(nRetCode == 2);

    nActionID = (int)Lua_ValueToNumber(L, 1);
    KGLOG_PROCESS_ERROR(nActionID > KAI_ACTION_ID_NONE);

    nActionKey = (int)Lua_ValueToNumber(L, 2);
    KGLOG_PROCESS_ERROR(nActionKey > eakInvalid);

    if (nActionKey < KAI_USER_ACTION)
    {
        KAI_ACTION_FUNC PAction  = NULL;

        PAction = g_pSO3World->m_AIManager.GetActionFunction(nActionKey);
        if (PAction == NULL)
        {
            KGLogPrintf(KGLOG_ERR, "[AI] Unregistered sys action(ID: %d, Key: %d) in ai %d\n", nActionID, nActionKey, m_nAIType);
            goto Exit0;
        }
    }
    else
    {
        KUSER_ACTION_TABLE::iterator it = m_UserActionTable.find(nActionKey);

        if (it == m_UserActionTable.end())
        {
            KGLogPrintf(KGLOG_ERR, "[AI] Unregistered lua actionID: %d, Key: %d) in ai %d\n", nActionID, nActionKey, m_nAIType);
            goto Exit0;
        }
    }

    RetPair = m_ActionTable.insert(std::make_pair(nActionID, KAIAction()));
    if (!RetPair.second)
    {
        KGLogPrintf(KGLOG_ERR, "[AI] Duplicated AI action(%d) in ai %d\n", nActionID, m_nAIType);
        goto Exit0;
    }

    pActionData = &(RetPair.first->second);

    pActionData->m_nKey = nActionKey;

    nResult = pActionData->LuaGetObj(L);
Exit0:
    return nResult;
}
Beispiel #8
0
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
    int nResult  = false;
    int nRetCode = false;
    int nKGLogInitFlag = false;
    KGLOG_PARAM KGLogParm = {"logs", "GameUpdater", KGLOG_OPTION_FILE, 1000 * 10};
    int nGameUpdaterInitFlag = false;
    KGU_GameUpdater GameUpdater;
    TCHAR szApplicationName[MAX_PATH];
    TCHAR szCurrentDir[MAX_PATH];    

    nRetCode = _SetCurrentDirectory();
    KG_PROCESS_ERROR(nRetCode);

    nRetCode = KGLogInit(KGLogParm, NULL);
    KG_PROCESS_ERROR(nRetCode);
    nKGLogInitFlag = true;

    // Log the build time which is useful for debugging.
    KGLogPrintf(KGLOG_INFO, "The gameupdater.exe is built at "__DATE__" "__TIME__"\n");

    // Log the application name, which could be distinguished the client is main version or child version.
    nRetCode = GetModuleFileName(NULL, szApplicationName, _countof(szApplicationName));
    KGLOG_PROCESS_ERROR(nRetCode > 0);
    KGLOG_PROCESS_ERROR(nRetCode < _countof(szApplicationName));
    KGLogPrintf(KGLOG_INFO, "The full file name is `%s`", szApplicationName);

    // Log the current working path, which is useful for debugging.
    nRetCode = GetCurrentDirectory(_countof(szCurrentDir), szCurrentDir);
    KGLOG_PROCESS_ERROR(nRetCode > 0);
    KGLOG_PROCESS_ERROR(nRetCode < _countof(szCurrentDir));
    KGLogPrintf(KGLOG_INFO, "The current working path is `%s`", szCurrentDir);

    nRetCode = GameUpdater.Init(lpCmdLine, NULL);
    KGLOG_PROCESS_ERROR(nRetCode && "Init()");
    nGameUpdaterInitFlag = true;

    nRetCode = GameUpdater.Run();
    KGLOG_PROCESS_ERROR(nRetCode && "Run()");
    
    nResult = true;
Exit0:
    if (nGameUpdaterInitFlag)
    {
        GameUpdater.UnInit(NULL);
        nGameUpdaterInitFlag = false;
    }
    if (nKGLogInitFlag)
    {
        KGLogUnInit(NULL);
        nKGLogInitFlag = false;
    }
    return nResult ? 0 : 1;
}
Beispiel #9
0
void KAIVM::DebugAICurrentStateInfo()
{
    assert(m_pState);

    KGLogPrintf(KGLOG_DEBUG, "[AI] DebugAI : AIType is %d, Current StateID is %d, ActionID is %d.\n", m_nAIType, m_nStateID, m_nActionID);
    KGLogPrintf(KGLOG_DEBUG, "[AI] DebugAI : nGameLoop is %lu\n", g_pSO3World->m_nGameLoop);
    KGLogPrintf(KGLOG_DEBUG, "[AI] DebugAI : PrimaryTimer is %lu\n", m_nPrimaryTimerFrame);
    KGLogPrintf(KGLOG_DEBUG, "[AI] DebugAI : SecondaryTimer is %lu\n", m_nSecondaryTimerFrame);
    KGLogPrintf(KGLOG_DEBUG, "[AI] DebugAI : TertiaryTimer is %lu\n", m_nTertiaryTimerFrame);
    m_pState->DebugStateInfo();

    return;
}
Beispiel #10
0
void KGTestLoadMaterial::TestLoadOneMtlFile(const char cszFileName[])
{
	HRESULT hrRetCode = E_FAIL;
	KG3DMaterial* pMaterial = NULL;

	_ASSERTE(cszFileName);

	KGLogPrintf(KGLOG_INFO, "Test Load Mtl: %s", cszFileName);

	hrRetCode = m_pMtlTable->LoadResourceFromFile(cszFileName, 0, 0, (IKG3DResourceBase**)&pMaterial);
	if (FAILED(hrRetCode) || pMaterial == NULL)
	{
		m_vecLoadFailedMtl.push_back(cszFileName);
	}
	else
	{
		KG3DMaterial::KG3DMaterialSubset* pSubset = NULL;
		bool bNoAnyTex = false;
		for (size_t i = 0; i < pMaterial->m_dwNumMaterials; i++)
		{
			pMaterial->GetSubMaterial((DWORD)i, (PVOID*)&pSubset);
			if (pSubset->m_dwNumUsedTexture != 0)
			{
				bNoAnyTex = true;
			}
		}
		if (!bNoAnyTex)
		{
			TextureInfoMap TexNames;
			m_mapErrorMtlFileInfo.insert(make_pair(cszFileName, TexNames));
			m_mapErrorMtlFileInfo[cszFileName].insert(make_pair("", NO_ANY_TEX));
		}
	}
	if (pMaterial)
	{
		//这里要注意加参数RELEASE_ATONCE,以便立即释放资源,默认是放入释放队列(RELEASE_INQUEUE)
		//否则内存中会一直占用释一定数量的资源,数量等于释放资源队列的大小
		hrRetCode = m_pMtlTable->ReleaseResource((KG3DMaterial*)pMaterial, RELEASE_ATONCE);
		if (FAILED(hrRetCode))
		{
			KGLogPrintf(KGLOG_ERR, "Release Mtl Failed!");
		}
		else
		{
			pMaterial = NULL;
		}
	}
	KGLogPrintf(KGLOG_INFO, "End Load Test");
}
Beispiel #11
0
BOOL KSO3RoleDBTools::CheckMailTable()
{
    BOOL                bResult     = false;
    BOOL                bRetCode    = 0;
    int                 nStrLen     = 0;

    nStrLen = snprintf(m_szSQL, sizeof(m_szSQL), 
        "create table if not exists %s( "
        "   ID           bigint     not null, "
        "   BaseTime     datetime   not null, "
        "   MailBoxInfo  mediumblob not null, "
        "   primary key (ID), index (ID, BaseTime) "
        "); ",
        MAIL_TABLE_NAME
    );
    KGLOG_PROCESS_ERROR(nStrLen > 0 && nStrLen < (int)sizeof(m_szSQL));

    bRetCode = DoQuery(m_szSQL);
    if (!bRetCode)
    {
        KGLogPrintf(
            KGLOG_ERR, 
            "DB ERROR when try to create table \'%s\'\n", 
            MAIL_TABLE_NAME
        );
        goto Exit0;
    }

    bResult = true;
Exit0:
    return bResult;
}
Beispiel #12
0
BOOL KDoodadTemplateList::LoadFromTemplate(DWORD dwTemplateID, KDoodad* pDoodad)
{
    BOOL                bResult     = false;
	BOOL                bRetCode    = false;
	KDoodadTemplate*    pTemplate   = NULL;

	pTemplate = GetTemplate(dwTemplateID);
	if (pTemplate == NULL)
	{
        KGLogPrintf(KGLOG_ERR, "Invalid doodad template: %u\n", dwTemplateID);

		pTemplate = GetTemplate(0);
		KGLOG_PROCESS_ERROR(pTemplate);
	}

	pDoodad->m_dwTemplateID     = dwTemplateID;
	pDoodad->m_eKind            = pTemplate->m_eKind;
	pDoodad->m_nOpenFrames      = pTemplate->m_dwOpenPrepareFrame;
	pDoodad->m_dwRepresentID    = pTemplate->m_dwRepresentID;
	pDoodad->m_pTemplate        = pTemplate;

	if (pTemplate->szScript[0] != '\0')
	{
		pDoodad->m_dwScriptID = g_FileNameHash(pTemplate->szScript);
	}

	strncpy(pDoodad->m_szName, pTemplate->m_szName, _NAME_LEN);
	pDoodad->m_szName[_NAME_LEN - 1] = 0;

	bResult = true;
Exit0:
	return bResult;
}
Beispiel #13
0
HRESULT KG3DGraphicsEngine::CheckDevice()
{
	HRESULT hr = S_OK;
    
    if (m_bDeviceLost)
    {
        hr = g_pd3dDevice->TestCooperativeLevel();
        switch (hr)
        {
        case D3D_OK:
            break;
        case D3DERR_DEVICELOST:
            Sleep(50);
            break;
        case D3DERR_DEVICENOTRESET:
            hr = Reset();
            KG_COM_PROCESS_ERROR(hr);
            break;
        case D3DERR_DRIVERINTERNALERROR:
            KGLogPrintf(KGLOG_ERR, "D3DERR_DRIVERINTERNALERROR\n");
            break;
        }
    }

Exit0:
    if (hr == D3DERR_DEVICELOST)
        m_bDeviceLost = true;
    else
        KGLOG_COM_CHECK_ERROR(hr);
	return hr;
}
Beispiel #14
0
//---------------------------------------------------------------------------
// 函数:	GetFloat
// 功能:	取得某行某列字符串的值
// 参数:	szRow			行
//			szColomn		列
//			nDefault		缺省值
//			pnValue			返回值
// 返回:	1:成功	0:表格不对	-1:未填,使用默认值
//---------------------------------------------------------------------------
int	KTabFile::GetFloat(const char* szRow, const char* szColumn,
						float fDefault, float *pfValue)
{
	int		nRow, nColumn;
	char	Buffer[32];
	int		nRet = 0;

	nRow = FindRow(szRow);
	nColumn = FindColumn(szColumn);
	nRet = GetValue(nRow - 1, nColumn - 1, Buffer, sizeof(Buffer));
	if (1 == nRet)
	{
		*pfValue = (float)atof(Buffer);
	}
	else
	{
		*pfValue = fDefault;
	}

    if (nRet == 0 && m_bErrorLogEnable)
    {
        KGLogPrintf(KGLOG_DEBUG, "GetFloat(%s, %s) failed !\n", szRow, szColumn);
    }

	return nRet;
}
Beispiel #15
0
int KG_RemoveOldRewardData(MYSQL *pMySQL, int nActivityID)
{
	int nResult  = false;
	int nRetCode = false;
    char szQuery[256];

    KGLOG_PROCESS_ERROR(pMySQL);

    nRetCode = snprintf(szQuery, sizeof(szQuery), "delete from `Activity` where Type = %d", nActivityID);
    KGLOG_PROCESS_ERROR(nRetCode > 0);
    KGLOG_PROCESS_ERROR(nRetCode < sizeof(szQuery));

    nRetCode = mysql_real_query(pMySQL, szQuery, (unsigned long)strlen(szQuery));
    KGD_MYSQL_PROCESS_ERROR(nRetCode == 0, pMySQL, szQuery);

    nRetCode = (int)mysql_affected_rows(pMySQL);
    if (nRetCode > 0)
    {
        printf("! There are %d rows of activity %d been removed\n", nRetCode, nActivityID);
        KGLogPrintf(KGLOG_INFO, "There are %d rows of activity %d been removed\n", nRetCode, nActivityID);
    }

	nResult = true;
Exit0:
	return nResult;
}
Beispiel #16
0
int KGPostRenderTestingMgr::Run()
{
	HRESULT hrRetCode = E_FAIL;
	int nRetCode	  = false;
	int nResult		  = false;
	

 	for (size_t i = 0; i < m_vecTestCases.size(); i++)
 	{
 		KGTestEffect* pTestEffect = NULL;
 		pTestEffect = m_vecTestCases[i];
 		if (pTestEffect)
 		{
 			nRetCode = pTestEffect->Run();
			if (!nRetCode)
			{
				KGLogPrintf(KGLOG_ERR, "%s Testing run failed.", pTestEffect->GetCaseName().c_str());
			}
 			pTestEffect->UnInit();
 			SAFE_DELETE(pTestEffect);
 			hrRetCode = m_pEngineMgr->SetEngineOption(&m_EngineOption);
 			KGLOG_COM_PROCESS_ERROR(hrRetCode);
 		}
 	}
 	m_vecTestCases.clear();

	nResult = true;
Exit0:
	return nResult;
}
Beispiel #17
0
//---------------------------------------------------------------------------
// 函数:	GetFloat
// 功能:	取得某行某列字符串的值
// 参数:	nRow			行
//			szColomn		列
//			nDefault		缺省值
//			pnValue			返回值
// 返回:	1:成功	0:表格不对	-1:未填,使用默认值
//---------------------------------------------------------------------------
int	KTabFile::GetFloat(int nRow, const char* szColumn, float fDefault,
						float *pfValue, int bColumnLab)
{
	char	Buffer[32];
	int		nColumn;
	int		nRet = 0;
	if (bColumnLab)
		nColumn = FindColumn(szColumn);
	else
		nColumn = Str2Col(szColumn);
	nRet = GetValue(nRow - 1, nColumn - 1, Buffer, sizeof(Buffer));
	if (1 == nRet)
	{
		*pfValue = (float)atof(Buffer);
	}
	else
	{
		*pfValue = fDefault;
	}

    if (nRet == 0 && m_bErrorLogEnable)
    {
        KGLogPrintf(KGLOG_DEBUG, "GetFloat(%d, %s) failed !\n", nRow, szColumn);
    }

	return nRet;
}
Beispiel #18
0
BOOL KProcessLock::CreateLock(const char cszLockName[])
{
    BOOL bResult    = false;
    BOOL bRetCode   = false;

    m_hLockFile = CreateFile(cszLockName, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_ALWAYS, 0, 0);
    KGLOG_PROCESS_ERROR(m_hLockFile != INVALID_HANDLE_VALUE);

    bRetCode = LockFile(m_hLockFile, 0, 0, 1, 0);

    if (!bRetCode)
    {
        KGLogPrintf(KGLOG_ERR, "Already start another process!");
        goto Exit0;
    }

    bResult = true;
Exit0:
    if (!bResult && m_hLockFile != INVALID_HANDLE_VALUE)
    {
        CloseHandle(m_hLockFile);
        m_hLockFile =INVALID_HANDLE_VALUE;
    }
    return bResult;
}
Beispiel #19
0
void KDownloadUpdatePackage::ProcessDownloadError(const TCHAR szFile[], int nError)
{
	KGLogPrintf(KGLOG_INFO, "Download File: %s , errcode = %d", szFile, nError);

	switch (nError)
	{
	case dec_err_success:
		break;
	case dec_err_notstart:
		break;
	case dec_err_stop:
		break;
	case dec_err_url:
	case dec_err_cannotconnect:
		KLastError::SetErrorCode(UPDATE_ERR_CANNOT_CONNECT_SERVER);
		break;
	case dec_err_disconnection:
		KLastError::SetErrorCode(UPDATE_ERR_DISCONNECTION);
		break;
	case dec_err_noenoughdiskspace:
		KLastError::SetErrorCode(UPDATE_ERR_NO_ENOUGH_DISK_SPACE);
		break;
	case dec_err_cannotdownload:
		KLastError::SetErrorCode(UPDATE_ERR_NOT_FOUND_DOWNLOAD_FILE);
		break;
	case dec_err_writefileerror:
		KLastError::SetErrorCode(UPDATE_ERR_WRITE_FILE_ERROR);
		break;
	default:
		break;
	}
}
Beispiel #20
0
BOOL KProcessLock::CreateLock(const char cszLockName[])
{
    BOOL            bResult     = false;
    int             nRetCode    = 0;
    struct flock    LockInfo;

    KGLOG_PROCESS_ERROR(m_nLockFile == -1);

    m_nLockFile = creat(cszLockName, S_IRWXU);
    KGLOG_PROCESS_ERROR(m_nLockFile != -1);

    LockInfo.l_type   = F_WRLCK;
    LockInfo.l_whence = SEEK_SET;
    LockInfo.l_start  = 0;
    LockInfo.l_len    = 0;

    nRetCode = fcntl(m_nLockFile, F_SETLK, &LockInfo);

    if (nRetCode == -1)
    {
        KGLOG_PROCESS_ERROR (errno == EACCES || errno == EAGAIN);
        KGLogPrintf(KGLOG_ERR, "Already start another process!");
        goto Exit0;
    }

    bResult = true;
Exit0:
    if (!bResult && m_nLockFile != -1)
    {
        close(m_nLockFile);
        m_nLockFile = -1;
    }
    return bResult;
}
Beispiel #21
0
void KWndTexture::RenderCallback(DWORD dwTextureID, void* pUserData)
{
    HRESULT hr = E_FAIL;
	KWndTexture* pWndTexture = NULL;
    BOOL bBeginRenderToTexture = FALSE;
    
    pWndTexture = reinterpret_cast<KWndTexture*>(pUserData);
    KGLOG_PROCESS_ERROR(pWndTexture);

    hr = g_pUI->m_p3DUI->BeginRenderToTexture(dwTextureID, 0);
    KG_COM_PROCESS_ERROR(hr);

    bBeginRenderToTexture = TRUE;

    pWndTexture->OnPaint();

Exit0:
    if (hr == D3DERR_DRIVERINTERNALERROR || hr == D3DERR_INVALIDCALL)
    {
        KGLogPrintf(KGLOG_ERR, "KGUI KWndTexture::RenderCallback %u.\n", hr);

        PostMessage(g_pUI->m_hWnd, WM_QUIT, 0, 0);
    }
    if (bBeginRenderToTexture)
    {
        hr = g_pUI->m_p3DUI->EndRenderToTexture();
        KGLOG_COM_CHECK_ERROR(hr);
    }
}
Beispiel #22
0
int KTestDownloadPack::CheckAndDelZip(const int cnPackNum)
{
	int nRetCode = false;
	int nResult  = false;
	TCHAR szPackName[MAX_PATH];
	//验证每个包的MD5
	for (int nIndex = 0; nIndex < cnPackNum; nIndex++)
	{
		nRetCode = _sntprintf(szPackName, MAX_PATH, _T("%s\\%s"), g_szTestingSpaceDir, ZIP_FILE_LIST[nIndex]);
		KGLOG_PROCESS_ERROR(nRetCode != 1);
		szPackName[MAX_PATH - 1] = _T('\0');
		nRetCode = KTestCommon::ValidateFileMD5(szPackName, ZIP_MD5_LIST[nIndex]);
		KGLOG_PROCESS_ERROR(nRetCode);
		nRetCode = ::DeleteFile(szPackName);
		KGLOG_PROCESS_ERROR(nRetCode);
	}

	nResult = true;
Exit0:
	if (!nResult)
	{
		KGLogPrintf(KGLOG_ERR, "ZIP NAME: %s", szPackName);
	}
	return nResult;
}
Beispiel #23
0
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;
}
Beispiel #24
0
void KSO3Gateway::Run()
{
    BOOL bRetCode = false;

    while (m_bRunFlag)
    {
        m_nTimeNow = time(NULL);

       // m_PaysysAgency.Activate();

        m_RelayAgency.Activate();

        m_PlayerManager.Activate();

        m_QueueManager.Activate();

        m_Eyes.Activate();

        m_SndaAgency.Activate();

        bRetCode = m_Eyes.GetQuitFlag();
        if (bRetCode)
            break;

        KGThread_Sleep(10);
    }

    KGLogPrintf(KGLOG_INFO, "Gateway exit !");
}
Beispiel #25
0
int KAILogic::LuaNewState(Lua_State* L)
{
    int                     nResult     = 0;
    int                     nRetCode    = 0;
    int                     nState      = 0;
    KAIState*               pState      = NULL;
    std::pair<KAI_STATE_TABLE::iterator, bool> RetPair;

    nRetCode = Lua_GetTopIndex(L);
    KGLOG_PROCESS_ERROR(nRetCode == 1);

    nState = (int)Lua_ValueToNumber(L, 1);
    KGLOG_PROCESS_ERROR(nState > 0);

    
    RetPair = m_StateTable.insert(std::make_pair(nState, KAIState(this, nState)));
    if (!RetPair.second)
    {
        KGLogPrintf(KGLOG_ERR, "[AI] Duplicated AI state(%d) in ai type %d\n", nState, m_nAIType);
        goto Exit0;
    }

    pState = &(RetPair.first->second);

    nResult = pState->LuaGetObj(L);
Exit0:
    return nResult;
}
Beispiel #26
0
int KG3DTestLoadMesh::Init(IKG3DAutoTestInterface* pTestInterface,
						   const char cszResultPath[])
{
	int nResult  = false;
	int nRetCode = false;
	char* pszResult = NULL;

	KG_ASSERT_EXIT(pTestInterface);
	_ASSERTE(cszResultPath);

	m_pTestInterface = pTestInterface;
	m_pTestInterface->AddRef();
	m_pMeshTable = m_pTestInterface->GetMeshTable();

	nRetCode = strncpy_s(m_szResultPath, sizeof(m_szResultPath), cszResultPath, strlen(cszResultPath));
	KGLOG_PROCESS_ERROR(nRetCode == 0);

	KGLogPrintf(KGLOG_INFO, "Ready to Test Load Mesh");

	nResult = true;
Exit0:
	if (!nResult)
	{
		UnInit();
	}
	return nResult;
}
Beispiel #27
0
BOOL KGFellowshipMgr::OnLoadFellowshipData(DWORD dwPlayerID, size_t uDataSize, BYTE byData[])
{
    BOOL                bResult         = false;
    BOOL                bRetCode        = false;
    KG_FELLOWSHIP_DB*   pFellowshipDB   = NULL;

    UnloadPlayerFellowship(dwPlayerID);
    m_GroupNamesMap[dwPlayerID].nGroupCount = 0;

    KG_PROCESS_SUCCESS(!uDataSize); // This player do not have any fellowship data saved before. 

    KGLOG_PROCESS_ERROR(uDataSize > sizeof(KG_FELLOWSHIP_DB));
    pFellowshipDB = (KG_FELLOWSHIP_DB*)byData;

    switch(pFellowshipDB->nVersion)
    {
    case 1:
        bRetCode = OnLoadFellowshipDataV1(dwPlayerID, uDataSize, byData);
        KGLOG_PROCESS_ERROR(bRetCode);
        break;

    default:
        KGLogPrintf(KGLOG_ERR, "Unexcepted fellowship data type: %d.", pFellowshipDB->nVersion);
    }

Exit1:
    m_OnlineIDSet.insert(dwPlayerID);
    bResult = true;
Exit0:
    if (!bResult)
    {
        UnloadPlayerFellowship(dwPlayerID);
    }
    return bResult;
}
Beispiel #28
0
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;
}
Beispiel #29
0
void KG3DTestLoadMesh::TestLoadOneMeshFile(const char cszFileName[])
{
	HRESULT hrRetCode = E_FAIL;
	KG3DMesh* pMesh = NULL;

	_ASSERTE(cszFileName);
	hrRetCode = m_pMeshTable->LoadResourceFromFile(cszFileName, 0, 0, (IKG3DResourceBase**)&pMesh);
	if (FAILED(hrRetCode) || pMesh == NULL)
	{
		m_vecLoadFailedMesh.push_back(cszFileName);
	}
	if (pMesh)
	{
		//这里要注意加参数RELEASE_ATONCE,以便立即释放资源,默认是放入释放队列(RELEASE_INQUEUE)
		//否则内存中会一直占用释一定数量的资源,数量等于释放资源队列的大小
		hrRetCode = m_pMeshTable->ReleaseResource((KG3DMesh*)pMesh, RELEASE_ATONCE);
		if (FAILED(hrRetCode))
		{
			KGLogPrintf(KGLOG_ERR, "Release Mtl Failed!");
		}
		else
		{
			pMesh = NULL;
		}
	}
}
KAILogic* KAIManager::CreateAI(int nType, DWORD dwScriptID)
{
    KAILogic* pResult       = NULL;
    BOOL      bRetCode      = false;
    KAILogic* pAI           = NULL;

    pAI = KMEMORY_NEW(KAILogic);
    KGLOG_PROCESS_ERROR(pAI);

    bRetCode = pAI->Setup(nType, dwScriptID);
    KGLOG_PROCESS_ERROR(bRetCode);

    pResult = pAI;
Exit0:
    if (!pResult)
    {
        if (pAI)
        {
            KMemory::Delete(pAI);
            pAI = NULL;
        }

        KGLogPrintf(KGLOG_ERR, "[AI] Setup AI failed, AIType: %d", nType);
    }
    return pResult;
}