mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-08-16 00:06:41 +00:00
Native HTTP get request implementation
This commit is contained in:
parent
aebbcfc3f6
commit
de1a7f80f2
@ -4,4 +4,4 @@ project(BeamNG-MP-Launcher)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
|
||||
add_executable(BeamNG-MP-Launcher main.cpp enet.h proxy.cpp Security.cpp)
|
||||
add_executable(BeamNG-MP-Launcher main.cpp enet.h proxy.cpp Security.cpp http.cpp)
|
||||
|
59
http.cpp
Normal file
59
http.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
#include <string>
|
||||
#include <WinSock2.h>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
std::string HTTP_REQUEST(){
|
||||
|
||||
WSADATA wsaData;
|
||||
SOCKET Socket;
|
||||
SOCKADDR_IN SockAddr;
|
||||
int lineCount=0;
|
||||
int rowCount=0;
|
||||
struct hostent *host;
|
||||
std::locale local;
|
||||
char buffer[10000];
|
||||
int i = 0 ;
|
||||
int nDataLength;
|
||||
|
||||
std::string website_HTML;
|
||||
|
||||
std::string url = "s1.yourthought.co.uk";
|
||||
|
||||
std::string get_http = "GET /servers-info HTTP/1.1\r\nHost: " + url + "\r\nConnection: close\r\n\r\n";
|
||||
|
||||
if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0){
|
||||
std::cout << "WSAStartup failed.\n";
|
||||
system("pause");
|
||||
//return 1;
|
||||
}
|
||||
|
||||
Socket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
|
||||
host = gethostbyname(url.c_str());
|
||||
|
||||
SockAddr.sin_port=htons(3599); //PORT
|
||||
SockAddr.sin_family=AF_INET;
|
||||
SockAddr.sin_addr.s_addr = *((unsigned long*)host->h_addr);
|
||||
|
||||
if(connect(Socket,(SOCKADDR*)(&SockAddr),sizeof(SockAddr)) != 0){
|
||||
std::cout << "Could not connect";
|
||||
//system("pause");
|
||||
//return 1;
|
||||
}
|
||||
|
||||
send(Socket,get_http.c_str(), strlen(get_http.c_str()),0 );
|
||||
|
||||
while ((nDataLength = recv(Socket,buffer,10000,0)) > 0){
|
||||
int i = 0;
|
||||
while (buffer[i] >= 32 || buffer[i] == '\n' || buffer[i] == '\r'){
|
||||
|
||||
website_HTML+=buffer[i];
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
|
||||
closesocket(Socket);
|
||||
WSACleanup();
|
||||
|
||||
return website_HTML;
|
||||
}
|
10
main.cpp
10
main.cpp
@ -6,23 +6,25 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
std::vector<std::string> Check();
|
||||
|
||||
void Exit(const std::string& Msg){
|
||||
std::cout << Msg << std::endl;
|
||||
std::cout << "Press Enter to Continue...";
|
||||
std::cout << "Press Enter to continue . . .";
|
||||
std::cin.ignore();
|
||||
exit(-1);
|
||||
}
|
||||
void ProxyStart();
|
||||
std::string HTTP_REQUEST();
|
||||
int main()
|
||||
{
|
||||
//Security
|
||||
std::vector<std::string> Data = Check();
|
||||
|
||||
std::cout << "You own BeamNG on this machine!" << std::endl;
|
||||
std::cout << Data.at(1) << "\\BeamNG.drive.exe" << std::endl;
|
||||
std::cout << Data.at(1) << "\\BeamNG.drive.exe";
|
||||
std::cout << "\nHTTP TEST :\n\n";
|
||||
|
||||
std::cout << HTTP_REQUEST();
|
||||
|
||||
/// Update, Mods ect...
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user