View Single Post
iceeedr
Veteran Member
Join Date: Apr 2017
Location: Brazil
Old 07-18-2018 , 23:35   Re: [HELP] Send commands to another server
Reply With Quote #7

Quote:
Originally Posted by Natsheh View Post
Try changing socket protocol to TCP
Here's the full code.

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

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

new g_Socket
new g_Forward

enum _
:Data
{
    
DataHost[32],
    
DataPort,
    
DataPassword[32],
    
DataCommand[192]
}
new 
g_Hostg_Portg_Pass
new g_Rcon[Data]

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
g_Host create_cvar("pug_hltv_host","IP:",FCVAR_NONE// With or without the ":"??
    
g_Port create_cvar("pug_hltv_port","port",FCVAR_NONE)
    
g_Pass create_cvar("pug_hltv_pass","Rcon pass",FCVAR_NONE)
}

RconCommand(Host[],Port,Password[],Command[])
{
    new 
Error;
    
g_Socket socket_open(Host,Port,SOCKET_UDP,Error,SOCK_NON_BLOCKING);
   
    if(
Error != -1)
    {
        new 
Send[256];
        
formatex(Send,sizeof(Send),"%c%c%c%cchallenge rcon",0xFF,0xFF,0xFF,0xFF);
       
        
socket_send2(g_Socket,Send,charsmax(Send));
       
        
copy(g_Rcon[DataHost],charsmax(g_Rcon[DataHost]),Host);
       
        
g_Rcon[DataPort] = Port;
   
        
copy(g_Rcon[DataPassword],charsmax(g_Rcon[DataPassword]),Password);
        
copy(g_Rcon[DataCommand],charsmax(g_Rcon[DataCommand]),Command);
 
        
g_Forward register_forward(FM_StartFrame,"FMStartFrame",true);
    }
    else
    {
        
socket_close(g_Socket);
    }
 
}  
 
public 
FMStartFrame()
{
    if(
socket_is_readable(g_Socket))
    {
        new 
Command[256],Rcon[32],None[64];
   
        
socket_recv(g_Socket,Command,charsmax(Command));
        
parse(Command,None,charsmax(None),None,charsmax(None),Rcon,charsmax(Rcon));
       
        
formatex(Command,sizeof(Command),"%c%c%c%crcon %s ^"%s^" %s",0xFF,0xFF,0xFF,0xFF,Rcon,g_Rcon[DataPassword],g_Rcon[DataCommand]);
        
socket_send2(g_Socket,Command,charsmax(Command));
       
        if(
socket_is_readable(g_Socket))
        {
            new 
Buffer[1024];
            
socket_recv(g_Socket,Buffer,charsmax(Buffer));
           
            
server_print(Buffer);
        }
       
        
socket_close(g_Socket);
       
        
unregister_forward(FM_StartFrame,g_Forward,true);
    }
}

public 
SendMessage()
{
    new 
HOST[32];
    
get_pcvar_string(g_Host,HOST,charsmax(HOST));
    
    new 
Command[60]
    
formatex(Commandcharsmax(Command), "changelevel de_inferno")
            
    new 
Password[32];
    
get_pcvar_string(g_Pass,Password,charsmax(Password));
    
    
RconCommand(HOST,get_pcvar_num(g_Port),Password,Command);

As you can see, I tried to use the changelevel command .. nothing happens .. I tried to send a say also nothing happens .. what's wrong?

Last edited by iceeedr; 07-18-2018 at 23:36.
iceeedr is offline
Send a message via Skype™ to iceeedr