I changed the command as you said, and i also added a Timeout Function that waits 3sec (hope its ok).
Now here is my code :
Code:
#include <iostream>
#include <winsock2.h>
#pragma comment(lib,"ws2_32.lib")
using namespace std;
static int initSocket(void);
static void endSocket(void);
int rbuffersize(0);
char buffer[32];
char rbuffer[256];
SOCKET sock;
int waitTimeOut(SOCKET &sock, unsigned int time);
int main()
{
initSocket();
sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if(sock == INVALID_SOCKET)
{
cout << "Error : Creating Socket." << endl;
endSocket();
return 1;
}
strcpy(buffer, "\xFF\xFF\xff\xFF" "rcon status");
sockaddr_in sin;
sin.sin_addr.s_addr = inet_addr("88.198.5.173");
sin.sin_port = htons(20008);
sin.sin_family = AF_INET;
int sent= 0;
if( (sent = sendto(sock, buffer, strlen(buffer),0, (SOCKADDR *)&sin, sizeof(sin) )) != strlen(buffer) )
{
printf("Error : Connexion Impossible on %s:%d\n",inet_ntoa(sin.sin_addr), htons(sin.sin_port));
printf("Error : %s", WSAGetLastError());
endSocket();
return 3;
}
cout << sent << " Bytes Sent." << endl;
if(waitTimeOut(sock, 3))
{
cout << "Error : Time out." << endl;
endSocket();
return 10;
}
int tempsize = sizeof(sin);
rbuffersize = recvfrom(sock,rbuffer,256,0, NULL, NULL); // Program gets stuck here...
if(rbuffersize != SOCKET_ERROR)
{
cout << "Received " << rbuffersize << " Bytes"<< endl;
}
else
{
cout << "Error : Nothing Received" << endl;
}
rbuffer[rbuffersize]=0;
printf("\nReceived Datas : %s",rbuffer);
endSocket();
return 0;
}
static int initSocket(void)
{
WSADATA WSAData;
int err = WSAStartup(MAKEWORD(2,2), &WSAData);
if(err < 0)
{
cout << "Error : Initialization Socket." << endl;
return 1;
}
return 0;
}
static void endSocket(void)
{
closesocket(sock);
WSACleanup();
}
int waitTimeOut(SOCKET &sock, unsigned int time)
{
fd_set readSet;
FD_ZERO(&readSet);
FD_SET(sock, &readSet);
struct timeval timeVal;
timeVal.tv_sec = time;
timeVal.tv_usec = 0;
if(select(sock+1, &readSet, NULL, NULL, &timeVal) > 0)
{
return true;
}
return false;
}
Still nothing is hapenning, it doesn't even say "Invalid Password" (Because i just send a Status command without logging in rcon)
Thanks in advance