summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/licensing.c36
-rw-r--r--src/licensing.h17
-rw-r--r--src/platform.h1
-rw-r--r--src/windows/platform.c49
4 files changed, 103 insertions, 0 deletions
diff --git a/src/licensing.c b/src/licensing.c
new file mode 100644
index 0000000..8de3604
--- /dev/null
+++ b/src/licensing.c
@@ -0,0 +1,36 @@
+/*
+* BSD 2-Clause “Simplified” License
+* Copyright (c) 2019, Aldrik Ramaekers, aldrik.ramaekers@protonmail.com
+* All rights reserved.
+*/
+
+#include "external/cJSON.h"
+
+static void* validate_license_thread(void *arg)
+{
+ char params[50];
+ sprintf(params, "can_run?ti=%s", license_key);
+
+ char response[MAX_INPUT_LENGTH];
+ if (platform_send_http_request("api.aldrik.org", params, response))
+ {
+ cJSON *result = cJSON_Parse(response);
+ if (!result) return false;
+ cJSON *canRun = cJSON_GetObjectItem(result, "canRun");
+ license_is_valid = canRun->valueint;
+ }
+
+ return 0;
+}
+
+void validate_license()
+{
+ license_is_valid = true;
+
+#ifdef MODE_DEVELOPER
+ return;
+#endif
+
+ thread license_thread = thread_start(validate_license_thread, NULL);
+ thread_detach(&license_thread);
+}
diff --git a/src/licensing.h b/src/licensing.h
new file mode 100644
index 0000000..5255ffd
--- /dev/null
+++ b/src/licensing.h
@@ -0,0 +1,17 @@
+/*
+* BSD 2-Clause “Simplified” License
+* Copyright (c) 2019, Aldrik Ramaekers, aldrik.ramaekers@protonmail.com
+* All rights reserved.
+*/
+
+#ifndef INCLUDE_LICENSING
+#define INCLUDE_LICENSING
+
+// NOTE DO NOT TOUCH THIS!
+char license_key[18] = { "[LICENSELOCATION]" };
+// NOTE DO NOT TOUCH THIS!
+
+bool license_is_valid = true;
+void validate_license();
+
+#endif \ No newline at end of file
diff --git a/src/platform.h b/src/platform.h
index 796226b..5575dcf 100644
--- a/src/platform.h
+++ b/src/platform.h
@@ -188,6 +188,7 @@ bool is_platform_in_darkmode();
void *platform_open_file_dialog_block(void *arg);
char *platform_get_full_path(char *file);
void platform_open_url(char *command);
+bool platform_send_http_request(char *url, char *params, char *response_buffer);
void platform_run_command(char *command);
void platform_window_make_current(platform_window *window);
void platform_init(int argc, char **argv);
diff --git a/src/windows/platform.c b/src/windows/platform.c
index dd7b97f..2172fd5 100644
--- a/src/windows/platform.c
+++ b/src/windows/platform.c
@@ -4,6 +4,7 @@
* All rights reserved.
*/
+#include <wininet.h>
#include <locale.h>
#include <windows.h>
#include <GL/gl.h>
@@ -1270,4 +1271,52 @@ s16 string_to_s16(char *str)
s8 string_to_s8(char *str)
{
return (s8)strtoul(str, 0, 10);
+}
+
+bool platform_send_http_request(char *url, char *params, char *response_buffer)
+{
+ // https://www.unix.com/programming/187337-c-http-get-request-using-sockets.html
+
+ bool response = true;
+ HINTERNET hIntSession = 0;
+ HINTERNET hHttpSession = 0;
+ HINTERNET hHttpRequest = 0;
+
+ hIntSession = InternetOpen("Text-Search", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
+ if (!hIntSession) goto failure;
+
+ hHttpSession = InternetConnect(hIntSession, url, 80, 0, 0, INTERNET_SERVICE_HTTP, 0, 0);
+ if (!hHttpSession) goto failure;
+
+ hHttpRequest = HttpOpenRequest(
+ hHttpSession,
+ "GET",
+ params,
+ 0, 0, 0, INTERNET_FLAG_RELOAD, 0);
+
+
+ char* szHeaders = "Content-Type: application/json";
+ char szReq[1024] = "";
+ if(!HttpSendRequest(hHttpRequest, szHeaders, strlen(szHeaders), szReq, strlen(szReq))) {
+ goto failure;
+ }
+
+ DWORD dwRead=0;
+ while(InternetReadFile(hHttpRequest, response_buffer, MAX_INPUT_LENGTH-1, &dwRead) && dwRead) {
+ response_buffer[dwRead] = 0;
+ dwRead=0;
+ }
+
+ goto done;
+
+ failure:
+ printf("failure");
+ response = false;
+
+ done:
+ InternetCloseHandle(hHttpRequest);
+ InternetCloseHandle(hHttpSession);
+ InternetCloseHandle(hIntSession);
+
+ return response;
} \ No newline at end of file