Potential auth fix

This commit is contained in:
Anonymous275 2021-01-07 15:28:51 +02:00
parent 78875c2c9c
commit 263b6c9c0d
3 changed files with 30 additions and 19 deletions

View File

@ -19,7 +19,5 @@ STRING(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
STRING(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG}) STRING(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
#-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static #-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static
target_link_libraries(${PROJECT_NAME} PRIVATE rstrtmgr discord-rpc CURL::libcurl ZLIB::ZLIB) target_link_libraries(${PROJECT_NAME} PRIVATE rstrtmgr discord-rpc CURL::libcurl ZLIB::ZLIB)
target_include_directories(${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>) target_include_directories(${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)

View File

@ -6,24 +6,37 @@
/// Created by Anonymous275 on 7/18/2020 /// Created by Anonymous275 on 7/18/2020
/// ///
#include "Security/Game.h"
#include <curl/curl.h> #include <curl/curl.h>
#include <iostream> #include <iostream>
#include <mutex> #include <mutex>
class CurlManager{
public:
CurlManager(){
curl = curl_easy_init();
}
~CurlManager(){
curl_easy_cleanup(curl);
}
inline CURL* Get(){
return curl;
}
private:
CURL *curl;
};
static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp){ static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp){
((std::string*)userp)->append((char*)contents, size * nmemb); ((std::string*)userp)->append((char*)contents, size * nmemb);
return size * nmemb; return size * nmemb;
} }
std::string HTTP_REQUEST(const std::string& IP,int port){ std::string HTTP_REQUEST(const std::string& IP,int port){
static thread_local CurlManager M;
static std::mutex Lock; static std::mutex Lock;
Lock.lock(); std::scoped_lock Guard(Lock);
CURL *curl; CURL *curl = M.Get();
CURLcode res; CURLcode res;
std::string readBuffer; std::string readBuffer;
curl = curl_easy_init();
if(curl) { if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, IP.c_str()); curl_easy_setopt(curl, CURLOPT_URL, IP.c_str());
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L);
@ -31,11 +44,10 @@ std::string HTTP_REQUEST(const std::string& IP,int port){
curl_easy_setopt(curl, CURLOPT_PORT, port); curl_easy_setopt(curl, CURLOPT_PORT, port);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);
res = curl_easy_perform(curl); res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
if(res != CURLE_OK)return "-1"; if(res != CURLE_OK)return "-1";
} }
Lock.unlock();
return readBuffer; return readBuffer;
} }
@ -70,10 +82,10 @@ static size_t my_fwrite(void *buffer,size_t size,size_t nmemb,void *stream){
return fwrite(buffer, size, nmemb, out->stream); return fwrite(buffer, size, nmemb, out->stream);
} }
int Download(const std::string& URL,const std::string& Path,bool close){ int Download(const std::string& URL,const std::string& Path,bool close){
CURL *curl; static thread_local CurlManager M;
CURL *curl = M.Get();
CURLcode res; CURLcode res;
struct File file = {Path.c_str(),nullptr}; struct File file = {Path.c_str(),nullptr};
curl = curl_easy_init();
if(curl){ if(curl){
curl_easy_setopt(curl, CURLOPT_URL,URL.c_str()); curl_easy_setopt(curl, CURLOPT_URL,URL.c_str());
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L);
@ -84,7 +96,6 @@ int Download(const std::string& URL,const std::string& Path,bool close){
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_bar); curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_bar);
curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_ALL); curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_ALL);
res = curl_easy_perform(curl); res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
if(res != CURLE_OK)return res; if(res != CURLE_OK)return res;
} }
if(file.stream)fclose(file.stream); if(file.stream)fclose(file.stream);
@ -93,10 +104,13 @@ int Download(const std::string& URL,const std::string& Path,bool close){
} }
std::string PostHTTP(const std::string& IP, const std::string& Fields) { std::string PostHTTP(const std::string& IP, const std::string& Fields) {
static auto *header = new curl_slist{(char*)"Content-Type: application/json"}; static auto *header = new curl_slist{(char*)"Content-Type: application/json"};
CURL* curl; static thread_local CurlManager M;
static std::mutex Lock;
std::scoped_lock Guard(Lock);
CURL* curl = M.Get();
CURLcode res; CURLcode res;
std::string readBuffer; std::string readBuffer;
curl = curl_easy_init();
if (curl) { if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, IP.c_str()); curl_easy_setopt(curl, CURLOPT_URL, IP.c_str());
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header);
@ -105,9 +119,8 @@ std::string PostHTTP(const std::string& IP, const std::string& Fields) {
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 5); curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);
res = curl_easy_perform(curl); res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
if (res != CURLE_OK) if (res != CURLE_OK)
return "-1"; return "-1";
} }

View File

@ -25,7 +25,7 @@ std::string GetVer(){
return "1.80"; return "1.80";
} }
std::string GetPatch(){ std::string GetPatch(){
return ".93"; return ".94";
} }
void ReLaunch(int argc,char*args[]){ void ReLaunch(int argc,char*args[]){
std::string Arg; std::string Arg;
@ -167,7 +167,7 @@ void CustomPort(int argc, char* argv[]){
warn("Running on custom port : " + std::to_string(DEFAULT_PORT)); warn("Running on custom port : " + std::to_string(DEFAULT_PORT));
} }
} }
if(argc > 2)Dev = false; if(argc > 2)Dev = true;
} }
} }
void InitLauncher(int argc, char* argv[]) { void InitLauncher(int argc, char* argv[]) {
@ -178,7 +178,7 @@ void InitLauncher(int argc, char* argv[]) {
CheckName(argc, argv); CheckName(argc, argv);
CheckLocalKey(); //will replace RequestRole CheckLocalKey(); //will replace RequestRole
Discord_Main(); Discord_Main();
Dev = true; //Dev = true;
//RequestRole(); //RequestRole();
CustomPort(argc, argv); CustomPort(argc, argv);
CheckForUpdates(argc, argv, std::string(GetVer()) + GetPatch()); CheckForUpdates(argc, argv, std::string(GetVer()) + GetPatch());