summaryrefslogtreecommitdiffhomepage
path: root/Stars45/Authorization.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Stars45/Authorization.cpp')
-rw-r--r--Stars45/Authorization.cpp238
1 files changed, 119 insertions, 119 deletions
diff --git a/Stars45/Authorization.cpp b/Stars45/Authorization.cpp
index a0dd411..a6c5084 100644
--- a/Stars45/Authorization.cpp
+++ b/Stars45/Authorization.cpp
@@ -1,15 +1,15 @@
/* Project Starshatter 4.5
- Destroyer Studios LLC
- Copyright © 1997-2004. All Rights Reserved.
+ Destroyer Studios LLC
+ Copyright © 1997-2004. All Rights Reserved.
- SUBSYSTEM: Stars.exe
- FILE: Authorization.cpp
- AUTHOR: John DiCamillo
+ SUBSYSTEM: Stars.exe
+ FILE: Authorization.cpp
+ AUTHOR: John DiCamillo
- OVERVIEW
- ========
- Authorization Sprite animation class
+ OVERVIEW
+ ========
+ Authorization Sprite animation class
*/
#include "MemDebug.h"
@@ -22,111 +22,111 @@
static Text GetCDKeyFromRegistry()
{
- Text cdkey;
- BYTE cdbuf[64];
- DWORD cdlen = 0;
- HKEY hkey = 0;
+ Text cdkey;
+ BYTE cdbuf[64];
+ DWORD cdlen = 0;
+ HKEY hkey = 0;
- ZeroMemory(cdbuf, sizeof(cdbuf));
+ ZeroMemory(cdbuf, sizeof(cdbuf));
- RegOpenKeyEx(HKEY_LOCAL_MACHINE,
- "SOFTWARE\\Matrix Games\\Starshatter",
- 0,
- KEY_QUERY_VALUE,
- &hkey);
+ RegOpenKeyEx(HKEY_LOCAL_MACHINE,
+ "SOFTWARE\\Matrix Games\\Starshatter",
+ 0,
+ KEY_QUERY_VALUE,
+ &hkey);
- if (hkey) {
- cdlen = 64;
+ if (hkey) {
+ cdlen = 64;
- LONG result =
- RegQueryValueEx(hkey,
- "authorized",
- NULL,
- NULL,
- cdbuf,
- &cdlen);
+ LONG result =
+ RegQueryValueEx(hkey,
+ "authorized",
+ NULL,
+ NULL,
+ cdbuf,
+ &cdlen);
- if (result == ERROR_SUCCESS && cdlen > 0)
- cdkey = (const char*) cdbuf;
+ if (result == ERROR_SUCCESS && cdlen > 0)
+ cdkey = (const char*) cdbuf;
- RegCloseKey(hkey);
- }
+ RegCloseKey(hkey);
+ }
- return cdkey;
+ return cdkey;
}
static Text GetCDKeyFromIniFile()
{
- Text cdkey;
- char cdbuf[256];
+ Text cdkey;
+ char cdbuf[256];
- ZeroMemory(cdbuf, sizeof(cdbuf));
+ ZeroMemory(cdbuf, sizeof(cdbuf));
- FILE* f = fopen("maga.mg", "r");
- if (f) {
- bool found_section = false;
+ FILE* f = fopen("maga.mg", "r");
+ if (f) {
+ bool found_section = false;
- while (fgets(cdbuf, sizeof(cdbuf)-1, f)) {
- Text line = Text(cdbuf).trim();
- line.setSensitive(false);
+ while (fgets(cdbuf, sizeof(cdbuf)-1, f)) {
+ Text line = Text(cdbuf).trim();
+ line.setSensitive(false);
- if (line == "[SerialNumber]")
- found_section = true;
+ if (line == "[SerialNumber]")
+ found_section = true;
- if (found_section) {
- if (line.indexOf("serial") == 0) {
- // found the proper line in the proper section,
- // now we need to parse the 'name = value' sentence:
+ if (found_section) {
+ if (line.indexOf("serial") == 0) {
+ // found the proper line in the proper section,
+ // now we need to parse the 'name = value' sentence:
- const char* p = line.data();
+ const char* p = line.data();
- // find the equal sign:
- while (p && *p && *p != '=')
- p++;
+ // find the equal sign:
+ while (p && *p && *p != '=')
+ p++;
- // skip the equal sign:
- p++;
+ // skip the equal sign:
+ p++;
- // find the string after the equal sign:
- while (p && *p && isspace(*p))
- p++;
+ // find the string after the equal sign:
+ while (p && *p && isspace(*p))
+ p++;
- if (p && *p) {
- // deal with quoted strings:
- int cutoff = sizeof(cdbuf)-1;
+ if (p && *p) {
+ // deal with quoted strings:
+ int cutoff = sizeof(cdbuf)-1;
- if (*p == '"') {
- char* s = cdbuf;
- p++;
+ if (*p == '"') {
+ char* s = cdbuf;
+ p++;
- while (*p && *p != '"' && cutoff-- > 0) {
- *s++ = *p++;
- }
+ while (*p && *p != '"' && cutoff-- > 0) {
+ *s++ = *p++;
+ }
- *s = 0;
- }
+ *s = 0;
+ }
- // and unquoted strings:
- else {
- char* s = cdbuf;
+ // and unquoted strings:
+ else {
+ char* s = cdbuf;
- while (*p && cutoff-- > 0) {
- *s++ = *p++;
- }
+ while (*p && cutoff-- > 0) {
+ *s++ = *p++;
+ }
- *s = 0;
- }
+ *s = 0;
+ }
- cdkey = cdbuf;
- }
- }
- }
- }
+ cdkey = cdbuf;
+ }
+ }
+ }
+ }
- fclose(f);
- }
+ fclose(f);
+ }
- return cdkey;
+ return cdkey;
}
// +--------------------------------------------------------------------+
@@ -137,15 +137,15 @@ int execRegistrationProgram();
bool
Authorization::IsUserAuthorized()
{
- // XXX DEBUG ONLY!
- // return true;
+ // XXX DEBUG ONLY!
+ // return true;
- int authcode = execRegistrationProgram();
- if (authcode != 1) {
- ::Print("Authorization failed, code = %d\n", authcode);
- }
+ int authcode = execRegistrationProgram();
+ if (authcode != 1) {
+ ::Print("Authorization failed, code = %d\n", authcode);
+ }
- return (authcode == 1);
+ return (authcode == 1);
}
// +--------------------------------------------------------------------+
@@ -153,50 +153,50 @@ Authorization::IsUserAuthorized()
const char*
Authorization::GetSerialNumber()
{
- return serial_number;
+ return serial_number;
}
// +--------------------------------------------------------------------+
int execRegistrationProgram()
{
- int result = 999;
- char cmdline[256];
- strcpy(cmdline, "SS2rez");
+ int result = 999;
+ char cmdline[256];
+ strcpy(cmdline, "SS2rez");
- STARTUPINFO s;
- ZeroMemory(&s, sizeof(s));
- s.cb = sizeof(s);
+ STARTUPINFO s;
+ ZeroMemory(&s, sizeof(s));
+ s.cb = sizeof(s);
- PROCESS_INFORMATION pi;
- ZeroMemory(&pi, sizeof(pi));
+ PROCESS_INFORMATION pi;
+ ZeroMemory(&pi, sizeof(pi));
- if (CreateProcess("SS2rez.exe", cmdline, 0, 0, 0, 0, 0, 0, &s, &pi)) {
- DWORD exitcode = STILL_ACTIVE;
+ if (CreateProcess("SS2rez.exe", cmdline, 0, 0, 0, 0, 0, 0, &s, &pi)) {
+ DWORD exitcode = STILL_ACTIVE;
- WaitForSingleObject(pi.hProcess, 20000);
- GetExitCodeProcess(pi.hProcess, &exitcode);
+ WaitForSingleObject(pi.hProcess, 20000);
+ GetExitCodeProcess(pi.hProcess, &exitcode);
- if (exitcode != STILL_ACTIVE)
- result = exitcode;
+ if (exitcode != STILL_ACTIVE)
+ result = exitcode;
- CloseHandle(pi.hProcess);
- CloseHandle(pi.hThread);
- }
- else {
- TCHAR message[256];
- DWORD errcode = GetLastError();
+ CloseHandle(pi.hProcess);
+ CloseHandle(pi.hThread);
+ }
+ else {
+ TCHAR message[256];
+ DWORD errcode = GetLastError();
- ::Print(" WARN: Failed to create authorization process: %08X.\n", errcode);
+ ::Print(" WARN: Failed to create authorization process: %08X.\n", errcode);
- if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, errcode, 0, message, 256, 0)) {
- ::Print(" ");
- ::Print(message);
- ::Print("\n");
- }
- }
+ if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, errcode, 0, message, 256, 0)) {
+ ::Print(" ");
+ ::Print(message);
+ ::Print("\n");
+ }
+ }
- return result;
+ return result;
}