Browse Source

Make UruLauncher use curl as well

--HG--
rename : Sources/example_server.ini => example_server.ini
Michael Hansen 14 years ago
parent
commit
c8cf53df80
  1. 2
      Sources/Plasma/Apps/plClient/winmain.cpp
  2. 3
      Sources/Plasma/Apps/plUruLauncher/CMakeLists.txt
  3. 136
      Sources/Plasma/Apps/plUruLauncher/Main.cpp
  4. 4
      Sources/Plasma/Apps/plUruLauncher/Pch.h
  5. 0
      example_server.ini

2
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];

3
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)

136
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_t>(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;
}

4
Sources/Plasma/Apps/plUruLauncher/Pch.h

@ -37,9 +37,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include <process.h>
#include <time.h>
#include <winsock2.h>
#include <windows.h>
#include <WinHttp.h>
#include <curl/curl.h>
#include "pnUtils/pnUtils.h"
#include "pnNetBase/pnNetBase.h"

0
Sources/example_server.ini → example_server.ini

Loading…
Cancel
Save