Obviously a crude example since I don't fully understand the output format, you get the point:
Code:
#include <amxmodx>
#include <sockets>
new hSocket;
new cmd[256] = "^xFF^xFF^xFF^xFF";
new rcon[] = "your rcon goes here";
public plugin_init() {
register_plugin("Test Plugin 4", "", "[ --{-@ ]");
register_srvcmd("testcmd", "test");
}
public test() {
new error
hSocket = socket_open("127.0.0.1", 27015, SOCKET_UDP, error);
if ( ! hSocket )
return;
copy(cmd[4], charsmax(cmd) - 4, "challenge rcon");
socket_send(hSocket, cmd, 18);
set_task(0.1, "ChallengeRcon");
}
public ChallengeRcon() {
static data[256];
socket_recv(hSocket, data, sizeof data);
new rcon_challenge[32];
copy(rcon_challenge, charsmax(rcon_challenge), data[19]);
trim(rcon_challenge);
formatex(cmd[4], charsmax(cmd) - 4, "rcon ^"%s^" ^"%s^" banid", rcon_challenge, rcon);
socket_send(hSocket, cmd, 18);
set_task(0.1, "ReadOutput");
}
public ReadOutput() {
static data[256];
socket_recv(hSocket, data, sizeof data)
trim(data);
server_print("Output: %s", data[5]);
socket_close(hSocket);
}
Code:
testcmd
Rcon from 127.0.0.1:58680:
rcon "632157337" "*" banid
L 06/08/2014 - 14:32:26: Rcon: "rcon "632157337" "*" banid" from "127.0.0.1:58680"
Usage: banid <minutes> <uniqueid or #userid> { kick }
Use 0 minutes for permanent
Output: Usage: banid <minutes> <uniqueid or #userid> { kick }
Use 0 minutes for permanent
__________________