Ejemplo n.º 1
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 !");
}
Ejemplo n.º 2
0
void TearDown()
{
	m_pGameServer->UnInit();
	delete m_pGameServer;
	KGThread_Sleep(200);
	TestTools::DeleteRole(&m_TestRoleInfo);
}
Ejemplo n.º 3
0
void KGatewaytest::TestUserLoginPaysysNotRespondAndUserOnLine()  // caseID:6660
{
    int nResult  = false;
    int nRetCode = false;
    char szTestCaseDscribe[] = "// caseID:6660,测试Paysys正常登陆但不返回验证结果,GameCenter返回用户在线时,Client玩家断线,Paysys收到登出信息";
    int HadRevUserLoginOut = false;
    unsigned    nLoopTimes            = 100;

    KGLogPrintf(KGLOG_INFO, "caseID:6660\n");

    FillTestUserLoginInfo(KG_USER_LOGIN, E_ACCOUNT_OR_PASSWORD, AccountUserLoginInfo,  PASSPODMODE_UNBIND,  ACTION_SUCCESS, true, true, USER_ACCOUNT_LOCKED, false);
    m_GatewayTestConfig.PaysysManagerConfig.nNotRespondProtocol = 62; // B2P_IB_PLAYER_IDENTITY_VERIFY = 62

    nRetCode = InitTestEnvironment(true, true, true, 1, m_GatewayTestConfig.ForecastConfig.nTestPoint);
    KGLOG_PROCESS_ERROR(nRetCode);

    nRetCode = m_pClientController->FillOperate(
        4, 
        onConnectToGateway,
        onHandShake,
        onAccountVerify,
        onDisConnect
    );
    KGLOG_PROCESS_ERROR(nRetCode);

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

    while(true)
    {
        KGThread_Sleep(100);
        nRetCode = m_pPaysys->HadRevUserLoginOut("0", &HadRevUserLoginOut);
        KGLOG_PROCESS_ERROR(nRetCode);
        KG_PROCESS_SUCCESS(!HadRevUserLoginOut);

        nLoopTimes--;
        KG_PROCESS_ERROR(nLoopTimes);
    }

Exit1:
    nResult = true;
Exit0:
    UnInitTestEnvironment();
#ifdef WIN32
    {
        KG_CASE_INFO(szTestCaseDscribe, "");
        KG_CPPUNIT_ASSERT(nResult);
    }
#else
    {
        //InsertInfo(CASEPURPOSE, (szTestCaseDscribe));
        //InsertInfo(PRECONDITION, (""));
        CPPUNIT_ASSERT(nResult);
    }
#endif
}
Ejemplo n.º 4
0
void KSOEditor::Run()
{
    KGLOG_PROCESS_ERROR(m_pNetworkMgr);

    while (m_bRunFlag)
    {
        m_pNetworkMgr->Process();
        KGThread_Sleep(100);
    }
Exit0:
    return;
}
Ejemplo n.º 5
0
int KLogClient::ThreadFunction()
{
    while (m_bRunFlag)
    {
        KGThread_Sleep(1000);

        if (m_piSocketStream != NULL)
            continue;

        Connect();
    }

    return 0;
}
Ejemplo n.º 6
0
void KGatewaytest::Idle(int nLoodTimes)
{
    unsigned  nLoopTimes = nLoodTimes;

    while(true)
    {
        KGThread_Sleep(100);
        nLoopTimes--;
        if (!nLoopTimes)
        {
            break;
        }
    }
}
Ejemplo n.º 7
0
int KSimulateRelay::ThreadFunction()
{
    int nResult  = false;    
    //int nRetCode = false;

    while (!m_nExitFlag)
    {
        Activate();
        KGThread_Sleep(100);
    }  

    nResult = true;
//Exit0:
    return nResult;
}
Ejemplo n.º 8
0
int KMonster::GameLoop()
{
    int nResult = FALSE;
    int nServerLoop = 0;

    KG_PROCESS_ERROR(m_PlayerClient.GetOnlineState() == gmsOnline);
    
    m_nOnlineState = osGameserverOnline;

    while (!m_nExitFlag)
    {
        m_PlayerClient.Breathe();

        if (m_PlayerClient.GetOnlineState() != gmsOnline)
        {
            Reset();
            goto Exit0;
        }

        nServerLoop = m_PlayerClient.GetServerLoop();
        while (m_nGameLoop < nServerLoop - GAME_FPS / 2)
        {
            Activate();
        }

        if (m_nGameLoop < nServerLoop + GAME_FPS / 2)
            Activate();

        m_piOperator->Activate();

        KGThread_Sleep(10);
    }
    nResult = TRUE;
Exit0:
    if (!nResult)
    {
        m_nOnlineState = osGameserverOffline;
    }
    return FALSE;
}
Ejemplo n.º 9
0
TEST_F(KTestPlayerLGStateConver, TestOfflineToLoginCreatingMap)
{
	BOOL	  bResult	 = false;
	int		  nRetCode	 = false;

    CASE_INFO("²âÊÔrsOfflineµÇ¼createingmap", "Íæ¼Ò״̬Ϊ rsOffline");

	KGameServerSimulator GS;
	SCOPEPROTOCOL(&GS, r2s_handshake_respond);
	SCOPEPROTOCOL(&GS, r2s_create_map_notify);

	ASSERT_TRUE(GS.Connect("127.0.0.1", GCSETTING->m_nGameServerPort, GCSETTING->m_nGatewayPingCycle));
	GS.DoHandshakeRequest();

	KGThread_Sleep(500);

	std::list<IKG_Buffer*>& List = GS.GetProtocolData(r2s_create_map_notify);
	ASSERT_TRUE(!List.empty());
	std::list<IKG_Buffer*>::iterator Iter = List.begin();
	R2S_CREATE_MAP_NOTIFY* p = (R2S_CREATE_MAP_NOTIFY*)((*Iter)->GetData());

    m_BaseData.BaseInfo.CurrentPos.dwMapID = p->dwMapID;
    m_BaseData.BaseInfo.CurrentPos.nMapCopyIndex = p->nMapCopyIndex;

	nRetCode = GATEWAY->DoGameLoginRequest(m_TestRoleInfo.szAccount, m_TestRoleInfo.dwPlayerID, m_BaseData);
	ASSERT_TRUE(nRetCode);

    R2G_GAME_LOGIN_RESPOND GameLoginRespond;
    nRetCode = GATEWAY->CheckGameLoginRespond(&GameLoginRespond);
    ASSERT_TRUE(nRetCode);
    ASSERT_TRUE(GameLoginRespond.byCode == (BYTE)eGameLoginQueueWait);
    ASSERT_TRUE(GameLoginRespond.dwRoleID == m_TestRoleInfo.dwPlayerID);

	nRetCode = ComparePlayerState(m_TestRoleInfo.dwPlayerID, rsOffline);
	ASSERT_TRUE(nRetCode);
}
Ejemplo n.º 10
0
void KGatewaytest::TestUserLoginPaysysNeedTokenClientDisconnectedPaysysNoRespond()   // caseID:24739
{
    int nResult  = false;
    int nRetCode = false;
    char szTestCaseDscribe[] = "// caseID:24739:,测试Paysys正常登陆,GameCenter返回Client玩家不在线,玩家设置了令牌密保,但玩家输入密保密码,但paysys不返回验证结果,玩家断线";
    unsigned    nLoopTimes   = 100;
    int HadRevUserLoginOut = false;

    KGLogPrintf(KGLOG_INFO, "caseID:24739\n");

    FillTestUserLoginInfo(KG_USER_MIBAO, ACTION_SUCCESS, AccountUserLoginInfo,  PASSPODMODE_ZPTOKEN, ACTION_SUCCESS, false, false, ACTION_SUCCESS, true);

    nRetCode = InitTestEnvironment(true, true, true, 1, m_GatewayTestConfig.ForecastConfig.nTestPoint);
    KGLOG_PROCESS_ERROR(nRetCode);

    nRetCode = m_pClientController->FillOperate(
        3,
        onConnectToGateway,
        onHandShake,
        onAccountVerify
        //onMibaoVerify
    );
    KGLOG_PROCESS_ERROR(nRetCode);

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

    Idle(70);
    nRetCode = m_pPaysys->SetNotHandleProtocol(74);//B2P_PLAYER_PASSPOD_VERIFY = 74
    KGLOG_PROCESS_ERROR(nRetCode);
    nRetCode = m_pClientController->AddOperateToClient(0, 2, onMibaoVerify, onDisConnect);
    KGLOG_PROCESS_ERROR(nRetCode);
    Idle(70);

    while(true)
    {
        KGThread_Sleep(100);
        nRetCode = m_pPaysys->HadRevUserLoginOut("0", &HadRevUserLoginOut);
        KGLOG_PROCESS_ERROR(nRetCode);
        KG_PROCESS_SUCCESS(HadRevUserLoginOut);

        nLoopTimes--;
        KGLOG_PROCESS_ERROR(nLoopTimes);
    }

Exit1:
    nResult = true;
Exit0:
    UnInitTestEnvironment();
#ifdef WIN32
    {
        KG_CASE_INFO(szTestCaseDscribe, "");
        KG_CPPUNIT_ASSERT(nResult);
    }
#else
    {
        //InsertInfo(CASEPURPOSE, (szTestCaseDscribe));
        //InsertInfo(PRECONDITION, (""));
        CPPUNIT_ASSERT(nResult);
    }
#endif
}
Ejemplo n.º 11
0
BOOL MySQL_Query(MYSQL* pHandle, const char cszSQL[], unsigned* puRetMySQLErrorCode /*= NULL*/)
{
    BOOL        bResult             = false;
    int         nRetCode            = false;
    int         nReconnectTimes     = 0;
    unsigned    uMySQLErrorCode     = 0;
    size_t      uStrLen             = strlen(cszSQL);

    assert(pHandle);
    assert(cszSQL);
    
    while (true) 
    {
        nRetCode = mysql_real_query(pHandle, cszSQL, (unsigned long)uStrLen);
        if (nRetCode == 0)
            break;

        uMySQLErrorCode = mysql_errno(pHandle);

        if (
            (uMySQLErrorCode != CR_SERVER_LOST) &&
            (uMySQLErrorCode != CR_CONN_HOST_ERROR) &&
            (uMySQLErrorCode != CR_SERVER_GONE_ERROR)
        )
        {
            KGLogPrintf(                                                        
                KGLOG_ERR,                                                    
                "[DB] Call \"mysql_real_query\" failed : %s\n",
                mysql_error(pHandle)
            );  
            goto Exit0;
        }
        
        while (nReconnectTimes < 5)
        { 
            nRetCode = mysql_ping(pHandle);
            if (nRetCode == 0)
                break;

            KGThread_Sleep(300);
            ++nReconnectTimes;
        }
        
        if (nReconnectTimes >= 5)
        {
            KGLogPrintf(                                                        
                KGLOG_ERR,                                                    
                "[DB] Call \"mysql_ping\" failed : %s\n",
                mysql_error(pHandle)
            );
            
            goto Exit0;
        }
    }

    bResult = true;
Exit0:
    if (puRetMySQLErrorCode)
    {
        *puRetMySQLErrorCode = uMySQLErrorCode;
    }
    return bResult; 
}
Ejemplo n.º 12
0
Archivo: main.cpp Proyecto: viticm/pap2
int Run()
{
	int nResult  = false;
	int nRetCode = false;

	char cCmd;
	const char cszCommandTip[] = "\n\n"
		"==========================================\n"
		"       1.Smart Create Robot               \n"
		"       2.Create Robot                     \n"
		"       3.Destroy Robot                    \n"
		"       4.Destroy All                      \n"        
		"       5.Connect List                     \n"
		"       6.Statistic                        \n"
		"       7.ReInit Monstre                   \n"
		"       8.Exit                             \n"
		"==========================================\n"
		"Select:";

	while (true)
	{
		printf(cszCommandTip);

		fflush(stdin);
		cCmd = getchar();

		switch(cCmd)
		{
		case '1':
			g_CtrlMgr.CreatMonsterSmart(InputRobotNumber(),InputCpuLimit());
			break;
		case '2':
			g_CtrlMgr.CreatMonster(InputConnectID(), InputRobotNumber());
			break;
		case '3':
			g_CtrlMgr.DestroyMonster(InputConnectID(), InputRobotNumber());
			break;
		case '4':            
			printf("***WARNING*** To Exit Monster?\n[yes/no]:");
			if (Affirm())
				g_CtrlMgr.DestroyAllMonster(InputConnectID());
			break;
		case '5':
			g_CtrlMgr.QueryMonsterList();
			break;
		case '6':
			g_CtrlMgr.Statistic();
			break;
		case '7':
			g_CtrlMgr.ReInitMonster();
			printf("reinit monster success\n");
			break;
		case '8':
			printf("***WARNING*** To Exit Monster?\n[yes/no]:");
			nRetCode = Affirm();
			KG_PROCESS_SUCCESS(nRetCode);
			break;
		default:
			printf(cszCommandTip);
			break;
		}
		KGThread_Sleep(100);
	}

Exit1:
	nResult = true;
	return nResult;
}
Ejemplo n.º 13
0
BOOL ComparePlayerState(DWORD dwPlayerID, KROLE_STATE eState)
{
	KGThread_Sleep(500); //µÈ´ýGC¸Ä±äÍæ¼Ò״̬
	return GC->RoleSate(dwPlayerID) == eState;
}
Ejemplo n.º 14
0
int KGatewaytest::InitTestEnvironment(
      int nNeedPaysys, 
      int nNeedRelay,
      int nNeedGateway, 
      int nClinetCount,
      int nTestPoint
)
{
    int     nResult                 = false;    
    int     nRetCode                = false;
    int     nPaysysHadConnected     = false;
    int     nRelayHadConnected      = false;

    KGLOG_PROCESS_ERROR(m_nHadReadTheConfig);
    KGLOG_PROCESS_ERROR(m_pPaysys);
    KGLOG_PROCESS_ERROR(m_pRelay);
    if (nClinetCount > 0)
    {
        KGLOG_PROCESS_ERROR(m_pClientController);
    }
    
#ifndef WIN32
    {
        Idle(20);
    }
#endif

    nRetCode = m_pGatewayMonitor->Init();
    KGLOG_PROCESS_ERROR(nRetCode);
    m_nGatewayMonitorInitFlag = true;

    if (nNeedPaysys)
    {
        for (int i = 0; i < 10; i++)
        {
            nRetCode = m_pPaysys->Init(m_GatewayTestConfig.PaysysManagerConfig);
            if (nRetCode)
            {
                break;
            }
        }
        
        KGLOG_PROCESS_ERROR(nRetCode);
        m_nPaysysInitFlag = true;
    }

    if (nNeedRelay)
    {
        for (int i = 0; i < 10; i++)
        {
            nRetCode = m_pRelay->Init(m_GatewayTestConfig.GameCenterConfig);
            if (nRetCode)
            {
                break;
            }
        }
        KGLOG_PROCESS_ERROR(nRetCode);
        m_nRelayInitFlag = true;
    }

    //if (nNeedGateway)
    //{
    //    KGThread_Sleep(100);
    //    #ifdef WIN32
    //        LPSECURITY_ATTRIBUTES processA = NULL;//Default
    //        LPSECURITY_ATTRIBUTES threadA = NULL;//Default
    //        BOOL shareRights = TRUE;//Default
    //        DWORD creationMask = CREATE_NEW_CONSOLE;//Window per process.
    //        LPVOID enviroment = NULL;//Default
    //        LPSTR curDir = NULL;//Default
    //        STARTUPINFO startInfo;//Result

    //        ZeroMemory(&startInfo, sizeof(startInfo));
    //        startInfo.cb = sizeof(startInfo);
    //        
    //        startInfo.dwFlags = STARTF_USESHOWWINDOW;
    //        startInfo.wShowWindow = SW_MINIMIZE;
    //        //startInfo.wShowWindow = SW_HIDE;
    //        for (int i = 0; i < 10; i++)
    //        {
    //            nRetCode = CreateProcess(
    //                NULL,//File name of executable
    //                m_GatewayTestConfig.m_szGatewayPath,//command line
    //                processA,//Process inherited security
    //                threadA, //Thread inherited security
    //                shareRights,//Rights propagation
    //                creationMask,//various creation flags
    //                enviroment,//Enviroment variable
    //                curDir,           //Child's current directory
    //                &startInfo,
    //                &m_GWprocInfo
    //            );
    //            if (nRetCode)
    //            {
    //                break;
    //            }
    //        }
    //        KGLOG_PROCESS_ERROR(nRetCode);

    //        m_nGatewayInitFlag = true;
    //    #else
    //        m_nGWpid = fork();
    //        if (m_nGWpid < 0)
    //        {
    //            goto Exit0;
    //        }
    //        else
    //        {
    //            if (m_nGWpid == 0)
    //            {
    //                execv("SO3Gateway_LinuxD", NULL);
    //                exit(0);
    //            }
    //        }
    //        m_nGatewayInitFlag = true;
    //    #endif
    //}
    if (nNeedGateway)
    {
        KGThread_Sleep(100);
        nRetCode = m_pGateway->Init();
        KGLOG_PROCESS_ERROR(nRetCode);
        m_nGatewayInitFlag = true;

        nRetCode = m_GatewayWorkThread.Create(GatewayWorkThreadFunction, this);
        KGLOG_PROCESS_ERROR(nRetCode);
        m_nGatewayWorkThreadFlag = true;
    }

    while (true)
    {
        nRetCode = m_pPaysys->HadConnections(&nPaysysHadConnected);
        KGLOG_PROCESS_ERROR(nRetCode);

        nRetCode = m_pRelay->HadConnections(&nRelayHadConnected);
        KGLOG_PROCESS_ERROR(nRetCode);

        if (nPaysysHadConnected && nRelayHadConnected)
        {
            break;
        }
    }

    if (m_GatewayTestConfig.PaysysManagerConfig.nPaysysLostconnect)
    {
        m_pPaysys->AllDisConnected(true);
    }

    if (nClinetCount > 0)
    {
        KGThread_Sleep(1000);
        nRetCode = m_pClientController->Init(m_GatewayTestConfig.ClientConfig, nTestPoint, nClinetCount);
        KGLOG_PROCESS_ERROR(nRetCode);
        m_nClientControllerInitFlag = true;
    }

    nResult  = true; 
Exit0:
    if (!nResult)
    {
        if (m_nClientControllerInitFlag)
        {
            m_pClientController->UnInit();
            m_nClientControllerInitFlag = false;
        }
        if (m_nGatewayWorkThreadFlag)
        {
            m_pGateway->Quit();
            KGThread_Sleep(100);

            m_GatewayWorkThread.Destroy();
            m_nGatewayWorkThreadFlag = false;
        }
        if (m_nGatewayInitFlag)
        {
            m_pGateway->UnInit();
            m_nGatewayInitFlag = false;
        }
        if (m_nRelayInitFlag)
        {
            m_pRelay->UnInit();
            m_nRelayInitFlag = false;
        }
        if (m_nPaysysInitFlag)
        {
            m_pPaysys->UnInit();
            m_nPaysysInitFlag = false;
        }
    }
    return nResult;
}
Ejemplo n.º 15
0
void KGatewaytest::UnInitTestEnvironment()
{
    if (m_nClientControllerInitFlag)
    {
        m_pClientController->UnInit();   
        m_nClientControllerInitFlag = false;
    }

    if (m_nGatewayWorkThreadFlag)
    {
        m_pGateway->Quit();
        KGThread_Sleep(10);
        m_GatewayWorkThread.Destroy();
        m_nGatewayWorkThreadFlag = false;
    }

    if (m_nGatewayInitFlag)
    {
        m_pGateway->UnInit();
        m_nGatewayInitFlag = false;
    }

    if (m_nRelayInitFlag)
    {
        m_pRelay->UnInit();  
        m_nRelayInitFlag = false;
    }
    if (m_nPaysysInitFlag)
    {
        m_pPaysys->UnInit();
        m_nPaysysInitFlag = false;
    }
//#ifdef WIN32
//    if (m_nGatewayInitFlag)
//    {
//
//        m_pGatewayMonitor->DoE2LStop();
//
//        HWND hGWwnd = ::FindWindow(NULL, m_GatewayTestConfig.m_szGatewayPath);
//        ::PostMessage(hGWwnd, WM_CHAR, ' ', NULL);
//
//        ::WaitForSingleObject(m_GWprocInfo.hProcess, 20000);
//        if (hGWwnd)
//        {
//            TerminateProcess(m_GWprocInfo.hProcess, 0);
//        }
//        else
//        {
//            KGLogPrintf(KGLOG_INFO, "SO3Gateway没正常关闭,之后的用例有可能执行不到\n");
//        }
//        // Close process and thread handles. 
//        ::CloseHandle(m_GWprocInfo.hProcess);
//        ::CloseHandle(m_GWprocInfo.hThread);
//    }
//#else
//    if (m_nGatewayInitFlag)
//    {
//        int nGWPid;
//        int nRet;
//
//        m_pGatewayMonitor->DoE2LGetPid();
//        KGThread_Sleep(1000);
//        m_pGatewayMonitor->GetGatewayPid(&nGWPid);
//
//        m_pGatewayMonitor->DoE2LStop();
//
//        nRet = waitpid(nGWPid, NULL, 0);  
//
//        KGThread_Sleep(6000);  //在linux下保证其他用例初始化环境时成功
//        m_nGatewayInitFlag = false;
//    }
//#endif

    if (m_pGatewayMonitor)
    {
        m_pGatewayMonitor->UnInit();
        m_nGatewayMonitorInitFlag = false;
    }
    m_nHadReadTheConfig = false;
}