Raised This Month: $51 Target: $400
 12% 

[INC] GoldSRC RCON Query


Post New Thread Reply   
 
Thread Tools Display Modes
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 12-31-2013 , 13:22   Re: [INC] GoldSRC RCON Query
Reply With Quote #11

Don't know how you're actually coding without having a common sense.

You just need to send a console echo, like how it does "status" command, "version" command, and that's returned in a single line.

PHP Code:
public return100function() {
     
server_print("100"// the return value it's something handled on the amxx core, nothing to do with a server query

__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
WiggPerson
Junior Member
Join Date: Dec 2013
Location: Slovakia
Old 12-31-2013 , 13:32   Re: [INC] GoldSRC RCON Query
Reply With Quote #12

Just tested with server_print(), not working.

// Edit

Now server_print() works, I finaly know what I was doing wrong. Library does not return result when status is RCON_GET_CHALLENGE_FAILED. I did not know why status is CHALLENGE_FAILED, but now the issue is solved. (CHALLENGE_FAILED is when you are trying to connect on local server, for me).
__________________
It does not matter who you are, just who you become.

Last edited by WiggPerson; 01-01-2014 at 04:40.
WiggPerson is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 01-08-2014 , 20:24   Re: [INC] GoldSRC RCON Query
Reply With Quote #13

Usefully for HLTV, thanks!

An option to not use the Forward ?
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
GordonFreeman (RU)
Veteran Member
Join Date: Jan 2010
Location: Uzbekistan
Old 01-08-2014 , 23:37   Re: [INC] GoldSRC RCON Query
Reply With Quote #14

I'm used forward because I'm think its only good way to wait reply from server and don't block game frame.
It's works in SQL_ThreadQuery native style.
__________________
The functional way is the right way
GordonFreeman (RU) is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 04-06-2015 , 23:56   Re: [INC] GoldSRC RCON Query
Reply With Quote #15

The last post is from 2014, but i made a conversion of this include from engine to fakemeta, if someone needs for any reason.

PHP Code:
#if !defined _fakemeta_included
    #include <fakemeta>
#endif

#if !defined _socket_included
    #include <sockets>
#endif

/*
    GoldSRC RCON Query include             v. 0.1
    by serfreeman1337        http://gf.hldm.org/
    
    Convert to fakemeta made by SmileY :D
*/

/*
    rcon_send(p[],port,szPass[],szCommand[],szForward[],Float:timeout)
    
    forward <my fwd>(iRconStatus,szResult[])
*/

enum _:RconReturn
{
    
RCON_CONNECTION_FAILED = -4,
    
RCON_GET_CHALLENGE_FAILED,
    
RCON_CREATE_FWD_FAIL,
    
RCON_TIMEOUT,
    
RCON_OK
}

enum _:RconSt
{
    
RCON_FAIL = -2,
    
RCON_GET_CHALLENGE,
    
RCON_IDLE
}

enum RconDataArray
{
    
RconSocket 0,
    
RconCommand[128],
    
RconPassword[32],
    
RconChallenge[16],
    
RconForward,
    
RconEntity,
    
RconPlugin,
    
RconStatus
}

const 
Float:RETRIVE_INTERVAL 0.01

stock RconData
[RconDataArray]
stock Float:RconTimeoutTime
stock Float
:RconTimeout

stock rcon_send
(ip[],port,szPass[],szCommand[],szForward[],Float:timeout 5.0)
{
    new 
iErr
    
    
if(!RconData[RconSocket])
    {
        
RconData[RconSocket] = socket_open(ip,port,SOCKET_UDP,iErr)
    }
    
    if(
iErr>0)
    {
        return 
RCON_CONNECTION_FAILED
    
}
    
    
RconData[RconStatus] = RCON_GET_CHALLENGE
    
    
new send[256]
    
    
formatex(send,255,"%c%c%c%cchallenge rcon",0xFF,0xFF,0xFF,0xFF)
    
socket_send(RconData[RconSocket],send,strlen(send))
    
    
formatex(RconData[RconPassword],31,szPass)
    
formatex(RconData[RconCommand],127,szCommand)
    
    if(!
pev_valid(RconData[RconEntity]))
    {
        
RconData[RconEntity] = engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,"info_target"));
        
        
set_pev(RconData[RconEntity],pev_classname,"rcon_think");
        
set_pev(RconData[RconEntity],pev_nextthink,get_gametime() + RETRIVE_INTERVAL);
        
        
register_forward(FM_Think,"_Rcon_Think");
    }
    else
    {
        
set_pev(RconData[RconEntity],pev_nextthink,get_gametime() + RETRIVE_INTERVAL);
    }
    
    
RconTimeoutTime timeout
    RconTimeout 
get_gametime() + timeout
    
    
if(!RconData[RconPlugin]){
        new 
plFile[64],plNull[1]
        
get_plugin(-1,plFile,63,plNull,0,plNull,0,plNull,0,plNull,0)
        
        
RconData[RconPlugin] = find_plugin_byfile(plFile,0)
    }
    
    if(!
RconData[RconForward]){
        
RconData[RconForward] = CreateOneForward(RconData[RconPlugin],szForward,FP_CELL,FP_STRING)
        
        if(
RconData[RconForward]<0)
            return 
RCON_CREATE_FWD_FAIL
    
}
    
    
    
RconTimeout get_gametime() + RconTimeoutTime
    
    
return RCON_OK
}

public 
_Rcon_Disconnect()
{
    
set_pev(RconData[RconEntity],pev_nextthink,999999.0);
    
    if(
RconData[RconPlugin])
        
RconData[RconPlugin] = 0
    
    
if(RconData[RconForward]){
        
DestroyForward(RconData[RconForward])
        
RconData[RconForward] = 0
    
}
    
    
RconData[RconStatus] = 0
    RconData
[RconChallenge][0] = 0
    RconData
[RconPassword][0] = 0
    
    
if(RconData[RconSocket]){
        
socket_close(RconData[RconSocket])
        
RconData[RconSocket] = 0
    
}
}

public 
_Rcon_Think(iEnt)
{
    if(
iEnt == RconData[RconEntity])
    {
        if(
RconData[RconStatus] == RCON_FAIL)
        {
            
_Rcon_Disconnect()
            
            return
        }
        
        new 
data[512]
        
        if(
socket_change(RconData[RconSocket],1000)){
            
socket_recv(RconData[RconSocket],data,511)
            
            if(
strlen(data)){
                
set_pev(RconData[RconEntity],pev_nextthink,999999.0);
            }else{
                
set_pev(RconData[RconEntity],pev_nextthink,get_gametime() + RETRIVE_INTERVAL);
            }
        }else{
            
set_pev(RconData[RconEntity],pev_nextthink,get_gametime() + RETRIVE_INTERVAL);
        }
        
        if(
strlen(data)>0){
            new 
none[1],ret
            
            
switch(RconData[RconStatus]){
                case 
RCON_GET_CHALLENGE:{
                    
parse(data,none,0,none,0,RconData[RconChallenge],10)
                    
                    if(
strlen(RconData[RconChallenge])>0){
                        
RconData[RconStatus] = RCON_IDLE
    
                        formatex
(data,511,"%c%c%c%crcon %s ^"%s^" %s",0xFF,0xFF,0xFF,0xFF,RconData[RconChallenge],RconData[RconPassword],RconData[RconCommand])
                        
socket_send(RconData[RconSocket],data,strlen(data))
        
                        
set_pev(RconData[RconEntity],pev_nextthink,get_gametime() + RETRIVE_INTERVAL);
                        
                    }else{
                        
RconData[RconStatus] = RCON_FAIL
                        
                        ExecuteForward
(RconData[RconForward],none[0],RCON_GET_CHALLENGE_FAILED,RconData[RconChallenge])
                    }
                }
                case 
RCON_IDLE:{
                    if(
strlen(data) || (strlen(data) - 1)){
                        
// remove ^n
                        
data[strlen(data)-1] = 0
                    
}
            
                    
// 0,1,2 - NULL
                    // 3,4 - WTF?
                    
formatex(data,511,data[5]) // remove l
                    
                    
ExecuteForward(RconData[RconForward],ret,RCON_OK,data)
                    
                    
_Rcon_Disconnect()
                }
            }
        }
        
        if(
get_gametime() > RconTimeout && RconData[RconStatus] != RCON_FAIL){
            new 
sda[12],ret
            formatex
(sda,11,"%.2f",get_gametime())
            
            
RconData[RconStatus] = RCON_FAIL
            
            ExecuteForward
(RconData[RconForward],ret,RCON_TIMEOUT,sda)
            
            
set_pev(RconData[RconEntity],pev_nextthink,get_gametime() + RETRIVE_INTERVAL);
        }
    }

Attached Files
File Type: inc rcon.inc (4.8 KB, 170 views)
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 

Last edited by ^SmileY; 04-06-2015 at 23:58.
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 04-07-2015 , 04:35   Re: [INC] GoldSRC RCON Query
Reply With Quote #16

And the reason for porting from engine to fakemeta is ?
__________________
HamletEagle is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 04-07-2015 , 08:46   Re: [INC] GoldSRC RCON Query
Reply With Quote #17

Quote:
Originally Posted by HamletEagle View Post
And the reason for porting from engine to fakemeta is ?
ready my post again.
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
Reply



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:50.


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