Raised This Month: $32 Target: $400
 8% 

Executing Commands Through Across Servers


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 07-11-2018 , 20:49   Executing Commands Through Across Servers
Reply With Quote #1

Hi there, the title just says it all. Searched around on the forums a bit, I found no nothing. I then got some help by our kind sir Dr!fter, he suggested me sql, rcon.

I could not see the code in my mind, would you guys mind helping me out a little, thanks.

Last edited by mug1wara; 07-12-2018 at 08:07.
mug1wara is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 07-12-2018 , 06:16   Re: Executing Commands Through Eform Servers
Reply With Quote #2

What are Eform servers?
__________________
Neuro Toxin is offline
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 07-12-2018 , 08:07   Re: Executing Commands Through Eform Servers
Reply With Quote #3

I have no idea what I said.
mug1wara is offline
Dr!fter
The Salt Boss
Join Date: Mar 2007
Old 07-12-2018 , 15:17   Re: Executing Commands Through Across Servers
Reply With Quote #4

GL HF

PHP Code:
#include <sourcemod>
#include <socket>

#pragma semicolon 1
#pragma newdecls required

int iRconID 0xDAB;
int iByteSize 1;
int iIntSize 4;

int iRconAuthPacket 3;
int iRconAuthResponsePacket 2;
int iRconExecCommandPacket 2;

char szRconPassword [] = "ihatecsgoserverowners";
char szIP [] = "256.256.256.256";
int iPort 27016;

Handle hSocket null;

bool bLoggedIn false;

methodmap RconLoginInfo StringMap
{
    public 
RconLoginInfo()
    {
        return 
view_as<RconLoginInfo>(new StringMap());
    }
    public 
void SetCommand(const char [] cmd)
    {
        
this.SetString("command"cmd);
    }
    public 
void SetPassword(const char [] pass)
    {
        
this.SetString("password"pass);
    }
    public 
void GetPassword(char [] bufferint size)
    {
        
this.GetString("password"buffersize);
    }
    public 
void GetCommand(char [] bufferint size)
    {
        
this.GetString("command"buffersize);
    }
};

public 
void OnPluginStart()
{
    
RegConsoleCmd("send_rcon"Send_Rcon);
}

public 
Action Send_Rcon(int clientint iArgs)
{
    
char szCMD[128];
    
    
GetCmdArgString(szCMDsizeof(szCMD));
    
    if(
hSocket && SocketIsConnected(hSocket) && bLoggedIn)
    {
        
SendCommand(szCMD);
    }
    else
    {
        
LoginQueueCmd(szCMD);
    }
}

void LoginQueueCmd(char [] szCMD)
{
    
Login(szIPszRconPasswordiPortszCMD);
}

void Login(char [] ipchar [] passwordint portchar [] cmd "")
{
    
hSocket SocketCreate(SOCKET_TCPOnSocketError);
    
    
RconLoginInfo info = new RconLoginInfo();
    
    if(!
info)
    {
        
LogMessage("Failed to create login info string map");
        return;
    }
    
    
info.SetPassword(password);
    
    if(
strlen(cmd) > 0)
        
info.SetCommand(cmd);
    
    
SocketSetArg(hSocketinfo);
    
SocketConnect(hSocketOnSocketConnectedOnSocketReceiveOnSocketDisconnectedipport);
}

void SendCommand(char [] szCmd)
{
    if(
hSocket && SocketIsConnected(hSocket) && bLoggedIn && strlen(szCmd) > 0)
    {
        
int iSize iIntSize*strlen(szCmd) + iByteSize;
        
        
int iFormatSize iSize+iIntSize;
        
char [] szRequest = new char[iFormatSize];
        
        
int iCurrentIndex 0;
        
WriteInt(szRequestiSizeiCurrentIndex);
        
WriteInt(szRequestiRconIDiCurrentIndex);
        
WriteInt(szRequestiRconExecCommandPacketiCurrentIndex);
        
WriteString(szRequestszCmdiCurrentIndex);
        
WriteNull(szRequestiCurrentIndex);
    
        
SocketSend(hSocketszRequestiFormatSize);
        
        
LogMessage("Sent %s as a command!"szCmd);
    }
}

public 
int OnSocketConnected(Handle socketany pack
{
    
//Send RCON auth packets.
    
char szPassword[128];
    
    
RconLoginInfo info view_as<RconLoginInfo>(pack);
    
info.GetPassword(szPasswordsizeof(szPassword));
    
    
int iSize iIntSize*strlen(szPassword) + iByteSize;
    
    
int iFormatSize iSize+iIntSize;
    
char [] szRequest = new char[iFormatSize];
    
    
int iCurrentIndex 0;
    
WriteInt(szRequestiSizeiCurrentIndex);
    
WriteInt(szRequestiRconIDiCurrentIndex);
    
WriteInt(szRequestiRconAuthPacketiCurrentIndex);
    
WriteString(szRequestszPasswordiCurrentIndex);
    
WriteNull(szRequestiCurrentIndex);
    
    
SocketSend(socketszRequestiFormatSize);
}

public 
int OnSocketReceive(Handle socketchar [] receivedData, const int dataSizeany pack
{
    if(
dataSize <= || bLoggedIn)
        return 
0;
    
    
//int size = GetInt(receivedData, 0);
    
int id GetInt(receivedData4);
    
int type GetInt(receivedData8);
    
    
LogMessage("Got %i id and %i type"idtype);
    
    if(
type != iRconAuthResponsePacket//We are only going to handle auth responses #POC.
        
return 0;
    
    if(
type == iRconAuthResponsePacket && id != iRconID)
    {
        
LogMessage("Incorrect rcon password");
        return 
0;
    }
    
    
LogMessage("Authed");
    
bLoggedIn true;
    
    
RconLoginInfo info view_as<RconLoginInfo>(pack);
    
    
char szCommand[128];
    
info.GetCommand(szCommandsizeof(szCommand));
    
    
SendCommand(szCommand);
    return 
1;
}

public 
int OnSocketDisconnected(Handle socketany pack
{
    
delete socket;
    
delete view_as<RconLoginInfo>(pack);
    
bLoggedIn false;
    
hSocket null;
    
    
PrintToServer("Disconnected");
}

public 
int OnSocketError(Handle socket, const int errorType, const int errorNumany pack
{
    
delete view_as<RconLoginInfo>(pack);
    
delete socket;
    
bLoggedIn false;
    
hSocket null;
    
    
LogMessage("Socket error Type %i Num %i"errorTypeerrorNum);
}

int GetInt(char [] bufferint iIndex)
{
    return ((
buffer[iIndex+3] & 0xff) << 24) | ((buffer[iIndex+2] & 0xff) << 16) | ((buffer[iIndex+1] & 0xff) << 8) | (buffer[iIndex] & 0xff);
}

void WriteInt(char [] bufferint iIntint &iPackIndex)
{
    for(
int i 0iIntSizei++)
    {
        
buffer[iPackIndex] = (iInt >> (8*i)) & 0xff;
        
iPackIndex++;
    }
}
void WriteString(char [] bufferchar [] szStringint &iPackIndex)
{
    for(
int i 0strlen(szString) + 1i++)
    {
        
buffer[iPackIndex] = szString[i];
        
iPackIndex++;
    }
}
void WriteNull(char [] bufferint &iPackIndex)
{
    
buffer[iPackIndex] = 0x00;
    
iPackIndex++;

This is heavily a POC do not use it live >_>
Dr!fter is offline
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 07-12-2018 , 16:36   Re: Executing Commands Through Across Servers
Reply With Quote #5

Dr!fter, ur the man.
mug1wara 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 03:38.


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