Raised This Month: $ Target: $400
 0% 

Socket a2s_players


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
rapierrr
New Member
Join Date: Sep 2012
Old 09-02-2012 , 14:33   Socket a2s_players
Reply With Quote #1

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;


Last edited by rapierrr; 09-02-2012 at 14:38. Reason: wrong code
rapierrr is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 09-02-2012 , 15:04   Re: Socket a2s_players
Reply With Quote #2

https://forums.alliedmods.net/showthread.php?t=142858
__________________

Last edited by xPaw; 09-02-2012 at 15:04.
xPaw is offline
joropito
AlliedModders Donor
Join Date: Mar 2009
Location: pfnAddToFullPack
Old 09-03-2012 , 20:09   Re: Socket a2s_players
Reply With Quote #3

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

Divide et vinces
approved plugins | steam account

I don't accept PM for support. Just ask on forums.
If you're looking for private work, PM me.
joropito is offline
Send a message via MSN to joropito
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 09-04-2012 , 01:58   Re: Socket a2s_players
Reply With Quote #4

Quote:
Originally Posted by joropito View Post
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.
__________________
xPaw 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 08:22.


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