#if !defined _socket_included
#include <sockets>
#endif
#define MAX_LEN_COMMAND 40
#define MAX_LEN_CHALLENGE 32
bool:hltv_open_connection(const host[], port, &socket, challenge[MAX_LEN_CHALLENGE])
{
new error
socket = socket_open(host, port, SOCKET_UDP, error)
if(!(SOCK_ERROR_CREATE_SOCKET <= error <= SOCK_ERROR_WHILE_CONNECTING))
{
socket_send2(socket, fmt("%c%c%c%cchallenge rcon", 0xFF, 0xFF, 0xFF, 0xFF), 23)
if(socket_is_readable(socket) && socket_recv(socket, challenge, MAX_LEN_CHALLENGE))
{
split_challenge(challenge)
return true
}
else
{
hltv_close_connection(socket)
return false
}
}
return false
}
bool:hltv_send_cmd(socket, challenge[MAX_LEN_CHALLENGE], adminpass[], cmd[MAX_LEN_COMMAND], any:...)
{
new buffer[MAX_LEN_COMMAND + MAX_LEN_CHALLENGE]
vformat(buffer, charsmax(buffer), cmd, 5)
format(buffer, charsmax(buffer), "%c%c%c%c%s ^"%s^" %s", 0xFF, 0xFF, 0xFF, 0xFF, challenge, adminpass, buffer)
return socket_send2(socket, buffer, charsmax(buffer)) ? true : false
}
bool:hltv_close_connection(socket)
{
return socket_close(socket) ? true : false
}
split_challenge(input[])
{
new i
while(i != 13)
{
input[i++] = ' '
}
trim(input)
}