Beispiel #1
0
void MainApp::logIn(const char* user, const char* pass)
{
	gcTrace("User: {0}", user);

	std::lock_guard<std::mutex> a(m_UserLock);

	safe_delete(g_pUserHandle);

	gcString path = UTIL::OS::getAppDataPath();

	g_pUserHandle = (UserCore::UserI*)UserCore::FactoryBuilderUC(USERCORE);
	g_pUserHandle->init(path.c_str(), m_strServiceProvider.c_str());


	try
	{
		//need to do this here as news items will be passed onlogin
		g_pUserHandle->getNewsUpdateEvent() += delegate(this, &MainApp::onNewsUpdate);
		g_pUserHandle->getGiftUpdateEvent() += delegate((MainAppNoUI*)this, &MainAppNoUI::onGiftUpdate);
		g_pUserHandle->getNeedCvarEvent() += delegate(this, &MainApp::onNeedCvar);

		g_pUserHandle->lockDelete();
		g_pUserHandle->logIn(user, pass);
		g_pUserHandle->unlockDelete();

#ifndef DEBUG
		if (gc_enable_api_debugging.getBool())
			g_pUserHandle->getWebCore()->enableDebugging();
#endif
	}
	catch (gcException)
	{
		g_pUserHandle->logOut();

		g_pUserHandle->getNewsUpdateEvent() -= delegate(this, &MainApp::onNewsUpdate);
		g_pUserHandle->getGiftUpdateEvent() -= delegate((MainAppNoUI*)this, &MainAppNoUI::onGiftUpdate);
		g_pUserHandle->getNeedCvarEvent() -= delegate(this, &MainApp::onNeedCvar);

		g_pUserHandle->unlockDelete();

		g_pUserHandle->logOut(false, false);
		safe_delete(g_pUserHandle);
		throw;
	}
}
Beispiel #2
0
void MainApp::offlineMode()
{
	if (m_iMode == APP_MODE::MODE_OFFLINE)
		return;

	if (m_bLoggedIn)
		logOut(false);

	closeMainForm();

	{
		std::lock_guard<std::mutex> a(m_UserLock);

		gcString path = UTIL::OS::getAppDataPath();

		if (g_pUserHandle)
			g_pUserHandle->destroy();

		g_pUserHandle = (UserCore::UserI*)UserCore::FactoryBuilderUC(USERCORE);
		g_pUserHandle->init(path.c_str());

		try
		{
			g_pUserHandle->getNeedCvarEvent() += delegate(this, &MainApp::onNeedCvar);
			g_pUserHandle->getItemManager()->loadItems();
		}
		catch (gcException &)
		{
			g_pUserHandle->getNeedCvarEvent() -= delegate(this, &MainApp::onNeedCvar);
			g_pUserHandle->logOut();
			g_pUserHandle->destroy();
			throw;
		}
	}

	GetCVarManager()->loadUser(GetUserCore()->getUserId());
	m_iMode = APP_MODE::MODE_OFFLINE;

	showMainWindow();
	m_pInternalLink = new InternalLink(this);
}