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

Rcon / HLTV Command stock


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 05-12-2013 , 22:07   Rcon / HLTV Command stock
Reply With Quote #1

Hi, i find in my files, a stock to send any command to HLTV Server or another server, i think its a rcon based protocol.

I not remember the author, but if it someone its the author, reply this

Ps.
If someone have a better method, reply this topic.

EDIT: Its required to use the stock Socket module, have fun

PHP Code:
stock Rcon_Command(const szHost[],iPort,const szPass[],const szCommand[])
{
    new 
iError;
    new 
iSocket socket_open(szHost,iPort,SOCKET_UDP,iError);
    
    switch(
iError)
    {
        case 
1:
        {
            
socket_close(iSocket);
            
server_print("* Error on creating the socket.");
            
            return 
PLUGIN_HANDLED;
        }
        case 
2:
        {
            
socket_close(iSocket);
            
server_print("* Error on resolve the given hostname.");
            
            return 
PLUGIN_HANDLED;
        }
        case 
3:
        {
            
socket_close(iSocket);
            
server_print("* Error on connecting.");

            return 
PLUGIN_HANDLED;
        }
    }
    
    new 
iSend[256],szCmd[256],szRcon[32],szNone[64];
    
    
formatex(iSend,sizeof(iSend),"%c%c%c%cchallenge rcon",255,255,255,255);
    
socket_send2(iSocket,iSend,charsmax(iSend));
    
    if(!
socket_change(iSocket,2000000)) // If socket not change in 2 seconds, then stop it
    
{
        
socket_close(iSocket);
        
server_print("* No response from %s:%d",szHost,iPort);

        return 
PLUGIN_HANDLED;
    }
    
socket_recv(iSocket,szCmd,charsmax(szCmd));
    
parse(szCmd,szNone,charsmax(szNone),szNone,charsmax(szNone),szRcon,charsmax(szRcon));
    
    
formatex(szCmd,sizeof(szCmd),"%c%c%c%crcon %s ^"%s^" %s",255,255,255,255,szRcon,szPass,szCommand);
    
socket_send2(iSocket,szCmd,charsmax(szCmd));
    
    if(
socket_change(iSocket))
    {
        new 
szBuffer[2048];
        
socket_recv(iSocket,szBuffer,charsmax(szBuffer));

        
server_print(szBuffer);
    }
    
socket_close(iSocket);

    return 
PLUGIN_HANDLED;

__________________
Projects:

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

Last edited by ^SmileY; 05-27-2013 at 08:11. Reason: Socket module
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 05-12-2013 , 22:11   Re: Rcon / HLTV Command stock
Reply With Quote #2

Simple and useful example of use this stock

EDIT:

hltv_host ; The host of HLTV server
hltv_port ; The Port
hltv_pass ; The "adminpassword" of HLTV server or rcon_password if then used stock to send commands to another HLDS server

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <sockets>

#pragma semicolon 1

new g_HLTV[] = "[HLTV]";

new 
g_Address;
new 
p_Host,p_Port,p_Pass;

public 
plugin_init()
{
    
register_plugin("HLTV (Beta)",AMXX_VERSION_STR,"AMXX Dev Team");
    
    
g_Address     get_cvar_pointer("net_address");
    
    
p_Host         register_cvar("hltv_host","XXX.XXX.XXX.XXX",FCVAR_PROTECTED);
    
p_Port         register_cvar("hltv_port","XXXXX",FCVAR_PROTECTED);
    
p_Pass         register_cvar("hltv_pass","XXXXX",FCVAR_PROTECTED);
    
    
register_concmd("hltv_rcon","HLTV_Rcon",ADMIN_RCON,"<Command>");
    
register_concmd("hltv_record","HLTV_Record",ADMIN_RCON,"<File>");
    
register_concmd("hltv_stop","HLTV_Stop",ADMIN_RCON,"- Removes the HLTV from server");
}

public 
HLTV_Rcon(id,level,cid)
{
    if(!
cmd_access(id,level,cid,2)) return PLUGIN_HANDLED;
    
    new 
szHost[32],szPass[32];
    
get_pcvar_string(p_Host,szHost,charsmax(szHost));
    
get_pcvar_string(p_Pass,szPass,charsmax(szPass));
    
    new 
szCommand[128];
    
read_args(szCommand,charsmax(szCommand));
    
remove_quotes(szCommand);
    
    
Rcon_Command(szHost,get_pcvar_num(p_Port),szPass,szCommand);
    
    return 
PLUGIN_HANDLED;
}

public 
HLTV_Record(id,level,cid)
{
    if(!
cmd_access(id,level,cid,2)) return PLUGIN_HANDLED;
    
    new 
szHost[32],szPass[32];
    
get_pcvar_string(p_Host,szHost,charsmax(szHost));
    
get_pcvar_string(p_Pass,szPass,charsmax(szPass));
    
    new 
szFile[32];
    
read_args(szFile,charsmax(szFile));
    
remove_quotes(szFile);
    
    new 
szAddress[32];
    
get_pcvar_string(g_Address,szAddress,charsmax(szAddress));

    new 
szCommand[128];
    
formatex(szCommand,charsmax(szCommand),"connect %s;record %s;autoretry 1",szAddress,szFile);
    
    
Rcon_Command(szHost,get_pcvar_num(p_Port),szPass,szCommand);
    
    
console_print(id,"%s Trying to connect in ^"%s^" (And recording in the file ^"%s^")",g_HLTV,szAddress,szFile);
    
    return 
PLUGIN_HANDLED;
}

public 
HLTV_Stop(id,level,cid)
{
    if(!
cmd_access(id,level,cid,1)) return PLUGIN_HANDLED;
    
    new 
szHost[32],szPass[32];
    
get_pcvar_string(p_Host,szHost,charsmax(szHost));
    
get_pcvar_string(p_Pass,szPass,charsmax(szPass));
    
    
Rcon_Command(szHost,get_pcvar_num(p_Port),szPass,"stop;disconnect;autoretry 0");
    
    
console_print(id,"%s O HLTV Disconnected!",g_HLTV);

    return 
PLUGIN_HANDLED;
}

stock Rcon_Command(const szHost[],iPort,const szPass[],const szCommand[])
{
    new 
iError;
    new 
iSocket socket_open(szHost,iPort,SOCKET_UDP,iError);
    
    switch(
iError)
    {
        case 
1:
        {
            
socket_close(iSocket);
            
server_print("* Error on creating the socket.");
            
            return 
PLUGIN_HANDLED;
        }
        case 
2:
        {
            
socket_close(iSocket);
            
server_print("* Error on resolve the given hostname.");
            
            return 
PLUGIN_HANDLED;
        }
        case 
3:
        {
            
socket_close(iSocket);
            
server_print("* Error on connecting.");

            return 
PLUGIN_HANDLED;
        }
    }
    
    new 
iSend[256],szCmd[256],szRcon[32],szNone[64];
    
    
formatex(iSend,sizeof(iSend),"%c%c%c%cchallenge rcon",255,255,255,255);
    
socket_send2(iSocket,iSend,charsmax(iSend));
    
    if(!
socket_change(iSocket,2000000)) // If socket not change in 2 seconds, then stop it
    
{
        
socket_close(iSocket);
        
server_print("* No response from %s:%d",szHost,iPort);

        return 
PLUGIN_HANDLED;
    }
    
socket_recv(iSocket,szCmd,charsmax(szCmd));
    
parse(szCmd,szNone,charsmax(szNone),szNone,charsmax(szNone),szRcon,charsmax(szRcon));
    
    
formatex(szCmd,sizeof(szCmd),"%c%c%c%crcon %s ^"%s^" %s",255,255,255,255,szRcon,szPass,szCommand);
    
socket_send2(iSocket,szCmd,charsmax(szCmd));
    
    if(
socket_change(iSocket))
    {
        new 
szBuffer[2048];
        
socket_recv(iSocket,szBuffer,charsmax(szBuffer));

        
server_print(szBuffer);
    }
    
socket_close(iSocket);

    return 
PLUGIN_HANDLED;

__________________
Projects:

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

Last edited by ^SmileY; 05-12-2013 at 22:16.
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
Cheezpuff
BANNED
Join Date: Oct 2012
Location: City of the Dead
Old 05-30-2013 , 23:05   Re: Rcon / HLTV Command stock
Reply With Quote #3

nice idea,
But if I want to follow someone.

How can I put details of his Sarver, and send me the details of his ?

Think of something reasonable utilization
Cheezpuff is offline
Send a message via Skype™ to Cheezpuff
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 05-30-2013 , 23:12   Re: Rcon / HLTV Command stock
Reply With Quote #4

I did not understand exactly what you need.
In the case of a response from the server that was used in the stock?

Edit: To use stock you need to put a server details in stock function, like this:

PHP Code:
    Rcon_Command("200.199.200.199",27015,"TheRconPasswordOfServer","changelevel de_inferno;ITs my awesome command"); 
__________________
Projects:

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

Last edited by ^SmileY; 05-30-2013 at 23:19.
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
TheDS1337
Veteran Member
Join Date: Jun 2012
Old 05-31-2013 , 06:59   Re: Rcon / HLTV Command stock
Reply With Quote #5

I think he means, how to make the hltv spectate a player
TheDS1337 is offline
joropito
AlliedModders Donor
Join Date: Mar 2009
Location: pfnAddToFullPack
Old 05-31-2013 , 17:32   Re: Rcon / HLTV Command stock
Reply With Quote #6

PHP Code:
if(!socket_change(iSocket,2000000)) // If socket not change in 2 seconds, then stop it 
You will block the game (no more than 2 seconds) waiting for response. Better to use asynchronous calls

__________________

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
Cheezpuff
BANNED
Join Date: Oct 2012
Location: City of the Dead
Old 06-01-2013 , 06:36   Re: Rcon / HLTV Command stock
Reply With Quote #7

Quote:
Originally Posted by ^SmileY View Post
I did not understand exactly what you need.
In the case of a response from the server that was used in the stock?

Edit: To use stock you need to put a server details in stock function, like this:

PHP Code:
    Rcon_Command("200.199.200.199",27015,"TheRconPasswordOfServer","changelevel de_inferno;ITs my awesome command"); 
you talk about me?
This code of HLTV.

If I can set a rcon password of someone's server and get it to a text document?

And take over his Sarver rcon password chosen
Will this work?

Last edited by Cheezpuff; 06-01-2013 at 06:37.
Cheezpuff is offline
Send a message via Skype™ to Cheezpuff
TheDS1337
Veteran Member
Join Date: Jun 2012
Old 06-01-2013 , 08:40   Re: Rcon / HLTV Command stock
Reply With Quote #8

maybe you can try Rcon_Command("200.199.200.199",27015,"TheRcon PasswordOfServer","rcon_password ^"new password here^"");
TheDS1337 is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 06-02-2013 , 11:13   Re: Rcon / HLTV Command stock
Reply With Quote #9

Quote:
Originally Posted by joropito View Post
PHP Code:
if(!socket_change(iSocket,2000000)) // If socket not change in 2 seconds, then stop it 
You will block the game (no more than 2 seconds) waiting for response. Better to use asynchronous calls

For me is not freeze the server, above if you use a very long distance from HLDS server.
Or post you suggestion here its welcome to do
__________________
Projects:

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

Last edited by ^SmileY; 06-02-2013 at 11:14.
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
joropito
AlliedModders Donor
Join Date: Mar 2009
Location: pfnAddToFullPack
Old 06-03-2013 , 10:11   Re: Rcon / HLTV Command stock
Reply With Quote #10

Quote:
Originally Posted by ^SmileY View Post
For me is not freeze the server, above if you use a very long distance from HLDS server.
Or post you suggestion here its welcome to do
Suggestions:

1- don't use socket blocking
2- read for socket change in a time basis without blocking (maybe server_frame)

Check other threads discussing on how to use sockets
__________________

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


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