Code:
int Socket2;
void Socket_Bypass()
{
XNetStartupParams xnsp;
memset(&xnsp, 0, sizeof(xnsp));
xnsp.cfgSizeOfStruct = sizeof(XNetStartupParams);
xnsp.cfgFlags = XNET_STARTUP_BYPASS_SECURITY;
int err = XNetStartup(&xnsp);
XNADDR pxna;
while (XNetGetTitleXnAddr(&pxna) == 0);
WSADATA wsaData;
err = WSAStartup(MAKEWORD(2, 2), &wsaData);
Socket2 = socket(AF_INET, SOCK_STREAM, 0);
int setting = 1;
setsockopt(Socket2, SOL_SOCKET, 0x5801, (char*)(&setting), sizeof(int));
}
#define SERVER_PORT htons(80)
struct sockaddr_in SocketAddress_;
char *HookName;
char* remove_headers(char* request)
{
if (request == NULL) return NULL;
request = strstr(request, "\r\n\r\n");
if (request) request += 4;
return request;
}
char Country[500]; //50000
int mConnected;
namespace SocketName
{
char* ConnectionSettings(char *pHost)
{
int setting = 1;
setsockopt(Socket2, SOL_SOCKET, 0x5801, (char*)(&setting), sizeof(int));
SocketAddress_.sin_addr.s_addr = inet_addr(pHost);
SocketAddress_.sin_family = AF_INET;
SocketAddress_.sin_port = SERVER_PORT;
Socket2 = socket(AF_INET, SOCK_STREAM, 0);
return pHost;
}
bool connect()
{
return mConnected = (!::connect(Socket2, (sockaddr *)&SocketAddress_, sizeof(SocketAddress_)));
}
void disconnect()
{
if (!mConnected)
{
return;
}
closesocket(Socket2);
mConnected = false;
}
bool checkError(int err)
{
if (err == 0 || err == -1)
{
disconnect();
return false;
}
return true;
}
bool get(void *pBuffer, int pSize)
{
if (!mConnected)
{
return false;
}
//return checkError(recv(Socket, pBuffer, pSize, NULL));
}
bool put(char *pData, int pSize)
{
if (!mConnected)
{
return false;
}
return checkError(send(Socket2, pData, pSize, NULL));
}
bool isConnected()
{
return mConnected;
}
bool httpRequest(char *params, char *out, size_t outSz)
{
char rqBuffer[255] = { 0 };
strcpy(rqBuffer, "GET / line/");
strcat(rqBuffer, (const char *)params);
strcat(rqBuffer, " HTTP/1.0\r\nHOST: ");
strcat(rqBuffer, "\r\n\r\n");
send(Socket2, rqBuffer, 255, 0);
recv(Socket2, out, outSz, 0);
return out;
}
}
char* GetIPgeo(int Player)
{
if (NETWORK::NETWORK_IS_PLAYER_CONNECTED(Player))
{
char GCN[64];
char* GGT = PLAYER::GET_PLAYER_NAME(Player);
unsigned char Ip1 = *(UINT8*)(GGT - 0x48);
unsigned char Ip2 = *(UINT8*)(GGT - 0x47);
unsigned char Ip3 = *(UINT8*)(GGT - 0x46);
unsigned char Ip4 = *(UINT8*)(GGT - 0x45);
sprintf(GCN, "%u.%u.%u.%u", Ip1, Ip2, Ip3, Ip4);
printf("%s", GCN);
return GCN;
}
else
return "0.0.0.0";
}
void IPCountry()
{
Socket_Bypass();
SocketAddress_.sin_addr.s_addr = inet_addr("ip-api.com");//69.195.146.130//ip-api.com
SocketAddress_.sin_family = AF_INET;
SocketAddress_.sin_port = SERVER_PORT;
SocketName::connect();
/*if (connect(Socket2, (sockaddr*)&SocketAddress, sizeof(SocketAddress)) < 0) {
snprintf(Country, sizeof(Country), "Not Connected");
}*/
char RequestCountry[255] = { 0 };
strcpy(RequestCountry, "GET /line/");
strcat(RequestCountry, GetIPgeo(selectedPlayerinfo));
strcat(RequestCountry, "?fields=country,regionName,city,isp");
strcat(RequestCountry, " HTTP/1.0\r\nHOST: ");
strcat(RequestCountry, "ip-api.com");//69.195.146.130
strcat(RequestCountry, "\r\n\r\n");
send(Socket2, RequestCountry, 255, 0);
recv(Socket2, RequestCountry, sizeof(RequestCountry), 0);
snprintf(Country, sizeof(Country), "%s", remove_headers(RequestCountry));
closesocket(Socket2);
}