Hi guys,
I thought I would expand my horizons and use sockets (Mostly for fun and learning). I'm currently using Valve wiki page on server queries (
https://developer.valvesoftware.com/...mplementations) but I'm having a little trouble with the A2S_PLAYER query. I've had success with A2S_INFO as the response packet uses bytes for the number of player etc.
I've managed to get a challenge response but I can figure out how to append the challenge id to my request. Furthermore, with this one the packet contains a 32bit integer and a 32bit float and to be honest I'm not sure how to go about taking these bytes and converting them to and int and float into sourcemod respectively.
Help with this would be fantastic and would really get me going. Thanks
PHP Code:
public void OnPluginStart()
{
Socket hSocket = new Socket(SOCKET_UDP, OnSocketError);
//SocketSetArg(hSocket, i);
SocketConnect(hSocket, OnSocketConnected, OnSocketReceive, OnSocketDisconnected, "IP of some kind", 27016);
}
public void OnSocketConnected(Socket hSocket, any Data)
{
char sRequest[25];
Format(sRequest, sizeof sRequest, "\xFF\xFF\xFF\xFF\x55\xFF\xFF\xFF\xFF");
SocketSend(hSocket, sRequest, sizeof sRequest);
}
public void OnSocketDisconnected(Socket hSocket, any Data)
{
delete hSocket;
}
public void OnSocketReceive(Socket hSocket, char[] sReceivedData, const int iSize, any Data)
{
if(iSize == 9)
{
char sRequest[25];
Format(sRequest, sizeof sRequest, "\xFF\xFF\xFF\xFF\x55%s", sReceivedData[5]);
SocketSend(hSocket, sRequest, sizeof sRequest);
}
else
{
PrintToConsoleAll("Received server player info");
}
}
public void OnSocketError(Socket hSocket, const int iErrorType, const int iErrorNum, any Data)
{
delete hSocket;
}
EDIT: I so stupid for deleting the socket handle after receiving. So that's fixed. Just not sure on how to process 32 bit info.