Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bin/libcurl.dll
Binary file not shown.
Binary file added bin/libeay32.dll
Binary file not shown.
Binary file added bin/ssleay32.dll
Binary file not shown.
7 changes: 6 additions & 1 deletion blakserv/account.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ void InitAccount(void)
console_account->last_login_time = 0;
console_account->suspend_time = 0;
console_account->credits = 0;
console_account->verified = 0;
}

void ResetAccount(void)
Expand Down Expand Up @@ -134,6 +135,7 @@ Bool CreateAccount(char *name,char *password,int type,int *account_id)
a->last_login_time = 0;
a->suspend_time = 0;
a->credits = 100*ConfigInt(CREDIT_INIT);
a->verified = 0;

InsertAccount(a);

Expand Down Expand Up @@ -170,6 +172,7 @@ int CreateAccountSecurePassword(char *name,char *password,int type)
a->last_login_time = 0;
a->suspend_time = 0;
a->credits = 100*ConfigInt(CREDIT_INIT);
a->verified = 0;

InsertAccount(a);

Expand Down Expand Up @@ -215,14 +218,15 @@ int RecreateAccountSecurePassword(int account_id,char *name,char *password,int t
a->last_login_time = 0;
a->suspend_time = 0;
a->credits = 100*ConfigInt(CREDIT_INIT);
a->verified = 0;

InsertAccount(a);

return a->account_id;
}

void LoadAccount(int account_id,char *name,char *password,int type,int last_login_time,
int suspend_time, int credits)
int suspend_time, int credits, int verified)
{
account_node *a;

Expand All @@ -241,6 +245,7 @@ void LoadAccount(int account_id,char *name,char *password,int type,int last_logi
a->last_login_time = last_login_time;
a->suspend_time = suspend_time;
a->credits = credits;
a->verified = verified;

InsertAccount(a);
}
Expand Down
3 changes: 2 additions & 1 deletion blakserv/account.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ typedef struct account_node_struct
int credits; /* remember, stored as 1/100 of a credit */
int last_login_time;
int suspend_time;
int verified;
struct account_node_struct *next;
} account_node;

Expand All @@ -36,7 +37,7 @@ Bool CreateAccount(char *name,char *password,int type,int *account_id);
int CreateAccountSecurePassword(char *name,char *password,int type);
int RecreateAccountSecurePassword(int account_id,char *name,char *password,int type);
void LoadAccount(int account_id,char *name,char *password,int type,int last_login_time,
int suspend_time, int credits);
int suspend_time, int credits, int verified);
Bool DeleteAccount(int account_id);
void SetAccountName(account_node *a,char *name);
void SetAccountPassword(account_node *a,char *password);
Expand Down
85 changes: 85 additions & 0 deletions blakserv/httpauth.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#include "blakserv.h"

CURL *curl;
CURLcode res;

void LoadCurl(void)
{
curl_global_init(CURL_GLOBAL_WIN32);
lprintf("Loading cURL: %s",curl_version());
}

void AuthenticateHttp()
{
curl = curl_easy_init();

struct HttpResponse response;

response.rdata = (char*)malloc(1);
response.size = 0;

if(curl)
{
curl_easy_setopt(curl, CURLOPT_USERAGENT, CURL_USER_AGENT);

#ifdef CURL_USE_SSL
curl_easy_setopt(curl, CURLOPT_URL, HTTPS_AUTH_URL);

#ifdef CURL_SKIP_PEER_VERIFICATION
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
#endif CURL_SKIP_PEER_VERIFICATION

#ifdef CURL_SKIP_HOSTNAME_VERIFICATION
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
#endif CURL_SKIP_HOSTNAME_VERIFICATION

#else // No CURL_USE_SSL
curl_easy_setopt(curl, CURLOPT_URL, HTTP_AUTH_URL);
#endif CURL_USE_SSL

curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, httpResponseToMemoryCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&response);

res = curl_easy_perform(curl);

if(res != CURLE_OK)
{
eprintf("HTTP authentication failed: %s\n",
curl_easy_strerror(res));
}
else
{
// got a response, process it
lprintf("Http authentication: received server response.\n");
}
}

if(response.rdata)
free(response.rdata);

curl_easy_cleanup(curl);
}

static size_t httpResponseToMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp)
{
size_t realsize = size * nmemb;
struct HttpResponse *response = (struct HttpResponse *)userp;

response->rdata = (char*) realloc(response->rdata, response->size + realsize + 1);
if(response->rdata == NULL) {
/* out of memory! */
eprintf("Http authentication failed: Not enough memory to store server response.\n");
return 0;
}

memcpy(&(response->rdata[response->size]), contents, realsize);
response->size += realsize;
response->rdata[response->size] = 0;

return realsize;
}

void UnloadCurl(void)
{
curl_global_cleanup();
}
26 changes: 26 additions & 0 deletions blakserv/httpauth.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <curl/curl.h>

#ifndef _HTTP_AUTH
#define _HTTP_AUTH

#define CURL_USER_AGENT "blakserv-agent/1.0"

#define HTTP_AUTH_URL "http://white.treyhome.com/m59auth"
#define HTTPS_AUTH_URL "https://white.treyhome.com/m59auth"

// SSL Options (Currently Disabled)
//#define CURL_USE_SSL
//#define CURL_SKIP_PEER_VERIFICATION
//#define CURL_SKIP_HOSTNAME_VERIFICATION

struct HttpResponse {
char *rdata;
size_t size;
};

void LoadCurl(void);
void AuthenticateHttp();
static size_t httpResponseToMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp);
void UnloadCurl(void);

#endif
31 changes: 23 additions & 8 deletions blakserv/loadacco.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ static int highestAccount = -1;
/* local function prototypes */
Bool LoadLineAccount(char *account_str,char *name_str,char *password_str,
char *type_str,char *last_login_str,char *suspend_str,
char *credits_str);
char *credits_str, char *verified_str);

Bool LoadAccounts(char *filename)
{
FILE *accofile;
char line[MAX_ACCOUNT_LINE+1];
char *type_str,*t1,*t2,*t3,*t4,*t5,*t6,*t7;
char *type_str,*t1,*t2,*t3,*t4,*t5,*t6,*t7,*t8;
int nextAccountID = -1;

if ((accofile = fopen(filename,"rt")) == NULL)
Expand All @@ -70,15 +70,29 @@ Bool LoadAccounts(char *filename)
t4 = strtok(NULL,":\n");
t5 = strtok(NULL,":\n");
t6 = strtok(NULL,":\n");
t7 = strtok(NULL,":\n");

/* t7 is suspend_str, note different order from LoadLineAccount args */
t7 = strtok(NULL,":\n");

/* t8 is a boolean that indicates the account is verified on the
openmeridian forums. If t8 is null then the line in the account file
is of the old format and the account is unverified. Replace the null
with 0 in this case, and the line will be of the new format next
savegame */
t8 = strtok(NULL,":\n");

if (t8 == NULL)
{
eprintf("found old account format, updating.");
t8 = "0\0";
}

if (*type_str == '#')
continue;

if (!stricmp(type_str,"ACCOUNT"))
{
if (!LoadLineAccount(t1,t2,t3,t4,t5,t7,t6))
if (!LoadLineAccount(t1,t2,t3,t4,t5,t7,t6,t8))
{
fclose(accofile);
return False;
Expand Down Expand Up @@ -109,9 +123,9 @@ Bool LoadAccounts(char *filename)

Bool LoadLineAccount(char *account_str,char *name_str,char *password_str,
char *type_str,char *last_login_str,char *suspend_str,
char *credits_str)
char *credits_str, char* verified_str)
{
int account_id,type,last_login_time,suspend_time,credits;
int account_id,type,last_login_time,suspend_time,credits,verified;
int index;
char decoded[100];
char *ptr,*end_password;
Expand All @@ -124,7 +138,8 @@ Bool LoadLineAccount(char *account_str,char *name_str,char *password_str,
sscanf(account_str,"%i",&account_id) != 1 ||
sscanf(type_str,"%i",&type) != 1 ||
sscanf(last_login_str,"%i",&last_login_time) != 1 ||
sscanf(credits_str,"%i",&credits) != 1)
sscanf(credits_str,"%i",&credits) != 1 ||
sscanf(verified_str,"%i",&verified) != 1 )
{
eprintf("LoadLineAccount (%i) found invalid account\n",lineno);
return False;
Expand Down Expand Up @@ -156,7 +171,7 @@ Bool LoadLineAccount(char *account_str,char *name_str,char *password_str,
highestAccount = account_id;
}

LoadAccount(account_id,name_str,decoded,type,last_login_time,suspend_time,credits);
LoadAccount(account_id,name_str,decoded,type,last_login_time,suspend_time,credits,verified);
return True;
}

Expand Down
3 changes: 3 additions & 0 deletions blakserv/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ OBJS = \
$(OUTDIR)\files.obj \
$(OUTDIR)\sprocket.obj \
$(OUTDIR)\database.obj \
$(OUTDIR)\httpauth.obj \

all : makedirs $(OUTDIR)\blakserv.exe

Expand All @@ -110,5 +111,7 @@ $(OUTDIR)\blakserv.exe: $(OBJS) $(OUTDIR)\blakserv.res
$(CP) $(BLAKLIBDIR)\libmysql.dll $(BLAKSERVRUNDIR) >nul
$(CP) $(BLAKBINDIR)\libcurl.dll $(BLAKSERVRUNDIR) >nul
$(CP) $(BLAKBINDIR)\jansson.dll $(BLAKSERVRUNDIR) >nul
$(CP) $(BLAKBINDIR)\libeay32.dll $(BLAKSERVRUNDIR)
$(CP) $(BLAKBINDIR)\ssleay32.dll $(BLAKSERVRUNDIR)

!include $(TOPDIR)\rules.mak
4 changes: 2 additions & 2 deletions blakserv/saveacco.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ void SaveEachAccount(account_node *a)
if (a->password[0] == 0)
fprintf(accofile,"None");

fprintf(accofile,":%i:%i:%i:%i\n",a->type,a->last_login_time,
a->credits,a->suspend_time);
fprintf(accofile,":%i:%i:%i:%i:%i\n",a->type,a->last_login_time,
a->credits,a->suspend_time,a->verified);
}
Loading