AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Socket a2s_players (https://forums.alliedmods.net/showthread.php?t=195013)

rapierrr 09-02-2012 14:33

Socket a2s_players
 
How to get another server's player list using sockets?
Server info (A2S_INFO) works perfectly, but player list and query challenge not.
No response for FF FF FF FF 57 query. I'm tried FF FF FF FF 55 FF FF FF FF (alternative challenge get) too, but server returns only -1.

Quote:

The challenge number can either be set to -1 (0xFF FF FF FF) to have the server reply with S2C_CHALLENGE, or use the value from a previous A2S_SERVERQUERY_GETCHALLENGE request.
Quote from: https://developer.valvesoftware.com/...Y_GETCHALLENGE

PHP Code:

#include <amxmodx>
#include <sockets>

#define PLUGIN "asd"
#define AUTHOR "RapieR"
#define VERSION "0.0"

new gServerIp[32];
new 
gServerPort[6];

new 
gSocketChallenge;

public 
plugin_init(){
    
register_plugin(PLUGINVERSIONAUTHOR);
    new 
pcVarServerIp register_cvar("amx_server""127.0.0.1:27015");
    
get_pcvar_string(pcVarServerIpgServerIpcharsmax(gServerIp));
    
strtok(gServerIpgServerIp31gServerPort5':');
    
set_task(5.0"GetChallenge"0""0);
}
public 
GetChallenge(){
    if(
gSocketChallenge 0)
        return;
    new 
iError;
    
gSocketChallenge socket_open(gServerIpstr_to_num(gServerPort), SOCKET_UDPiError);
    if(
gSocketChallenge <= || iError){
        switch(
iError){
            case 
log_amx("No error!");
            case 
log_amx("Error while creating socket");
            case 
log_amx("Couldn't resolve hostname");
            case 
log_amx("Couldn't connect to given hostname : port");
        }
        return;
    }
    new 
iRequest[6];
    
format(iRequest5"%c%c%c%c%c"25525525525587);
    
//for(new i = -1; i < 4; i++)
    
socket_send2(gSocketChallengeiRequest5);
    
set_task(0.1"ReceiveChallenge"387__"b");
    
set_task(1.0"EndChallenge");
}
public 
ReceiveChallenge(){
    if(
socket_change(gSocketChallenge1)){
        new 
iReceiveBuffer[1400], iReceiveBufferLength;
        
iReceiveBufferLength socket_recv(gSocketChallengeiReceiveBuffercharsmax(iReceiveBuffer));
        if(
iReceiveBufferLength 5){
            if(
equal(iReceiveBuffer, {-1, -1, -1, -1}, 4)){
                new 
aIndexes[100];
                if(
iReceiveBuffer[4] == 'A'){
                    
index_create(iReceiveBufferiReceiveBufferLength"44"aIndexes);
                    
server_print("Type : %c"iReceiveBuffer[aIndexes[1]]);
                    
server_print("Challenge : %d"iReceiveBuffer[aIndexes[2]]);
                }
            }
        }
    }
}
public 
EndChallenge( ) {
    
remove_task(387);
    
socket_close(gSocketChallenge);
    
gSocketChallenge 0;



xPaw 09-02-2012 15:04

Re: Socket a2s_players
 
https://forums.alliedmods.net/showthread.php?t=142858

joropito 09-03-2012 20:09

Re: Socket a2s_players
 
You can't send A2S_INFO directly, you have to get first a valid challenge to be used in queries

xPaw 09-04-2012 01:58

Re: Socket a2s_players
 
Quote:

Originally Posted by joropito (Post 1790768)
You can't send A2S_INFO directly, you have to get first a valid challenge to be used in queries

A2S_INFO doesn't require a challenge.


All times are GMT -4. The time now is 08:22.

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