#include <amxmodx>
#include <sockets>
#include <amxmisc>
#define AUTHOR "Wuss"
#define PLUGIN "S2S"
#define VERSION "0.1"
new sock = 0
new rconid[13]
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_cvar("s2s_ip", "74.52.157.234")
register_cvar("s2s_rcon", "")
register_srvcmd("remote_names", "retNames")
}
public retNames()
{
new snd[201]
format(snd, 200, "amx_who")
//server_cmd("amx_chat %s", snd)
new ip[21], rconpass[31]
get_cvar_string("s2s_ip",ip,20)
get_cvar_string("s2s_rcon",rconpass,30)
hlds_rcon_cmd(ip, 27015, rconpass, snd)
socket_close(sock)
sock = 0
}
public hlds_makesock(host[], port, rcon[])
{
new error=0
// Get hlds rcon. Don't eaven bother if it's not set.
if(!rcon[0])
{
log_amx("There is no HLDS rcon set.")
return PLUGIN_HANDLED
}
// hlds ip/port/password
// Connect to HLDS Server
sock = socket_open(host, port, SOCKET_UDP, error)
if (error != 0)
{
log_amx("HLDS Connection Failed - error %i",error)
return PLUGIN_HANDLED
}
if (sock <= 0)
{
log_message("hldsconnect error: %d; hlds_address: %d", error, sock)
}
//log_amx("sock opened to %s:%s", host, port, rcon)
hlds_challenge()
return PLUGIN_CONTINUE
}
public hlds_rcon_cmd(host[], port, rcon[], cmd[])
{
// If HLDS connection not available, try connecting first
if(sock <= 0)
{
hlds_makesock(host, port, rcon)
//log_amx("%s:%s:%s", host, port, rcon)
if(sock <= 0)
{
// Still no connection. Give up.
return PLUGIN_HANDLED
}
}
// Just to be sure, get challenge
hlds_challenge()
new snd[256]
// send rcon command
setc(snd,255,0x00)
setc(snd,4,0xff)
format(snd[4],255,"rcon %s ^"%s^" %s",rconid, rcon, cmd)
socket_send(sock,snd,255)
new data[1025]
new statusFile[64]
get_configsdir(statusFile, 63)
format(statusFile, 63, "%s/status.log", statusFile)
// delete the temp file
delete_file(statusFile)
socket_recv(sock,data,1024)
new line = 0
write_file(statusFile, data, line)
// Close the socket
socket_close(sock)
statusParse()
return PLUGIN_CONTINUE
}
public statusParse()
{
new statusFile[64]
get_configsdir(statusFile, 63)
format(statusFile, 63, "%s/status.log", statusFile)
new textline[256], blank[64], len
// Open the status.log file, and read line 4 to get the player count
new playersline = 4, cur_players[3]
while ( read_file(statusFile, playersline++, textline, 255, len))
{
// Player Count
if (equal(textline, "players", 1))
{
parse(textline, blank, 0, blank, 0, cur_players, 2)
log_amx("Player Count: %s", cur_players)
}
}
// Open the status.log file, and read line by line looking for steamid's and names
// The lines we need will all start with #
new namesline = 7, name[64], steamid[64]
while ( read_file(statusFile, namesline++, textline, 255, len))
{
// We need two diffrent if statements because of the output of status
// # 1 vs #10
// List of users if > 9 and their steam id's
if (equal(textline, "#", 1))
{
parse(textline, blank, 0, name, 63, blank, 0, steamid, 63)
log_amx("Name: %s Steam: %s", name, steamid)
}
// List of users id < 10 and their steam id's
else if (equal(textline, "# ", 1))
{
parse(textline, blank, 0, blank, 0, name, 63, blank, 0, steamid, 63)
log_amx("Name: %s Steam: %s", name, steamid)
}
}
}
public hlds_challenge() {
// Try couple of times in row to get challenge
new iNum=5,i
for(i = 0; i <= iNum; i++) {
//send challenge rcon and receive response
new rcv[256],snd[256]
setc(snd,4,0xff)
copy(snd[4],255,"challenge rcon")
setc(snd[18],1,'^n')
socket_send(sock,snd,255)
//log_amx("Snd: %s",snd)
socket_recv(sock,rcv,255)
//log_amx("Rec:%s",rcv)
// get hlds rcon challenge number from response
copy(rconid,12,rcv[19])
replace(rconid,255,"^n","")
if(rconid[0]) break
}
if(!rconid[0]) {
log_amx("Could not get rcon challenge")
return PLUGIN_HANDLED
}
return PLUGIN_CONTINUE
}
public plugin_end()
{
socket_close(sock)
}