Merge branch 'upstream' into dev

Conflicts:
	src/powder.c
This commit is contained in:
jacksonmj
2011-02-04 19:59:50 +00:00
5 changed files with 189 additions and 48 deletions

View File

@@ -8,9 +8,9 @@
#endif
#define SAVE_VERSION 46
#define MINOR_VERSION 0
#define MINOR_VERSION 1
#define IDENT_VERSION "G" //Change this if you're not Simon! It should be a single letter.
//#define BETA
#define BETA
#define SERVER "powdertoy.co.uk"

View File

@@ -441,7 +441,7 @@ static const part_type ptypes[PT_NUM] =
{"FIRW", PIXPACK(0xFFA040), 0.7f, 0.02f * CFDS, 0.96f, 0.80f, -0.99f, 0.1f, 0.00f, 0.000f * CFDS, 1, 0, 0, 0, 30, 1, 55, SC_EXPLOSIVE, R_TEMP+0.0f +273.15f, 70, "Fireworks!", ST_SOLID, TYPE_PART, &update_FIRW},
{"FUSE", PIXPACK(0x0A5706), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.0f, 0.0f * CFDS, 0, 0, 0, 0, 20, 1, 100, SC_SOLIDS, R_TEMP+0.0f +273.15f, 200, "Solid. Burns slowly. Ignites at somewhat high temperatures and electricity.", ST_SOLID, TYPE_SOLID, &update_FUSE},
{"FSEP", PIXPACK(0x63AD5F), 0.7f, 0.02f * CFDS, 0.96f, 0.80f, 0.0f, 0.1f, 0.00f, 0.000f * CFDS, 1, 0, 0, 0, 30, 1, 70, SC_POWDERS, R_TEMP+0.0f +273.15f, 70, "Fuse Powder. See FUSE.", ST_SOLID, TYPE_PART, &update_FSEP},
{"AMTR", PIXPACK(0x808080), 0.7f, 0.02f * CFDS, 0.96f, 0.80f, 0.00f, 0.10f, 1.00f, 0.0000f * CFDS, 0, 0, 0, 0, 0, 1, 100, SC_NUCLEAR, R_TEMP+0.0f +273.15f, 70, "Anti-Matter, Destroys a majority of particles", ST_NONE, TYPE_PART, NULL}, //Maybe TYPE_ENERGY?
{"AMTR", PIXPACK(0x808080), 0.7f, 0.02f * CFDS, 0.96f, 0.80f, 0.00f, 0.10f, 1.00f, 0.0000f * CFDS, 0, 0, 0, 0, 0, 1, 100, SC_NUCLEAR, R_TEMP+0.0f +273.15f, 70, "Anti-Matter, Destroys a majority of particles", ST_NONE, TYPE_PART, &update_AMTR}, //Maybe TYPE_ENERGY?
{"BCOL", PIXPACK(0x333333), 0.4f, 0.04f * CFDS, 0.94f, 0.95f, -0.1f, 0.3f, 0.00f, 0.000f * CFDS, 1, 0, 0, 5, 2, 1, 90, SC_POWDERS, R_TEMP+0.0f +273.15f, 150, "Broken Coal. Heavy particles. See COAL", ST_SOLID, TYPE_PART, &update_BCOL},
{"PCLN", PIXPACK(0x3B3B10), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 100, SC_ELEC, R_TEMP+0.0f +273.15f, 251, "Solid. When activated, duplicates any particles it touches.", ST_NONE, TYPE_SOLID, &update_PCLN},
{"HSWC", PIXPACK(0x3B1010), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 1, 1, 1, 100, SC_ELEC, R_TEMP+0.0f +273.15f, 251, "Heat switch. Conducts Heat only when activated", ST_NONE, TYPE_SOLID, &update_HSWC},

View File

@@ -867,7 +867,7 @@ void login_ui(pixel *vid_buf)
if (res && !strncmp(res, "OK ", 3))
{
char *s_id,*u_e,*nres;
printf("\n{%s}\n", res);
printf("{%s}\n", res);
s_id = strchr(res+3, ' ');
if (!s_id)
goto fail;
@@ -885,7 +885,7 @@ void login_ui(pixel *vid_buf)
strcpy(svf_session_id, s_id);
nres = mystrdup(u_e);
printf("\n{%s} {%s} {%s}\n", svf_user_id, svf_session_id, nres);
printf("{%s} {%s} {%s}\n", svf_user_id, svf_session_id, nres);
if (!strncmp(nres, "ADMIN", 5))
{
@@ -3965,6 +3965,7 @@ int console_parse_type(char *txt, int *element, char *err)
if (strcmp(txt,num)==0)
{
*element = i;
strcpy(err,"");
return 1;
}
}
@@ -3976,12 +3977,14 @@ int console_parse_type(char *txt, int *element, char *err)
if (i>=0)
{
*element = i;
strcpy(err,"");
return 1;
}
for (i=1; i<PT_NUM; i++) {
if (strcasecmp(txt,ptypes[i].name)==0)
{
*element = i;
strcpy(err,"");
return 1;
}
}
@@ -3991,32 +3994,20 @@ int console_parse_type(char *txt, int *element, char *err)
int console_parse_coords(char *txt, int *x, int *y, char *err)
{
// TODO: use regex?
char *coordtxt;
char num[10] = "";
int nx = -1, ny = -1;
txt = mystrdup(txt);
coordtxt = strtok(txt, ",");
if (coordtxt) nx = atoi(coordtxt);
if (nx>=0 && nx<XRES) sprintf(num,"%d",nx);
if (!coordtxt || strcmp(coordtxt, num)!=0)
sscanf(txt,"%d,%d",&nx,&ny);
if (nx<0 && nx>=XRES)
{
strcpy(err,"Invalid coordinates");
free(txt);
return 0;
}
strcpy(num,"");
coordtxt = strtok(NULL, ",");
if (coordtxt) ny = atoi(coordtxt);
if (ny>=0 && ny<YRES) sprintf(num,"%d",ny);
if (!coordtxt || strcmp(coordtxt, num)!=0)
if (ny<0 && ny>=YRES)
{
strcpy(err,"Invalid coordinates");
free(txt);
return 0;
}
*x = nx;
*y = ny;
free(txt);
return 1;
}
int console_parse_partref(char *txt, int *which, char *err)
@@ -4044,6 +4035,7 @@ int console_parse_partref(char *txt, int *which, char *err)
if (i>=0 && i<NPART && parts[i].type)
{
*which = i;
strcpy(err,"");
return 1;
}
strcpy(err,"Particle does not exist");

View File

@@ -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)
{
@@ -1780,7 +1853,7 @@ int main(int argc, char *argv[])
console = console_ui(vid_buf,console_error);
console = mystrdup(console);
strcpy(console_error,"");
if(process_command(vid_buf,console,&console_error)==0)
if(process_command(vid_buf,console,&console_error)==-1)
{
free(console);
break;
@@ -2626,38 +2699,93 @@ int main(int argc, char *argv[])
return 0;
}
int process_command(pixel *vid_buf,char *console,char *console_error) {
int nx,ny,i,j,k;
char *console2;
char *console3;
char *console4;
char *console5;
int y,x,nx,ny,i,j,k,m;
int do_next = 1;
char xcoord[10];
char ycoord[10];
char console2[15];
char console3[15];
char console4[15];
char console5[15];
//sprintf(console_error, "%s", console);
if(console && strcmp(console, "")!=0 && strncmp(console, " ", 1)!=0)
{
console2 = strtok(console, " ");
console3 = strtok(NULL, " ");
console4 = strtok(NULL, " ");
console5 = strtok(NULL, " ");
sscanf(console,"%14s %14s %14s %14s", console2, console3, console4, console5);//why didn't i know about this function?!
if(strcmp(console2, "quit")==0)
{
return 0;
return -1;
}
else if(strcmp(console2, "file")==0 && console3)
{
FILE *f=fopen(console3, "r");
if(f)
{
nx = 0;
ny = 0;
j = 0;
m = 0;
if(console4)
console_parse_coords(console4, &nx , &ny, console_error);
char fileread[5000];//TODO: make this change with file size
char pch[5000];
memset(pch,0,sizeof(pch));
memset(fileread,0,sizeof(fileread));
char tokens[10];
int tokensize;
fread(fileread,1,5000,f);
j = 0;
for(i=0; i<strlen(fileread); i++)
{
if(fileread[i] != '\n')
pch[i-j] = fileread[i];
else
{
process_command(vid_buf, pch, console_error);
pch[i-j] = fileread[i];
if(fileread[i] != ' ')
tokens[i-m] = fileread[i];
}
if(fileread[i] == ' ' || fileread[i] == '\n')
{
if(sregexp(tokens,"^x.[0-9],y.[0-9]")==0)//TODO: fix regex matching to work with x,y ect, right now it has to have a +0 or -0
{
char temp[5];
int starty = 0;
tokensize = strlen(tokens);
x = 0;
y = 0;
sscanf(tokens,"x%d,y%d",&x,&y);
sscanf(tokens,"%9s,%9s",xcoord,ycoord);
x += nx;
y += ny;
sprintf(xcoord,"%d",x);
sprintf(ycoord,"%d",y);
for(k = 0; k<strlen(xcoord);k++)//rewrite pch with numbers
{
pch[i-j-tokensize+k] = xcoord[k];
starty = k+1;
}
pch[i-j-tokensize+starty] = ',';
starty++;
for(k=0;k<strlen(ycoord);k++)
{
pch[i-j-tokensize+starty+k] = ycoord[k];
}
pch[i-j-tokensize +strlen(xcoord) +1 +strlen(ycoord)] = ' ';
j = j -tokensize +strlen(xcoord) +1 +strlen(ycoord);
}
memset(tokens,0,sizeof(tokens));
m = i+1;
}
if(fileread[i] == '\n')
{
if(do_next)
{
if(strcmp(pch,"else")==0)
do_next = 0;
else
do_next = process_command(vid_buf, pch, console_error);
}
else if(strcmp(pch,"endif")==0 || strcmp(pch,"else")==0)
do_next = 1;
memset(pch,0,sizeof(pch));
j = i+1;
}
@@ -2681,6 +2809,22 @@ int process_command(pixel *vid_buf,char *console,char *console_error) {
console_mode = 0;
}
}
else if(strcmp(console2, "if")==0 && console3)
{
if(strcmp(console3, "type")==0)//TODO: add more than just type, and be able to check greater/less than
{
if (console_parse_partref(console4, &i, console_error)
&& console_parse_type(console5, &j, console_error))
{
if(parts[i].type==j)
return 1;
else
return 0;
}
else
return 0;
}
}
else if (strcmp(console2, "create")==0 && console3 && console4)
{
if (console_parse_type(console3, &j, console_error)

View File

@@ -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;