Пример #1
0
ApplicationFail Application::Init() {
    BeforeInit();

    if ( glfwInit() == false ) { return ApplicationFail::GLFW_INIT; }

    window_glfw_ = glfwCreateWindow( 1280, 720, name_string_.c_str(), nullptr, nullptr );
    if ( window_glfw_ == nullptr ) {
        glfwTerminate();
        return ApplicationFail::GLFW_CREATE_WINDOW;
    }
    glfwMakeContextCurrent( window_glfw_ );

    if ( ogl_LoadFunctions() == ogl_LOAD_FAILED ) {
        glfwDestroyWindow( window_glfw_ );
        glfwTerminate();
        return ApplicationFail::OGL_LOAD_FUNCTIONS;
    }

    const int OGL_MAJOR = ogl_GetMajorVersion();
    const int OGL_MINOR = ogl_GetMinorVersion();
    printf( "OpenGL Version: %i.%i\n", OGL_MAJOR, OGL_MINOR );

    glClearColor( 0.25f, 0.25f, 0.25f, 1.0f );
    glEnable( GL_DEPTH_TEST );

    time_previous_d_ = glfwGetTime();

    InputDevice::Init( window_glfw_ );

    AfterInit();

    return ApplicationFail::NONE;
}
Пример #2
0
void CRequest::Run()
{
	if(BeforeInit())
	{
		m_State = HTTP_ERROR;
		return;
	}

	CURL *pHandle = curl_easy_init();
	if(!pHandle)
	{
		m_State = HTTP_ERROR;
		return;
	}

	if(g_Config.m_DbgCurl)
	{
		curl_easy_setopt(pHandle, CURLOPT_VERBOSE, 1L);
	}
	char aErr[CURL_ERROR_SIZE];
	curl_easy_setopt(pHandle, CURLOPT_ERRORBUFFER, aErr);

	if(m_CanTimeout)
	{
		curl_easy_setopt(pHandle, CURLOPT_CONNECTTIMEOUT_MS, (long)g_Config.m_ClHTTPConnectTimeoutMs);
		curl_easy_setopt(pHandle, CURLOPT_LOW_SPEED_LIMIT, (long)g_Config.m_ClHTTPLowSpeedLimit);
		curl_easy_setopt(pHandle, CURLOPT_LOW_SPEED_TIME, (long)g_Config.m_ClHTTPLowSpeedTime);
	}
	else
	{
		curl_easy_setopt(pHandle, CURLOPT_CONNECTTIMEOUT_MS, 0L);
		curl_easy_setopt(pHandle, CURLOPT_LOW_SPEED_LIMIT, 0L);
		curl_easy_setopt(pHandle, CURLOPT_LOW_SPEED_TIME, 0L);
	}
	curl_easy_setopt(pHandle, CURLOPT_SHARE, gs_Share);
	curl_easy_setopt(pHandle, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
	curl_easy_setopt(pHandle, CURLOPT_FOLLOWLOCATION, 1L);
	curl_easy_setopt(pHandle, CURLOPT_MAXREDIRS, 4L);
	curl_easy_setopt(pHandle, CURLOPT_FAILONERROR, 1L);
	curl_easy_setopt(pHandle, CURLOPT_URL, m_aUrl);
	curl_easy_setopt(pHandle, CURLOPT_NOSIGNAL, 1L);
	curl_easy_setopt(pHandle, CURLOPT_USERAGENT, "DDNet " GAME_RELEASE_VERSION " (" CONF_PLATFORM_STRING "; " CONF_ARCH_STRING ")");

	// We only trust our own custom-selected CAs for our own servers.
	// Other servers can use any CA trusted by the system.
	if(false
		|| str_comp_nocase_num("maps.ddnet.tw/", m_aUrl, 14) == 0
		|| str_comp_nocase_num("http://maps.ddnet.tw/", m_aUrl, 21) == 0
		|| str_comp_nocase_num("https://maps.ddnet.tw/", m_aUrl, 22) == 0
		|| str_comp_nocase_num("http://info.ddnet.tw/", m_aUrl, 21) == 0
		|| str_comp_nocase_num("https://info.ddnet.tw/", m_aUrl, 22) == 0
		|| str_comp_nocase_num("https://update4.ddnet.tw/", m_aUrl, 25) == 0)
	{
		curl_easy_setopt(pHandle, CURLOPT_CAINFO, CA_FILE_PATH);
	}
	curl_easy_setopt(pHandle, CURLOPT_WRITEDATA, this);
	curl_easy_setopt(pHandle, CURLOPT_WRITEFUNCTION, WriteCallback);
	curl_easy_setopt(pHandle, CURLOPT_NOPROGRESS, 0L);
	curl_easy_setopt(pHandle, CURLOPT_PROGRESSDATA, this);
	curl_easy_setopt(pHandle, CURLOPT_PROGRESSFUNCTION, ProgressCallback);

	if(AfterInit(pHandle))
	{
		curl_easy_cleanup(pHandle);
		m_State = HTTP_ERROR;
		return;
	}

	dbg_msg("http", "http %s", m_aUrl);
	m_State = HTTP_RUNNING;
	int Ret = curl_easy_perform(pHandle);
	BeforeCompletion();
	if(Ret != CURLE_OK)
	{
		dbg_msg("http", "task failed. libcurl error: %s", aErr);
		m_State = (Ret == CURLE_ABORTED_BY_CALLBACK) ? HTTP_ABORTED : HTTP_ERROR;
	}
	else
	{
		dbg_msg("http", "task done %s", m_aUrl);
		m_State = HTTP_DONE;
	}

	curl_easy_cleanup(pHandle);

	OnCompletion();
}