#pragma once #define WIN32_LEAN_AND_MEAN #include #include #include #include #include #pragma comment(lib, "wininet.lib") namespace AuthEngine { struct ResponseData { bool success = false; std::string message; }; struct UserData { std::string username; std::string subscription; std::string expiry; std::string ip; std::string hwid; }; class api { private: std::string name; std::string ownerid; std::string secret; std::string version; std::string url; std::string sessionid; std::string get_hwid() { HW_PROFILE_INFO hwProfileInfo; if (GetCurrentHwProfile(&hwProfileInfo)) { char buffer[128]; size_t converted = 0; wcstombs_s(&converted, buffer, sizeof(buffer), hwProfileInfo.szHwProfileGuid, _TRUNCATE); return std::string(buffer); } return "DEFAULT_HWID_000"; } std::string http_post(const std::string& post_data) { std::string response; HINTERNET hInternet = InternetOpenA("AuthEngine-SDK/1.2", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); if (!hInternet) return ""; // Parse URL into host and path std::string scheme = "http://"; std::string host = url; std::string path = "/api/1.2/"; INTERNET_PORT port = INTERNET_DEFAULT_HTTP_PORT; if (url.rfind("https://", 0) == 0) { scheme = "https://"; port = INTERNET_DEFAULT_HTTPS_PORT; host = url.substr(8); } else if (url.rfind("http://", 0) == 0) { host = url.substr(7); } size_t slash_pos = host.find('/'); if (slash_pos != std::string::npos) { path = host.substr(slash_pos); host = host.substr(0, slash_pos); } size_t colon_pos = host.find(':'); if (colon_pos != std::string::npos) { port = static_cast(std::stoi(host.substr(colon_pos + 1))); host = host.substr(0, colon_pos); } HINTERNET hConnect = InternetConnectA(hInternet, host.c_str(), port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); if (!hConnect) { InternetCloseHandle(hInternet); return ""; } DWORD flags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE; if (port == INTERNET_DEFAULT_HTTPS_PORT) { flags |= INTERNET_FLAG_SECURE | INTERNET_FLAG_IGNORE_CERT_CN_INVALID | INTERNET_FLAG_IGNORE_CERT_DATE_INVALID; } HINTERNET hRequest = HttpOpenRequestA(hConnect, "POST", path.c_str(), NULL, NULL, NULL, flags, 0); if (!hRequest) { InternetCloseHandle(hConnect); InternetCloseHandle(hInternet); return ""; } std::string headers = "Content-Type: application/x-www-form-urlencoded\r\n"; BOOL sent = HttpSendRequestA(hRequest, headers.c_str(), static_cast(headers.length()), (LPVOID)post_data.c_str(), static_cast(post_data.length())); if (sent) { char buffer[4096]; DWORD bytesRead = 0; while (InternetReadFile(hRequest, buffer, sizeof(buffer) - 1, &bytesRead) && bytesRead > 0) { buffer[bytesRead] = '\0'; response.append(buffer, bytesRead); } } InternetCloseHandle(hRequest); InternetCloseHandle(hConnect); InternetCloseHandle(hInternet); return response; } // Lightweight zero-dependency JSON string extraction std::string extract_json_value(const std::string& json, const std::string& key) { std::string search = "\"" + key + "\":"; size_t pos = json.find(search); if (pos == std::string::npos) return ""; pos += search.length(); while (pos < json.length() && (json[pos] == ' ' || json[pos] == '\"')) pos++; size_t end = pos; if (pos > 0 && json[pos - 1] == '\"') { end = json.find('\"', pos); } else { end = json.find_first_of(",}\n", pos); } if (end == std::string::npos) return ""; return json.substr(pos, end - pos); } bool extract_json_bool(const std::string& json, const std::string& key) { std::string search = "\"" + key + "\":"; size_t pos = json.find(search); if (pos == std::string::npos) return false; pos += search.length(); while (pos < json.length() && json[pos] == ' ') pos++; return json.substr(pos, 4) == "true"; } public: ResponseData response; UserData user_data; api(std::string name, std::string ownerid, std::string secret, std::string version, std::string url) : name(name), ownerid(ownerid), secret(secret), version(version), url(url) {} void init() { std::string data = "type=init&name=" + name + "&ownerid=" + ownerid + "&secret=" + secret + "&ver=" + version; std::string raw = http_post(data); response.success = extract_json_bool(raw, "success"); response.message = extract_json_value(raw, "message"); if (response.success) { sessionid = extract_json_value(raw, "sessionid"); } } void login(std::string username, std::string password) { std::string hwid = get_hwid(); std::string data = "type=login&username=" + username + "&pass=" + password + "&hwid=" + hwid + "&sessionid=" + sessionid + "&name=" + name + "&ownerid=" + ownerid; std::string raw = http_post(data); response.success = extract_json_bool(raw, "success"); response.message = extract_json_value(raw, "message"); if (response.success) { user_data.username = extract_json_value(raw, "username"); user_data.expiry = extract_json_value(raw, "expiry"); user_data.hwid = extract_json_value(raw, "hwid"); user_data.ip = extract_json_value(raw, "ip"); } } void register_user(std::string username, std::string password, std::string key) { std::string hwid = get_hwid(); std::string data = "type=register&username=" + username + "&pass=" + password + "&key=" + key + "&hwid=" + hwid + "&sessionid=" + sessionid + "&name=" + name + "&ownerid=" + ownerid; std::string raw = http_post(data); response.success = extract_json_bool(raw, "success"); response.message = extract_json_value(raw, "message"); if (response.success) { user_data.username = username; user_data.expiry = extract_json_value(raw, "expiry"); } } void license(std::string key) { std::string hwid = get_hwid(); std::string data = "type=license&key=" + key + "&hwid=" + hwid + "&sessionid=" + sessionid + "&name=" + name + "&ownerid=" + ownerid; std::string raw = http_post(data); response.success = extract_json_bool(raw, "success"); response.message = extract_json_value(raw, "message"); if (response.success) { user_data.username = extract_json_value(raw, "username"); user_data.expiry = extract_json_value(raw, "expiry"); user_data.hwid = extract_json_value(raw, "hwid"); } } bool check() { std::string data = "type=check&sessionid=" + sessionid + "&name=" + name + "&ownerid=" + ownerid; std::string raw = http_post(data); return extract_json_bool(raw, "success"); } std::string get_var(std::string varid) { std::string data = "type=var&varid=" + varid + "&sessionid=" + sessionid + "&name=" + name + "&ownerid=" + ownerid; std::string raw = http_post(data); if (extract_json_bool(raw, "success")) { return extract_json_value(raw, "message"); } return ""; } void log(std::string message) { std::string data = "type=log&message=" + message + "&sessionid=" + sessionid + "&name=" + name + "&ownerid=" + ownerid; http_post(data); } }; }