summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBryan Hoyle <starfoxprime@gmail.com>2011-08-24 00:28:55 (GMT)
committer Bryan Hoyle <starfoxprime@gmail.com>2011-08-24 00:28:55 (GMT)
commitf577c319db982e6b3d3b3731f1980c89182da982 (patch)
treebba8666efd304f70392a5659c4b84107008f1ea9 /src
parent03ee03ed1e735352082fa35a06444bbf389bf9c6 (diff)
downloadpowder-f577c319db982e6b3d3b3731f1980c89182da982.zip
powder-f577c319db982e6b3d3b3731f1980c89182da982.tar.gz
Working tpt.getscriptid(<string: id>). Retrieves and runs a script from online
Diffstat (limited to 'src')
-rw-r--r--src/interface.c1
-rw-r--r--src/luaconsole.c79
2 files changed, 79 insertions, 1 deletions
diff --git a/src/interface.c b/src/interface.c
index 5679a5f..de226f3 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -1191,7 +1191,6 @@ void login_ui(pixel *vid_buf)
strcpy(svf_user, ed1.str);
md5_ascii(svf_pass, (unsigned char *)ed2.str, 0);
-
res = http_multipart_post(
"http://" SERVER "/Login.api",
NULL, NULL, NULL,
diff --git a/src/luaconsole.c b/src/luaconsole.c
index 186764d..c56c1a3 100644
--- a/src/luaconsole.c
+++ b/src/luaconsole.c
@@ -2,6 +2,11 @@
#include <powder.h>
#include <console.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;
int step_functions[6] = {0, 0, 0, 0, 0, 0};
@@ -56,6 +61,7 @@ void luacon_open(){
{"setfire", &luatpt_setfire},
{"setdebug", &luatpt_setdebug},
{"setfpscap",&luatpt_setfpscap},
+ {"getscriptid",&luatpt_getscriptid},
{NULL,NULL}
};
@@ -1062,4 +1068,77 @@ int fpscap = luaL_optint(l, 1, 0);
limitFPS = fpscap;
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