Homebrew Question [C++/SPRX] Get char* from website / webRequests - NextGenUpdate
THREAD: [C++/SPRX] Get char* from website / webRequests
  1. 12-27-2017, 12:42 AM
    #1
    makeabce's Avatar
    makeabce
    I defeated!
    makeabce's Avatar
    makeabce
    I defeated!
    614
    Posts
    5,842
    Reputation
    Feb 2013
    NextGenUpdate
    Sponsored Links

    Hey, i' think i've already asked this once but never got enough info about this...

    So, basicly i want to be able to get char* from websites(on this case my own) to get show up in SPRX Message dialog/in-game messges.
    I tried BLB's webRequest, it did exactly what i needed, but it only worked for MW3 properly. Tried also MW2, but after calling the function,it doesn't let me play online at all,black ops 1/2 this just freezes the console.

    I also tried other code(Some kind of sockets..), it did the job on all games, but the problem was that it showed more than the char* i wanted from the website(HTTP: 1.0, version...ect)
    Tried making function that removes those unnecessary information but it causes freeze or didn't work at all.
  2. Sponsored Links
  3. 12-27-2017, 01:05 AM
    #2
    John's Avatar
    John
    skid
    John's Avatar
    John
    skid
    1,827
    Posts
    65,724
    Reputation
    Dec 2012
    NextGenUpdate
    Code:
    bool Requests::get(char *host, char *params, char *out, size_t outSz) {
    	sockaddr_in SocketAddress;
    	hostent *hent = gethostbyname(host);
    
    	SocketAddress.sin_addr.s_addr = *((unsigned long*)hent->h_addr);
    	SocketAddress.sin_family = AF_INET;
    	SocketAddress.sin_port = htons(80);
    	int sock = socket(AF_INET, SOCK_STREAM, 0);
    	if (connect(sock, (struct sockaddr *)&SocketAddress, sizeof(SocketAddress)) != 0) {
    		return false;
    	}
    	char rqBuffer[255] = { 0 };
    	strcpy(rqBuffer, "GET /");
    	strcat(rqBuffer, (const char *)params);
    	strcat(rqBuffer, " HTTP/1.0\r\nHOST: ");
    	strcat(rqBuffer, host);
    	strcat(rqBuffer, "\r\n\r\n");
    
    	send(sock, rqBuffer, 255, 0);
    	
    	recv(sock, out, outSz, 0);
    	
    	socketclose(sock);
    
    	return true;
    }
    char *Requests::removeRequestHeader(char *request) {
    	char *httpbody = strstr(request, "\r\n\r\n");
    	if (httpbody) httpbody += 4;
    
    	return httpbody;
    }
    usage:
    Code:
    char reqRt[2048];
    char request[255];
    Requests::get("myserver.com", "Version.txt", reqRt, sizeof(reqRt));
    char *reqNoHeader = Requests::removeRequestHeader(reqRt);
    
    ShowDialog(reqNoHeader);
    potential buffer overflow here, so dont fuck that up
    Last edited by John; 12-29-2017 at 03:53 PM.

  4. The Following 3 Users Say Thank You to John For This Useful Post:

    , ,

  5. 12-27-2017, 01:51 AM
    #3
    makeabce's Avatar
    makeabce
    I defeated!
    makeabce's Avatar
    makeabce
    I defeated!
    614
    Posts
    5,842
    Reputation
    Feb 2013
    NextGenUpdate
    Originally Posted by John View Post
    Code:
    bool Requests::get(char *host, char *params, char *out, size_t outSz) {
    	sockaddr_in SocketAddress;
    	hostent *hent = gethostbyname(host);
    
    	SocketAddress.sin_addr.s_addr = *((unsigned long*)hent->h_addr);
    	SocketAddress.sin_family = AF_INET;
    	SocketAddress.sin_port = htons(80);
    	int sock = socket(AF_INET, SOCK_STREAM, 0);
    	if (connect(sock, (struct sockaddr *)&SocketAddress, sizeof(SocketAddress)) != 0) {
    		return false;
    	}
    	char rqBuffer[255] = { 0 };
    	strcpy(rqBuffer, "GET /");
    	strcat(rqBuffer, (const char *)params);
    	strcat(rqBuffer, " HTTP/1.0\r\nHOST: ");
    	strcat(rqBuffer, host);
    	strcat(rqBuffer, "\r\n\r\n");
    
    	send(sock, rqBuffer, 255, 0);
    	
    	recv(sock, out, outSz, 0);
    	
    	socketclose(sock);
    
    	return true;
    }
    char *Requests::removeRequestHeader(char *request) {
    	char *httpbody = strstr(request, "\r\n\r\n");
    	if (httpbody) httpbody += 4;
    
    	return httpbody;
    }
    usage:
    Code:
    char reqRt[2048];
    char request[255];
    Requests::get("myserver.com", "Version.txt", reqRt, sizeof(reqRt));
    char *reqNoHeader = Requests::removeRequestHeader(reqRt);
    
    ShowDialog(reqNoHeader);
    Hail to the king!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •