diff --git a/includes/powder.h b/includes/powder.h index 31d57fa71..f6a7b3733 100644 --- a/includes/powder.h +++ b/includes/powder.h @@ -438,7 +438,7 @@ void STKM_interact(playerst* playerp, int i, int x, int y); struct part_type { - const char *name; + char *name; pixel pcolors; float advection; float airdrag; diff --git a/src/console.c b/src/console.c index c9714a173..6d8ffe2f9 100644 --- a/src/console.c +++ b/src/console.c @@ -20,14 +20,14 @@ int console_parse_type(char *txt, int *element, char *err) else if (strcasecmp(txt,"NONE")==0) i = PT_NONE; if (i>=0 && i= PT_NUM || offset==-1) { + free(key); return luaL_error(l, "Invalid property"); } switch(format) @@ -614,6 +619,25 @@ int luacon_elementwrite(lua_State* l){ break; case 2: tempstring = mystrdup(luaL_optstring(l, 3, "")); + if(strcmp(key, "name")==0) + { + int j = 0; + //Convert to upper case + for(j = 0; j < strlen(tempstring); j++) + tempstring[j] = toupper(tempstring[j]); + if(strlen(tempstring)>4) + { + free(tempstring); + free(key); + return luaL_error(l, "Name too long"); + } + if(console_parse_type(tempstring, NULL, NULL)) + { + free(tempstring); + free(key); + return luaL_error(l, "Name in use"); + } + } *((char**)(((void*)&ptypes[i])+offset)) = tempstring; //Need some way of cleaning up previous values break;