示例#1
0
文件: main.cpp 项目: viticm/pap2
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;
}
示例#2
0
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;
}
示例#3
0
文件: KG_Public.cpp 项目: viticm/pap2
int KG_LoadMySQLDatabaseParameter(const char cszConfigFileName[], KG_MYSQL_PARAM *pRetParam)
{
	int nResult  = false;
	int nRetCode = false;
    IIniFile *piIniFile = NULL;
    char szPassword[64];

    KGLOG_PROCESS_ERROR(cszConfigFileName);
    KGLOG_PROCESS_ERROR(cszConfigFileName[0]);
    KGLOG_PROCESS_ERROR(pRetParam);

    piIniFile = g_OpenIniFile(cszConfigFileName);
    KGLOG_PROCESS_ERROR(piIniFile && "g_OpenIniFile()");

    nRetCode = piIniFile->GetString(
        "DatabaseServer", "Server", NULL, pRetParam->szServer, sizeof(pRetParam->szServer)
    );
    KGLOG_PROCESS_ERROR(nRetCode && "Unable load \"[DatabaseServer]:Server\"");

    nRetCode = piIniFile->GetString(
        "DatabaseServer", "Database", NULL, pRetParam->szDatabase, sizeof(pRetParam->szDatabase)
    );
    KGLOG_PROCESS_ERROR(nRetCode && "Unable load \"[DatabaseServer]:Database\"");

    nRetCode = piIniFile->GetString(
        "DatabaseServer", "UserName", NULL, pRetParam->szUserName, sizeof(pRetParam->szUserName)
    );
    KGLOG_PROCESS_ERROR(nRetCode && "Unable load \"[DatabaseServer]:UserName\"");

    nRetCode = piIniFile->GetString("DatabaseServer", "Password", NULL, szPassword, sizeof(szPassword));
    KGLOG_PROCESS_ERROR(nRetCode && "Unable load \"[DatabaseServer]:Password\"");

#ifdef _DEBUG
    strncpy(pRetParam->szPassword, szPassword, sizeof(pRetParam->szPassword));
    KGLOG_PROCESS_ERROR(pRetParam->szPassword[sizeof(pRetParam->szPassword) -1] == '\0');
#else
    nRetCode = (int)strlen(szPassword);
    KGLOG_PROCESS_ERROR((nRetCode == PG_RESULTLENSTD) && "Password error");
    nRetCode = SimplyDecryptPassword(pRetParam->szPassword, szPassword);
    KGLOG_PROCESS_ERROR(nRetCode && "Password error");
#endif

	nResult = true;
Exit0:
    KG_COM_RELEASE(piIniFile);
    if (!nResult && cszConfigFileName)
        KGLogPrintf(KGLOG_DEBUG, "Failed to load parameter from the file : %s", cszConfigFileName);
	return nResult;
}
示例#4
0
int KGTestMapDisuseResource::FindResInModelset(const char cszResourceName[], set<string>& vecResList)
{
	//参照KG3DRepresentObjectSet::LoadFromIniFile
	int nRetCode = false;
	int nResult  = false;
	IIniFile* pIniFile = NULL;
	char szSourcePathName[MAX_PATH] = {0};

	KG_ASSERT_EXIT(cszResourceName);
	KGLOG_PROCESS_ERROR(cszResourceName[0] != '\0');

	nRetCode = _snprintf_s(szSourcePathName,
		sizeof(szSourcePathName),
		sizeof(szSourcePathName) - 1,
		"%s%s",
		m_szClientPath,
		cszResourceName);
	KGLOG_PROCESS_ERROR(nRetCode > 0);

	pIniFile = g_OpenIniFile(szSourcePathName);
	KGLOG_PROCESS_ERROR(pIniFile);

	int nCount = 0;
	pIniFile->GetInteger("MAIN", "Count", 0, &nCount);

	for (int i = 0; i < nCount; i++)
	{
		char szSecName[MAX_PATH]  = {0};
		char szMeshName[MAX_PATH] = {0};
		char szMtlName[MAX_PATH]  = {0};

		nRetCode = _snprintf_s(szSecName, sizeof(szSecName), sizeof(szSecName) - 1, "Model%d", i);
		KGLOG_PROCESS_ERROR(nRetCode> 0);
		pIniFile->GetString(szSecName, "MeshName", "", szMeshName, sizeof(szMeshName));
		FindResource(szMeshName, vecResList);
		pIniFile->GetString(szSecName, "MtlName", "", szMtlName, sizeof(szMtlName));
		FindResource(szMtlName, vecResList);
	}

	nResult = true;
Exit0:
	if (pIniFile)
	{	
		pIniFile->Release();
		pIniFile = NULL;
	}
	return nResult;
}
示例#5
0
int KUiWndCheckBoxCommon::SelAnimate(int *pnSelResult)
{
    int nResult     = false;
    int nRetCode    = false;
    char szUiTexFileName[MAX_PATH];
    char szRoot[MAX_PATH];
    int nSelAinmate = 0;
    IIniFile *pIni = NULL;

    pIni = g_Ui.GetIni();
    KG_PROCESS_ERROR(pIni);

    g_GetRootPath(szRoot);
    KG_PROCESS_ERROR(szRoot[0] != '\0');

    szUiTexFileName[0] = '\0';
    pIni->GetString(m_szName, "Image", "", szUiTexFileName, sizeof(szUiTexFileName));
    KG_PROCESS_ERROR(szUiTexFileName[0] != '\0');

    strcat(szRoot, "\\");
    strcat(szRoot, szUiTexFileName);
    strcpy(szUiTexFileName, szRoot);

    nSelAinmate = SELANIMATE::OnSelAnimate(szUiTexFileName, m_hWnd);    
    KG_PROCESS_ERROR(nSelAinmate != -1);

    *pnSelResult = nSelAinmate;

    nResult = true;
Exit0:
    return nResult;
}
示例#6
0
BOOL KSndaAgency::LoadConfig()
{
	BOOL        bResult     = false;
	BOOL        bRetCode    = false;
	IIniFile*   piIniFile   = NULL;

	piIniFile = g_OpenIniFile(GATEWAY_CONFIG_FILE);
	LOG_PROCESS_ERROR(piIniFile);

	m_bOpen = true;
	bRetCode = piIniFile->IsSectionExist("SDOA");
	if (!bRetCode)
	{
		m_bOpen = false;
		goto EXIT1;
	}

	bRetCode = piIniFile->GetString("SDOA", "AdultIDCard", "not configed", m_szAdultIDCard, sizeof(m_szAdultIDCard)); 
	LOG_PROCESS_ERROR(bRetCode);

EXIT1:
	bResult = true;
EXIT0:
	SAFE_RELEASE(piIniFile);
	return bResult;
}
示例#7
0
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;
}
示例#8
0
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);
}
示例#9
0
    bool KFilePathMgr::Init()
    {
        bool bResult = false;
        char szPath[MAX_PATH];
        char szKey[128];
        IIniFile *pIni = NULL;

#ifdef KG_PUBLISH
		pIni = g_OpenIniFileInPak("\\ui\\configfilepath.ini");
		if (!pIni)
			pIni = g_OpenIniFile("\\ui\\configfilepath.ini");
		KGLOG_PROCESS_ERROR(pIni && "open ini file ui\\configfilepath.ini failed!\n");
#else
		pIni = g_OpenIniFile("\\ui\\configfilepath.ini");
		KGLOG_PROCESS_ERROR(pIni && "open ini file ui\\configfilepath.ini failed!\n");
#endif

        szKey[0] = '\0';
    	while (pIni->GetNextKey("FILE_PATH", szKey, szKey))
        {
            pIni->GetString("FILE_PATH", szKey, "", szPath, _countof(szPath));
            FormatFilePath(szPath);

            m_KeyToPath[szKey] = szPath;
        }

        bResult = true;
Exit0:
        SAFE_RELEASE(pIni);
        return bResult;
    }
示例#10
0
int KGSFXModelViewPage::FillTreeFromFileMap()
{
	int nResult  = false;
	int nRetCode = false;

	char szSection[32] = TEXT("");
	char szKeyName[32] = TEXT("");
	char szKeyData[32] = TEXT("");
	char szKeyType[32] = TEXT("");

	TCHAR szMapFileName[MAX_PATH];
	sprintf(szMapFileName, "%s%s", g_szDefWorkDirectory, TEXT("\\sfx_editor_file_map.ini"));

	m_tree.DeleteAllItems();
	IIniFile* pMapFile = NULL;
	pMapFile = g_OpenIniFile(szMapFileName);

	KG_PROCESS_ERROR(pMapFile);

	while (pMapFile->GetNextKey(TEXT("Main"), szKeyName, szKeyName))
	{
		pMapFile->GetString(TEXT("Main"), szKeyName, TEXT(""), szKeyData, sizeof(szKeyData));
		pMapFile->GetString(TEXT("Type"), szKeyData, TEXT(""), szKeyType, sizeof(szKeyType));
		_FillTreeFromFileMap(&m_tree, NULL, pMapFile, szKeyData, GetImageIndex(szKeyType));
	}

	nResult = true;
Exit0:
	SAFE_RELEASE(pMapFile);
	return nResult;
}
示例#11
0
void KGT_g_OpenIniFileFromArgumentsTest::Test_g_OpenFileFromArguments_04()
{
    int nResult = false;
    int nRetCode = false;

    IIniFile *piIniFile = NULL;
    char *pszArgv[] = {
        "KG_GoddessD.exe",
        "--Version.version=2",
        "--Database.name=mysql"
    };
    int nArgc = sizeof(pszArgv) / sizeof(pszArgv[0]);
    char szRetVersion[IIniFile::INI_MAX_SUPPORT_SECTION_AND_KEY_SIZE];
    szRetVersion[0] = '\0';
    char szRetName[IIniFile::INI_MAX_SUPPORT_SECTION_AND_KEY_SIZE];
    szRetName[0] = '\0';

    KG_CASE_INFO("不同的section不同的key", "");

    piIniFile = g_OpenIniFileFromArguments(nArgc, pszArgv);
    KG_PROCESS_ERROR(piIniFile);

    nRetCode = piIniFile->IsSectionExist("Version");
    KG_PROCESS_ERROR(nRetCode);

    nRetCode = piIniFile->IsSectionExist("Database");
    KG_PROCESS_ERROR(nRetCode);

    nRetCode = piIniFile->GetString("Version", "version", "", szRetVersion, sizeof(szRetVersion) / sizeof(szRetVersion[0]));
    KG_PROCESS_ERROR(nRetCode);
    szRetVersion[sizeof(szRetVersion) / sizeof(szRetVersion[0]) -1] = '\0';
    nRetCode = strncmp(szRetVersion, "2", sizeof(szRetVersion) / sizeof(szRetVersion[0]));
    KG_PROCESS_ERROR(nRetCode == 0);

    nRetCode = piIniFile->GetString("Database", "name", "", szRetName, sizeof(szRetName) / sizeof(szRetName[0]));
    KG_PROCESS_ERROR(nRetCode);
    szRetName[sizeof(szRetName) / sizeof(szRetName[0]) -1] = '\0';
    nRetCode = strncmp(szRetName, "mysql", sizeof(szRetName) / sizeof(szRetName[0]));
    KG_PROCESS_ERROR(nRetCode == 0);

    nResult = true;
Exit0:
    KG_COM_RELEASE(piIniFile);
    CPPUNIT_ASSERT(nResult);
}
示例#12
0
BOOL KPlayerManager::Init()
{
    BOOL                        bResult                = false;
    BOOL                        bRetCode               = false;
    BOOL                        nSocketServerInitFlag  = false;
    IIniFile*                   piIniFile              = NULL;
    int                         nPort                  = 0;
    char                        szIP[_NAME_LEN];

    m_pSocketEvents = new KG_SOCKET_EVENT[MAX_SOCKET_EVENT];
    KGLOG_PROCESS_ERROR(m_pSocketEvents);

    m_pSockerServer = new KG_SocketServerAcceptor();
    KGLOG_PROCESS_ERROR(m_pSockerServer);

    piIniFile = g_OpenIniFile(GATEWAY_CONFIG_FILE);
    KGLOG_PROCESS_ERROR(piIniFile);

    bRetCode = piIniFile->GetInteger("Player", "MaxPlayer", 8192, &m_nMaxPlayer);
    KGLOG_PROCESS_ERROR(bRetCode);

    bRetCode = piIniFile->GetString("Player", "IP", "", szIP, (unsigned int)sizeof(szIP));
    KGLOG_PROCESS_ERROR(bRetCode);

    bRetCode = piIniFile->GetInteger("Player", "Port", 0, &nPort);
    KGLOG_PROCESS_ERROR(bRetCode);

    bRetCode = piIniFile->GetInteger("Player", "PingCycle", 20, &m_nPingCycle);
    KGLOG_PROCESS_ERROR(bRetCode);

    bRetCode = m_pSockerServer->Init(
        szIP, nPort, MAX_WAIT_ACCEPT, 
        1024 * 4, 1024 * 16, KSG_ENCODE_DECODE, NULL
    );
    KGLOG_PROCESS_ERROR(bRetCode);
    nSocketServerInitFlag = true;

    bResult = true;
Exit0:

    KGLogPrintf(KGLOG_INFO, "Start service at %s:%d ... ... [%s]\n", szIP, nPort, bResult ? "OK" : "Failed");

    if (!bResult)
    {
        if (nSocketServerInitFlag)
        {
            m_pSockerServer->UnInit(NULL);
            nSocketServerInitFlag = false;
        }
        KG_DELETE(m_pSockerServer);
        KG_DELETE_ARRAY(m_pSocketEvents);
    }
    KG_COM_RELEASE(piIniFile);
    return bResult;
}
示例#13
0
HRESULT KG3DTerrainRepresentInfo::InitDefaultSfx()
{
    HRESULT hResult = E_FAIL;
    HRESULT hRetCode = E_FAIL;
    IIniFile *pFile = NULL;
    pFile = g_OpenIniFile(s_strGroundEffectConfigFile);
    KG_PROCESS_ERROR(pFile);

    pFile->GetString("ROOT","DefaultSfx1","",m_DefaultSfx.str_DefaultSfx[0],MAX_PATH);
    pFile->GetString("ROOT","DefaultSfx2","",m_DefaultSfx.str_DefaultSfx[1],MAX_PATH);
    pFile->GetString("ROOT","DefaultSfx3","",m_DefaultSfx.str_DefaultSfx[2],MAX_PATH);
    pFile->GetString("ROOT","DefaultSfx4","",m_DefaultSfx.str_DefaultSfx[3],MAX_PATH);
    pFile->GetString("ROOT","DefaultSfxTerrain","",m_DefaultSfx.str_DefaultSfxTerrain,MAX_PATH);
    pFile->GetFloat("ROOT","DefaultSfxTerrainPlayRate",0.0,&m_DefaultSfx.fPlayRate);

    hResult = S_OK;
Exit0:
    SAFE_RELEASE(pFile);
    return hResult;
}
示例#14
0
void KGT_g_OpenIniFileFromArgumentsTest::Test_g_OpenFileFromArguments_10()
{
    int nResult = false;
    int nRetCode = false;

    IIniFile *piIniFile = NULL;
    int nArgc = 0;
    char *pszArgv[2] = {0};
    char szArgv[2][IIniFile::INI_MAX_SUPPORT_VALUE_SIZE + 100] = {0};
    nArgc = sizeof(szArgv) / sizeof(szArgv[0]);
    char szValue[IIniFile::INI_MAX_SUPPORT_VALUE_SIZE];
    szValue[0] = '\0';
    char szRetValue[IIniFile::INI_MAX_SUPPORT_VALUE_SIZE];
    szRetValue[0] = '\0';

    pszArgv[0] = szArgv[0];
    pszArgv[1] = szArgv[1];

    strncpy(szArgv[0], "KG_GoddessD.exe", sizeof(szArgv[0]));
    szArgv[0][IIniFile::INI_MAX_SUPPORT_SECTION_AND_KEY_SIZE] = '\0';

    KG_CASE_INFO("value的长度为最大值", "");

    nRetCode = _DataGenerator(sizeof(szValue), szValue);
    KG_PROCESS_ERROR(nRetCode);

    nRetCode = _snprintf(
        szArgv[1],
        sizeof(szArgv[1]) / sizeof(szArgv[1][0]) - 1,
        "--Database.name=%s",
        szValue
    );
    KG_PROCESS_ERROR(nRetCode > 0);

    piIniFile = g_OpenIniFileFromArguments(nArgc, pszArgv);
    KG_PROCESS_ERROR(piIniFile);

    nRetCode = piIniFile->GetString("Database", "name", "", szRetValue, sizeof(szRetValue) / sizeof(szRetValue[0]));
    KG_PROCESS_ERROR(nRetCode);

    nRetCode = strcmp(szValue, szRetValue);
    KG_PROCESS_ERROR(nRetCode == 0);

    nResult = true;
Exit0:
    KG_COM_RELEASE(piIniFile);
    CPPUNIT_ASSERT(nResult);
}
示例#15
0
BOOL KRelayAgency::Init()
{
	BOOL                  bResult               = false;
	int                   nRetCode              = false;
	IIniFile*             piIniFile             = NULL;
	ISocketStream*     piSocket              = NULL;
	int                   nPort                 = 0;
	char                  szIP[_NAME_LEN];
	QSocketConnector    Connector;
	timeval               TimeoutValue;

	piIniFile = g_OpenIniFile(GATEWAY_CONFIG_FILE);
	LOG_PROCESS_ERROR(piIniFile);

	nRetCode = piIniFile->GetString("Relay", "IP", "", szIP, sizeof(szIP));
	LOG_PROCESS_ERROR(nRetCode);

	nRetCode = piIniFile->GetInteger("Relay", "Port", 0, &nPort);
	LOG_PROCESS_ERROR(nRetCode);

	nRetCode = piIniFile->GetInteger("Relay", "PingCycle", 20, &m_nPingCycle);
	LOG_PROCESS_ERROR(nRetCode);

	piSocket = Connector.Connect(szIP, nPort);
	LOG_PROCESS_ERROR(piSocket);

	TimeoutValue.tv_sec  = 1;
	TimeoutValue.tv_usec = 0;

	nRetCode = piSocket->SetTimeout(&TimeoutValue);
	LOG_PROCESS_ERROR(nRetCode);

	m_piSocket = piSocket;
	m_piSocket->AddRef();
	m_bSocketError = false;

	bResult = true;
EXIT0:
	QLogPrintf(LOG_INFO, "Connect to Relay %s:%d ... ... [%s]\n", szIP, nPort, bResult ? "OK" : "Failed");
	SAFE_RELEASE(piSocket);
	SAFE_RELEASE(piIniFile);
	return bResult;
}
示例#16
0
BOOL KSO3Gateway::LoadConfig()
{
    BOOL        bResult     = false;
    BOOL        bRetCode    = false;
    IIniFile*   piIniFile   = NULL;

    piIniFile = g_OpenIniFile(GATEWAY_CONFIG_FILE);
    KGLOG_PROCESS_ERROR(piIniFile);

    bRetCode = piIniFile->GetString("Global", "Locale", "", m_szLocale, sizeof(m_szLocale));
    KGLOG_PROCESS_ERROR(bRetCode);

    bRetCode = piIniFile->GetBool("Global", "SD", &m_bSndaAgent);
    KGLOG_PROCESS_ERROR(bRetCode);

    bResult = true;
Exit0:
    KG_COM_RELEASE(piIniFile);
    return bResult;
}
示例#17
0
BOOL KSOEditor::Init()
{
    BOOL        bResult             = false;
    int         nRetCode            = 0;
    BOOL        bNetWorkInitFlag    = false;
    IIniFile*   piFile              = NULL;
    int         nPort               = 0;
    int         nMaxConnection      = 0;
    char        szLocalIP[32];

    g_SetRootPath(NULL);

    piFile = g_OpenIniFile("KSOEditorServer.ini");
    KGLOG_PROCESS_ERROR(piFile);

    piFile->GetString("Server", "IP", "127.0.0.1", szLocalIP, sizeof(szLocalIP));
    piFile->GetInteger("Server", "Port", 0, &nPort);
    piFile->GetInteger("Server", "MaxConnection", 100, &nMaxConnection);

    m_pNetworkMgr = new KNetworkMgr;
    KGLOG_PROCESS_ERROR(m_pNetworkMgr);
    
    nRetCode = m_pNetworkMgr->Init(szLocalIP, nPort, nMaxConnection);
    KGLOG_PROCESS_ERROR(nRetCode);
    bNetWorkInitFlag = true;

    bResult = true;
Exit0:
    if (!bResult)
    {
        if (bNetWorkInitFlag)
        {
            m_pNetworkMgr->UnInit();
            bNetWorkInitFlag = false;
        }
        SAFE_DELETE(m_pNetworkMgr);
    }

    KG_COM_RELEASE(piFile);
    return bResult;
}
示例#18
0
BOOL KSO3GameCenterSettings::LoadCenterConst()
{
    BOOL        bResult     = false;
	int         nRetCode    = false;	
    IIniFile*	piIniFile   = NULL;
	int			nValue      = 0;

	piIniFile = g_OpenIniFile(CENTER_CONST_FILENAME);
	KGLOG_PROCESS_ERROR(piIniFile);

    // Mail System config
    nRetCode = piIniFile->GetInteger(GCS_SECTION_MAIL, "SurvivalTime", 3600, &m_nMailSurvivalTime);
    KGLOG_PROCESS_ERROR(nRetCode && m_nMailSurvivalTime > 0);
    nRetCode = piIniFile->GetInteger(GCS_SECTION_MAIL, "MaxPlayerMailCount", 100, &m_nMaxPlayerMailCount);
    KGLOG_PROCESS_ERROR(nRetCode && m_nMaxPlayerMailCount > 0);
    nRetCode = piIniFile->GetInteger(GCS_SECTION_MAIL, "MaxAuctionMailCount", 100, &m_nMaxAuctionMailCount);
    KGLOG_PROCESS_ERROR(nRetCode && m_nMaxAuctionMailCount > 0);
    nRetCode = piIniFile->GetInteger(GCS_SECTION_MAIL, "MaxSystemMailCount", 100, &m_nMaxSystemMailCount);
    KGLOG_PROCESS_ERROR(nRetCode && m_nMaxSystemMailCount > 0);
    nRetCode = piIniFile->GetInteger(GCS_SECTION_MAIL, "MaxGmMsgMailCount", 50, &m_nMaxGmMsgMailCount);
    KGLOG_PROCESS_ERROR(nRetCode && m_nMaxGmMsgMailCount > 0);
    nRetCode = piIniFile->GetInteger(GCS_SECTION_MAIL, "MaxPlayerMsgMailCount", 50, &m_nMaxPlayerMsgMailCount);
    KGLOG_PROCESS_ERROR(nRetCode && m_nMaxPlayerMsgMailCount > 0);
    nRetCode = piIniFile->GetString(GCS_SECTION_MAIL, "SendFailedName", "System", m_szMailSendFailedName, sizeof(m_szMailSendFailedName));
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = piIniFile->GetString(GCS_SECTION_MAIL, "WithdrawName", "System", m_szMailWithdrawName, sizeof(m_szMailWithdrawName));
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = piIniFile->GetString(GCS_SECTION_MAIL, "UserReturnTitle", "Return", m_szMailUserReturnTitle, sizeof(m_szMailUserReturnTitle));
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = piIniFile->GetString(GCS_SECTION_MAIL, "SystemMailSender", "[SYSTEM]", m_szSystemMailSender, sizeof(m_szSystemMailSender));
    KGLOG_PROCESS_ERROR(nRetCode);

    // PlayerRelation System config
    nRetCode = piIniFile->GetInteger(GCS_SECTION_FELLOWSHIP, "SaveIntervalFrame", 60, &m_nFellowshipSaveInterval);
    KGLOG_PROCESS_ERROR(nRetCode && m_nFellowshipSaveInterval > 0);
    
    // Auction config
    nRetCode = piIniFile->GetString(GCS_SECTION_AUCTION, "AuctionName", "Auction", m_szAuctionName, sizeof(m_szAuctionName));
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = piIniFile->GetString(GCS_SECTION_AUCTION, "Gold", "Gold", m_szGold, sizeof(m_szGold));
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = piIniFile->GetString(GCS_SECTION_AUCTION, "Silver", "Silver", m_szSilver, sizeof(m_szSilver));
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = piIniFile->GetString(GCS_SECTION_AUCTION, "Copper", "Copper", m_szCopper, sizeof(m_szCopper));
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = piIniFile->GetString(GCS_SECTION_AUCTION, "SellSucceed", "SellSucceed", m_szSellSucceed, sizeof(m_szSellSucceed));
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = piIniFile->GetString(GCS_SECTION_AUCTION, "Buyyer", "Buyyer", m_szBuyyer, sizeof(m_szBuyyer));
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = piIniFile->GetString(GCS_SECTION_AUCTION, "Price", "Price", m_szPrice, sizeof(m_szPrice));
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = piIniFile->GetString(GCS_SECTION_AUCTION, "CustodyCharges", "CustodyCharges", m_szCustodyCharges, sizeof(m_szCustodyCharges));
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = piIniFile->GetString(GCS_SECTION_AUCTION, "TaxMoney", "TaxMoney", m_szTaxMoney, sizeof(m_szTaxMoney));
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = piIniFile->GetString(GCS_SECTION_AUCTION, "GetMoney", "GetMoney", m_szGetMoney, sizeof(m_szGetMoney));
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = piIniFile->GetString(GCS_SECTION_AUCTION, "CancelSucceed", "CancelSucceed", m_szCancelSucceed, sizeof(m_szCancelSucceed));
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = piIniFile->GetString(GCS_SECTION_AUCTION, "BidFailed", "BidFailed", m_szBidFailed, sizeof(m_szBidFailed));
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = piIniFile->GetString(GCS_SECTION_AUCTION, "BuySucceed", "BuySucceed", m_szBuySucceed, sizeof(m_szBuySucceed));
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = piIniFile->GetString(GCS_SECTION_AUCTION, "BuyItNowPrice", "BuyItNowPrice", m_szBuyItNowPrice, sizeof(m_szBuyItNowPrice));
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = piIniFile->GetString(GCS_SECTION_AUCTION, "TopPrice", "TopPrice", m_szTopPrice, sizeof(m_szTopPrice));
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = piIniFile->GetString(GCS_SECTION_AUCTION, "Seller", "Seller", m_szSeller, sizeof(m_szSeller));
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = piIniFile->GetString(GCS_SECTION_AUCTION, "Coin", "Coin", m_szCoin, sizeof(m_szCoin));
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = piIniFile->GetInteger(GCS_SECTION_AUCTION, "AuctionTaxRate", 5, &m_nAuctionTaxRate);
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = piIniFile->GetInteger(GCS_SECTION_AUCTION, "GameCardTaxRate", 5, &m_nGameCardTaxRate);
    KGLOG_PROCESS_ERROR(nRetCode);

    // Role config
    nRetCode = piIniFile->GetInteger(GCS_SECTION_ROLE, "MaxNameLen", 0, &m_nMaxRoleNameLength);
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = piIniFile->GetInteger(GCS_SECTION_ROLE, "MinNameLen", 0, &m_nMinRoleNameLength);
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = piIniFile->GetInteger(GCS_SECTION_ROLE, "MaxRoleCount", 0, &m_nMaxRoleCount);
    KGLOG_PROCESS_ERROR(nRetCode);
    /*
    nRetCode = piIniFile->GetInteger(GCS_SECTION_ROLE, "DeleteProtectLevel", 0, &m_nDeleteProtectLevel);
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = piIniFile->GetInteger(GCS_SECTION_ROLE, "DeleteDelayTime", 0, &m_nDeleteDelayTime);
    KGLOG_PROCESS_ERROR(nRetCode);
    */
    m_nDeleteProtectLevel   = 20;
    m_nDeleteDelayTime      = 7 * 24 * 60 * 60;

    // Tong
    nRetCode = piIniFile->GetString(
        GCS_SECTION_TONG, "TongReturnMoneyMailTitle", "tong system return money", 
        m_szTongReturnMoneyMailTitle, sizeof(m_szTongReturnMoneyMailTitle)
    );
    KGLOG_PROCESS_ERROR(nRetCode);

    // AntiFarmer
    nRetCode = piIniFile->GetBool(GCS_SECTION_ANTI_FARMER, "IsEnable", &m_bAntiFarmerEnable);
    KGLOG_PROCESS_ERROR(nRetCode);

    bResult = true;
Exit0:
	KG_COM_RELEASE(piIniFile);
	return bResult;
}
示例#19
0
BOOL KSO3GameCenterSettings::LoadRelaySettings()
{
    BOOL        bResult     = false;
    int         nRetCode    = false;	
    IIniFile*	piIniFile   = NULL;
    int			nValue      = 0;

    piIniFile = g_OpenIniFile(RELAY_SETTINGS_FILENAME);
    KGLOG_PROCESS_ERROR(piIniFile);

    // Global
    nRetCode = piIniFile->GetString(GCS_SECTION_GLOBAL, "Locale", "", m_szLocale, sizeof(m_szLocale));
    KGLOG_PROCESS_ERROR(nRetCode);

    // Gateway config
    nRetCode = piIniFile->GetString(GCS_SECTION_GATEWAY, "IP", "127.0.0.1", m_szGatewayIP, sizeof(m_szGatewayIP));
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = piIniFile->GetInteger(GCS_SECTION_GATEWAY, "Port", 9001, &m_nGatewayPort);
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = piIniFile->GetInteger(GCS_SECTION_GATEWAY, "PingCycle", 30, (int*)&m_nGatewayPingCycle);
    KGLOG_PROCESS_ERROR(nRetCode);

    // GS config
    nRetCode = piIniFile->GetInteger(GCS_SECTION_GAMESERVER, "Port", 5003, &m_nGameServerPort);
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = piIniFile->GetInteger(GCS_SECTION_GAMESERVER, "ConnectionTimeout", 20, &m_nConnectionTimeout);
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = piIniFile->GetInteger(GCS_SECTION_GAMESERVER, "MemoryLimitForCreateMap", 1400, &m_nMemoryLimitForCreateMap);
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = piIniFile->GetFloat(GCS_SECTION_GAMESERVER, "AveragePerformanceLimitForCreateMap", 6.0f, &m_fAveragePerformanceLimitForCreateMap);
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = piIniFile->GetFloat(GCS_SECTION_GAMESERVER, "ImmediatePerformanceLimitForCreateMap", 8.0f, &m_fImmediatePerformanceLimitForCreateMap);
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = piIniFile->GetFloat(GCS_SECTION_GAMESERVER, "AveragePerformanceLimitForNewPlayer", 4.0f, &m_fAveragePerformanceLimitForNewPlayer);
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = piIniFile->GetFloat(GCS_SECTION_GAMESERVER, "ImmediatePerformanceLimitForNewPlayer", 6.0f, &m_fImmediatePerformanceLimitForNewPlayer);
    KGLOG_PROCESS_ERROR(nRetCode);

    // MySQL
    nRetCode = piIniFile->GetString(GCS_SECTION_MYSQL, "IP", "127.0.0.1", m_szDBIP, sizeof(m_szDBIP));
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = piIniFile->GetInteger(GCS_SECTION_MYSQL, "Port", 3306, &m_nDBPort);
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = piIniFile->GetString(GCS_SECTION_MYSQL, "Account", "", m_szDBAcc, sizeof(m_szDBAcc));
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = piIniFile->GetString(GCS_SECTION_MYSQL, "Password", "", m_szDBPsw, sizeof(m_szDBPsw));
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = piIniFile->GetString(GCS_SECTION_MYSQL, "Database", "", m_szDBName, sizeof(m_szDBName));
    KGLOG_PROCESS_ERROR(nRetCode);

    // Apex Proxy
    nRetCode = piIniFile->GetString(
        GCS_SECTION_APEXPROXY, "IP", "127.0.0.1", m_szApexServerIP, sizeof(m_szApexServerIP)
    );
    KGLOG_PROCESS_ERROR(nRetCode);

    nRetCode = piIniFile->GetInteger(GCS_SECTION_APEXPROXY, "Port", 10001, &m_nApexServerPort);
    KGLOG_PROCESS_ERROR(nRetCode);

    nRetCode = piIniFile->GetInteger(GCS_SECTION_APEXPROXY, "PingCycle", 5, &m_nApexPingCycle);
    KGLOG_PROCESS_ERROR(nRetCode);

    nRetCode = piIniFile->GetInteger(GCS_SECTION_APEXPROXY, "MaxKickCount", 1, &m_nMaxKickCount);
    KGLOG_PROCESS_ERROR(nRetCode);

    // LogServer
    nRetCode = piIniFile->GetString(GCS_SECTION_LOGSERVER, "IP", "127.0.0.1", m_szLogServerIP, sizeof(m_szLogServerIP));
    KGLOG_PROCESS_ERROR(nRetCode);

    nRetCode = piIniFile->GetInteger(GCS_SECTION_LOGSERVER, "Port", 5100, &m_nLogServerPort);
    KGLOG_PROCESS_ERROR(nRetCode);

    nRetCode = piIniFile->GetInteger(GCS_SECTION_LOGSERVER, "PingCycle", 30, &m_nLogServerPingCycle);
    KGLOG_PROCESS_ERROR(nRetCode);

    nRetCode = piIniFile->GetString(GCS_SECTION_LOGSERVER, "Identity", "", m_szLogServerIdentity, sizeof(m_szLogServerIdentity));
    KGLOG_PROCESS_ERROR(nRetCode);

    bResult = true;
Exit0:
    KG_COM_RELEASE(piIniFile);
    return bResult;
}
示例#20
0
BOOL KPlayerManager::Init(KE_ACCOUNT_VERIFIER eAccountVerifier)
{
	BOOL                        bResult                = false;
	BOOL                        bRetCode               = false;
	BOOL                        nSocketServerInitFlag  = false;
	IIniFile*                   piIniFile              = NULL;
	int                         nPort                  = 0;
	char                        szIP[_NAME_LEN];

	m_pSocketEvents = new QSOCKET_EVENT[MAX_SOCKET_EVENT];
	LOG_PROCESS_ERROR(m_pSocketEvents);

	m_pSockerServer = new QSocketServerAcceptor();
	LOG_PROCESS_ERROR(m_pSockerServer);

	piIniFile = g_OpenIniFile(GATEWAY_CONFIG_FILE);
	LOG_PROCESS_ERROR(piIniFile);

	bRetCode = piIniFile->GetInteger("Player", "MaxPlayer", 8192, &m_nMaxPlayer);
	LOG_PROCESS_ERROR(bRetCode);

	bRetCode = piIniFile->GetString("Player", "IP", "", szIP, (unsigned int)sizeof(szIP));
	LOG_PROCESS_ERROR(bRetCode);

	bRetCode = piIniFile->GetInteger("Player", "Port", 0, &nPort);
	LOG_PROCESS_ERROR(bRetCode);

	bRetCode = piIniFile->GetInteger("Player", "PingCycle", 20, &m_nPingCycle);
	LOG_PROCESS_ERROR(bRetCode);

	m_eAccountVerifier = eAccountVerifier;
	if (m_eAccountVerifier & emACCOUNT_VERIFIER_WHITE_LIST)
	{
		bRetCode = _LoadWhiteList();
		LOG_PROCESS_ERROR(bRetCode);
	}

	bRetCode = m_pSockerServer->Init(
		szIP, nPort, MAX_WAIT_ACCEPT, 
		SOCKET_RECV_BUFFER_SIZE, SOCKET_SEND_BUFFER_SIZE, ENCODE_DECODE_NONE/*ENCODE_DECODE*/, NULL
		);
	LOG_PROCESS_ERROR(bRetCode);
	nSocketServerInitFlag = true;

	bResult = true;
EXIT0:

	QLogPrintf(LOG_INFO, "Start service at %s:%d ... ... [%s]\n", szIP, nPort, bResult ? "OK" : "Failed");

	if (!bResult)
	{
		if (nSocketServerInitFlag)
		{
			m_pSockerServer->UnInit(NULL);
			nSocketServerInitFlag = false;
		}
		SAFE_DELETE(m_pSockerServer);
		SAFE_DELETE_ARRAY(m_pSocketEvents);
	}
	SAFE_RELEASE(piIniFile);
	return bResult;
}
示例#21
0
int KGatewaytest::FillConnectConfig(const char cszConnectConfigFileName[])
{
    int         nResult     = false;
    int         nRetCode    = false;
    IIniFile*   piIniFile   = NULL;

    ASSERT(cszConnectConfigFileName);

    piIniFile = g_OpenIniFile(cszConnectConfigFileName);
    KGLOG_PROCESS_ERROR(piIniFile);

    nRetCode = piIniFile->GetString(
        "Paysys", 
        "UserName",
        "",
        m_GatewayTestConfig.m_szTestGWUserName,
        sizeof(m_GatewayTestConfig.m_szTestGWUserName)
    );
    KGLOG_PROCESS_ERROR(nRetCode);

    nRetCode = piIniFile->GetString(
        "Relay", 
        "IP", 
        "", 
        m_GatewayTestConfig.GameCenterConfig.szRelayIPAddr,
        sizeof(m_GatewayTestConfig.GameCenterConfig.szRelayIPAddr)
    );
    KGLOG_PROCESS_ERROR(nRetCode);

    nRetCode = piIniFile->GetInteger(
        "Relay", 
        "Port", 
        0, 
        &m_GatewayTestConfig.GameCenterConfig.nRelayPort
    );
    KGLOG_PROCESS_ERROR(nRetCode);

    nRetCode = piIniFile->GetString(
        "Paysys",
        "IP", 
        "", 
        m_GatewayTestConfig.PaysysManagerConfig.szPaysysIPAddr, 
        sizeof(m_GatewayTestConfig.PaysysManagerConfig.szPaysysIPAddr)
    );
    KGLOG_PROCESS_ERROR(nRetCode);

    nRetCode = piIniFile->GetInteger(
        "Paysys",
        "Port", 
        0, 
        &m_GatewayTestConfig.PaysysManagerConfig.nPaysysPort
    );
    KGLOG_PROCESS_ERROR(nRetCode);

    nRetCode = piIniFile->GetString(
        "Player", 
        "IP",
        "", 
        m_GatewayTestConfig.ClientConfig.szConnectIPAddr, 
        sizeof(m_GatewayTestConfig.ClientConfig.szConnectIPAddr)
    );
    KGLOG_PROCESS_ERROR(nRetCode);

    nRetCode = piIniFile->GetInteger(
        "Player", 
        "Port", 
        0, 
        &m_GatewayTestConfig.ClientConfig.nConnectPort
    );
    KGLOG_PROCESS_ERROR(nRetCode);

#ifdef WIN32
    nRetCode = piIniFile->GetString(
        "TestConfig", 
        "GateWay_WinPath",
        "d", 
        m_GatewayTestConfig.m_szGatewayPath, 
        sizeof(m_GatewayTestConfig.m_szGatewayPath)
    );
    KGLOG_PROCESS_ERROR(nRetCode);
#else
    nRetCode = piIniFile->GetString(
        "TestConfig", 
        "GateWay_LinuxPath",
        "d", 
        m_GatewayTestConfig.m_szGatewayPath, 
        sizeof(m_GatewayTestConfig.m_szGatewayPath)
    );
    KGLOG_PROCESS_ERROR(nRetCode);
#endif

    nResult = true;
Exit0:
    KG_COM_RELEASE(piIniFile);
    return nResult;
}
示例#22
0
int KGObjectPropertyEditDlg::LoadConfig(const TCHAR pcszAbsName[])
{
	int nResult  = false;
	int nRetCode = false;

	TCHAR     szValue[MAX_PATH] = {0};
	CString   szSection;
	IIniFile* pIniFile = NULL;

	CString szPath      = /*g_Work_Directory +*/ CString("\\");
	CString szNamePlate = szPath + "nameplate.ini";
	CString szTemplate  = szPath + "template.ini";

	ASSERT(pcszAbsName);
	KG_PROCESS_ERROR(pcszAbsName);

	pIniFile = g_OpenIniFile(pcszAbsName);
	KG_PROCESS_ERROR(pIniFile);

	switch (m_eEditType)
	{
	case PROPERTY_EDIT_TYPE_EQUIP :
		szSection = "EQUIP";
		break;
	case PROPERTY_EDIT_TYPE_NPC_ANI :
		szSection = "NPC_ANI";
		break;
	case PROPERTY_EDIT_TYPE_PLAYER_ANI :
		szSection = "PLAYER_ANI";
		break;
	default:
		KG_PROCESS_ERROR(false);
		break;
	}

	pIniFile->GetString(
		szSection.GetBuffer(), "Directory", szPath.GetBuffer(),
		szValue, sizeof(szValue)
	);
	m_szDirectory = CString(szValue);

	pIniFile->GetString(
		szSection.GetBuffer(), "Nameplate", szNamePlate.GetBuffer(),
		szValue, sizeof(szValue)
	);
	m_szNamePlate = CString(szValue);

	pIniFile->GetString(
		szSection.GetBuffer(), "Template", szTemplate.GetBuffer(),
		szValue, sizeof(szValue)
	);

	m_szTemplate = CString(szValue);

	nResult = true;
Exit0:
	if (pIniFile)
	{
		pIniFile->Release();
	}
	return nResult;
}
示例#23
0
void KUiWndFrameTabControl::OnSelWnd()
{
    typedef std::vector<_tstring>	ListItemArray; 
    ListItemArray aList;
    char  szWndType[128] = "";  
    char  szWndName[128] = "";
    HMENU hMenu = NULL;
    int   i = 0;
    POINT MousePosition;
    int   nId = 0;
    int   nSel = 0;
    int   nMax = 0;
    IIniFile *pIni = g_Ui.GetIni();
    KG_PROCESS_ERROR(pIni);

    while (g_Ui.GetNextUnit(szWndName)) 
    {
        pIni->GetString(szWndName, "._WndType", "", szWndType, sizeof(szWndType));

        if (!IsItemExist(szWndName) && _tcsicmp(szWndType, g_GetWndTypeKey(UI_WND_FRAME)) != 0) 
        {
            aList.push_back(szWndName);
        }
    }

    nId =91000;
	hMenu = CreatePopupMenu();
    KG_PROCESS_ERROR(hMenu);   
    nMax = aList.size();
    for (i = 0; i < nMax; i++) 
    {
        strcpy(szWndName, aList[i].c_str());
        AppendMenu(hMenu, MF_ENABLED | MF_STRING, nId, szWndName);
        nId++;
    }
    AppendMenu(hMenu, MF_ENABLED | MF_STRING, nId, "全部添加");
    nId++;

    GetCursorPos(&MousePosition);
    nSel = TrackPopupMenu(hMenu, TPM_RETURNCMD | TPM_LEFTBUTTON | TPM_NONOTIFY, 
        MousePosition.x, MousePosition.y, 0, m_hWnd, NULL);
	DestroyMenu(hMenu);

    KG_PROCESS_ERROR(nSel >= 91000 && nSel < nId);
    if (nSel == nId - 1) 
    {
        nMax = aList.size();
        for (i = 0; i < nMax; i++) 
        {
            strcpy(szWndName, aList[i].c_str());
            LV_ITEM			lvi;
            memset(&lvi, 0, sizeof(LV_ITEM));
            lvi.mask = LVIF_TEXT;
            lvi.pszText		= (char*)szWndName;
            lvi.cchTextMax  = strlen(szWndName);
            lvi.iItem       = ListView_GetItemCount(m_hListWnd);
            lvi.iItem		= ListView_InsertItem(m_hListWnd, &lvi);
        }
    }
    else
    {
        strcpy(szWndName, aList[nSel - 91000].c_str());
        LV_ITEM			lvi;
        memset(&lvi, 0, sizeof(LV_ITEM));
        lvi.mask = LVIF_TEXT;
        lvi.pszText		= (char*)szWndName;
        lvi.cchTextMax  = strlen(szWndName);
        lvi.iItem       = ListView_GetItemCount(m_hListWnd);
        lvi.iItem		= ListView_InsertItem(m_hListWnd, &lvi);
    }

    SaveData();

Exit0:
    aList.clear();
    return;
}
示例#24
0
int KG_Jx3DBChecker::_LoadSettings()
{
    int nResult = false;
    int nRetCode = false;

    IIniFile*   piIniFile   = NULL;

    piIniFile = g_OpenIniFile(DBCHECKER_CONFIG_FILE);
    KGLOG_PROCESS_ERROR(piIniFile);

    nRetCode = piIniFile->GetString("SrcDatabaseServer1", "Server", "", m_mySqlConnectParan[0].szServer, sizeof(m_mySqlConnectParan[0].szServer));
    KGLOG_PROCESS_ERROR(nRetCode);

    nRetCode = piIniFile->GetString("SrcDatabaseServer1", "UserName", "", m_mySqlConnectParan[0].szUserName, sizeof(m_mySqlConnectParan[0].szUserName));
    KGLOG_PROCESS_ERROR(nRetCode);

    nRetCode = piIniFile->GetString("SrcDatabaseServer1", "Password", "", m_mySqlConnectParan[0].szPassword, sizeof(m_mySqlConnectParan[0].szPassword));
    KGLOG_PROCESS_ERROR(nRetCode);

    nRetCode = piIniFile->GetString("SrcDatabaseServer1", "DBName", "", m_mySqlConnectParan[0].szDBName, sizeof(m_mySqlConnectParan[0].szDBName));
    KGLOG_PROCESS_ERROR(nRetCode);

    nRetCode = piIniFile->GetString("SrcDatabaseServer2", "Server", "", m_mySqlConnectParan[1].szServer, sizeof(m_mySqlConnectParan[1].szServer));
    KGLOG_PROCESS_ERROR(nRetCode);

    nRetCode = piIniFile->GetString("SrcDatabaseServer2", "UserName", "", m_mySqlConnectParan[1].szUserName, sizeof(m_mySqlConnectParan[1].szUserName));
    KGLOG_PROCESS_ERROR(nRetCode);

    nRetCode = piIniFile->GetString("SrcDatabaseServer2", "Password", "", m_mySqlConnectParan[1].szPassword, sizeof(m_mySqlConnectParan[1].szPassword));
    KGLOG_PROCESS_ERROR(nRetCode);

    nRetCode = piIniFile->GetString("SrcDatabaseServer2", "DBName", "", m_mySqlConnectParan[1].szDBName, sizeof(m_mySqlConnectParan[1].szDBName));
    KGLOG_PROCESS_ERROR(nRetCode);

    nRetCode = piIniFile->GetString("DstDatabaseServer", "Server", "", m_mySqlConnectParan[2].szServer, sizeof(m_mySqlConnectParan[2].szServer));
    KGLOG_PROCESS_ERROR(nRetCode);

    nRetCode = piIniFile->GetString("DstDatabaseServer", "UserName", "", m_mySqlConnectParan[2].szUserName, sizeof(m_mySqlConnectParan[2].szUserName));
    KGLOG_PROCESS_ERROR(nRetCode);

    nRetCode = piIniFile->GetString("DstDatabaseServer", "Password", "", m_mySqlConnectParan[2].szPassword, sizeof(m_mySqlConnectParan[2].szPassword));
    KGLOG_PROCESS_ERROR(nRetCode);

    nRetCode = piIniFile->GetString("DstDatabaseServer", "DBName", "", m_mySqlConnectParan[2].szDBName, sizeof(m_mySqlConnectParan[2].szDBName));
    KGLOG_PROCESS_ERROR(nRetCode);

    nResult = true;
Exit0:
    KG_COM_RELEASE(piIniFile);
    return nResult;
}
示例#25
0
int  KGObjectPropertyEditDlg::ShowPropertyTable(
	CString szNamePlate, CString szTemplate, CString szIniFile
)
{
	m_listProperty.DeleteAllItems();
	m_arrayPropertyListItem.RemoveAll();

	m_szCurIniFileName = szIniFile;
	SetWindowText(m_szWindowTextt + " 正在编辑 : " + m_szCurIniFileName);

	SAFE_RELEASE(m_pIniFile);
	m_pIniFile          = g_OpenIniFile(szTemplate.GetBuffer());
	IIniFile* pIniFile  = g_OpenIniFile(szIniFile);
	IIniFile* pNameFile = g_OpenIniFile(szNamePlate.GetBuffer());

	if (!pNameFile)  return FALSE;
	if (!m_pIniFile) return FALSE;
	if (!pIniFile)   return FALSE;

	char szSection[256] = "";
	char szKey[256]     = "";
	char szPlate[256]   = "";
	char szValue[512]   = "";
	char szType[256]    = "";

	UINT uIndex = 0;

	while (m_pIniFile->GetNextSection(szSection, szSection))
	{
		PropertyListItem item(szSection, szSection);
		m_arrayPropertyListItem.Add(item);
		pNameFile->GetString(
			szSection, "Title", "未知标题", szPlate, sizeof(szPlate)
		);
		m_listProperty.InsertItem (uIndex, NULL);
		m_listProperty.SetItemText(uIndex, 0, szPlate);
		//m_listProperty.SetItemData(uIndex, VALUE_TITLE);
		uIndex++;

		*szKey = '\0';
		while (m_pIniFile->GetNextKey(szSection, szKey, szKey))
		{
			pNameFile->GetString(
				"Globe", szKey, "未知键名", szPlate, sizeof(szPlate)
			);
			if (CString(szPlate) == "未知键名")
			{
				pNameFile->GetString(
					szSection, szKey, "未知键名", szPlate, sizeof(szPlate)
				);
			}

			CString szKeyType = CString(szKey) + CString("Type");

			pNameFile->GetString(
				"Globe", szKeyType.GetBuffer(), "VALUE_UNKNOW",
				szType, sizeof(szType)
			);
			if (CString(szType) == "VALUE_UNKNOW")
			{
				pNameFile->GetString(
					szSection, szKeyType.GetBuffer(), "STRING",
					szType, sizeof(szType)
				);
			}

			m_pIniFile->GetString(
				szSection, szKey, "未知键值", szValue, sizeof(szValue)
			);
			pIniFile->GetString(
				szSection, szKey, szValue, szValue, sizeof(szValue)
			);
			m_pIniFile->WriteString(szSection, szKey, szValue);

			PropertyListItem item(szSection, szKey);
			m_arrayPropertyListItem.Add(item);

			m_listProperty.InsertItem (uIndex, NULL);
			m_listProperty.SetItemText(uIndex, 0, szPlate);
			m_listProperty.SetItemText(uIndex, 1, szValue);
			m_listProperty.SetItemData(uIndex, GetKeyType(CString(szType)));
			uIndex++;
		}
	}

	pIniFile->Release();
	pNameFile->Release();

	return TRUE;
}
示例#26
0
// 初始化面向客户端的连接
BOOL KPlayerServer::Init()
{
    BOOL            bResult                 = false;
    int             nRetCode                = false;
    BOOL            bSocketServerInit       = false;
    IIniFile*	    piIniFile               = NULL;
    unsigned long   ulInternalIPAddressMask = 0;
    unsigned long   ulExternalIPAddress     = INADDR_NONE;
    unsigned long   ulInternalIPAddress     = INADDR_NONE;
    //int				nListenPort             = 0;
    int             nNatPort                = 0;
    int 			nMaxConnection          = 0;
    int             nRecvBufferSize         = 0;
    int             nSendBufferSize         = 0;
    int             nClientGM               = 0;
    int             nMaxClientPackPerFrame  = 0;
    char            szNatIP[16];
    char            szInternalIPMask[16];
    unsigned char   byInternalMacAddress[6];
    unsigned char   byExternalMacAddress[6];
    struct          in_addr  InAddr;
    
    assert(g_pSO3World);
    
    piIniFile = g_OpenIniFile(GS_SETTINGS_FILENAME);
	KGLOG_PROCESS_ERROR(piIniFile);

    memset(szNatIP, 0, sizeof(szNatIP));

    piIniFile->GetString("GS-Player", "NatIP", "", szNatIP, sizeof(szNatIP));
    piIniFile->GetInteger("GS-Player", "NatPort", 0, &nNatPort);
    piIniFile->GetString("GS-Player", "InternalIPAddressMask", "192.168.0.0", szInternalIPMask, 16);
	piIniFile->GetInteger("GS-Player", "MaxConnection", 1024, &nMaxConnection);
	piIniFile->GetInteger("GS-Player", "RecvBufferSize", 8000, &nRecvBufferSize);
	piIniFile->GetInteger("GS-Player", "SendBufferSize", 64000, &nSendBufferSize); 
    piIniFile->GetInteger("GS-Player", "PingCycle", 0, &m_nPingCycle);
    piIniFile->GetInteger("GS-Player", "ClientGM", 0, &nClientGM);
    piIniFile->GetInteger("GS-Player", "MaxClientPackPerFrame", 256, &nMaxClientPackPerFrame);

    if (m_szLocalIP[0] != '\0')
    {
         ulExternalIPAddress = (unsigned long)inet_addr(m_szLocalIP);
         if (ulExternalIPAddress == INADDR_NONE)
         {
             KGLogPrintf(KGLOG_ERR, "[KPlayerServerBase] Invalid ip address or format.\n");
             goto Exit0;
         }    
    }
    else
    {
        char* pszInternetAddr = NULL;

        ulInternalIPAddressMask = inet_addr(szInternalIPMask);
        KGLOG_PROCESS_ERROR(ulInternalIPAddressMask != INADDR_NONE);

        nRetCode = gGetMacAndIPAddress(
            byInternalMacAddress, &ulInternalIPAddress, 
            byExternalMacAddress, &ulExternalIPAddress, ulInternalIPAddressMask
        );
        KGLOG_PROCESS_ERROR(nRetCode > 0);

        InAddr.s_addr = ulExternalIPAddress;
        pszInternetAddr = inet_ntoa(InAddr);
        KGLOG_PROCESS_ERROR(pszInternetAddr);

        strcpy(m_szLocalIP, pszInternetAddr);
    }
    
    KGLOG_PROCESS_ERROR(nMaxConnection > 0);
    
    m_dwTimeNow = KG_GetTickCount();
    m_nClientGM = nClientGM;

    ResetPakStat();

	m_nMaxConnection = nMaxConnection;
    m_nMaxClientPackPerFrame = nMaxClientPackPerFrame;

	m_ConnectionDataList = new KConnectionData[nMaxConnection];
	KGLOG_PROCESS_ERROR(m_ConnectionDataList);

    m_ConnectionDataListFreeVector.reserve(nMaxConnection);

    for (int i = 0; i < nMaxConnection; i++)
    {
        m_ConnectionDataListFreeVector.push_back(nMaxConnection - i - 1);
    }

    m_nSocketEventCount = nMaxConnection + KG_MAX_ACCEPT_EACH_WAIT;

    m_pSocketEventArray = new KG_SOCKET_EVENT[m_nSocketEventCount];
    KGLOG_PROCESS_ERROR(m_pSocketEventArray);

    nRetCode = m_SocketServerAcceptor.Init(
        m_szLocalIP, m_nListenPort, KG_MAX_ACCEPT_EACH_WAIT, 
        nRecvBufferSize, nSendBufferSize, KSG_ENCODE_DECODE_NONE, NULL
    );

    KGLogPrintf(
        KGLOG_INFO, "Start service at %s:%d ... ... [%s]",
        m_szLocalIP, m_nListenPort, nRetCode ? "OK" : "Failed"
    );
    
    KGLOG_PROCESS_ERROR(nRetCode);
    bSocketServerInit = true;

	m_dwInternetAddr    = ulExternalIPAddress;
    if (szNatIP[0] != '\0')
    {
        m_nListenPort       = nNatPort;
        m_dwInternetAddr    = (unsigned long)inet_addr(szNatIP);

        KGLogPrintf(KGLOG_INFO, "NAT at %s:%d", szNatIP, nNatPort);
    }

    m_nNextCheckConnection = 0;

    bResult = true;
Exit0:
    if (!bResult)
    {
        if (bSocketServerInit)
        {
            m_SocketServerAcceptor.UnInit(NULL);
            bSocketServerInit = false;
        }
        KG_DELETE_ARRAY(m_pSocketEventArray);
    	KG_DELETE_ARRAY(m_ConnectionDataList);
    }
    KG_COM_RELEASE(piIniFile);
	return bResult;
}