/*
Copyright 2011 - 2012, m0skVi4a ;]
Plugin created in Rousse, Bulgaria
Plugin thread 1:
http://amxmodxbg.org/forum/viewtopic.php?t=38972
Plugin thread 2:
https://forums.alliedmods.net/showthread.php?t=183491
Original posted by m0skVi4a ;]
Description:
With this plugin you can set prefixes to Admins with special flags. Also Admins can put custom prefixes to them or to other players if they want, but only if they have the required flag.
Commands:
ap_reload_prefixes
Reloads Prefixes' file from console without restarting the server.
ap_reload_badprefixes
Reloads Bad Prefixes' file from console without restarting the server.
ap_put "prefix"
Puts your prefix if you have the special flag. Or if there is no prefix typed, removes the prefix which you have.
ap_put_player "name" "prefix"
Puts prefix to the name you type if you have the special flag. Or if there is no prefix typed, removes the prefix which the player has.
CVARS:
"ap_bad_prefixes" - Is the Bad Prefixes option on(1) or off(0). Default: 1
"ap_listen" - Is the Admin Listen option on(1) or off(0). Default: 1
"ap_listen_flag" - The flag, needed for Listen option. Default: a
"ap_custom_current" - Is the Custom Prefix option for each Admin is on(1) or off(0). Default: 1
"ap_custom_current_flag" - The flag, needed for setting custom prefix. Default: b
"ap_custom_others" - Is the Custom Prefix Change option is on(1) or off(0). Default: 1
"ap_custom_others_flag" - The flag, needed for setting custom prefix to other players. Default: c
"ap_say_characters" - Is the Start Say Characters option on(1) or off(0). Default: 1
"ap_prefix_characters" - Is the Checker for Characters in Custom Prefixes' Options on(1) or off(0). Default: 1
All CVARS are without quotes
Credits:
m0skVi4a ;] - for the idea, making and testing the plugin
SpeeDeeR - for little help with the plugin
Ant1Lamer - for testing the plugin
Vasilii-Zaicev - for testing the plugin
Changelog:
April 22, 2012 - V1.0:
- First Release
May 19, 2012 - V2.0:
- Full optimization
- Added Bad Prefixes' file
- Added Multi-Lingual file
- Added IP and Name support in ap_prefixes.ini
- Added Forbidden Say characters
- New CVARS for setting the flags for each of the options
May 29, 2012 - V2.1:
- Fixed bug with some say or say_team commands are not executed
June 26, 2012 - V2.2:
- Fixed bug which blocks the default name change message in CS
- Fixed bug with the white chat plugin which does not worked
Visit:
http://www.forums.alliedmods.net
http://www.amxmodxbg.org
Contact me on:
E-MAIL:
[email protected]
SKYPE: pa7ohin
*/
#include <amxmodx>
#include <amxmisc>
#include <nvault>
#define FLAG_LOAD ADMIN_CFG
#define MAX_PREFIXES 33
#define MAX_BAD_PREFIXES 100
new g_bad_prefix, g_listen, g_listen_flag, g_custom_current, g_custom_current_flag, g_custom_others, g_custom_others_flag, g_say_characters, g_prefix_characters;
new pre_ips_count = 0, pre_names_count = 0, pre_flags_count = 0, bad_prefix_count = 0, i, temp_cvar[2];
new configs_dir[64], file[128], text[128], prefix[32], type[2], acc_type[32], length, line = 0, error[256];
new g_saytxt, g_maxplayers, g_nvault, g_team;
new g_typed[192], g_message[192], g_name[32], typed_prefix[33];
new pre_ips_collect[MAX_PREFIXES][33], ips_collect[MAX_PREFIXES][32], pre_names_collect[MAX_PREFIXES][33], names_collect[MAX_PREFIXES][33], pre_flags_collect[MAX_PREFIXES][33], flags_collect[MAX_PREFIXES][2], bad_prefixes_collect[MAX_BAD_PREFIXES][33], client_prefix[33][33];
new const forbidden_say_symbols[] = {
"/",
"!",
"%",
"$"
}
new const forbidden_prefixes_symbols[] = {
"/",
"\",
"%",
"$",
".",
":",
"?",
"!",
"@",
"#",
"%"
}
new const separator[] = "************************************************"
new const in_prefix[] = "[AdminPrefixes]"
public plugin_init()
{
register_plugin("Admin Prefixes", "2.2", "m0skVi4a ;]")
g_bad_prefix = register_cvar("ap_bad_prefixes", "1")
g_listen = register_cvar("ap_listen", "1")
g_listen_flag = register_cvar("ap_listen_flag", "a")
g_custom_current = register_cvar("ap_custom_current", "1")
g_custom_current_flag = register_cvar("ap_custom_current_flag", "b")
g_custom_others = register_cvar("ap_custom_others", "1")
g_custom_others_flag = register_cvar("ap_custom_others_flag", "c")
g_say_characters = register_cvar("ap_say_characters", "1")
g_prefix_characters = register_cvar("ap_prefix_characters", "1")
g_saytxt = get_user_msgid ("SayText")
g_maxplayers = get_maxplayers()
g_nvault = nvault_open("CustomAdminPrefixes")
register_concmd("ap_reload_prefixes", "LoadPrefixes")
register_concmd("ap_reload_badprefixes", "LoadBadPrefixes")
register_concmd("ap_put", "SetPrefix")
register_concmd("ap_put_player", "SetPlayerPrefix")
register_clcmd("say", "HookSay")
register_clcmd("say_team", "HookSayTeam")
register_dictionary("admin_prefixes.txt")
get_configsdir(configs_dir, charsmax(configs_dir))
LoadPrefixes(0)
LoadBadPrefixes(0)
}
public LoadPrefixes(id)
{
if(!(get_user_flags(id) & FLAG_LOAD))
{
console_print(id, "%L", LANG_SERVER, "PREFIX_PERMISSION", in_prefix)
return PLUGIN_HANDLED
}
line = 0, pre_flags_count = 0, pre_ips_count = 0, pre_names_count = 0;
formatex(file, charsmax(file), "%s/ap_prefixes.ini", configs_dir)
if(!file_exists(file))
{
formatex(error, charsmax(error), "%L", LANG_SERVER, "PREFIX_NOT_FOUND", in_prefix, file)
set_fail_state(error)
}
server_print(separator)
while(read_file(file, line++ , text, charsmax(text), length) && pre_flags_count <= MAX_PREFIXES)
{
if(!text[0] || text[0] == '^n' || text[0] == ';')
continue
parse(text, type, charsmax(type), prefix, charsmax(prefix), acc_type, charsmax(acc_type))
trim(prefix)
if(!type[0] || !prefix[0] || !acc_type[0])
continue
replace_all(prefix, charsmax(prefix), "!g", "^x04")
replace_all(prefix, charsmax(prefix), "!t", "^x03")
replace_all(prefix, charsmax(prefix), "!n", "^x01")
switch(type[0])
{
case 'i':
{
pre_ips_count++
pre_ips_collect[pre_ips_count] = prefix
ips_collect[pre_ips_count] = acc_type
server_print("%L", LANG_SERVER, "PREFIX_LOAD_IP", in_prefix, prefix, acc_type)
}
case 'n':
{
pre_names_count++
pre_names_collect[pre_names_count] = prefix
names_collect[pre_names_count] = acc_type
server_print("%L", LANG_SERVER, "PREFIX_LOAD_NAME", in_prefix, prefix, acc_type)
}
case 'f':
{
pre_flags_count++
pre_flags_collect[pre_flags_count] = prefix
flags_collect[pre_flags_count][0] = acc_type[0]
server_print("%L", LANG_SERVER, "PREFIX_LOAD_FLAG", in_prefix, prefix, acc_type[0])
}
default:
{
continue
}
}
}
if(pre_flags_count <= 0 && pre_ips_count <= 0 && pre_names_count <= 0)
{
server_print("%L", LANG_SERVER, "PREFIX_NO", in_prefix)
}
get_user_name(id, g_name, charsmax(g_name))
server_print("%L", LANG_SERVER, "PREFIX_LOADED_BY", in_prefix, g_name)
console_print(id, "%L", LANG_SERVER, "PREFIX_LOADED", in_prefix)
server_print(separator)
for(new i = 1; i <= g_maxplayers; i++)
{
client_prefix[id] = ""
CheckNvaultPrefix(i)
}
return PLUGIN_HANDLED
}
public LoadBadPrefixes(id)
{
if(!get_pcvar_num(g_bad_prefix))
{
console_print(id, "%L", LANG_SERVER, "BADP_OFF", in_prefix)
return PLUGIN_HANDLED
}
if(!(get_user_flags(id) & FLAG_LOAD))
{
console_print(id, "%L", LANG_SERVER, "BADP_PERMISSION", in_prefix)
return PLUGIN_HANDLED
}
line = 0, bad_prefix_count = 0;
formatex(file, charsmax(file), "%s/ap_bad_prefixes.ini", configs_dir)
if(!file_exists(file))
{
console_print(id, "%L", LANG_SERVER, "BADP_NOT_FOUND", in_prefix, file)
return PLUGIN_HANDLED
}
server_print(separator)
while(read_file(file, line++ , text, charsmax(text), length) && bad_prefix_count <= MAX_BAD_PREFIXES)
{
if(!text[0] || text[0] == '^n' || text[0] == ';')
continue
parse(text, prefix, charsmax(prefix))
if(!prefix[0])
continue
bad_prefix_count++
bad_prefixes_collect[bad_prefix_count] = prefix
server_print("%L", LANG_SERVER, "BADP_LOAD", in_prefix, prefix)
}
if(bad_prefix_count <= 0)
{
server_print("%L", LANG_SERVER, "BADP_LOAD", in_prefix)
}
get_user_name(id, g_name, charsmax(g_name))
server_print("%L", LANG_SERVER, "BADP_LOADED_BY", in_prefix, g_name)
console_print(id, "%L", LANG_SERVER, "BADP_LOADED", in_prefix)
server_print(separator)
for(new i = 1; i <= g_maxplayers; i++)
{
CheckNvaultPrefix(i)
}
return PLUGIN_HANDLED
}
public client_putinserver(id)
{
client_prefix[id] = ""
CheckNvaultPrefix(id)
}
public HookSay(id)
{
read_args(g_typed, charsmax(g_typed))
remove_quotes(g_typed)
if(equal(g_typed, "") || !is_user_connected(id))
return PLUGIN_HANDLED_MAIN
if((client_prefix[id][0] && get_pcvar_num(g_say_characters) == 1) || (!client_prefix[id][0] && get_pcvar_num(g_say_characters) == 2) || get_pcvar_num(g_say_characters) == 3)
{
if(check_say_characters(g_typed))
return PLUGIN_HANDLED_MAIN
}
get_user_name(id, g_name, charsmax(g_name))
g_team = get_user_team(id)
new const team_info[2][][] = {
{"*SPEC* ", "*DEAD* ", "*DEAD* ", "*SPEC* "},
{"", "", "", ""}
}
if(client_prefix[id][0])
{
formatex(g_message, charsmax(g_message), "^1%s^4%s^3 %s :^4 %s", team_info[is_user_alive(id)][g_team], client_prefix[id], g_name, g_typed)
}
else
{
formatex(g_message, charsmax(g_message), "^1%s^3%s :^1 %s", team_info[is_user_alive(id)][g_team], g_name, g_typed)
}
get_pcvar_string(g_listen_flag, temp_cvar, charsmax(temp_cvar))
for(new i = 1; i <= g_maxplayers; i++)
{
if(!is_user_connected(i))
continue
if(is_user_alive(id) && is_user_alive(i) || !is_user_alive(id) && !is_user_alive(i) || get_pcvar_num(g_listen) && get_user_flags(i) & read_flags(temp_cvar))
{
send_message(g_message, id, i)
}
}
return PLUGIN_HANDLED_MAIN
}
public HookSayTeam(id)
{
read_args(g_typed, charsmax(g_typed))
remove_quotes(g_typed)
if(equal(g_typed, "") || !is_user_connected(id))
return PLUGIN_HANDLED_MAIN
if((client_prefix[id][0] && get_pcvar_num(g_say_characters) == 1) || (!client_prefix[id][0] && get_pcvar_num(g_say_characters) == 2) || get_pcvar_num(g_say_characters) == 3)
{
if(check_say_characters(g_typed))
return PLUGIN_HANDLED_MAIN
}
get_user_name(id, g_name, charsmax(g_name))
g_team = get_user_team(id)
new const team_info[2][][] = {
{"(Spectator) ", "*DEAD*(Terrorist) ", "*DEAD*(Counter-Terrorist) ", "(Spectator) "},
{"(Spectator) ", "(Terrorist) ", "(Counter-Terrorist) ", "(Spectator) "}
}
if(client_prefix[id][0])
{
formatex(g_message, charsmax(g_message), "^1%s^4%s^3 %s :^4 %s", team_info[is_user_alive(id)][g_team], client_prefix[id], g_name, g_typed)
}
else
{
formatex(g_message, charsmax(g_message), "^1%s^3%s :^1 %s", team_info[is_user_alive(id)][g_team], g_name, g_typed)
}
get_pcvar_string(g_listen_flag, temp_cvar, charsmax(temp_cvar))
for(new i = 1; i <= g_maxplayers; i++)
{
if(!is_user_connected(i))
continue
if(get_user_team(id) == get_user_team(i) || get_pcvar_num(g_listen) && get_user_flags(i) & read_flags(temp_cvar))
{
if(is_user_alive(id) && is_user_alive(i) || !is_user_alive(id) && !is_user_alive(i) || get_pcvar_num(g_listen) && get_user_flags(i) & read_flags(temp_cvar))
{
send_message(g_message, id, i)
}
}
}
return PLUGIN_HANDLED_MAIN
}
public SetPrefix(id)
{
if(!get_pcvar_num(g_custom_current) || !get_pcvar_string(g_custom_current_flag, temp_cvar, charsmax(temp_cvar)))
{
console_print(id, "%L", LANG_SERVER, "CUSTOM_OFF", in_prefix)
return PLUGIN_HANDLED
}
if(!(get_user_flags(id) & read_flags(temp_cvar)))
{
console_print(id, "%L", LANG_SERVER, "CUSTOM_PERMISSION", in_prefix)
return PLUGIN_HANDLED
}
read_args(typed_prefix, charsmax(typed_prefix))
remove_quotes(typed_prefix)
trim(typed_prefix)
if(get_pcvar_num(g_bad_prefix) && is_bad_prefix(typed_prefix))
{
console_print(id, "%L", LANG_SERVER, "CUSTOM_FORBIDDEN", in_prefix, typed_prefix)
return PLUGIN_HANDLED
}
if(get_pcvar_num(g_prefix_characters) && check_prefix_characters(typed_prefix))
{
console_print(id, "%L", LANG_SERVER, "CUSTOM_SYMBOL", in_prefix, typed_prefix, forbidden_prefixes_symbols[i])
return PLUGIN_HANDLED
}
get_user_name(id, g_name, charsmax(g_name))
if(equal(typed_prefix, ""))
{
nvault_remove(g_nvault, g_name)
console_print(id, "%L", LANG_SERVER, "CUSTOM_REMOVE", in_prefix)
server_print("%L", LANG_SERVER, "CUSTOM_REMOVE_INFO", in_prefix, g_name)
PutPrefix(id)
return PLUGIN_HANDLED
}
nvault_set(g_nvault, g_name, typed_prefix)
client_prefix[id] = typed_prefix
console_print(id, "%L", LANG_SERVER, "CUSTOM_CHANGE", in_prefix, typed_prefix)
server_print("%L", LANG_SERVER, "CUSTOM_CHANGE_INFO", in_prefix, g_name, typed_prefix)
return PLUGIN_HANDLED
}
public SetPlayerPrefix(id)
{
if(!get_pcvar_num(g_custom_current) || !get_pcvar_string(g_custom_current_flag, temp_cvar, charsmax(temp_cvar)) || !get_pcvar_num(g_custom_others) || !get_pcvar_string(g_custom_others_flag, temp_cvar, charsmax(temp_cvar)))
{
console_print(id, "%L", LANG_SERVER, "CO_OFF", in_prefix)
return PLUGIN_HANDLED
}
if(!(get_user_flags(id) & read_flags(temp_cvar)))
{
console_print(id, "%L", LANG_SERVER, "CO_FORBIDDEN", in_prefix)
return PLUGIN_HANDLED
}
new name_tag[64], typed_name[32];
read_args(name_tag, charsmax(name_tag))
remove_quotes(name_tag)
parse(name_tag, typed_name, charsmax(typed_name), typed_prefix, charsmax(typed_prefix))
trim(typed_prefix)
if(get_pcvar_num(g_bad_prefix) && is_bad_prefix(typed_prefix))
{
console_print(id, "%L", LANG_SERVER, "CUSTOM_FORBIDDEN", in_prefix, typed_prefix)
return PLUGIN_HANDLED
}
if(get_pcvar_num(g_prefix_characters) && check_prefix_characters(typed_prefix))
{
console_print(id, "%L", LANG_SERVER, "CUSTOM_SYMBOL", in_prefix, typed_prefix, forbidden_prefixes_symbols[i])
return PLUGIN_HANDLED
}
get_user_name(id, g_name, charsmax(g_name))
new target = cmd_target(id, typed_name, 1)
if(!target)
return PLUGIN_HANDLED
if(equal(typed_prefix, ""))
{
nvault_remove(g_nvault, typed_name)
console_print(id, "%L", LANG_SERVER, "CO_REMOVE", in_prefix, typed_name)
server_print("%L", LANG_SERVER, "CO_REMOVE_INFO", in_prefix, g_name, typed_name)
PutPrefix(target)
return PLUGIN_HANDLED
}
nvault_set(g_nvault, typed_name, typed_prefix)
client_prefix[id] = typed_prefix
console_print(id, "%L", LANG_SERVER, "CO_CHANGE", in_prefix, typed_name, typed_prefix)
server_print("%L", LANG_SERVER, "CO_CHANGE_INFO", in_prefix, g_name, typed_name, typed_prefix)
return PLUGIN_HANDLED
}
public client_infochanged(id)
{
if(!is_user_connected(id))
return PLUGIN_CONTINUE
new g_old_name[32];
get_user_info(id, "name", g_name, charsmax(g_name))
get_user_name(id, g_old_name, charsmax(g_old_name))
if(!equal(g_name, g_old_name))
{
client_prefix[id] = ""
set_task(0.5, "CheckNvaultPrefix", id)
return PLUGIN_HANDLED
}
return PLUGIN_CONTINUE
}
public CheckNvaultPrefix(const id)
{
new nvault_prefix[33];
get_user_name(id, g_name, charsmax(g_name))
get_pcvar_string(g_custom_current_flag, temp_cvar, charsmax(temp_cvar))
new data = nvault_get(g_nvault, g_name, nvault_prefix, charsmax(nvault_prefix))
if(data && get_pcvar_num(g_custom_current) && get_user_flags(id) & read_flags(temp_cvar))
{
if((get_pcvar_num(g_bad_prefix) && is_bad_prefix(nvault_prefix)) || (get_pcvar_num(g_prefix_characters) && check_prefix_characters(nvault_prefix)))
{
PutPrefix(id)
return PLUGIN_HANDLED
}
client_prefix[id] = nvault_prefix
return PLUGIN_HANDLED
}
else
{
PutPrefix(id)
return PLUGIN_HANDLED
}
return PLUGIN_HANDLED
}
stock PutPrefix(const id)
{
new temp_ip[16];
get_user_ip(id, temp_ip, charsmax(temp_ip), 1)
for(new i = 0; i <= pre_ips_count; i++)
{
if(equal(temp_ip, ips_collect[i]))
{
client_prefix[id] = pre_ips_collect[i]
return PLUGIN_HANDLED
}
}
get_user_name(id, g_name, charsmax(g_name))
for(new i = 0; i <= pre_names_count; i++)
{
if(equal(g_name, names_collect[i]))
{
client_prefix[id] = pre_names_collect[i]
return PLUGIN_HANDLED
}
}
for(new i = 0; i <= pre_flags_count; i++)
{
if(get_user_flags(id) & read_flags(flags_collect[i]))
{
client_prefix[id] = pre_flags_collect[i]
return PLUGIN_HANDLED
}
}
return PLUGIN_HANDLED
}
stock send_message(const message[], const id, const i)
{
message_begin(MSG_ONE, g_saytxt, {0, 0, 0}, i)
write_byte(id)
write_string(message)
message_end()
}
bool:check_say_characters(const check_message[])
{
for(new i = 0; i < charsmax(forbidden_say_symbols); i++)
{
if(check_message[0] == forbidden_say_symbols[i])
{
return true
}
}
return false
}
bool:check_prefix_characters(const check_prefix[])
{
for(i = 0; i < charsmax(forbidden_prefixes_symbols); i++)
{
if(containi(check_prefix, forbidden_prefixes_symbols[i]) != -1)
{
return true
}
}
return false
}
bool:is_bad_prefix(const check_prefix[])
{
for(new i = 0; i <= bad_prefix_count; i++)
{
if(equali(check_prefix, bad_prefixes_collect[i]))
{
return true
}
}
return false
}