Use HTTP instead of sockets
This commit is contained in:
parent
309ec4b07a
commit
80e10460b8
@ -1078,11 +1078,9 @@ int luatpt_getscriptid(lua_State* l)
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
int sock, port, numrec;
|
|
||||||
struct sockaddr_in serv_addr;
|
|
||||||
struct hostent *server;
|
|
||||||
char * id;
|
char * id;
|
||||||
char * filedatabuffer[1024];
|
|
||||||
id = mystrdup(luaL_optstring(l, 1, "1"));
|
id = mystrdup(luaL_optstring(l, 1, "1"));
|
||||||
for (int i = 0; i < strlen(id);i++)
|
for (int i = 0; i < strlen(id);i++)
|
||||||
if(id[i]>57||id[i]<48){
|
if(id[i]>57||id[i]<48){
|
||||||
@ -1090,64 +1088,38 @@ int luatpt_getscriptid(lua_State* l)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(!confirm_ui(vid_buf,"Do you want to install script?",id,"Install"))
|
if(!confirm_ui(vid_buf,"Do you want to install script?",id,"Install"))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
port = 10457;
|
|
||||||
sock = socket(AF_INET, SOCK_STREAM, 0);
|
|
||||||
|
|
||||||
server = gethostbyname("chaos.powdertoy.co.uk");
|
|
||||||
//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];
|
char file[80];
|
||||||
|
char addr[300];
|
||||||
|
strcpy(addr,"http://chaos.powdertoy.co.uk/ScriptRepo.php?id=");
|
||||||
|
//strcpy(addr,"http://localhost:80/ScriptRepo.php?id=");
|
||||||
|
strcat(addr,id);
|
||||||
|
|
||||||
strcpy(file,id);
|
strcpy(file,id);
|
||||||
strcat(file,".lua");
|
strcat(file,".lua");
|
||||||
FILE *filetowriteto;
|
FILE *filetowriteto;
|
||||||
filetowriteto=fopen(file, "w");
|
filetowriteto=fopen(file, "w");
|
||||||
strcpy(newid,id);
|
int ret,len;
|
||||||
strcat(newid,"\n");
|
char* luadata = http_auth_get(addr, svf_user_id, NULL, svf_session_id, &ret, &len);
|
||||||
write(sock,newid,strlen(newid));
|
if(ret != 200){
|
||||||
while(1){
|
printf("%d",ret);
|
||||||
bzero(filedatabuffer,1024);
|
luaL_error(l, "Error connecting to server.");
|
||||||
numrec = read(sock,filedatabuffer,1024);
|
return 0;
|
||||||
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];
|
if(len <=0||!luadata){
|
||||||
strcpy(tempstr,"dofile(\"");
|
luaL_error(l, "Error retreiving file.");
|
||||||
strcat(tempstr,file);
|
return 0;
|
||||||
strcat(tempstr,"\")");
|
}
|
||||||
luacon_eval(tempstr);
|
fputs(luadata,filetowriteto);
|
||||||
return 0;
|
|
||||||
|
fclose(filetowriteto);
|
||||||
|
char tempstr[120];
|
||||||
|
strcpy(tempstr,"dofile(\"");
|
||||||
|
strcat(tempstr,file);
|
||||||
|
strcat(tempstr,"\")");
|
||||||
|
luacon_eval(tempstr);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user