Esempio n. 1
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;
}
void KSceneEditorDialogAutoGrass::LoadTextureSettings()
{
	CString strTextureName;
	TCHAR strIniFileName[MAX_PATH];
	int nCurSel = m_ComboxBoxTexture.GetCurSel();
	IIniFile* pInIFile = NULL;
	int nReturnCode = 0;

	KG_PROCESS_ERROR(nCurSel != CB_ERR);

	m_ComboxBoxTexture.GetLBText(nCurSel, strTextureName);
	sprintf(strIniFileName, "%s%s.ini", m_GrassTexturePath, strTextureName);
	
	////把文件的只读属性去掉////////////////////////////////////by huangjinshou
	DWORD dwFileAttribute = ::GetFileAttributes(strIniFileName);
	dwFileAttribute &=~FILE_ATTRIBUTE_READONLY; 
	::SetFileAttributes(strIniFileName,dwFileAttribute);
	///////////////////////////////////////////////////////////
	pInIFile = g_OpenIniFile(strIniFileName, false, true);
	KG_PROCESS_ERROR(pInIFile);

	pInIFile->GetInteger("Texture", "StrideX", 1, &m_nWidhtCount);
	pInIFile->GetInteger("Texture", "StrideY", 1, &m_nHeightCount);

	UpdateData(FALSE);
Exit0:
	SAFE_RELEASE(pInIFile);
	return;
}
Esempio n. 3
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;
}
Esempio n. 4
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;
}
Esempio n. 5
0
BOOL KGameServer::_InitEnv()
{
	// Get GameCenter Ip/Port
	IIniFile* pIniFile = g_OpenIniFile(KDF_SERVER_CFG);
	QCONFIRM_RET_FALSE(pIniFile);

	//pIniFile->GetInteger("GameCenter", "Port", 5135, &m_nGameCenterPort);
	//pIniFile->GetString("GameCenter", "Ip", "", m_szGameCenterIp, countof(m_szGameCenterIp));

	pIniFile->GetInteger("GameServer", "ServerId", 0, &g_cOrpgWorld.m_nServerId);
	pIniFile->GetInteger("GameServer", "ServerMode", 0, &g_cOrpgWorld.m_nServerMode);
	return TRUE;
}
Esempio n. 6
0
void KUiWndFrameTabControl::SaveData()
{
    KG_PROCESS_ERROR(m_hListWnd);
    KG_PROCESS_ERROR(m_szName[0]);
    IIniFile *pIni = g_Ui.GetIni();
    KG_PROCESS_ERROR(pIni);

    int nMaxNum = 0;
    int i = 0;
    char szKey[128] = "";
    char szKeyValue[128] = "";
    pIni->GetInteger(m_szName, "ItemCount", 0, &nMaxNum);
    for (i = 0; i < nMaxNum; i++) 
    {
        sprintf(szKey, "Item_%d", i);
        pIni->EraseKey(m_szName, szKey);
    }

    nMaxNum = ListView_GetItemCount(m_hListWnd);
    pIni->WriteInteger(m_szName, "ItemCount", nMaxNum);
    for (i = 0; i < nMaxNum; i++) 
    {
        sprintf(szKey, "Item_%d", i);
        ListView_GetItemText(m_hListWnd, i, 0, szKeyValue, sizeof(szKeyValue));
        pIni->WriteString(m_szName, szKey, szKeyValue);
    }

	g_ClientManager.UpDataWndInClient(g_Ui.GetIni(true));
    ShowErrorInformation();

Exit0:
    return;
}
Esempio n. 7
0
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;
}
Esempio n. 8
0
BOOL KGameServer::_LoadMiniServerScene()
{
	IIniFile* pIniFile = g_OpenIniFile(KDF_SERVER_CFG);
	QCONFIRM_RET_FALSE(pIniFile);

	INT nSceneCount = 0;
	pIniFile->GetInteger("PreloadScene", "Count", 0, &nSceneCount);

	if (nSceneCount > 0)
	{
		INT* pSceneTemplateIds = new INT[nSceneCount];
		INT nActualCount = pIniFile->GetMultiInteger("PreloadScene", "Scenes", pSceneTemplateIds, nSceneCount);
		QCONFIRM(nActualCount == nSceneCount);
		nSceneCount = nActualCount;

		for (INT j = 0; j < nSceneCount; j++)
		{
			INT nSceneId = pSceneTemplateIds[j];
			if (nSceneId > 0)
				g_pSceneMgr->LoadScene((DWORD)nSceneId, 0);
		}
	}

	return TRUE;
}
Esempio n. 9
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;
}
Esempio n. 10
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;
}
Esempio n. 11
0
void KG3DAnimationSoundTagInfo::Init()
{
	int nHeight = 0;
	ITabFile *pTabFile = NULL;
    IIniFile *pIniFile = NULL;
    pTabFile = g_OpenTabFile(s_strConfigTabFile);
	KG_PROCESS_ERROR(pTabFile);
	m_SoundType.clear();
	m_AnimationSoundTagInfo.clear();
	for (size_t i = 0 ; i < sizeof(s_strSoundType) / sizeof(TCHAR *) ; i ++)
	{
		std::string strFirst = s_strSoundType[i];
		m_SoundType[strFirst] = i;
	}
	nHeight = pTabFile->GetHeight();
	for (int i = 2 ; i <= nHeight ; i ++)
	{
		AnimationSoundTagInfo Info;
		TCHAR strSoundType[MAX_PATH];
		std::string SoundTypetemp;
		iter it = m_SoundType.begin();
		int nSoundType = 0;
		pTabFile->GetString(i,COL_SOUNDTYPE,"",strSoundType,MAX_PATH);
		pTabFile->GetString(i,COL_FILENAME,"",Info.strFileName,MAX_PATH);
		pTabFile->GetFloat(i,COL_RATE,0.0f,&Info.fRate);
		_strlwr_s(strSoundType,MAX_PATH);
		SoundTypetemp = strSoundType;
		KG_PROCESS_ERROR(m_SoundType.find(SoundTypetemp) != m_SoundType.end());
		Info.soundType = static_cast<SoundType>(m_SoundType[SoundTypetemp]);
		nSoundType = m_SoundType[SoundTypetemp];
		if(m_AnimationSoundTagInfo.find(nSoundType) 
			!= m_AnimationSoundTagInfo.end())
		{
			m_AnimationSoundTagInfo[nSoundType].push_back(Info);
		}
		else
		{
			std::vector<AnimationSoundTagInfo> vec;
			vec.push_back(Info);
			m_AnimationSoundTagInfo[nSoundType] = vec;
		}
	}
	Adjust();
    pIniFile = g_OpenIniFile(s_strConfigIniFile);
    KG_PROCESS_ERROR(pIniFile);
    pIniFile->GetInteger("ROOT","SaveVersion3Data",0,&m_nSaveVersion3Data);
	m_bInit = TRUE;
Exit0:
    SAFE_RELEASE(pTabFile);
    SAFE_RELEASE(pIniFile);
	;
}
Esempio n. 12
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;
}
Esempio n. 13
0
void KGT_g_OpenIniFileFromArgumentsTest::Test_g_OpenFileFromArguments_07()
{
    int nResult = false;
    int nRetCode = false;

    IIniFile *piIniFile = NULL;
    int nRetValue = 0;
    int nArgc = 0;
    char *pszArgv[2] = {0};
    char szArgv[2][IIniFile::INI_MAX_SUPPORT_SECTION_AND_KEY_SIZE * 2] = {0};
    nArgc = sizeof(szArgv) / sizeof(szArgv[0]);
    char szKey[IIniFile::INI_MAX_SUPPORT_SECTION_AND_KEY_SIZE];
    szKey[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("key的长度为最大值", "");

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

    nRetCode = _snprintf(
        szArgv[1],
        sizeof(szArgv[1]) / sizeof(szArgv[1][0]) - 1,
        "--Version.%s=2",
        szKey
    );
    KG_PROCESS_ERROR(nRetCode > 0);

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

    nRetCode = piIniFile->GetInteger("Version", szKey, 0, &nRetValue);
    KG_PROCESS_ERROR(nRetCode);

    KG_PROCESS_ERROR(nRetValue == 2);

    nResult = true;
Exit0:
    KG_COM_RELEASE(piIniFile);
    CPPUNIT_ASSERT(nResult);
}
Esempio n. 14
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;
}
Esempio n. 15
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;
}
Esempio n. 16
0
HRESULT KG3DSelector::Init()
{
	HRESULT hRetCode = E_FAIL;
	HRESULT hResult = E_FAIL;

	IIniFile *pConfig = g_OpenIniFile(g_szConfigFilePath);
	int nResult = 0;
	KG_PROCESS_ERROR(pConfig);

	nResult = pConfig->GetInteger("KG3DENGINE", "SelectorScale", 2, &m_nScale);
	
	//处理Scale == 0的情况
	if (m_nScale == 0)
	{
		m_nScale = 1;
	}

	m_nWidth = static_cast<int>(g_cGraphicsEngine.GetPresentParameters().BackBufferWidth);
	m_nHeight = static_cast<int>(g_cGraphicsEngine.GetPresentParameters().BackBufferHeight);
	
	hResult= D3DXCreateTexture(g_pd3dDevice, 
		m_nWidth / m_nScale, 
		m_nHeight / m_nScale, 
		1, 
		D3DUSAGE_RENDERTARGET, 
		D3DFMT_A8, 
		D3DPOOL_DEFAULT, 
		&m_pStencilRT);
	KG_COM_PROCESS_ERROR(hResult);

	hResult = g_pd3dDevice->CreateDepthStencilSurface(m_nWidth / m_nScale, 
		m_nHeight / m_nScale, 
		D3DFMT_D24X8, 
		D3DMULTISAMPLE_NONE, 
		0, 
		FALSE, 
		&m_pStencilDepth, 
		NULL);
	KG_COM_PROCESS_ERROR(hResult);

	hResult = g_pd3dDevice->CreateRenderTarget(1, 
		1, 
		D3DFMT_A8R8G8B8, 
		D3DMULTISAMPLE_NONE, 
		0, 
		FALSE, 
		&m_pRT, 
		NULL);
	KG_COM_PROCESS_ERROR(hResult);

	hResult = D3DXCreateTexture(g_pd3dDevice, 
		1, 
		1, 
		0, 
		0, 
		D3DFMT_A8R8G8B8, 
		D3DPOOL_SYSTEMMEM, 
		&m_pResult);
	KG_COM_PROCESS_ERROR(hResult);

	ScreenRect[0].vec4Pos = D3DXVECTOR4(0.0f, 0.0f, .0f, 1.0f);
	ScreenRect[1].vec4Pos = D3DXVECTOR4(static_cast<float>(m_nWidth), 0.0f, .0f, 1.0f);
	ScreenRect[2].vec4Pos = D3DXVECTOR4(static_cast<float>(m_nWidth), static_cast<float>(m_nHeight), .0f, 1.0f);
	ScreenRect[3].vec4Pos = D3DXVECTOR4(0.0f, static_cast<float>(m_nHeight), .0f, 1.0f);

	ScreenRect[0].vec2UV = D3DXVECTOR2(0.0f, 0.0f);
	ScreenRect[1].vec2UV = D3DXVECTOR2(1.0f, 0.0f);
	ScreenRect[2].vec2UV = D3DXVECTOR2(1.0f, 1.0f);
	ScreenRect[3].vec2UV = D3DXVECTOR2(0.0f, 1.0f);

	hRetCode = S_OK;
Exit0:
	SAFE_RELEASE(pConfig);
	return hRetCode;
}
Esempio n. 17
0
BOOL KSO3World::Init(IRecorderFactory* piFactory)
{
    BOOL        bResult                     = false;
	BOOL        bRetCode                    = false;
    int         nRetCode                    = 0;
    BOOL        bTeamInitFlag               = false;
    BOOL        bRelationMgrInitFlag        = false;
    BOOL        bSettingsInitFlag           = false;
    BOOL        bScriptCenterInitFlag       = false;
    BOOL        bItemManagerInitFlag        = false;
    BOOL        bShopCenterInitFlag         = false;
    BOOL        bProfessionManagerInitFlag  = false;
    BOOL        bRoadManageInitFlag         = false;
    BOOL        bAIManageInitFlag           = false;
    BOOL        bDropCenterInitFlag         = false;
    BOOL        bSkillManagerInitFlag       = false;
    BOOL        bBuffManagerInitFlag        = false;
    BOOL        bTextFilterInitFlag         = false;
    BOOL        bCampInfoInitFlag           = false;
    BOOL        bPQInitFlag                 = false;
    BOOL        bTransListInitFlag          = false;
    BOOL        bStatDataServerInitFlag     = false;
    DWORD       dwRandSeed                  = 0;
    IIniFile*   piIniFile                   = NULL;

#ifdef _CLIENT
    BOOL    bTongClientInitFlag         = false;
    BOOL    bApexClientInitFlag         = false;
#endif

    m_eWorldMode            = wmNormal;
    m_nBaseTime             = 0;
    m_dwStartTime           = 0;
    m_nStartLoop            = 0;
    m_nGameLoop             = 0;

#ifdef _SERVER
    m_bFastBootMode         = 0;

    m_bTalkRecNearby        = 0;
    m_bTalkRecTeam          = 0;
    m_bTalkRecRaid         = 0;
    m_bTalkRecBattleField   = 0;
    m_bTalkRecScene         = 0;
    m_bTalkRecWhisper       = 0;
    m_bTalkRecTong          = 0;
    m_bTalkRecWorld         = 0;
    m_bTalkRecForce         = 0;
    m_bTalkRecCamp          = 0;
#endif

    assert(piFactory);

    m_piRecorderTools = piFactory->CreateToolsInterface();
    KGLOG_PROCESS_ERROR(m_piRecorderTools);

    m_nCurrentTime  = m_piRecorderTools->GetTime();
    m_dwStartTime   = m_piRecorderTools->GetTickCount();

#ifdef _SERVER
    m_piSceneLoader = piFactory->CreateSceneLoader();
    KGLOG_PROCESS_ERROR(m_piSceneLoader);

    piIniFile = g_OpenIniFile(GS_SETTINGS_FILENAME);
	KGLOG_PROCESS_ERROR(piIniFile);

    bRetCode = piIniFile->GetInteger("Global", "FastBootMode", 0, &m_bFastBootMode);
    KGLOG_PROCESS_ERROR(bRetCode);

    bRetCode = piIniFile->GetInteger("TalkRec", "Nearby", 0, &m_bTalkRecNearby);
    //KGLOG_PROCESS_ERROR(bRetCode);

    bRetCode = piIniFile->GetInteger("TalkRec", "Team", 0, &m_bTalkRecTeam);
    //KGLOG_PROCESS_ERROR(bRetCode);

    bRetCode = piIniFile->GetInteger("TalkRec", "Party", 0, &m_bTalkRecRaid);
    //KGLOG_PROCESS_ERROR(bRetCode);

    bRetCode = piIniFile->GetInteger("TalkRec", "BattleField", 0, &m_bTalkRecBattleField);
    //KGLOG_PROCESS_ERROR(bRetCode);

    bRetCode = piIniFile->GetInteger("TalkRec", "Scene", 0, &m_bTalkRecScene);
    //KGLOG_PROCESS_ERROR(bRetCode);

    bRetCode = piIniFile->GetInteger("TalkRec", "Whisper", 0, &m_bTalkRecWhisper);
    //KGLOG_PROCESS_ERROR(bRetCode);

    bRetCode = piIniFile->GetInteger("TalkRec", "Tong", 0, &m_bTalkRecTong);
    //KGLOG_PROCESS_ERROR(bRetCode);

    bRetCode = piIniFile->GetInteger("TalkRec", "World", 0, &m_bTalkRecWorld);
    //KGLOG_PROCESS_ERROR(bRetCode);

    bRetCode = piIniFile->GetInteger("TalkRec", "Force", 0, &m_bTalkRecForce);
    //KGLOG_PROCESS_ERROR(bRetCode);

    bRetCode = piIniFile->GetInteger("TalkRec", "Camp", 0, &m_bTalkRecCamp);
    //KGLOG_PROCESS_ERROR(bRetCode);
#endif

    g_RandomSeed(m_dwStartTime);
    srand(m_dwStartTime);

#ifdef _SERVER
    //bRetCode = m_TeamCache.Init();
    bRetCode = m_TeamServer.Init();
#endif

#ifdef _CLIENT
    bRetCode = m_TeamClient.Init();
#endif
    KGLOG_PROCESS_ERROR(bRetCode);
    bTeamInitFlag = true;

    bRetCode = m_FellowshipMgr.Init();
    KGLOG_PROCESS_ERROR(bRetCode);
    bRelationMgrInitFlag = true;

	bRetCode = m_Settings.Init();
	KGLOG_PROCESS_ERROR(bRetCode);
    bSettingsInitFlag = true;

	bRetCode = m_ScriptCenter.Init();
	KGLOG_PROCESS_ERROR(bRetCode);
    bScriptCenterInitFlag = true;

	bRetCode = InitAttributeFunctions();
	KGLOG_PROCESS_ERROR(bRetCode);

	bRetCode = m_ItemManager.Init();
	KGLOG_PROCESS_ERROR(bRetCode);
    bItemManagerInitFlag = true;

    bRetCode = m_ShopCenter.Init();
    KGLOG_PROCESS_ERROR(bRetCode);
    bShopCenterInitFlag = true;

	bRetCode = m_ProfessionManager.Init();
	KGLOG_PROCESS_ERROR(bRetCode);
    bProfessionManagerInitFlag = true;

    bRetCode = m_RoadManager.Init();
    KGLOG_PROCESS_ERROR(bRetCode);
    bRoadManageInitFlag = true;

    bRetCode = m_AIManager.Init();
    KGLOG_PROCESS_ERROR(bRetCode);
    bAIManageInitFlag = true;

    bRetCode = m_BuffManager.Init();
    KGLOG_CHECK_ERROR(bRetCode);
    bBuffManagerInitFlag = true;

    bRetCode = m_SkillManager.Init();
    KGLOG_PROCESS_ERROR(bRetCode);
    bSkillManagerInitFlag = true;

#ifdef _SERVER
	bRetCode = m_DropCenter.Init();
	KGLOG_PROCESS_ERROR(bRetCode);
    bDropCenterInitFlag = true;
#endif
    
    bRetCode = m_CampInfo.Init();
    KGLOG_PROCESS_ERROR(bRetCode);
    bCampInfoInitFlag = true;

    bRetCode = m_PQManager.Init();
    KGLOG_PROCESS_ERROR(bRetCode);
    bPQInitFlag = true;

#ifdef _CLIENT
    bRetCode = m_TongClient.Init();
    KGLOG_PROCESS_ERROR(bRetCode);
    bTongClientInitFlag = true;

    bRetCode = m_ApexClient.Init();
    KGLOG_PROCESS_ERROR(bRetCode);
    bApexClientInitFlag = true;
#endif

#ifdef _SERVER
    bRetCode = m_TransmissionList.Init();
    KGLOG_PROCESS_ERROR(bRetCode);
    bTransListInitFlag = true;

    bRetCode = m_StatDataServer.Init();
    KGLOG_PROCESS_ERROR(bRetCode);
    bStatDataServerInitFlag = true;
#endif

    m_NpcSet.SetPrefix(NPC_ID_PREFIX);

#ifdef _CLIENT
	m_ItemSet.SetPrefix(CLIENT_ITEM_ID_PREFIX);

    m_LinkItemQue.clear();

    m_piTextFilter = CreateTextFilterInterface();
    KGLOG_PROCESS_ERROR(m_piTextFilter);

    bRetCode = m_piTextFilter->LoadFilterFile(SETTING_DIR"/TextFilter.txt");
    KGLOG_PROCESS_ERROR(bRetCode);

    g_pSO3World->m_dwBattleFieldPQID            = 0;
    g_pSO3World->m_dwBattleFieldPQTemplateID    = 0;
    g_pSO3World->m_nBattleFieldPQBeginTime      = 0;
    g_pSO3World->m_nBattleFieldPQEndTime        = 0;
    memset(g_pSO3World->m_nBattleFieldObjectiveCurrent, 0, sizeof(g_pSO3World->m_nBattleFieldObjectiveCurrent));
    memset(g_pSO3World->m_nBattleFieldObjectiveTarget, 0, sizeof(g_pSO3World->m_nBattleFieldObjectiveTarget));
#endif

#ifdef _SERVER
    m_bRunFlag             = true;
    m_nIdleFrame           = 0;
#endif

#ifdef _SERVER
    m_CenterRemote.Setup();
    m_ScriptServer.Setup();
#else
    m_ScriptClient.Setup();
#endif

#ifdef _CLIENT
    m_bForwardCharacterPosition = false;
#endif

    nRetCode = lzo_init();
    KGLOG_PROCESS_ERROR(nRetCode == LZO_E_OK);

	bResult = true;
Exit0:
    if (!bResult)
    {
#ifdef _SERVER
        if (m_pPlayerTalkLogFile)
        {
            fclose(m_pPlayerTalkLogFile);
            m_pPlayerTalkLogFile = NULL;
            m_nPlayerTalkLogFileDay = 0;
        }
#endif

#ifdef _CLIENT
        KG_COM_RELEASE(m_piTextFilter);
#endif

#ifdef _CLIENT
        if (bApexClientInitFlag)
        {
            m_ApexClient.UnInit();
            bApexClientInitFlag = false;
        }

        if (bTongClientInitFlag)
        {
            m_TongClient.UnInit();
            bTongClientInitFlag = false;
        }
#endif
        if (bPQInitFlag)
        {
            m_PQManager.UnInit();
            bPQInitFlag = false;
        }

        if (bCampInfoInitFlag)
        {
            m_CampInfo.UnInit();
            bCampInfoInitFlag = false;
        }
#ifdef _SERVER
        if (bDropCenterInitFlag)
        {
            m_DropCenter.UnInit();
            bDropCenterInitFlag = false;
        }
#endif
        if (bBuffManagerInitFlag)
        {
            m_BuffManager.UnInit();
            bBuffManagerInitFlag = false;
        }

        if (bSkillManagerInitFlag)
        {
            m_SkillManager.UnInit();
            bSkillManagerInitFlag = false;
        }

        if (bAIManageInitFlag)
        {
            m_AIManager.UnInit();
            bAIManageInitFlag = false;
        }

        if (bRoadManageInitFlag)
        {
            m_RoadManager.UnInit();
            bRoadManageInitFlag = false;
        }
        
        if (bProfessionManagerInitFlag)
        {
            m_ProfessionManager.UnInit();
            bProfessionManagerInitFlag = false;
        }

        if (bShopCenterInitFlag)
        {
            m_ShopCenter.UnInit();
            bShopCenterInitFlag = false;
        }

        if (bItemManagerInitFlag)
        {
            m_ItemManager.UnInit();
            bItemManagerInitFlag = false;
        }        
        
        if (bScriptCenterInitFlag)
        {
            m_ScriptCenter.UnInit();
            bScriptCenterInitFlag = false;
        }

        if (bSettingsInitFlag)
        {
            m_Settings.UnInit();
            bSettingsInitFlag = false;
        }

        if (bRelationMgrInitFlag)
        {
            m_FellowshipMgr.UnInit();
            bRelationMgrInitFlag = false;
        }

        if (bTeamInitFlag)
        {
#ifdef _SERVER
            m_TeamServer.UnInit();
#endif
#ifdef _CLIENT
            m_TeamClient.UnInit();
#endif
            bTeamInitFlag = false;
        }

#ifdef _SERVER
        if (bTransListInitFlag)
        {
            m_TransmissionList.UnInit();
            bTransListInitFlag = false;
        }
        
        if (bStatDataServerInitFlag)
        {
            m_StatDataServer.UnInit();
            bStatDataServerInitFlag = false;
        }
#endif

#ifdef _SERVER
        KG_COM_RELEASE(m_piSceneLoader);
#endif
        KG_COM_RELEASE(m_piRecorderTools);
    }

    KG_COM_RELEASE(piIniFile);
    KGLogPrintf(KGLOG_INFO, "Load game settings ... ... [%s]", bResult ? "OK" : "Failed");
    
	return bResult;
}
Esempio n. 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;
}
Esempio n. 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;
}
Esempio n. 20
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;
}