From c8cf53df80fb550b4e63afd39818fa5a22541611 Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Sun, 17 Apr 2011 11:53:32 -0700 Subject: [PATCH] Make UruLauncher use curl as well --HG-- rename : Sources/example_server.ini => example_server.ini --- Sources/Plasma/Apps/plClient/winmain.cpp | 2 +- .../Plasma/Apps/plUruLauncher/CMakeLists.txt | 3 +- Sources/Plasma/Apps/plUruLauncher/Main.cpp | 136 +++++------------- Sources/Plasma/Apps/plUruLauncher/Pch.h | 4 +- .../example_server.ini => example_server.ini | 0 5 files changed, 40 insertions(+), 105 deletions(-) rename Sources/example_server.ini => example_server.ini (100%) diff --git a/Sources/Plasma/Apps/plClient/winmain.cpp b/Sources/Plasma/Apps/plClient/winmain.cpp index 2032cb8e..32604a3c 100644 --- a/Sources/Plasma/Apps/plClient/winmain.cpp +++ b/Sources/Plasma/Apps/plClient/winmain.cpp @@ -1196,7 +1196,7 @@ static void LoadUserPass (const wchar *accountName, char *username, ShaDigest *p } } -size_t CurlCallback(void *buffer, size_t size, size_t nmemb, void *param) +static size_t CurlCallback(void *buffer, size_t size, size_t nmemb, void *param) { static char status[256]; diff --git a/Sources/Plasma/Apps/plUruLauncher/CMakeLists.txt b/Sources/Plasma/Apps/plUruLauncher/CMakeLists.txt index 01b34014..4b2daced 100644 --- a/Sources/Plasma/Apps/plUruLauncher/CMakeLists.txt +++ b/Sources/Plasma/Apps/plUruLauncher/CMakeLists.txt @@ -5,6 +5,7 @@ include_directories("../../NucleusLib") include_directories("../../PubUtilLib") include_directories(${OPENSSL_INCLUDE_DIR}) +include_directories(${CURL_INCLUDE_DIR}) set(plUruLauncher_HEADERS Intern.h @@ -56,8 +57,8 @@ target_link_libraries(plUruLauncher ${DirectX_LIBRARIES}) target_link_libraries(plUruLauncher ${OPENSSL_LIBRARIES}) target_link_libraries(plUruLauncher ${Ogg_LIBRARIES}) target_link_libraries(plUruLauncher ${Vorbis_LIBRARIES}) +target_link_libraries(plUruLauncher ${CURL_LIBRARY}) target_link_libraries(plUruLauncher ws2_32) -target_link_libraries(plUruLauncher winhttp) target_link_libraries(plUruLauncher rpcrt4) target_link_libraries(plUruLauncher comctl32) diff --git a/Sources/Plasma/Apps/plUruLauncher/Main.cpp b/Sources/Plasma/Apps/plUruLauncher/Main.cpp index 6dbe555e..3aeb2b1b 100644 --- a/Sources/Plasma/Apps/plUruLauncher/Main.cpp +++ b/Sources/Plasma/Apps/plUruLauncher/Main.cpp @@ -150,6 +150,7 @@ static LISTDECL(WndEvent, link) s_eventQ; static CEvent s_shutdownEvent(kEventManualReset); static wchar s_workingDir[MAX_PATH]; static CEvent s_statusEvent(kEventManualReset); +static char s_curlError[CURL_ERROR_SIZE]; /***************************************************************************** @@ -591,122 +592,51 @@ static bool TGCheckForFrameworkUpdate () } //============================================================================ -static void HttpRequestPost(HINTERNET hConnect) +static size_t CurlCallback(void *buffer, size_t size, size_t nmemb, void *) { - const wchar *path = BuildTypeServerStatusPath(); - HINTERNET hRequest = 0; - char data[256] = {0}; - DWORD bytesRead; - - hRequest = WinHttpOpenRequest( - hConnect, - L"POST", - path, - NULL, - WINHTTP_NO_REFERER, - WINHTTP_DEFAULT_ACCEPT_TYPES, - 0 - ); - if(hRequest) - { - BOOL b = WinHttpSendRequest( - hRequest, - L"Content-Type: application/x-www-form-urlencoded\r\n", - 0, - (void *)s_postKey, - sizeof(s_postKey), - sizeof(s_postKey), - 0 - ); - DWORD err = GetLastError(); - WinHttpReceiveResponse(hRequest, 0); - WinHttpReadData(hRequest, data, arrsize(data)-1, &bytesRead); - data[bytesRead] = 0; - } - if(bytesRead) - SetStatusText(data); - WinHttpCloseHandle(hRequest); -} + static char status[256]; -//============================================================================ -static void HttpRequestGet(HINTERNET hConnect) -{ - const wchar *path = BuildTypeServerStatusPath(); - HINTERNET hRequest = 0; - char data[256] = {0}; - DWORD bytesRead; - - hRequest = WinHttpOpenRequest( - hConnect, - L"GET", - path, - NULL, - WINHTTP_NO_REFERER, - WINHTTP_DEFAULT_ACCEPT_TYPES, - 0 - ); - if(hRequest) - { - BOOL b = WinHttpSendRequest( - hRequest, - WINHTTP_NO_ADDITIONAL_HEADERS, - 0, - WINHTTP_NO_REQUEST_DATA, - 0, - 0, - 0 - ); - if(b) - { - DWORD err = GetLastError(); - WinHttpReceiveResponse(hRequest, 0); - WinHttpReadData(hRequest, data, arrsize(data)-1, &bytesRead); - data[bytesRead] = 0; - } - } - if(bytesRead) - SetStatusText(data); - WinHttpCloseHandle(hRequest); + strncpy(status, (const char *)buffer, std::min(size * nmemb, 256)); + status[255] = 0; + SetStatusText(status); + return size * nmemb; } //============================================================================ static void StatusCallback(void *) { - HINTERNET hSession = 0; - HINTERNET hConnect = 0; + CURL *hCurl; + + char *serverStatus = hsWStringToString(BuildTypeServerStatusPath()); + char serverUrl[256]; + snprintf(serverUrl, 256, "http://support.cyanworlds.com%s", serverStatus); + delete [] serverStatus; + + hCurl = curl_easy_init(); + curl_easy_setopt(hCurl, CURLOPT_ERRORBUFFER, s_curlError); // update while we are running while(!s_shutdown) { if(BuildTypeServerStatusPath()) { - hSession = WinHttpOpen( - L"UruClient/1.0", - WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, - WINHTTP_NO_PROXY_NAME, - WINHTTP_NO_PROXY_BYPASS, - 0 - ); + //TODO: Get a server status path from the server.ini, without + // pulling in all the annoying pfConsole dependencies. + // Alternatively, make a better launcher... + + curl_easy_setopt(hCurl, CURLOPT_USERAGENT, "UruClient/1.0"); + curl_easy_setopt(hCurl, CURLOPT_URL, serverUrl); - if(hSession) + if(StrLen(s_postKey)) { - hConnect = WinHttpConnect( - hSession, - STATUS_PATH, - INTERNET_DEFAULT_HTTP_PORT, - 0 - ); - if(hConnect) - { - if(StrLen(s_postKey)) - HttpRequestPost(hConnect); - else - HttpRequestGet(hConnect); - } + char *safeData = curl_easy_escape(hCurl, s_postKey, strlen(s_postKey)); + curl_easy_setopt(hCurl, CURLOPT_POST, 1); + curl_easy_setopt(hCurl, CURLOPT_POSTFIELDS, safeData); + curl_free(safeData); } - - WinHttpCloseHandle(hConnect); - WinHttpCloseHandle(hSession); + + if (curl_easy_perform(hCurl) != 0) + SetStatusText(s_curlError); } for(unsigned i = 0; i < UPDATE_STATUSMSG_SECONDS && !s_shutdown; ++i) @@ -715,6 +645,8 @@ static void StatusCallback(void *) } } + curl_easy_cleanup(hCurl); + s_statusEvent.Signal(); } @@ -856,6 +788,8 @@ int __stdcall WinMain ( StrPrintf(s_launcherInfo.cmdLine, arrsize(s_launcherInfo.cmdLine), appCmdLine); s_launcherInfo.returnCode = 0; + curl_global_init(CURL_GLOBAL_ALL); + if(!isTempPatcher) { // create window thread @@ -1032,6 +966,8 @@ int __stdcall WinMain ( pTGApp = NULL; } + curl_global_cleanup(); + return s_launcherInfo.returnCode; } diff --git a/Sources/Plasma/Apps/plUruLauncher/Pch.h b/Sources/Plasma/Apps/plUruLauncher/Pch.h index 9207fcd4..8afb21db 100644 --- a/Sources/Plasma/Apps/plUruLauncher/Pch.h +++ b/Sources/Plasma/Apps/plUruLauncher/Pch.h @@ -37,9 +37,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include #include -#include -#include -#include +#include #include "pnUtils/pnUtils.h" #include "pnNetBase/pnNetBase.h" diff --git a/Sources/example_server.ini b/example_server.ini similarity index 100% rename from Sources/example_server.ini rename to example_server.ini