Raised This Month: $32 Target: $400
 8% 

Sockets - Reading Hexidecimal, Bytes


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Weetabix
Member
Join Date: Feb 2017
Location: United Kingdom
Old 11-27-2020 , 15:46   Sockets - Reading Hexidecimal, Bytes
Reply With Quote #1

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.

Last edited by Weetabix; 11-27-2020 at 17:48.
Weetabix is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:45.


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