Working tpt.getscriptid(<string: id>). Retrieves and runs a script from online

This commit is contained in:
Bryan Hoyle 2011-08-23 20:28:55 -04:00
parent 03ee03ed1e
commit f577c319db
4 changed files with 81 additions and 2 deletions

View File

@ -7,7 +7,7 @@ PY_INCPATH := $(shell $(PY_BIN) -c "import os.path,sys;print os.path.join(sys.ex
PY_LDFLAGS := $(shell $(PY_BIN) -c "import distutils.sysconfig;print distutils.sysconfig.get_config_var('LINKFORSHARED')") PY_LDFLAGS := $(shell $(PY_BIN) -c "import distutils.sysconfig;print distutils.sysconfig.get_config_var('LINKFORSHARED')")
PYCOMMAND := $(PY_BIN) getheader.py PYCOMMAND := $(PY_BIN) getheader.py
CFLAGS := -w -std=c99 -D_POSIX_C_SOURCE=200112L -DLUACONSOLE -DGRAVFFT -Iincludes/ CFLAGS := -w -std=c99 -D_POSIX_C_SOURCE=200112L -DLUACONSOLE -DGRAVFFT -Iincludes/ -D_GNU_SOURCE
OFLAGS := -O3 -ffast-math -ftree-vectorize -funsafe-math-optimizations OFLAGS := -O3 -ffast-math -ftree-vectorize -funsafe-math-optimizations
LFLAGS := -lpthread -lSDL -lfftw3f -lm -lbz2 -lX11 -llua5.1 #-lpython$(PY_VERSION) -L$(PY_LIBPATH) -I$(PY_INCPATH) $(PY_LDFLAGS) LFLAGS := -lpthread -lSDL -lfftw3f -lm -lbz2 -lX11 -llua5.1 #-lpython$(PY_VERSION) -L$(PY_LIBPATH) -I$(PY_INCPATH) $(PY_LDFLAGS)
LFLAGS_X := -lm -lbz2 -lSDLmain -I/Library/Frameworks/Python.framework/Versions/$(PY_VERSION)/include/python$(PY_VERSION) LFLAGS_X := -lm -lbz2 -lSDLmain -I/Library/Frameworks/Python.framework/Versions/$(PY_VERSION)/include/python$(PY_VERSION)

View File

@ -67,4 +67,5 @@ int luatpt_heat(lua_State* l);
int luatpt_setfire(lua_State* l); int luatpt_setfire(lua_State* l);
int luatpt_setdebug(lua_State* l); int luatpt_setdebug(lua_State* l);
int luatpt_setfpscap(lua_State* l); int luatpt_setfpscap(lua_State* l);
int luatpt_getscriptid(lua_State* l);
#endif #endif

View File

@ -1191,7 +1191,6 @@ void login_ui(pixel *vid_buf)
strcpy(svf_user, ed1.str); strcpy(svf_user, ed1.str);
md5_ascii(svf_pass, (unsigned char *)ed2.str, 0); md5_ascii(svf_pass, (unsigned char *)ed2.str, 0);
res = http_multipart_post( res = http_multipart_post(
"http://" SERVER "/Login.api", "http://" SERVER "/Login.api",
NULL, NULL, NULL, NULL, NULL, NULL,

View File

@ -2,6 +2,11 @@
#include <powder.h> #include <powder.h>
#include <console.h> #include <console.h>
#include <luaconsole.h> #include <luaconsole.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <string.h>
#include <sys/types.h>
lua_State *l; lua_State *l;
int step_functions[6] = {0, 0, 0, 0, 0, 0}; int step_functions[6] = {0, 0, 0, 0, 0, 0};
@ -56,6 +61,7 @@ void luacon_open(){
{"setfire", &luatpt_setfire}, {"setfire", &luatpt_setfire},
{"setdebug", &luatpt_setdebug}, {"setdebug", &luatpt_setdebug},
{"setfpscap",&luatpt_setfpscap}, {"setfpscap",&luatpt_setfpscap},
{"getscriptid",&luatpt_getscriptid},
{NULL,NULL} {NULL,NULL}
}; };
@ -1062,4 +1068,77 @@ int fpscap = luaL_optint(l, 1, 0);
limitFPS = fpscap; limitFPS = fpscap;
return 0; return 0;
} }
int luatpt_getscriptid(lua_State* l)
{
int sock, port, numrec;
struct sockaddr_in serv_addr;
struct hostent *server;
char * id;
char * filedatabuffer[1024];
id = mystrdup(luaL_optstring(l, 1, "1"));
for (int i = 0; i < strlen(id);i++)
if(id[i]>57||id[i]<48){
luaL_error(l, "Invalid ID format.");
return 0;
}
port = 10457;
sock = socket(AF_INET, SOCK_STREAM, 0);
server = gethostbyname(SERVER);
//server = gethostbyname("localhost");
if (server == NULL) {
luaL_error(l, "Error fetching host IP.");
return 0;
}
bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
bcopy((char *)server->h_addr,
(char *)&serv_addr.sin_addr.s_addr,
server->h_length);
serv_addr.sin_port = htons(port);
if (connect(sock,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0) {
luaL_error(l, "Error connecting to host.");
return 0;
}
char newid[80];
char file[80];
strcpy(file,id);
strcat(file,".lua");
FILE *filetowriteto;
filetowriteto=fopen(file, "w");
strcpy(newid,id);
strcat(newid,"\n");
write(sock,newid,strlen(newid));
while(1){
bzero(filedatabuffer,1024);
numrec = read(sock,filedatabuffer,1024);
if(numrec<0){
luaL_error(l, "Transfer Error");
return 0;
}
fputs(filedatabuffer,filetowriteto);
if(numrec<=1)
{
break;
}
if(numrec<1024)
break;
}
fclose(filetowriteto);
char tempstr[120];
strcpy(tempstr,"dofile(\"");
strcat(tempstr,file);
strcat(tempstr,"\")");
luacon_eval(tempstr);
return 0;
}
#endif #endif