AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Sockets - Reading Hexidecimal, Bytes (https://forums.alliedmods.net/showthread.php?t=328834)

Weetabix 11-27-2020 15:46

Sockets - Reading Hexidecimal, Bytes
 
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_UDPOnSocketError);
    
//SocketSetArg(hSocket, i);
    
SocketConnect(hSocketOnSocketConnectedOnSocketReceiveOnSocketDisconnected"IP of some kind"27016);
}

public 
void OnSocketConnected(Socket hSocketany Data)
{
    
char sRequest[25];
    
Format(sRequestsizeof sRequest"\xFF\xFF\xFF\xFF\x55\xFF\xFF\xFF\xFF");
    
    
SocketSend(hSocketsRequestsizeof sRequest);
}

public 
void OnSocketDisconnected(Socket hSocketany Data)
{
    
delete hSocket;
}

public 
void OnSocketReceive(Socket hSocketchar[] sReceivedData, const int iSizeany Data)
{
    if(
iSize == 9)
    {
        
char sRequest[25];
        
Format(sRequestsizeof sRequest"\xFF\xFF\xFF\xFF\x55%s"sReceivedData[5]);
        
        
SocketSend(hSocketsRequestsizeof sRequest);
    }
    else
    {
        
PrintToConsoleAll("Received server player info");
    }
}

public 
void OnSocketError(Socket hSocket, const int iErrorType, const int iErrorNumany 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.


All times are GMT -4. The time now is 11:37.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.