Session checking on startup and compatibility fixes

This commit is contained in:
Simon 2011-02-04 12:16:45 +00:00
parent dd5ca12223
commit aef66fbfe3
2 changed files with 91 additions and 13 deletions

View File

@ -1181,9 +1181,10 @@ int main(int argc, char *argv[])
pixel *vid_buf=calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE); pixel *vid_buf=calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE);
pixel *pers_bg=calloc((XRES+BARSIZE)*YRES, PIXELSIZE); pixel *pers_bg=calloc((XRES+BARSIZE)*YRES, PIXELSIZE);
void *http_ver_check; 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] = ""; 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 #ifdef INTERNAL
int vs = 0; int vs = 0;
#endif #endif
@ -1285,6 +1286,10 @@ int main(int argc, char *argv[])
#else #else
http_ver_check = http_async_req_start(NULL, "http://" SERVER "/Update.api?Action=CheckVersion", NULL, 0, 0); http_ver_check = http_async_req_start(NULL, "http://" SERVER "/Update.api?Action=CheckVersion", NULL, 0, 0);
#endif #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()) while (!sdl_poll())
{ {
@ -1367,6 +1372,74 @@ int main(int argc, char *argv[])
} }
do_check = (do_check+1) & 15; 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) if (sdl_key=='q' || sdl_key==SDLK_ESCAPE)
{ {

View File

@ -92,7 +92,7 @@ void strlist_free(struct strlist **list)
void save_presets(int do_update) void save_presets(int do_update)
{ {
FILE *f=fopen("powder.def", "wb"); 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; unsigned char tmp = sdl_scale;
if (!f) if (!f)
return; return;
@ -136,7 +136,7 @@ void load_presets(void)
if (!f) if (!f)
return; return;
fread(sig, 1, 4, f); 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) if (sig[0]==0x4D && sig[1]==0x6F && sig[2]==0x46 && sig[3]==0x6F)
{ {
@ -158,15 +158,20 @@ void load_presets(void)
remove("powder.def"); remove("powder.def");
return; return;
} }
if (load_string(f, svf_user, 63)) if(sig[3]==0x66){
goto fail; if (load_string(f, svf_user, 63))
//if (load_string(f, svf_pass, 63)) goto fail;
//goto fail; if (load_string(f, svf_pass, 63))
if (load_string(f, svf_user_id, 63)) goto fail;
goto fail; } else {
if (load_string(f, svf_session_id, 63)) if (load_string(f, svf_user, 63))
goto fail; goto fail;
svf_login = !!svf_user[0]; 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) if (fread(&tmp, 1, 1, f) != 1)
goto fail; goto fail;
sdl_scale = (tmp == 2) ? 2 : 1; sdl_scale = (tmp == 2) ? 2 : 1;