summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon <simon@hardwired.org.uk>2011-02-04 12:16:45 (GMT)
committer Simon <simon@hardwired.org.uk>2011-02-04 12:16:45 (GMT)
commitaef66fbfe3738924a3c7a39d53693df60dd2867a (patch)
tree458f7c5e7beba3046ef7a70b36f6d916250adf22 /src
parentdd5ca12223db92a9a9731e6dfd31708af724025c (diff)
downloadpowder-aef66fbfe3738924a3c7a39d53693df60dd2867a.zip
powder-aef66fbfe3738924a3c7a39d53693df60dd2867a.tar.gz
Session checking on startup and compatibility fixes
Diffstat (limited to 'src')
-rw-r--r--src/main.c77
-rw-r--r--src/misc.c27
2 files changed, 91 insertions, 13 deletions
diff --git a/src/main.c b/src/main.c
index 8c3afd7..69aa5a8 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1181,9 +1181,10 @@ int main(int argc, char *argv[])
pixel *vid_buf=calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE);
pixel *pers_bg=calloc((XRES+BARSIZE)*YRES, PIXELSIZE);
void *http_ver_check;
- char *ver_data=NULL, *tmp;
+ void *http_session_check;
+ char *ver_data=NULL, *check_data=NULL, *tmp;
char console_error[255] = "";
- int i, j, bq, fire_fc=0, do_check=0, old_version=0, http_ret=0, major, minor, old_ver_len;
+ int i, j, bq, fire_fc=0, do_check=0, do_s_check=0, old_version=0, http_ret=0,http_s_ret=0, major, minor, old_ver_len;
#ifdef INTERNAL
int vs = 0;
#endif
@@ -1285,6 +1286,10 @@ int main(int argc, char *argv[])
#else
http_ver_check = http_async_req_start(NULL, "http://" SERVER "/Update.api?Action=CheckVersion", NULL, 0, 0);
#endif
+ if(svf_login){
+ http_session_check = http_async_req_start(NULL, "http://" SERVER "/Login.api?Action=CheckSession", NULL, 0, 0);
+ http_auth_headers(http_session_check, svf_user_id, NULL, svf_session_id);
+ }
while (!sdl_poll())
{
@@ -1367,6 +1372,74 @@ int main(int argc, char *argv[])
}
do_check = (do_check+1) & 15;
}
+ if(http_session_check)
+ {
+ if(!do_s_check && http_async_req_status(http_session_check))
+ {
+ check_data = http_async_req_stop(http_session_check, &http_s_ret, NULL);
+ if(http_ret==200 && check_data)
+ {
+ printf("{%s}\n", check_data);
+ if(!strncmp(check_data, "EXPIRED", 7))
+ {
+ //Session expired
+ strcpy(svf_user, "");
+ strcpy(svf_pass, "");
+ strcpy(svf_user_id, "");
+ strcpy(svf_session_id, "");
+ svf_login = 0;
+ svf_own = 0;
+ svf_admin = 0;
+ svf_mod = 0;
+ }
+ else if(!strncmp(check_data, "BANNED", 6))
+ {
+ //User banned
+ strcpy(svf_user, "");
+ strcpy(svf_pass, "");
+ strcpy(svf_user_id, "");
+ strcpy(svf_session_id, "");
+ svf_login = 0;
+ svf_own = 0;
+ svf_admin = 0;
+ svf_mod = 0;
+ }
+ else if(!strncmp(check_data, "OK", 2))
+ {
+ //Session valid
+ if(strlen(check_data)>2){
+ //User is elevated
+ if (!strncmp(check_data+3, "ADMIN", 5))
+ {
+ svf_admin = 1;
+ svf_mod = 0;
+ }
+ else if (!strncmp(check_data+3, "MOD", 3))
+ {
+ svf_admin = 0;
+ svf_mod = 1;
+ }
+ }
+ save_presets(0);
+ }
+ else
+ {
+ //No idea, but log the user out anyway
+ strcpy(svf_user, "");
+ strcpy(svf_pass, "");
+ strcpy(svf_user_id, "");
+ strcpy(svf_session_id, "");
+ svf_login = 0;
+ svf_own = 0;
+ svf_admin = 0;
+ svf_mod = 0;
+ }
+ free(check_data);
+ }
+ http_session_check = NULL;
+ }
+ do_s_check = (do_s_check+1) & 15;
+ }
if (sdl_key=='q' || sdl_key==SDLK_ESCAPE)
{
diff --git a/src/misc.c b/src/misc.c
index 702ff03..c98c5a3 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -92,7 +92,7 @@ void strlist_free(struct strlist **list)
void save_presets(int do_update)
{
FILE *f=fopen("powder.def", "wb");
- unsigned char sig[4] = {0x50, 0x44, 0x65, 0x66};
+ unsigned char sig[4] = {0x50, 0x44, 0x65, 0x67};
unsigned char tmp = sdl_scale;
if (!f)
return;
@@ -136,7 +136,7 @@ void load_presets(void)
if (!f)
return;
fread(sig, 1, 4, f);
- if (sig[0]!=0x50 || sig[1]!=0x44 || sig[2]!=0x65 || sig[3]!=0x66)
+ if (sig[0]!=0x50 || sig[1]!=0x44 || sig[2]!=0x65)
{
if (sig[0]==0x4D && sig[1]==0x6F && sig[2]==0x46 && sig[3]==0x6F)
{
@@ -158,15 +158,20 @@ void load_presets(void)
remove("powder.def");
return;
}
- if (load_string(f, svf_user, 63))
- goto fail;
- //if (load_string(f, svf_pass, 63))
- //goto fail;
- if (load_string(f, svf_user_id, 63))
- goto fail;
- if (load_string(f, svf_session_id, 63))
- goto fail;
- svf_login = !!svf_user[0];
+ if(sig[3]==0x66){
+ if (load_string(f, svf_user, 63))
+ goto fail;
+ if (load_string(f, svf_pass, 63))
+ goto fail;
+ } else {
+ if (load_string(f, svf_user, 63))
+ goto fail;
+ if (load_string(f, svf_user_id, 63))
+ goto fail;
+ if (load_string(f, svf_session_id, 63))
+ goto fail;
+ }
+ svf_login = !!svf_session_id[0];
if (fread(&tmp, 1, 1, f) != 1)
goto fail;
sdl_scale = (tmp == 2) ? 2 : 1;