AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Executing Commands Through Across Servers (https://forums.alliedmods.net/showthread.php?t=309053)

mug1wara 07-11-2018 20:49

Executing Commands Through Across Servers
 
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.

Neuro Toxin 07-12-2018 06:16

Re: Executing Commands Through Eform Servers
 
What are Eform servers?

mug1wara 07-12-2018 08:07

Re: Executing Commands Through Eform Servers
 
I have no idea what I said.

Dr!fter 07-12-2018 15:17

Re: Executing Commands Through Across Servers
 
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 >_>

mug1wara 07-12-2018 16:36

Re: Executing Commands Through Across Servers
 
Dr!fter, ur the man.


All times are GMT -4. The time now is 08:28.

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