|
Veteran Member
Join Date: Nov 2004
Location: CA USA
|

08-22-2011
, 21:40
[REQ$] plugin edit for HLTV
|
#1
|
can someone please edit this plugin so my HLTV server can remain in the server without being kicked. As it's coded now, my HLTV server joins and gets kicked.
I have given the HLTV servers IP immunity and it's set for IP, but it still gets kicked. I've checked everything else, so it must be the code. Thanks.
Code:
/***************************************************************************************************
*
* HLTV_Report
*
* Copyright (C) 2007 |PJ|Shorty
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
****************************************************************************************************
*
* Description:
* if a player says "/cheater" or started with menu, an HLTV connect,
* record a movie and disconnect
*
* demo will be stored in /cstrike/ from the hltv server, name starting with
* the steam-id from the cheater.
*
* optional stored in a mysql database
*
* Required:
* - Socket Module
* - SQL Module (opt.)
* - Running 1.6 Server with latest AMXX (tested with 1.76d and above)
* - Running HLTV Server
*
* Usage:
* config files goes to /configs/hltv_report/
*
* you only have to start an HLTV-server without any parameters ("./hltv","hltv.exe"),
* the standard-port will then be 27020. you can change this by set the parameter
* -port <port> after your start-command.
*
* if you want to set an static ip for the hltv-server, add -ip xxx.xxx.xxx.xxx
*
* example linux: "./hltv -ip 123.123.123.123 -port 27050"
*
* hltv-rcon-password is set by:
* adminpassword <pw> in your hltv.cfg (if you dont have one, create it)
*
* other interesting hltv-cvars:
* name <text> - sets the HLTV proxy scoreboard name
* maxclients <n> - set spectator number limit for this proxy (default 128)
*
* any other hltv-cvars not needed for working, so change to whatever you want.
*
*
*
* PLUGIN:
*
* clcmds (changing access or switching off, see defines):
*
* "say /cheater" - start reporting by say-command
* "cheater_menu" - for use with amxx menu
*
* main cvars:
*
* hlr_hltv_ip - ip from the hltv-server
* hlr_hltv_port - port from the hltv-server
* hlr_hltv_rectime - how long recording the movie (seconds)
* hlr_hltv_rconpw - rcon-password (adminpassword) from the hltv-server
* hlr_hltv_delay - delay for hltv-server, will be added to hltv_rectime to
* get full rectime movie (seconds)
* hlr_server_alias - Servername saved to SQL and shown in web control panel,
* if "" using IP
*
* hlr_immunity <1|0> - honor immunity flag?
*
* hlr_reason_menu <1|0> - use the reason menu?
* hlr_ban_after <1|0> - ban player after reporting (ADMIN_BAN flag needed)
* hlr_ban_time <time> - if yes, ban time?
* hlr_ban_reason <REASON> - default ban reason (without menu)
*
* hlr_use_hud <1|0> - use info hud for reporting player
*
* hlr_steambans_cmd - command to execute for steambans demo
* (default: "maxrate 8000;loopcmd 1 120 servercmd sb_status")
*
* Changelog:
* - 0.1beta: 1st try
* - 0.2beta: added menu to choose the cheater
* - 0.3beta: added a lot from todo, todo list cleared
* - 0.4beta: changed main cvars to hlr_ style, renamed plugin
* - 0.5beta: added mysql support, ban after demo
* - 0.6beta: added reason menu, server alias
* - 0.7beta: added info hud
* - 0.8beta: changed: most defines to cvars, fixed some bugs
* - 0.9beta: bug fixes
* - 0.91beta:added random hltv hostnames
* - 0.94beta:fixed auto amxbans support
* - 0.95RC1: 1st release
* - 0.96RC1: added steambans support (thx Mordekay)
* - 0.96RC2: fixed bug if steambans not running
* - 0.96RC3: fixed bug if sqlite and mysql module running both
* - 0.97RC1: option to kick not allowed htlv (see defines)
* - 0.98RC1: chat command hidden to other player (see defines)
* - 0.99RC1: menu to choose the recording time, small bug fixes
* - 0.99RC2: added backwards compatibility with 1.76d
* - 0.99RC3: fixed sql bug: player names with ' cause an error
* - 0.99RC5: fixed amxbans bug: no ban reason sometimes
* - 1.0.0: 1st release
* - 1.0.1: fixed: SAYADMIN ADMIN_ALL not working
* fixed: task not stoped if player left before record ends
* - 1.1.0: fixed: now works on win too (thx slmclarengt)
* - 1.1.1: fixed: bug if debugmode is on (thx hasta)
*
* ToDo:
* - nothing yet
*
* Credits:
* - arCanuM: beta testing
* - Hawk552: sqlx tut (http://forums.alliedmods.net/showthread.php?t=46779)
* - Mordekay: steambans idea and help
* - AMXX Team: for creating excellent AmxModX ;-)
* - slmclarengt: help with windows fix
*
****************************************************************************************************
*** Change to your needs ***************************************************************************
***************************************************************************************************/
#define HLTV_IP "127.0.0.1" //default HLTV Server values
#define HLTV_PORT "27020"
#define HLTV_RECTIME "300" //record time (default: 120sec)
#define HLTV_DELAY "0" //should be 0 for working demo-link
#define HLTV_RCONPW "password" //"adminpassword" from hltv
#define HLTV_NAME "HLTV" //default HLTV connect name
#define HLTV_MAX_NAMES 10 //max HLTV names in hltv_names.cfg
#define USE_RECTIME_MENU //menu to choose the recording time
#define KICK_OTHER_HLTV //kick hltv not allowed (only IP check)
//comment to disable
#define ADMIN ADMIN_KICK //admin flag for console / menu command
#define SAYCOMMAND //allow say-command "/cheater"
#define HIDE_SAYCOMMAND //hide say command to other player
//comment to disable
#define SAYADMIN ADMIN_KICK //admin flag for say command (0 for all)
//only if SAYCOMMAND is enabled
#define MAX_ALLOWED_USERS 64 //max authids from allowed_users.txt
#define REPORT_FILE "cheater_reports.txt" //log for reporting players, located to /logs/
#define USE_SQL //save recorded data to database, for use with php
//comment to disable
#define REASONS_ARRAY {"Wallhack/ Aimbot","HighContrastModels/ MapExploiting/ Insults","TrashTalking","TK/TA","MicSpamming"}
#define RECTIME_ARRAY {120,240,300,360,420,600}
/**************************************************************************************************/
/** Nothing to change from here *******************************************************************/
/**************************************************************************************************/
#include <amxmodx>
#include <amxmisc>
#include <sockets>
#if defined USE_SQL
#include <sqlx>
#endif
#if (AMXX_VERSION_NUM > 176) //backwards compatibility with 1.76d (get_pcvar_string)
#define AMXX18
#endif
#define PLUGIN "HLTV_Report"
#define VERSION "1.1.1"
#define AUTHOR "|PJ|ShOrTy"
new hltvip[16] //ip, port and rconpw from hltv-server
new hltvpw[32]
new hltvport
new hltvgsip[22]
new hltvname[HLTV_MAX_NAMES][33]
new hltvname_num
new allowed_authid[MAX_ALLOWED_USERS][36]
new allowed_authid_num
new s_error=0
new s_handle=0
new recvattempts=0
new query_in_progress=0
new rec_in_progress=0
new hltvrcon[32]
new command[256]
new demofile[64]
new bool:is_stopped
//pcvarhandler
new pcvarip,pcvarport,pcvarpw,pcvarrectime,pcvardelay
new pcvarreasonmenu,pcvarban,pcvarbantime,pcvarbanreason
new pcvarimmun,pcvarusehud,pcvardebug
new pcvarsteambans,pcvarsteambanscmd
#if defined USE_SQL
new sqlHost[64],sqlUser[64],sqlPass[64],sqlDb[64],sqlTable[32],sqlLink[128]
new Handle:g_SqlTuple
new g_Cache[1024]
new pcvaralias
#endif
new g_Reasons[][]=REASONS_ARRAY
new g_Rectimes[]=RECTIME_ARRAY
new rec_time, rec_time_left
new g_Menu //Menu handler
new g_Menu_Players[32]
new g_PNum //PlayerNum
new g_RepPLid //reported Player ID
new g_RepPLname[33] //reported Player Name
new g_RepPLauthid[35] //reported Player AuthID
new g_RepPLip[16] //reported Player IP
new g_RepName[33] //reporting Player Name
new g_RepAuthid[35] //reporting Player AuthID
new g_Repid //reporting Player ID
new g_Rep_Reason[32] //Reason for reporting
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR);
register_dictionary("hltv_report.txt");
register_dictionary("common.txt");
register_cvar("hltv_report",VERSION,FCVAR_SERVER|FCVAR_SPONLY);
//register_concmd("hltv_start","hltv_connect")
//register_concmd("hltv_stop","hltv_disconnect")
#if defined SAYCOMMAND
register_clcmd("say /cheater","player_report",0,"- Starts Reporting with HLTV");
register_clcmd("say_team /cheater","player_report",0,"- Starts Reporting with HLTV");
#endif
register_clcmd("cheater_menu","player_report",ADMIN,"- Starts Reporting with HLTV");
AddMenuItem("Cheater Report","cheater_menu",ADMIN,"HLTV_Report")
//main cvars
pcvarip = register_cvar("hlr_hltv_ip",HLTV_IP);
pcvarport = register_cvar("hlr_hltv_port",HLTV_PORT);
pcvarrectime = register_cvar("hlr_hltv_rectime",HLTV_RECTIME);
pcvarpw = register_cvar("hlr_hltv_rconpw",HLTV_RCONPW);
pcvardelay = register_cvar("hlr_hltv_delay",HLTV_DELAY);
pcvarimmun = register_cvar("hlr_immunity","1");
pcvardebug = register_cvar("hlr_debug","0");
pcvarreasonmenu = register_cvar("hlr_reason_menu","1");
pcvarban = register_cvar("hlr_ban_after","0");
pcvarbantime = register_cvar("hlr_ban_time","0");
pcvarbanreason = register_cvar("hlr_ban_reason","Cheating");
pcvarusehud = register_cvar("hlr_use_hud","1");
pcvarsteambans = get_cvar_pointer("sbsrv_version");
pcvarsteambanscmd = register_cvar("hlr_steambans_cmd","maxrate 8000;loopcmd 1 120 servercmd sb_status");
#if defined USE_SQL
pcvaralias = register_cvar("hlr_server_alias","");
//sql cvars, no pcvar, only called at plugin-start
register_cvar("hlr_sql_host","127.0.0.1");
register_cvar("hlr_sql_user","root");
register_cvar("hlr_sql_pass","");
register_cvar("hlr_sql_db","amxx");
register_cvar("hlr_sql_table","amx_hlr_reports");
register_cvar("hlr_sql_link","");
#endif
}
public plugin_cfg()
{
set_cvar_string("hltv_report",VERSION);
new amx_cfg_dir[128]
new plugin_cfg_file[128]
get_configsdir(amx_cfg_dir,sizeof amx_cfg_dir -1);
formatex(plugin_cfg_file,sizeof plugin_cfg_file -1,"%s/hltv_report/main.cfg",amx_cfg_dir);
//load main config file
if (file_exists(plugin_cfg_file))
{
server_cmd("exec %s",plugin_cfg_file);
server_exec();
} else {
log_amx("[INFO] Loading file ^"/hltv_report/main.cfg^" failed, defaults loaded.");
}
//load hltv names cfg file
formatex(plugin_cfg_file,sizeof plugin_cfg_file -1,"%s/hltv_report/hltv_names.cfg",amx_cfg_dir);
if (file_exists(plugin_cfg_file))
{
new line,data[33],len
while(read_file(plugin_cfg_file,line,data,sizeof data -1,len) != 0){
trim(data);
if (!(equali(data,"//",2) || equali(data,""))){
copy(hltvname[hltvname_num],sizeof hltvname[] -1,data);
if (get_pcvar_num(pcvardebug))
log_amx("[DEBUG] loaded hostname (ID %d): %s ",hltvname_num,hltvname[hltvname_num]);
hltvname_num++;
}
line++;
}
}
if (!hltvname_num) {
if (get_pcvar_num(pcvardebug))
log_amx("[INFO] Loading file ^"/hltv_report/hltv_names.cfg^" failed, using default name.");
copy(hltvname[0],sizeof hltvname[] -1,HLTV_NAME);
hltvname_num=1;
}
//load allowed user names cfg file
formatex(plugin_cfg_file,127,"%s/hltv_report/allowed_user.cfg",amx_cfg_dir);
if (file_exists(plugin_cfg_file))
{
new line,data[128],l_data[36],r_data[93],len
while(read_file(plugin_cfg_file,line,data,sizeof data -1,len) != 0){
strbreak(data,l_data,sizeof l_data -1,r_data,sizeof r_data -1)
trim(l_data);
if (equal(l_data,"STEAM_",6)){
copy(allowed_authid[allowed_authid_num],sizeof allowed_authid[] -1,l_data);
if (get_pcvar_num(pcvardebug))
log_amx("[DEBUG] loaded allowed user (ID %d): %s ",allowed_authid_num,allowed_authid[allowed_authid_num]);
allowed_authid_num++;
}
line++;
}
}
new proxies = get_cvar_num("sv_proxies");
if (!proxies)
{
set_cvar_num("sv_proxies",1);
if (get_pcvar_num(pcvardebug))
log_amx("[INFO] Fixed sv_proxies cvar to allow HLTV connection!");
}
#if defined USE_SQL
formatex(plugin_cfg_file,127,"%s/hltv_report/sql.cfg",amx_cfg_dir);
if (file_exists(plugin_cfg_file))
{
server_cmd("exec %s",plugin_cfg_file);
server_exec();
get_cvar_string("hlr_sql_host",sqlHost,sizeof sqlHost -1);
get_cvar_string("hlr_sql_user",sqlUser,sizeof sqlUser -1);
get_cvar_string("hlr_sql_pass",sqlPass,sizeof sqlPass -1);
get_cvar_string("hlr_sql_db",sqlDb,sizeof sqlDb -1);
get_cvar_string("hlr_sql_table",sqlTable,sizeof sqlTable -1);
get_cvar_string("hlr_sql_link",sqlLink,sizeof sqlLink -1);
} else {
if (get_pcvar_num(pcvardebug))
log_amx("[INFO] Loading file ^"/hltv_report/sql.cfg^" failed, default sql.cfg loaded.");
get_cvar_string("amx_sql_host",sqlHost,sizeof sqlHost -1);
get_cvar_string("amx_sql_user",sqlUser,sizeof sqlUser -1);
get_cvar_string("amx_sql_pass",sqlPass,sizeof sqlPass -1);
get_cvar_string("amx_sql_db",sqlDb,sizeof sqlDb -1);
get_cvar_string("amx_sql_table",sqlTable,sizeof sqlTable -1);
}
set_task(2.0,"sql_init",199);
#endif
//set_task(10.0,"remove_hltvs",999);
}
#if defined KICK_OTHER_HLTV
public client_authorized(id) {
if(is_user_hltv(id)) {
new conIP[16],cvarIP[16],defaultIP[16];
get_user_ip(id,conIP,sizeof conIP -1,1);
#if defined AMXX18
get_pcvar_string(pcvarip,cvarIP,sizeof cvarIP -1)
#else
get_cvar_string("hlr_hltv_ip",cvarIP,sizeof cvarIP -1)
#endif
copy(defaultIP,sizeof defaultIP -1,"127.0.0.1"); //connecting hltv from localhost also allowed
if(equal(conIP,cvarIP) || equal(conIP,defaultIP)) {
if(get_pcvar_num(pcvardebug))
log_amx("[DEBUG] HLTV authorized (%s or %s)",cvarIP,defaultIP);
return PLUGIN_CONTINUE;
}
new userid = get_user_userid(id);
server_cmd("kick #%d",userid);
log_amx("[INFO] Kicked not allowed HLTV (IP: %s)",conIP);
}
return PLUGIN_CONTINUE;
}
#endif
/*
public remove_hltvs()
{
//disconnect hltv on map start if one is connected
if (hltv_is_connected())
{
hltv_disconnect();
}
}*/
build_player_menu(id)
{
new Players[32]
new pname[33]
new choice[3]
new m_title[33],m_back[10],m_next[10],m_exit[10]
if (!get_pcvar_num(pcvardebug))
{
get_players(Players,g_PNum,"ch");
} else {
get_players(Players,g_PNum,"h"); //for testing with bots
}
g_Menu = menu_create("MENU_TITLE","menu_handle");
formatex(m_title,32,"\r%L\w",id,"MENU_TITLE");
formatex(m_back,9,"%L",id,"BACK");
formatex(m_next,9,"%L",id,"MORE");
formatex(m_exit,9,"%L",id,"EXIT");
menu_setprop(g_Menu,MPROP_TITLE,m_title);
menu_setprop(g_Menu,MPROP_BACKNAME,m_back);
menu_setprop(g_Menu,MPROP_NEXTNAME,m_next);
menu_setprop(g_Menu,MPROP_EXITNAME,m_exit);
menu_setprop(g_Menu,MPROP_PERPAGE,7);
new pos_pl=0
new bool:b_show
for (new i=0; i<g_PNum; i++)
{
b_show=true;
if (get_pcvar_num(pcvarimmun) && access(Players[i],ADMIN_IMMUNITY))
b_show=false;
if (!get_pcvar_num(pcvardebug) && Players[i] == id)
b_show=false;
if(b_show)
{
g_Menu_Players[pos_pl]=Players[i];
num_to_str(pos_pl,choice,2);
get_user_name(Players[i],pname,32);
menu_additem(g_Menu,pname,choice);
pos_pl++;
}
}
if (!pos_pl)
{
client_print(id,print_chat,"[HLR] %L",id,"NO_PL_POSSIBLE");
return PLUGIN_HANDLED;
}
set_task(0.2,"show_usermenu",id);
return PLUGIN_CONTINUE;
}
public show_usermenu(id)
{
menu_display(id,g_Menu,0);
}
public menu_handle(id, menu, item)
{
if (id == 0) return PLUGIN_HANDLED;
if (item == MENU_EXIT)
{
menu_destroy(menu);
return PLUGIN_HANDLED;
}
// Get item info
new cmd[3]
new access, callback
new name[33]
menu_item_getinfo(menu, item, access, cmd,2,name,32, callback);
new n_cmd = str_to_num(cmd);
//get ids, names, ip and steamidīs and save to global variables
get_user_authid(id,g_RepAuthid,34);
get_user_name(id,g_RepName,32);
get_user_authid(g_Menu_Players[n_cmd],g_RepPLauthid,34);
get_user_ip(g_Menu_Players[n_cmd],g_RepPLip,15,1);
get_user_name(g_Menu_Players[n_cmd],g_RepPLname,32);
g_Repid=id;
g_RepPLid=g_Menu_Players[n_cmd];
formatex (demofile,sizeof demofile -1,"%s",g_RepPLauthid);
//win bug fix
if(!is_linux_server()) {
replace_all(demofile,sizeof demofile -1,":","-")
if(pcvardebug)
log_amx("[DEBUG] replace : with - (windows)")
}
menu_destroy(menu);
if (get_pcvar_num(pcvardebug))
log_amx("[DEBUG] Menu Player choice (%s,%s)",g_RepPLname,g_RepPLauthid)
if(get_pcvar_num(pcvarreasonmenu))
{
if(get_user_flags(id) & ADMIN_BAN)
{
set_task(0.2,"build_reason_menu",id);
} else {
set_task(0.2,"hltv_connect",id);
}
} else {
client_print(id, print_chat, "[HLR] %L", id,"START",g_RepPLname);
#if defined USE_RECTIME_MENU
set_task(0.1,"build_rectime_menu",id);
#else
set_task(0.2,"hltv_connect",id);
#endif
}
return PLUGIN_HANDLED;
}
public build_reason_menu(id)
{
new m_title[33],m_back[10],m_next[10],m_exit[10]
g_Menu = menu_create("MENU_TITLE_REASONS","menu_reason_handle");
formatex(m_title,32,"\r%L\w",id,"MENU_TITLE_REASONS");
formatex(m_back,9,"%L",id,"BACK");
formatex(m_next,9,"%L",id,"MORE");
formatex(m_exit,9,"%L",id,"EXIT");
menu_setprop(g_Menu,MPROP_TITLE,m_title);
menu_setprop(g_Menu,MPROP_BACKNAME,m_back);
menu_setprop(g_Menu,MPROP_NEXTNAME,m_next);
menu_setprop(g_Menu,MPROP_EXITNAME,m_exit);
menu_setprop(g_Menu,MPROP_PERPAGE,7);
menu_setprop(g_Menu,MPROP_EXIT,MEXIT_NEVER);
new temp[3]
for(new i=0;i < (sizeof g_Reasons); i++)
{
num_to_str(i,temp,2);
menu_additem(g_Menu,g_Reasons[i],temp);
}
set_task(0.2,"show_usermenu",id);
return PLUGIN_CONTINUE;
}
public menu_reason_handle(id, menu, item)
{
if (id == 0) return PLUGIN_HANDLED;
if (item == MENU_EXIT)
{
menu_destroy(menu);
return PLUGIN_HANDLED;
}
new cmd[3]
new access, callback
new name[33]
menu_item_getinfo(menu, item, access, cmd,2,name,32, callback);
menu_destroy(menu);
new i_cmd = str_to_num(cmd)
copy(g_Rep_Reason,sizeof g_Rep_Reason -1,g_Reasons[i_cmd]);
if (get_pcvar_num(pcvardebug))
log_amx("[DEBUG] Menu Reason choice (%s)",g_Rep_Reason)
#if defined USE_RECTIME_MENU
set_task(0.1,"build_rectime_menu",id);
#else
client_print(id, print_chat, "[HLR] %L", id,"START",g_RepPLname);
set_task(0.2,"hltv_connect",id);
#endif
return PLUGIN_HANDLED;
}
public build_rectime_menu(id)
{
new m_title[64],m_back[10],m_next[10],m_exit[10]
g_Menu = menu_create("MENU_TITLE_REASONS","menu_rectime_handle");
formatex(m_title,63,"\r%L\w",id,"MENU_TITLE_RECTIME");
formatex(m_back,9,"%L",id,"BACK");
formatex(m_next,9,"%L",id,"MORE");
formatex(m_exit,9,"%L",id,"EXIT");
menu_setprop(g_Menu,MPROP_TITLE,m_title);
menu_setprop(g_Menu,MPROP_BACKNAME,m_back);
menu_setprop(g_Menu,MPROP_NEXTNAME,m_next);
menu_setprop(g_Menu,MPROP_EXITNAME,m_exit);
menu_setprop(g_Menu,MPROP_PERPAGE,7);
menu_setprop(g_Menu,MPROP_EXIT,MEXIT_NEVER);
new temp[3],temp_time[8]
for(new i=0;i < (sizeof g_Rectimes); i++)
{
num_to_str(i,temp,2);
if(rec_time == g_Rectimes[i]) {
formatex(temp_time,7,"%d *",g_Rectimes[i])
} else {
formatex(temp_time,7,"%d",g_Rectimes[i])
}
menu_additem(g_Menu,temp_time,temp);
}
set_task(0.2,"show_usermenu",id);
return PLUGIN_CONTINUE;
}
public menu_rectime_handle(id, menu, item)
{
if (id == 0) return PLUGIN_HANDLED;
if (item == MENU_EXIT)
{
menu_destroy(menu);
return PLUGIN_HANDLED;
}
new cmd[3]
new access, callback
new name[33]
menu_item_getinfo(menu, item, access, cmd,2,name,32, callback);
menu_destroy(menu);
new i_cmd = str_to_num(cmd)
rec_time=g_Rectimes[i_cmd];
client_print(id, print_chat, "[HLR] %L", id,"START",g_RepPLname);
if (get_pcvar_num(pcvardebug))
log_amx("[DEBUG] Menu Rectime choice (%d sec)",rec_time)
set_task(0.2,"hltv_connect",id);
return PLUGIN_HANDLED;
}
public player_report (id,level,cid)
{
new authid[36]
new bool:is_allowed
get_user_authid(id,authid,35)
for(new i;i < allowed_authid_num;i++) {
if(equal(authid,allowed_authid[i])) {
is_allowed=true
break
}
}
if(!is_allowed && SAYADMIN!=ADMIN_ALL) {
//if (!cmd_access(id,level,cid,1))
if (!(get_user_flags(id) & SAYADMIN)) {
client_print(id,print_chat,"[HLR] %L",id,"NO_ACCESS")
client_print(id,print_chat,"[HLR] %L",id,"NO_ACCESS2")
return PLUGIN_HANDLED;
}
}
if (rec_in_progress) {
client_print(id, print_chat, "[HLR] %L", id,"INPROGRESS");
return PLUGIN_HANDLED;
}
rec_time=get_pcvar_num(pcvarrectime);
#if defined AMXX18
get_pcvar_string(pcvarbanreason,g_Rep_Reason,sizeof g_Rep_Reason -1)
#else
get_cvar_string("hlr_ban_reason",g_Rep_Reason,sizeof g_Rep_Reason -1)
#endif
build_player_menu(id);
#if defined HIDE_SAYCOMMAND
return PLUGIN_HANDLED;
#else
return PLUGIN_CONTINUE;
#endif
}
public hltv_connect(id)
{
if (rec_in_progress) {
client_print(id, print_chat, "[HLR] %L", id,"INPROGRESS");
return PLUGIN_HANDLED;
}
rec_in_progress=1;
client_print(id,print_chat,"HLTV Connect");
new timeleft = get_timeleft() + get_pcvar_num(pcvardelay);
if(get_cvar_num("mp_timelimit") > 0) {
if (timeleft < 60)
{
client_print(id, print_chat, "[HLR] %L", id,"NOT_ENOUGH_TIME_REMAIN");
rec_in_progress=0;
return PLUGIN_HANDLED;
}
if (timeleft < rec_time)
{
rec_time = timeleft - 30;
client_print(id, print_chat, "[HLR] %L", id,"NOT_ENOUGH_TIME",rec_time);
}
}
if(!id) {
copy(demofile,sizeof demofile -1,"console");
//copy(g_RepPLname,sizeof g_RepPLname,"console");
//copy(g_RepPLip,sizeof g_RepPLip,"console");
//copy(g_RepPLauthid,sizeof g_RepPLauthid,"console");
//copy(g_RepName,sizeof g_RepName,"console");
//copy(g_RepAuthid,sizeof g_RepPLname,"console");
//copy(g_Rep_Reason,sizeof g_Rep_Reason,"console");
}
get_user_ip(0,hltvgsip,21,0);
new name[33]
if(hltvname_num > 1) {
new name_num = random_num(0,hltvname_num-1)
copy(name,32,hltvname[name_num]);
if (get_pcvar_num(pcvardebug))
log_amx("[DEBUG] Choose Random HLTV Name ID %d: %s",name_num,hltvname[name_num]);
} else {
copy(name,32,hltvname[0]);
}
formatex (command,sizeof command -1,"name %s;delay %d;autoretry 1;connect %s",name,get_pcvar_num(pcvardelay),hltvgsip);
is_stopped=false;
sock_open();
return PLUGIN_CONTINUE;
}
public hltv_disconnect()
{
formatex (command,sizeof command -1,"stoprecording;autoretry 0;stop");
if(task_exists(123))
remove_task(123)
sock_open();
is_stopped=true;
rec_in_progress=0;
}
public sock_open()
{
if (query_in_progress) {
return PLUGIN_HANDLED;
}
if (s_handle) {
socket_close(s_handle);
}
query_in_progress=1;
#if defined AMXX18
get_pcvar_string(pcvarip,hltvip,15); //get ip, port and pw from cvars
get_pcvar_string(pcvarpw,hltvpw,31);
#else
get_cvar_string("hlr_hltv_ip",hltvip,15); //get ip, port and pw from cvars
get_cvar_string("hlr_hltv_rconpw",hltvpw,31);
#endif
hltvport=get_pcvar_num(pcvarport);
s_handle = socket_open(hltvip,hltvport,SOCKET_UDP,s_error);
if (s_error) {
switch (s_error) {
case 1:
log_amx("Error creating socket.");
case 2:
log_amx("Could not find server %s:%d", hltvip,hltvport);
case 3:
log_amx("Could not connect to server.");
}
s_handle = 0;
query_in_progress=0;
rec_in_progress=0;
is_stopped=true;
return PLUGIN_HANDLED;
}
if (get_pcvar_num(pcvardebug))
log_amx("[DEBUG] Open Socket to %s:%s",hltvip,hltvport)
set_task(0.1,"send_challenge_hltv");
return PLUGIN_CONTINUE;
}
public send_challenge_hltv()
{
new packetstr[32]
//call challenge number from hltv-server
formatex (packetstr,sizeof packetstr -1,"%c%c%c%cchallenge rcon^n",-1,-1,-1,-1);
socket_send2(s_handle, packetstr, sizeof packetstr -1);
if (get_pcvar_num(pcvardebug))
log_amx("[DEBUG] challenge number request sent")
set_task(0.1, "get_rconquery");
}
public get_rconquery()
{
if (!s_handle) {
log_amx("get_rconquery called with null socket");
query_in_progress = 0;
is_stopped=true;
return PLUGIN_CONTINUE;
}
if (!socket_change(s_handle, 1)) {
recvattempts += 1;
if (recvattempts > 5) {
log_amx("[ERROR] No response from the server.");
abort_query();
recvattempts = 0;
return PLUGIN_HANDLED;
} else {
if (get_pcvar_num(pcvardebug))
log_amx("[DEBUG] get challenge number try: %d",recvattempts);
set_task(0.2, "get_rconquery"); //5 * 0.2: 1sek timeout
return PLUGIN_CONTINUE;
}
}
recvattempts = 0;
new packet[64]
socket_recv(s_handle, packet, sizeof packet -1);
if (!equal(packet, {-1,-1,-1,-1,'c'}, 5)) {
log_amx("[ERROR] wrong challenge-nr response from HLTV server.");
log_amx("[ERROR] returning packet: %s",packet);
abort_query();
return PLUGIN_HANDLED;
}
if(get_pcvar_num(pcvardebug))
log_amx("[DEBUG] returning challengenr packet: %s",packet);
//build challenge number
new i=0
new offset = 19
while(47 < packet[i+offset] < 58) {
copy(hltvrcon[i],1,packet[i+offset]) ;
i++;
}
i=0;
set_task(0.5,"send_command");
return PLUGIN_CONTINUE;
}
public send_command()
{
new gspassword[32]
get_cvar_string("sv_password",gspassword,31); //game-server has a password? then get it
if(!equal(gspassword,"")) {
new temp[256]
copy(temp,sizeof temp -1,command);
formatex (command,sizeof command -1,"serverpassword %s;%s",gspassword,temp);
}
new packetstr[256]
formatex (packetstr, sizeof packetstr -1, "%c%c%c%crcon %s ^"%s^" %s^n", -1,-1,-1,-1,hltvrcon,hltvpw,command);
socket_send2(s_handle, packetstr, sizeof packetstr -1);
if (get_pcvar_num(pcvardebug))
log_amx("[DEBUG] sending command: %s",command)
if(!is_stopped) {
new connecttime;
connecttime=rec_time + 1; //+1 = offset task start recording
set_task(float(connecttime),"hltv_disconnect",123);
log_to_file(REPORT_FILE,"Report (%d sec) from %s (%s): %s (%s); Reason: %s",\
rec_time,g_RepName,g_RepAuthid,g_RepPLname,g_RepPLauthid,g_Rep_Reason);
set_task(1.0,"send_record");
} else {
abort_query();
if(is_user_connected(g_Repid)) {
client_print(g_Repid,print_chat,"[HLR] %L",g_Repid,"STOPPING_REC");
if (get_pcvar_num(pcvarusehud))
stop_remaining_hud();
}
if(get_pcvar_num(pcvarban) && is_user_connected(g_Repid)) {
if(get_user_flags(g_Repid) & ADMIN_BAN) {
client_print(g_Repid,print_chat,"[HLR] %L",g_Repid,"PLAYER_BAN",g_RepPLname);
}
set_task(2.0,"ban_cheater",321); //delayed cheater ban
}
}
return PLUGIN_CONTINUE;
}
public send_record()
{
if (!hltv_is_connected()) {
new hud[32]
formatex(hud,sizeof hud -1,"%L",g_Repid,"HUD_WAIT_HLTV");
show_hud_to_player(g_Repid,hud);
recvattempts += 1;
if (recvattempts > 5) {
log_amx("[ERROR] No HLTV is connected, sending ^"record^" command failed.");
if(is_user_connected(g_Repid)) {
client_print(g_Repid,print_chat,"[HLR] %L",g_Repid,"NO_HLTV");
client_print(g_Repid,print_chat,"[HLR] %L",g_Repid,"TRY_AGAIN");
}
abort_query();
recvattempts = 0;
rec_in_progress=0;
hltv_disconnect(); //only safety
return PLUGIN_HANDLED;
} else {
if (get_pcvar_num(pcvardebug))
log_amx("[DEBUG] waiting for hltv connect: %d sec",recvattempts);
set_task(1.0, "send_record");
return PLUGIN_CONTINUE;
}
}
recvattempts = 0;
if(is_user_connected(g_Repid)) {
client_print(g_Repid,print_chat,"[HLR] %L",g_Repid,"STARTING_REC",rec_time);
}
new packetstr[128];
//steambans support
if(pcvarsteambans) {
new sb_cmd[128];
#if defined AMXX18
get_pcvar_string(pcvarsteambanscmd,sb_cmd,sizeof sb_cmd -1);
#else
get_cvar_string("hlr_steambans_cmd",sb_cmd,sizeof sb_cmd -1)
#endif
formatex (packetstr, sizeof packetstr -1, "%c%c%c%crcon %s ^"%s^" %s ^n", -1,-1,-1,-1,hltvrcon,hltvpw,sb_cmd);
if (get_pcvar_num(pcvardebug))
log_amx("[DEBUG] Steambans running, sending: %s",sb_cmd);
} else {
formatex (packetstr, sizeof packetstr -1, "%c%c%c%crcon %s ^"%s^" loopcmd 1 120 servercmd status ^n", -1,-1,-1,-1,hltvrcon,hltvpw);
}
socket_send2(s_handle,packetstr,sizeof packetstr -1)
if (get_pcvar_num(pcvardebug))
log_amx("[DEBUG] sending record command (file: %s)",demofile)
formatex (packetstr, sizeof packetstr -1, "%c%c%c%crcon %s ^"%s^" record %s ^n", -1,-1,-1,-1,hltvrcon,hltvpw,demofile);
socket_send2(s_handle, packetstr, sizeof packetstr -1);
abort_query();
rec_in_progress=1;
if(get_pcvar_num(pcvarusehud) && is_user_connected(g_Repid)) {
rec_time_left=rec_time;
show_remaining_hud();
}
#if defined USE_SQL
new ServerName[64],Alias[64]
new Link[128],CurDate[11],CurTime[9],TimeStamp[11],CurMap[64]
get_time("%y%m%d%H%M",TimeStamp,10);
get_mapname(CurMap,63);
#if defined AMXX18
get_pcvar_string(pcvaralias,Alias,63);
#else
get_cvar_string("hlr_server_alias",Alias,63);
#endif
if (equali(Alias,""))
{
get_user_ip(0,ServerName,63,0);
} else {
copy(ServerName,63,Alias);
}
get_time("%y-%m-%d",CurDate,10);
get_time("%H:%M:%S",CurTime,8);
if(!equali(sqlLink,""))
{
formatex(Link,127,"%s/%s-%s-%s.dem",sqlLink,demofile,TimeStamp,CurMap);
} else {
formatex(Link,127,"%s-%s-%s.dem",demofile,TimeStamp,CurMap);
}
if (!get_pcvar_num(pcvarreasonmenu))
{
#if defined AMXX18
get_pcvar_string(pcvarbanreason,g_Rep_Reason,sizeof g_Rep_Reason -1);
#else
get_cvar_string("hlr_ban_reason",g_Rep_Reason,sizeof g_Rep_Reason -1);
#endif
}
// sql bug fix if a playername has a ' inside
new RepPLname_safe[65],RepName_safe[65]
copy(RepPLname_safe,64,g_RepPLname)
copy(RepName_safe,64,g_RepName)
replace_all(RepPLname_safe,64,"'","''")
replace_all(RepName_safe,64,"'","''")
formatex(g_Cache,1023,"INSERT INTO %s VALUES(\
'0','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','NEW')",\
sqlTable,CurDate,CurTime,RepPLname_safe,g_RepPLauthid,g_RepPLip,\
RepName_safe,g_RepAuthid,g_Rep_Reason,ServerName,Link);
SQL_ThreadQuery(g_SqlTuple,"QueryHandle",g_Cache);
#endif
return PLUGIN_CONTINUE;
}
public abort_query()
{
if(get_pcvar_num(pcvarusehud))
{
stop_remaining_hud(); //only for savely removing hud
}
socket_close(s_handle);
query_in_progress=0;
s_handle=0;
if (get_pcvar_num(pcvardebug))
log_amx("[DEBUG] Socket closed.",rec_time)
}
public client_disconnect(id)
{
if ((id == g_RepPLid) && rec_in_progress)
{
set_task(5.0,"delayed_hltv_stop");
}
}
public delayed_hltv_stop()
{
if(is_user_connected(g_Repid))
{
client_print(g_Repid,print_chat,"[HLR] %L",g_Repid,"PL_LEFT");
if(get_pcvar_num(pcvarusehud))
stop_remaining_hud();
}
query_in_progress=0;
hltv_disconnect();
}
public plugin_end()
{
//query_in_progress=0
//hltv_disconnect()
#if defined USE_SQL
SQL_FreeHandle(g_SqlTuple);
#endif
return PLUGIN_HANDLED;
}
public ban_cheater()
{
new reason[32]
if (get_pcvar_num(pcvarreasonmenu))
{
formatex(reason,31,"%s, demo will be checked",g_Rep_Reason);
} else {
#if defined AMXX18
get_pcvar_string(pcvarbanreason,g_Rep_Reason,sizeof g_Rep_Reason -1);
#else
get_cvar_string("hlr_ban_reason",g_Rep_Reason,sizeof g_Rep_Reason -1);
#endif
copy(reason,sizeof reason -1,g_Rep_Reason)
}
new bantime = get_pcvar_num(pcvarbantime);
new amxbans_version[16]
get_cvar_string("amxbans_version",amxbans_version,15) //check if amxbans running
if(strlen(amxbans_version)) {
//if (get_pcvar_num(pcvaramxbans)) { //different ban with amxbans
client_cmd(g_Repid,"amx_ban %d %s %s",bantime,g_RepPLauthid,reason);
if (get_pcvar_num(pcvardebug))
log_amx("[DEBUG] Ban via amxbans (time: %d,steamid %s,reason %s",bantime,g_RepPLauthid,reason);
} else {
new uid = get_user_userid(g_RepPLid);
client_cmd(g_Repid,"amx_ban %d %d ^"%s^"",uid,bantime,reason);
if (get_pcvar_num(pcvardebug))
log_amx("[DEBUG] Ban (time: %d,userid %s,reason %s",bantime,uid,reason);
}
//server_exec();
}
#if defined USE_SQL
public sql_init()
{
SQL_SetAffinity("mysql");
g_SqlTuple = SQL_MakeDbTuple(sqlHost,sqlUser,sqlPass,sqlDb);
formatex(g_Cache,1023,"CREATE TABLE IF NOT EXISTS %s (\
id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (id),\
Date DATE NOT NULL DEFAULT '0000-00-00',\
Time TIME NOT NULL DEFAULT '00:00:00',\
RepName TEXT NOT NULL DEFAULT '',\
RepAuthID TEXT NOT NULL DEFAULT '',\
RepIP TEXT NOT NULL DEFAULT '',\
fromName TEXT NOT NULL DEFAULT '',\
fromAuthID TEXT NOT NULL DEFAULT '',\
Reason TEXT NOT NULL DEFAULT '',\
Server TEXT NOT NULL DEFAULT '',\
DemoLink TEXT NOT NULL DEFAULT '',\
Status TEXT NOT NULL DEFAULT '')",sqlTable);
SQL_ThreadQuery(g_SqlTuple,"TableHandle",g_Cache);
}
public TableHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
// lots of error checking
if(FailState == TQUERY_CONNECT_FAILED)
return set_fail_state("Could not connect to SQL database.");
else if(FailState == TQUERY_QUERY_FAILED)
return set_fail_state("SQL Table Query failed.");
if(Errcode)
return log_amx("SQL Error on table query: %s",Error);
return PLUGIN_CONTINUE;
}
public QueryHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
// lots of error checking
if(FailState == TQUERY_CONNECT_FAILED)
return set_fail_state("Could not connect to SQL database.");
else if(FailState == TQUERY_QUERY_FAILED)
return set_fail_state("SQL Query failed.");
if(Errcode)
return log_amx(" SQL Error on query: %s",Error);
if (get_pcvar_num(pcvardebug))
log_amx("[DEBUG] saved demodata to sql.",rec_time)
return PLUGIN_CONTINUE;
}
#endif
public show_remaining_hud()
{
if(is_user_connected(g_Repid) && rec_in_progress)
{
new hud[64]
formatex(hud,63,"%L",g_Repid,"HUD_REC",rec_time,rec_time_left);
set_hudmessage(255, 255, 255, 0.02, 0.2, 0, 1.0, 0.3, 0.1, 0.8, -1);
show_hudmessage(g_Repid,hud);
rec_time_left--;
set_task(1.0,"show_remaining_hud",99);
}
}
hltv_is_connected()
{
new HLTVs[32]
new hltv_num=0
new pnum=0
get_players(HLTVs,pnum,"c") ;
for(new i;i < pnum;i++)
{
if (is_user_hltv(HLTVs[i])) { //get only hltv server
hltv_num++;
}
}
return hltv_num;
}
stop_remaining_hud()
{
if(task_exists(99))
remove_task(99);
}
show_hud_to_player(id,hud[])
{
set_hudmessage(255, 255, 255, 0.02, 0.2, 0, 1.0, 0.3, 0.1, 0.8, -1);
show_hudmessage(id,hud);
}
[edit] I think I found what was wrong. I needed to comment this line for the HLTV server to not be kicked. It is not being kicked now. Maybe someone who knows can confirm if this is the correct way to do this ?
#define KICK_OTHER_HLTV //kick hltv not allowed (only IP check)
__________________
{FJ}Justice STEAM_0:0:633975 If anyone needs any help with their server, Just add me to steam friends and I'll help you out.
Last edited by MAUGHOLD; 08-30-2011 at 19:13.
|
|