diff --git a/.editorconfig b/.editorconfig index a9c0ece..09d2f4c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,10 +12,9 @@ charset = utf-8 # Set default charset [*.{sma,inc,sh}] indent_style = space -indent_size = 2 +indent_size = 4 trim_trailing_whitespace = true - [{.vscode/*,.github/*}] indent_style = space -indent_size = 2 +indent_size = 4 diff --git a/cstrike/addons/amxmodx/scripting/CA_Addon_DeathMute.sma b/cstrike/addons/amxmodx/scripting/CA_Addon_DeathMute.sma index 06fff73..e9f72aa 100644 --- a/cstrike/addons/amxmodx/scripting/CA_Addon_DeathMute.sma +++ b/cstrike/addons/amxmodx/scripting/CA_Addon_DeathMute.sma @@ -4,235 +4,234 @@ #include <ChatAdditions> -#pragma ctrlchar '\' -#pragma tabsize 2 +#pragma tabsize 4 new Float: ca_deathmute_time, - bool: ca_deathmute_dead_hear_alive, - NotifyType_s: ca_deathmute_notify_type, - bool: ca_deathmute_notify_show_progressbar, - Float: ca_deathmute_notify_hud_x, - Float: ca_deathmute_notify_hud_y, - ca_deathmute_notify_hud_r, - ca_deathmute_notify_hud_g, - ca_deathmute_notify_hud_b, - ca_deathmute_immunity_flags[16] + bool: ca_deathmute_dead_hear_alive, + NotifyType_s: ca_deathmute_notify_type, + bool: ca_deathmute_notify_show_progressbar, + Float: ca_deathmute_notify_hud_x, + Float: ca_deathmute_notify_hud_y, + ca_deathmute_notify_hud_r, + ca_deathmute_notify_hud_g, + ca_deathmute_notify_hud_b, + ca_deathmute_immunity_flags[16] enum NotifyType_s: { - notify_Disabled, - notify_Chat, - notify_HUD + notify_Disabled, + notify_Chat, + notify_HUD } new bool: g_canSpeakWithAlive[MAX_PLAYERS + 1] new g_syncHudOj -public stock const PluginName[] = "CA Addon: Death mute" -public stock const PluginVersion[] = CA_VERSION -public stock const PluginAuthor[] = "Sergey Shorokhov" -public stock const PluginURL[] = "https://github.com/ChatAdditions/" -public stock const PluginDescription[] = "Alive players don't hear dead players after 5 secs" +public stock const PluginName[] = "CA Addon: Death mute" +public stock const PluginVersion[] = CA_VERSION +public stock const PluginAuthor[] = "Sergey Shorokhov" +public stock const PluginURL[] = "https://github.com/ChatAdditions/" +public stock const PluginDescription[] = "Alive players don't hear dead players after 5 secs" public plugin_init() { - register_plugin(PluginName, PluginVersion, PluginAuthor) + register_plugin(PluginName, PluginVersion, PluginAuthor) - register_dictionary("CA_Addon_DeathMute.txt") + register_dictionary("CA_Addon_DeathMute.txt") - Create_CVars() + Create_CVars() - AutoExecConfig(true, "CA_Addon_DeathMute", "ChatAdditions") + AutoExecConfig(true, "CA_Addon_DeathMute", "ChatAdditions") - // RegisterHam(Ham_TFC_Killed, "player", "CBasePlayer_Killed", .Post = true) // Does it need ?! - RegisterHam(Ham_Killed, "player", "CBasePlayer_Killed", .Post = true) - RegisterHam(Ham_Spawn, "player", "CBasePlayer_Spawn", .Post = true) + // RegisterHam(Ham_TFC_Killed, "player", "CBasePlayer_Killed", .Post = true) // Does it need ?! + RegisterHam(Ham_Killed, "player", "CBasePlayer_Killed", .Post = true) + RegisterHam(Ham_Spawn, "player", "CBasePlayer_Spawn", .Post = true) - g_syncHudOj = CreateHudSyncObj() + g_syncHudOj = CreateHudSyncObj() } Create_CVars() { - bind_pcvar_float(create_cvar("ca_deathmute_time", "5.0", - .description = "Time (in seconds) for killed players, during which they can report information to living players.\n\ - 0 - disabled functionality", - .has_min = true, .min_val = 0.0, - .has_max = true, .max_val = 240.0 - ), ca_deathmute_time - ) - - bind_pcvar_num(create_cvar("ca_deathmute_dead_hear_alive", "1", - .description = "Death mute mode\n\ - 0 - alive hear only alive, dead hear all\n\ - 1 - alive hear only alive, dead hear only dead", - .has_min = true, .min_val = 0.0, - .has_max = true, .max_val = 1.0 - ), ca_deathmute_dead_hear_alive - ) - - bind_pcvar_num(create_cvar("ca_deathmute_notify_type", "1", - .description = "Notification type for dead players \n\ - 0 - disabled functionality\n\ - 1 - chat message\n\ - 2 - HUD message" - ), ca_deathmute_notify_type - ) - - bind_pcvar_num(create_cvar("ca_deathmute_notify_show_progressbar", "1", - .description = "Show progressbar \n\ - 0 - disabled functionality" - ), ca_deathmute_notify_show_progressbar - ) - - bind_pcvar_float(create_cvar("ca_deathmute_notify_hud_x", "-1.0", - .description = "X position for HUD message\n\ - -1.0 - center", - .has_min = true, .min_val = -1.0, - .has_max = true, .max_val = 1.0 - ), ca_deathmute_notify_hud_x - ) - - bind_pcvar_float(create_cvar("ca_deathmute_notify_hud_y", "0.15", - .description = "Y position for HUD message\n\ - -1.0 - center", - .has_min = true, .min_val = -1.0, - .has_max = true, .max_val = 1.0 - ), ca_deathmute_notify_hud_y - ) - - bind_pcvar_num(create_cvar("ca_deathmute_notify_hud_r", "200", - .description = "Red color value (in RGB) [0...255]", - .has_min = true, .min_val = 0.0, - .has_max = true, .max_val = 255.0 - ), ca_deathmute_notify_hud_r - ) - - bind_pcvar_num(create_cvar("ca_deathmute_notify_hud_g", "50", - .description = "Green color value (in RGB) [0...255]", - .has_min = true, .min_val = 0.0, - .has_max = true, .max_val = 255.0 - ), ca_deathmute_notify_hud_g - ) - - bind_pcvar_num(create_cvar("ca_deathmute_notify_hud_b", "0", - .description = "Blue color value (in RGB) [0...255]", - .has_min = true, .min_val = 0.0, - .has_max = true, .max_val = 255.0 - ), ca_deathmute_notify_hud_b - ) - - bind_pcvar_string(create_cvar("ca_deathmute_immunity_flags", "a", - .description = "User immunity flag" - ), - ca_deathmute_immunity_flags, charsmax(ca_deathmute_immunity_flags) - ) + bind_pcvar_float(create_cvar("ca_deathmute_time", "5.0", + .description = "Time (in seconds) for killed players, during which they can report information to living players.^n\ + 0 - disabled functionality", + .has_min = true, .min_val = 0.0, + .has_max = true, .max_val = 240.0 + ), ca_deathmute_time + ) + + bind_pcvar_num(create_cvar("ca_deathmute_dead_hear_alive", "1", + .description = "Death mute mode^n\ + 0 - alive hear only alive, dead hear all^n\ + 1 - alive hear only alive, dead hear only dead", + .has_min = true, .min_val = 0.0, + .has_max = true, .max_val = 1.0 + ), ca_deathmute_dead_hear_alive + ) + + bind_pcvar_num(create_cvar("ca_deathmute_notify_type", "1", + .description = "Notification type for dead players ^n\ + 0 - disabled functionality^n\ + 1 - chat message^n\ + 2 - HUD message" + ), ca_deathmute_notify_type + ) + + bind_pcvar_num(create_cvar("ca_deathmute_notify_show_progressbar", "1", + .description = "Show progressbar ^n\ + 0 - disabled functionality" + ), ca_deathmute_notify_show_progressbar + ) + + bind_pcvar_float(create_cvar("ca_deathmute_notify_hud_x", "-1.0", + .description = "X position for HUD message^n\ + -1.0 - center", + .has_min = true, .min_val = -1.0, + .has_max = true, .max_val = 1.0 + ), ca_deathmute_notify_hud_x + ) + + bind_pcvar_float(create_cvar("ca_deathmute_notify_hud_y", "0.15", + .description = "Y position for HUD message^n\ + -1.0 - center", + .has_min = true, .min_val = -1.0, + .has_max = true, .max_val = 1.0 + ), ca_deathmute_notify_hud_y + ) + + bind_pcvar_num(create_cvar("ca_deathmute_notify_hud_r", "200", + .description = "Red color value (in RGB) [0...255]", + .has_min = true, .min_val = 0.0, + .has_max = true, .max_val = 255.0 + ), ca_deathmute_notify_hud_r + ) + + bind_pcvar_num(create_cvar("ca_deathmute_notify_hud_g", "50", + .description = "Green color value (in RGB) [0...255]", + .has_min = true, .min_val = 0.0, + .has_max = true, .max_val = 255.0 + ), ca_deathmute_notify_hud_g + ) + + bind_pcvar_num(create_cvar("ca_deathmute_notify_hud_b", "0", + .description = "Blue color value (in RGB) [0...255]", + .has_min = true, .min_val = 0.0, + .has_max = true, .max_val = 255.0 + ), ca_deathmute_notify_hud_b + ) + + bind_pcvar_string(create_cvar("ca_deathmute_immunity_flags", "a", + .description = "User immunity flag" + ), + ca_deathmute_immunity_flags, charsmax(ca_deathmute_immunity_flags) + ) } public client_disconnected(id) { - g_canSpeakWithAlive[id] = false + g_canSpeakWithAlive[id] = false - remove_task(id) + remove_task(id) } public CBasePlayer_Spawn(const id) { - if(!is_user_alive(id)) - return + if (!is_user_alive(id)) + return - g_canSpeakWithAlive[id] = true + g_canSpeakWithAlive[id] = true - remove_task(id) + remove_task(id) } public CBasePlayer_Killed(const id, const attacker) { - if(ca_deathmute_time <= 0.0) { - return - } + if (ca_deathmute_time <= 0.0) { + return + } - set_task_ex(ca_deathmute_time, "DisableSpeakWithAlive", .id = id) + set_task_ex(ca_deathmute_time, "DisableSpeakWithAlive", .id = id) - switch(ca_deathmute_notify_type) { - case notify_Disabled: return + switch (ca_deathmute_notify_type) { + case notify_Disabled: return - case notify_Chat: client_print_color(id, print_team_red, "%L %L", id, "DeathMute_prefix", id, "DeathMute_ChatMessage", ca_deathmute_time) + case notify_Chat: client_print_color(id, print_team_red, "%L %L", id, "DeathMute_prefix", id, "DeathMute_ChatMessage", ca_deathmute_time) - case notify_HUD: { - set_hudmessage( - ca_deathmute_notify_hud_r, - ca_deathmute_notify_hud_g, - ca_deathmute_notify_hud_b, - ca_deathmute_notify_hud_x, - ca_deathmute_notify_hud_y, - .fadeouttime = 0.0, - .holdtime = ca_deathmute_time - 1.0 - ) + case notify_HUD: { + set_hudmessage( + ca_deathmute_notify_hud_r, + ca_deathmute_notify_hud_g, + ca_deathmute_notify_hud_b, + ca_deathmute_notify_hud_x, + ca_deathmute_notify_hud_y, + .fadeouttime = 0.0, + .holdtime = ca_deathmute_time - 1.0 + ) - static clearedMessage[256] + static clearedMessage[256] - formatex(clearedMessage, charsmax(clearedMessage), "%L", id, "DeathMute_ChatMessage", ca_deathmute_time) - ReplaceColors(clearedMessage, charsmax(clearedMessage)) + formatex(clearedMessage, charsmax(clearedMessage), "%L", id, "DeathMute_ChatMessage", ca_deathmute_time) + ReplaceColors(clearedMessage, charsmax(clearedMessage)) - ShowSyncHudMsg(id, g_syncHudOj, clearedMessage) + ShowSyncHudMsg(id, g_syncHudOj, clearedMessage) + } } - } - if(ca_deathmute_notify_show_progressbar) { - UTIL_BarTime(id, floatround(ca_deathmute_time)) - } + if (ca_deathmute_notify_show_progressbar) { + UTIL_BarTime(id, floatround(ca_deathmute_time)) + } } public DisableSpeakWithAlive(const id) { - g_canSpeakWithAlive[id] = false + g_canSpeakWithAlive[id] = false - switch(ca_deathmute_notify_type) { - case notify_Chat: client_print_color(id, print_team_red, "%L %L", id, "DeathMute_prefix", id, "DeathMute_YouMuted") + switch (ca_deathmute_notify_type) { + case notify_Chat: client_print_color(id, print_team_red, "%L %L", id, "DeathMute_prefix", id, "DeathMute_YouMuted") - case notify_HUD: { - set_hudmessage( - ca_deathmute_notify_hud_r, - ca_deathmute_notify_hud_g, - ca_deathmute_notify_hud_b, - ca_deathmute_notify_hud_x, - ca_deathmute_notify_hud_y, - .fadeouttime = 0.0, - .holdtime = ca_deathmute_time - 1.0 - ) + case notify_HUD: { + set_hudmessage( + ca_deathmute_notify_hud_r, + ca_deathmute_notify_hud_g, + ca_deathmute_notify_hud_b, + ca_deathmute_notify_hud_x, + ca_deathmute_notify_hud_y, + .fadeouttime = 0.0, + .holdtime = ca_deathmute_time - 1.0 + ) - static clearedMessage[256] + static clearedMessage[256] - formatex(clearedMessage, charsmax(clearedMessage), "%L", id, "DeathMute_YouMuted", ca_deathmute_time) - ReplaceColors(clearedMessage, charsmax(clearedMessage)) + formatex(clearedMessage, charsmax(clearedMessage), "%L", id, "DeathMute_YouMuted", ca_deathmute_time) + ReplaceColors(clearedMessage, charsmax(clearedMessage)) - ShowSyncHudMsg(id, g_syncHudOj, clearedMessage) + ShowSyncHudMsg(id, g_syncHudOj, clearedMessage) + } } - } } public CA_Client_Voice(const listener, const sender) { - if(ca_deathmute_time <= 0.0) { - return CA_CONTINUE - } - - new bool: listenerHasImmunity = bool: (get_user_flags(listener) & read_flags(ca_deathmute_immunity_flags)) + if (ca_deathmute_time <= 0.0) { + return CA_CONTINUE + } + + new bool: listenerHasImmunity = bool: (get_user_flags(listener) & read_flags(ca_deathmute_immunity_flags)) - if(listenerHasImmunity) { - return CA_CONTINUE - } + if (listenerHasImmunity) { + return CA_CONTINUE + } - new bool: listenerAlive = bool: is_user_alive(listener) - new bool: senderAlive = bool: is_user_alive(sender) + new bool: listenerAlive = bool: is_user_alive(listener) + new bool: senderAlive = bool: is_user_alive(sender) - if(!g_canSpeakWithAlive[sender] && !senderAlive && listenerAlive) { - return CA_SUPERCEDE - } + if (!g_canSpeakWithAlive[sender] && !senderAlive && listenerAlive) { + return CA_SUPERCEDE + } - if(!ca_deathmute_dead_hear_alive && !listenerAlive && senderAlive) { - return CA_SUPERCEDE - } + if (!ca_deathmute_dead_hear_alive && !listenerAlive && senderAlive) { + return CA_SUPERCEDE + } - return CA_CONTINUE + return CA_CONTINUE } stock ReplaceColors(text[], len) { - replace_string(text, len, "\1", "") - replace_string(text, len, "\3", "") - replace_string(text, len, "\4", "") + replace_string(text, len, "^1", "") + replace_string(text, len, "^3", "") + replace_string(text, len, "^4", "") } diff --git a/cstrike/addons/amxmodx/scripting/CA_Addon_RankRestrictions.sma b/cstrike/addons/amxmodx/scripting/CA_Addon_RankRestrictions.sma index a3bf274..2626f76 100644 --- a/cstrike/addons/amxmodx/scripting/CA_Addon_RankRestrictions.sma +++ b/cstrike/addons/amxmodx/scripting/CA_Addon_RankRestrictions.sma @@ -3,307 +3,306 @@ #include <ChatAdditions> -#pragma ctrlchar '\' -#pragma tabsize 2 +#pragma tabsize 4 // Natives -native aes_get_player_level(const player); -native ar_get_user_level(const player, rankName[] = "", len = 0); -native crxranks_get_user_level(const player); -native cmsranks_get_user_level(player, level[] = "", len = 0); -native csstats_get_user_stats(const player, const stats[22]); -native Float:cmsstats_get_user_skill(player, skillname[] = "", namelen = 0, &skill_level = 0); -native get_user_skill(player, &Float: skill); -native get_user_stats(player, stats[STATSX_MAX_STATS], bodyhits[MAX_BODYHITS]); +native aes_get_player_level(const player) +native ar_get_user_level(const player, rankName[] = "", len = 0) +native crxranks_get_user_level(const player) +native cmsranks_get_user_level(player, level[] = "", len = 0) +native csstats_get_user_stats(const player, const stats[22]) +native Float:cmsstats_get_user_skill(player, skillname[] = "", namelen = 0, &skill_level = 0) +native get_user_skill(player, &Float: skill) +native get_user_stats(player, stats[STATSX_MAX_STATS], bodyhits[MAX_BODYHITS]) // enum any: eChatType { - voice_chat, - text_chat + voice_chat, + text_chat } enum any: eRankRestrictionsType { - rr_type_none, - rr_type_level, - rr_type_frags + rr_type_none, + rr_type_level, + rr_type_frags } new ca_rankrestrictions_type, - ca_rankrestrictions_type_kills, - ca_rankrestrictions_min_kills_voice_chat, - ca_rankrestrictions_min_kills_text_chat, - ca_rankrestrictions_type_level, - ca_rankrestrictions_min_level_voice_chat, - ca_rankrestrictions_min_level_text_chat, - ca_rankrestrictions_immunity_flag[16], - ca_rankrestrictions_steam_immunity - -public stock const PluginName[] = "CA Addon: Rank restrictions" -public stock const PluginVersion[] = CA_VERSION -public stock const PluginAuthor[] = "steelzzz" -public stock const PluginURL[] = "https://github.com/ChatAdditions/" -public stock const PluginDescription[] = "Restrict chat until you reach the rank of a statistic" + ca_rankrestrictions_type_kills, + ca_rankrestrictions_min_kills_voice_chat, + ca_rankrestrictions_min_kills_text_chat, + ca_rankrestrictions_type_level, + ca_rankrestrictions_min_level_voice_chat, + ca_rankrestrictions_min_level_text_chat, + ca_rankrestrictions_immunity_flag[16], + ca_rankrestrictions_steam_immunity + +public stock const PluginName[] = "CA Addon: Rank restrictions" +public stock const PluginVersion[] = CA_VERSION +public stock const PluginAuthor[] = "steelzzz" +public stock const PluginURL[] = "https://github.com/ChatAdditions/" +public stock const PluginDescription[] = "Restrict chat until you reach the rank of a statistic" public plugin_init() { - register_plugin(PluginName, PluginVersion, PluginAuthor) - register_dictionary("CA_Addon_RankRestrictions.txt") + register_plugin(PluginName, PluginVersion, PluginAuthor) + register_dictionary("CA_Addon_RankRestrictions.txt") - Create_CVars() + Create_CVars() - AutoExecConfig(true, "CA_Addon_RankRestrictions", "ChatAdditions") + AutoExecConfig(true, "CA_Addon_RankRestrictions", "ChatAdditions") } public plugin_natives() { - set_native_filter("native_filter") + set_native_filter("native_filter") } public native_filter(const name[], index, trap) { - if(strcmp(name, "aes_get_player_level")) { - return PLUGIN_HANDLED - } + if (strcmp(name, "aes_get_player_level")) { + return PLUGIN_HANDLED + } - if(strcmp(name, "ar_get_user_level")) { - return PLUGIN_HANDLED - } + if (strcmp(name, "ar_get_user_level")) { + return PLUGIN_HANDLED + } - if(strcmp(name, "crxranks_get_user_level")) { - return PLUGIN_HANDLED - } + if (strcmp(name, "crxranks_get_user_level")) { + return PLUGIN_HANDLED + } - if(strcmp(name, "csstats_get_user_stats")) { - return PLUGIN_HANDLED - } + if (strcmp(name, "csstats_get_user_stats")) { + return PLUGIN_HANDLED + } - if(strcmp(name, "cmsranks_get_user_level")) { - return PLUGIN_HANDLED - } + if (strcmp(name, "cmsranks_get_user_level")) { + return PLUGIN_HANDLED + } - if(strcmp(name, "cmsstats_get_user_skill")) { - return PLUGIN_HANDLED - } + if (strcmp(name, "cmsstats_get_user_skill")) { + return PLUGIN_HANDLED + } - if(strcmp(name, "get_user_stats")) { - return PLUGIN_HANDLED - } + if (strcmp(name, "get_user_stats")) { + return PLUGIN_HANDLED + } - return PLUGIN_CONTINUE + return PLUGIN_CONTINUE } Create_CVars() { - bind_pcvar_num(create_cvar("ca_rankrestrictions_type", "1", - .description = "Restrictions Type\n\ - 0 - Disable restrictions\n\ - 1 - Level restrictions\n\ - 2 - Kills count restrictions", - .has_min = true, .min_val = 0.0, - .has_max = true, .max_val = 2.0 - ), ca_rankrestrictions_type - ) - - bind_pcvar_num(create_cvar("ca_rankrestrictions_type_kills", "1", - .description = "Kill System Types\n\ - 0 - CSStats MySQL\n\ - 1 - CSX Module", - .has_min = true, .min_val = 0.0, - .has_max = true, .max_val = 1.0 - ), ca_rankrestrictions_type_kills - ) - - bind_pcvar_num(create_cvar("ca_rankrestrictions_min_kills_voice_chat", "10", - .description = "Min kills count to access VOICE chat", - .has_min = true, .min_val = 0.0 - ), ca_rankrestrictions_min_kills_voice_chat - ) - - bind_pcvar_num(create_cvar("ca_rankrestrictions_min_kills_text_chat", "10", - .description = "Min kills count to access TEXT chat", - .has_min = true, .min_val = 0.0 - ), ca_rankrestrictions_min_kills_text_chat - ) - - bind_pcvar_num(create_cvar("ca_rankrestrictions_type_level", "1", - .description = "Level System Types\n\ - 0 - Advanced Experience System\n\ - 1 - Army Ranks Ultimate\n\ - 2 - OciXCrom's Rank System\n\ - 3 - CMSStats Ranks\n\ - 4 - CMSStats MySQL\n\ - 5 - CSstatsX SQL\n\ - 6 - CSX Module", - .has_min = true, .min_val = 0.0, - .has_max = true, .max_val = 6.0 - ), ca_rankrestrictions_type_level - ) - - bind_pcvar_num(create_cvar("ca_rankrestrictions_min_level_voice_chat", "2", - .description = "Min Level to access VOICE chat", - .has_min = true, .min_val = 0.0 - ), ca_rankrestrictions_min_level_voice_chat - ) - - bind_pcvar_num(create_cvar("ca_rankrestrictions_min_level_text_chat", "2", - .description = "Min Level to access TEXT chat", - .has_min = true, .min_val = 0.0 - ), ca_rankrestrictions_min_level_text_chat - ) - - bind_pcvar_string(create_cvar("ca_rankrestrictions_immunity_flag", "a", - .description = "User immunity flag" - ), - ca_rankrestrictions_immunity_flag, charsmax(ca_rankrestrictions_immunity_flag) - ) - - bind_pcvar_num(create_cvar("ca_rankrestrictions_steam_immunity", "0", - .description = "Enable immunity for steam players", - .has_min = true, .min_val = 0.0, - .has_max = true, .max_val = 1.0 - ), ca_rankrestrictions_steam_immunity - ) + bind_pcvar_num(create_cvar("ca_rankrestrictions_type", "1", + .description = "Restrictions Type^n\ + 0 - Disable restrictions^n\ + 1 - Level restrictions^n\ + 2 - Kills count restrictions", + .has_min = true, .min_val = 0.0, + .has_max = true, .max_val = 2.0 + ), ca_rankrestrictions_type + ) + + bind_pcvar_num(create_cvar("ca_rankrestrictions_type_kills", "1", + .description = "Kill System Types^n\ + 0 - CSStats MySQL^n\ + 1 - CSX Module", + .has_min = true, .min_val = 0.0, + .has_max = true, .max_val = 1.0 + ), ca_rankrestrictions_type_kills + ) + + bind_pcvar_num(create_cvar("ca_rankrestrictions_min_kills_voice_chat", "10", + .description = "Min kills count to access VOICE chat", + .has_min = true, .min_val = 0.0 + ), ca_rankrestrictions_min_kills_voice_chat + ) + + bind_pcvar_num(create_cvar("ca_rankrestrictions_min_kills_text_chat", "10", + .description = "Min kills count to access TEXT chat", + .has_min = true, .min_val = 0.0 + ), ca_rankrestrictions_min_kills_text_chat + ) + + bind_pcvar_num(create_cvar("ca_rankrestrictions_type_level", "1", + .description = "Level System Types^n\ + 0 - Advanced Experience System^n\ + 1 - Army Ranks Ultimate^n\ + 2 - OciXCrom's Rank System^n\ + 3 - CMSStats Ranks^n\ + 4 - CMSStats MySQL^n\ + 5 - CSstatsX SQL^n\ + 6 - CSX Module", + .has_min = true, .min_val = 0.0, + .has_max = true, .max_val = 6.0 + ), ca_rankrestrictions_type_level + ) + + bind_pcvar_num(create_cvar("ca_rankrestrictions_min_level_voice_chat", "2", + .description = "Min Level to access VOICE chat", + .has_min = true, .min_val = 0.0 + ), ca_rankrestrictions_min_level_voice_chat + ) + + bind_pcvar_num(create_cvar("ca_rankrestrictions_min_level_text_chat", "2", + .description = "Min Level to access TEXT chat", + .has_min = true, .min_val = 0.0 + ), ca_rankrestrictions_min_level_text_chat + ) + + bind_pcvar_string(create_cvar("ca_rankrestrictions_immunity_flag", "a", + .description = "User immunity flag" + ), + ca_rankrestrictions_immunity_flag, charsmax(ca_rankrestrictions_immunity_flag) + ) + + bind_pcvar_num(create_cvar("ca_rankrestrictions_steam_immunity", "0", + .description = "Enable immunity for steam players", + .has_min = true, .min_val = 0.0, + .has_max = true, .max_val = 1.0 + ), ca_rankrestrictions_steam_immunity + ) } public CA_Client_Say(player, const bool: isTeamMessage, const message[]) { - if(!CanCommunicate(player, true, text_chat)) { - return CA_SUPERCEDE - } + if (!CanCommunicate(player, true, text_chat)) { + return CA_SUPERCEDE + } - return CA_CONTINUE + return CA_CONTINUE } public CA_Client_Voice(const listener, const sender) { - if(!CanCommunicate(sender, false, voice_chat)) { - // need chat notification? - return CA_SUPERCEDE - } - - return CA_CONTINUE + if (!CanCommunicate(sender, false, voice_chat)) { + // need chat notification? + return CA_SUPERCEDE + } + + return CA_CONTINUE } bool: CanCommunicate(const player, const bool: print, chatType) { - if(ca_rankrestrictions_type <= rr_type_none) { - return true - } - - // check is gagged? - if(get_user_flags(player) & read_flags(ca_rankrestrictions_immunity_flag)) { - return true - } - - if(ca_rankrestrictions_steam_immunity && _is_user_steam(player)) { - return true - } - - switch(chatType) { - case voice_chat: { - if(ca_rankrestrictions_type == rr_type_level && GetUserLevel(player) < ca_rankrestrictions_min_level_voice_chat) { - if(print) { - client_print_color(player, print_team_red, "%L", - player, "RankRestrictions_Warning_MinLevel", ca_rankrestrictions_min_level_voice_chat - ) - } - - return false - } + if (ca_rankrestrictions_type <= rr_type_none) { + return true + } - if(ca_rankrestrictions_type == rr_type_frags && GetUserFragsFromStats(player) < ca_rankrestrictions_min_kills_voice_chat) { - if(print) { - client_print_color(player, print_team_red, "%L", - player, "RankRestrictions_Warning_MinKills", ca_rankrestrictions_min_kills_voice_chat - ) - } + // check is gagged? + if (get_user_flags(player) & read_flags(ca_rankrestrictions_immunity_flag)) { + return true + } - return false - } + if (ca_rankrestrictions_steam_immunity && _is_user_steam(player)) { + return true } - case text_chat: { - if(ca_rankrestrictions_type == rr_type_level && GetUserLevel(player) < ca_rankrestrictions_min_level_text_chat) { - if(print) { - client_print_color(player, print_team_red, "%L", - player, "RankRestrictions_Warning_MinLevel", ca_rankrestrictions_min_level_text_chat - ) + switch (chatType) { + case voice_chat: { + if (ca_rankrestrictions_type == rr_type_level && GetUserLevel(player) < ca_rankrestrictions_min_level_voice_chat) { + if (print) { + client_print_color(player, print_team_red, "%L", + player, "RankRestrictions_Warning_MinLevel", ca_rankrestrictions_min_level_voice_chat + ) + } + + return false + } + + if (ca_rankrestrictions_type == rr_type_frags && GetUserFragsFromStats(player) < ca_rankrestrictions_min_kills_voice_chat) { + if (print) { + client_print_color(player, print_team_red, "%L", + player, "RankRestrictions_Warning_MinKills", ca_rankrestrictions_min_kills_voice_chat + ) + } + + return false + } } - return false - } - - if(ca_rankrestrictions_type == rr_type_frags && GetUserFragsFromStats(player) < ca_rankrestrictions_min_kills_text_chat) { - if(print) { - client_print_color(player, print_team_red, "%L", - player, "RankRestrictions_Warning_MinKills", ca_rankrestrictions_min_kills_text_chat - ) + case text_chat: { + if (ca_rankrestrictions_type == rr_type_level && GetUserLevel(player) < ca_rankrestrictions_min_level_text_chat) { + if (print) { + client_print_color(player, print_team_red, "%L", + player, "RankRestrictions_Warning_MinLevel", ca_rankrestrictions_min_level_text_chat + ) + } + + return false + } + + if (ca_rankrestrictions_type == rr_type_frags && GetUserFragsFromStats(player) < ca_rankrestrictions_min_kills_text_chat) { + if (print) { + client_print_color(player, print_team_red, "%L", + player, "RankRestrictions_Warning_MinKills", ca_rankrestrictions_min_kills_text_chat + ) + } + + return false + } } - - return false - } } - } - return true + return true } GetUserLevel(const player) { - switch(ca_rankrestrictions_type_level) { - case 0: return aes_get_player_level(player) - case 1: return ar_get_user_level(player) - case 2: return crxranks_get_user_level(player) - case 3: return cmsranks_get_user_level(player) - case 4: { - new iSkill - cmsstats_get_user_skill(player, .skill_level = iSkill) - return iSkill - } - case 5: { - new Float:iSkill - get_user_skill(player, iSkill) - return floatround(iSkill) - } - case 6: { - new stats[STATSX_MAX_STATS], hits[MAX_BODYHITS] - get_user_stats(player, stats, hits) - return stats[STATSX_RANK] + switch (ca_rankrestrictions_type_level) { + case 0: return aes_get_player_level(player) + case 1: return ar_get_user_level(player) + case 2: return crxranks_get_user_level(player) + case 3: return cmsranks_get_user_level(player) + case 4: { + new iSkill + cmsstats_get_user_skill(player, .skill_level = iSkill) + return iSkill + } + case 5: { + new Float:iSkill + get_user_skill(player, iSkill) + return floatround(iSkill) + } + case 6: { + new stats[STATSX_MAX_STATS], hits[MAX_BODYHITS] + get_user_stats(player, stats, hits) + return stats[STATSX_RANK] + } } - } - return 0 + return 0 } GetUserFragsFromStats(const player) { - enum { stats_Frags/* , stats_Deaths, stats_Rounds = 16 */ } - - switch(ca_rankrestrictions_type_kills) { - case 0: { - new stats[22] - csstats_get_user_stats(player, stats) - return stats[stats_Frags] - } - case 1: { - new stats[STATSX_MAX_STATS], hits[MAX_BODYHITS] - get_user_stats(player, stats, hits) - return stats[STATSX_KILLS] - } - } - - return 0 + enum { stats_Frags/* , stats_Deaths, stats_Rounds = 16 */ } + + switch (ca_rankrestrictions_type_kills) { + case 0: { + new stats[22] + csstats_get_user_stats(player, stats) + return stats[stats_Frags] + } + case 1: { + new stats[STATSX_MAX_STATS], hits[MAX_BODYHITS] + get_user_stats(player, stats, hits) + return stats[STATSX_KILLS] + } + } + + return 0 } static stock bool: _is_user_steam(const player) { - #if (defined _reapi_reunion_included) - if(has_reunion()) - return (REU_GetAuthtype(player) == CA_TYPE_STEAM) - #endif + #if (defined _reapi_reunion_included) + if (has_reunion()) + return (REU_GetAuthtype(player) == CA_TYPE_STEAM) + #endif - static dp_r_id_provider - if (dp_r_id_provider || (dp_r_id_provider = get_cvar_pointer("dp_r_id_provider"))) { - server_cmd("dp_clientinfo %i", player) - server_exec() + static dp_r_id_provider + if (dp_r_id_provider || (dp_r_id_provider = get_cvar_pointer("dp_r_id_provider"))) { + server_cmd("dp_clientinfo %i", player) + server_exec() - #define DP_AUTH_STEAM 2 - if(get_pcvar_num(dp_r_id_provider) == DP_AUTH_STEAM) - return true + #define DP_AUTH_STEAM 2 + if (get_pcvar_num(dp_r_id_provider) == DP_AUTH_STEAM) + return true - return false - } + return false + } - return false + return false } diff --git a/cstrike/addons/amxmodx/scripting/CA_Addon_RequestUnGag.sma b/cstrike/addons/amxmodx/scripting/CA_Addon_RequestUnGag.sma index d17c2f9..16cf8b5 100644 --- a/cstrike/addons/amxmodx/scripting/CA_Addon_RequestUnGag.sma +++ b/cstrike/addons/amxmodx/scripting/CA_Addon_RequestUnGag.sma @@ -4,96 +4,95 @@ #include <ChatAdditions> #include <CA_GAG_API> -#pragma ctrlchar '\' -#pragma tabsize 2 +#pragma tabsize 4 new Float: g_userNextRequestTime[MAX_PLAYERS + 1] new ca_requestungag_cmd[32], - Float: ca_requestungag_delay, - ca_gag_access_flags_high[32], - ca_gag_access_flags[32] + Float: ca_requestungag_delay, + ca_gag_access_flags_high[32], + ca_gag_access_flags[32] -public stock const PluginName[] = "CA Addon: Request UnGAG" -public stock const PluginVersion[] = CA_VERSION -public stock const PluginAuthor[] = "steelzzz" -public stock const PluginURL[] = "https://github.com/ChatAdditions/" -public stock const PluginDescription[] = "A player can apologize to the administration" +public stock const PluginName[] = "CA Addon: Request UnGAG" +public stock const PluginVersion[] = CA_VERSION +public stock const PluginAuthor[] = "steelzzz" +public stock const PluginURL[] = "https://github.com/ChatAdditions/" +public stock const PluginDescription[] = "A player can apologize to the administration" public plugin_init() { - register_plugin(PluginName, PluginVersion, PluginAuthor) - register_dictionary("CA_Addon_RequestUngag.txt") + register_plugin(PluginName, PluginVersion, PluginAuthor) + register_dictionary("CA_Addon_RequestUngag.txt") - Create_CVars() + Create_CVars() - AutoExecConfig(true, "CA_Addon_RequestUnGag", "ChatAdditions") + AutoExecConfig(true, "CA_Addon_RequestUnGag", "ChatAdditions") } public Create_CVars() { - bind_pcvar_string(create_cvar("ca_requestungag_cmd", "/sorry", - .description = "Request ungag command"), - ca_requestungag_cmd, charsmax(ca_requestungag_cmd) - ) - - bind_pcvar_float(create_cvar("ca_requestungag_delay", "40.0", - .description = "delay time request ungag", - .has_min = true, .min_val = 1.0), - ca_requestungag_delay - ) - - bind_pcvar_string(get_cvar_pointer("ca_gag_access_flags_high"), - ca_gag_access_flags_high, charsmax(ca_gag_access_flags_high) - ) - - bind_pcvar_string(get_cvar_pointer("ca_gag_access_flags"), - ca_gag_access_flags, charsmax(ca_gag_access_flags) - ) + bind_pcvar_string(create_cvar("ca_requestungag_cmd", "/sorry", + .description = "Request ungag command"), + ca_requestungag_cmd, charsmax(ca_requestungag_cmd) + ) + + bind_pcvar_float(create_cvar("ca_requestungag_delay", "40.0", + .description = "delay time request ungag", + .has_min = true, .min_val = 1.0), + ca_requestungag_delay + ) + + bind_pcvar_string(get_cvar_pointer("ca_gag_access_flags_high"), + ca_gag_access_flags_high, charsmax(ca_gag_access_flags_high) + ) + + bind_pcvar_string(get_cvar_pointer("ca_gag_access_flags"), + ca_gag_access_flags, charsmax(ca_gag_access_flags) + ) } // TODO: Create `_PRE` hook forward instead this. public CA_Client_Say(player, const bool: isTeamMessage, const message[]) { - if(strcmp(message, ca_requestungag_cmd) != 0) - return CA_CONTINUE + if (strcmp(message, ca_requestungag_cmd) != 0) + return CA_CONTINUE - if(!ca_has_user_gag(player)) { - client_print_color(player, print_team_default, "%L", player, "RequestUnGag_NoAccess") + if (!ca_has_user_gag(player)) { + client_print_color(player, print_team_default, "%L", player, "RequestUnGag_NoAccess") - return CA_SUPERCEDE - } + return CA_SUPERCEDE + } - new Float: gametime = get_gametime() - if(g_userNextRequestTime[player] > gametime) { - new timeLeft = floatround(g_userNextRequestTime[player] - gametime, floatround_ceil) - client_print_color(player, print_team_default, "%L", player, "RequestUnGag_TimeOut", timeLeft) + new Float: gametime = get_gametime() + if (g_userNextRequestTime[player] > gametime) { + new timeLeft = floatround(g_userNextRequestTime[player] - gametime, floatround_ceil) + client_print_color(player, print_team_default, "%L", player, "RequestUnGag_TimeOut", timeLeft) - return CA_SUPERCEDE - } + return CA_SUPERCEDE + } - new userID = get_user_userid(player) + new userID = get_user_userid(player) - new players[MAX_PLAYERS], count - get_players_ex(players, count, (GetPlayers_ExcludeBots | GetPlayers_ExcludeHLTV)) + new players[MAX_PLAYERS], count + get_players_ex(players, count, (GetPlayers_ExcludeBots | GetPlayers_ExcludeHLTV)) - new accessFlagsHigh = read_flags(ca_gag_access_flags_high) - new accessFlags = read_flags(ca_gag_access_flags) + new accessFlagsHigh = read_flags(ca_gag_access_flags_high) + new accessFlags = read_flags(ca_gag_access_flags) - for(new i; i < count; i++) { - new receiver = players[i] + for(new i; i < count; i++) { + new receiver = players[i] - if(receiver == player) - continue + if (receiver == player) + continue - if(!(get_user_flags(receiver) & (accessFlags | accessFlagsHigh))) - continue + if (!(get_user_flags(receiver) & (accessFlags | accessFlagsHigh))) + continue - client_print_color(receiver, print_team_default, "%L", - receiver, "RequestUnGag_Requested", - player, userID - ) - } + client_print_color(receiver, print_team_default, "%L", + receiver, "RequestUnGag_Requested", + player, userID + ) + } - g_userNextRequestTime[player] = gametime + ca_requestungag_delay + g_userNextRequestTime[player] = gametime + ca_requestungag_delay - client_print_color(player, print_team_default, "%L", player, "RequestUnGag_YouRequested") - return CA_SUPERCEDE + client_print_color(player, print_team_default, "%L", player, "RequestUnGag_YouRequested") + return CA_SUPERCEDE } diff --git a/cstrike/addons/amxmodx/scripting/CA_Addon_VoteGag.sma b/cstrike/addons/amxmodx/scripting/CA_Addon_VoteGag.sma index 056c592..12144d4 100644 --- a/cstrike/addons/amxmodx/scripting/CA_Addon_VoteGag.sma +++ b/cstrike/addons/amxmodx/scripting/CA_Addon_VoteGag.sma @@ -33,195 +33,195 @@ const IMMUNITY_FLAGS = ADMIN_IMMUNITY; // Иммунитет к функция #if !defined MAX_PLAYERS - const MAX_PLAYERS = 32; + const MAX_PLAYERS = 32 #endif -new g_VotingMenu; -new g_iVotingIndex, g_iVotingLasttime; -new g_arrPlayers[MAX_PLAYERS], g_iPnum; -new bool:g_bPlayerVoted[MAX_PLAYERS + 1], g_iPlayersVotedCount; +new g_VotingMenu +new g_iVotingIndex, g_iVotingLasttime +new g_arrPlayers[MAX_PLAYERS], g_iPnum +new bool:g_bPlayerVoted[MAX_PLAYERS + 1], g_iPlayersVotedCount public plugin_init() { - register_plugin("CA: VoteGAG", "1.0.1-alpha", "Sergey Shorokhov"); + register_plugin("CA: VoteGAG", "1.0.1-alpha", "Sergey Shorokhov") - register_clcmd("say /votegag", "clcmd_VoteGag"); - register_clcmd("say_team /votegag", "clcmd_VoteGag"); - register_clcmd("votegag", "clcmd_VoteGag") + register_clcmd("say /votegag", "clcmd_VoteGag") + register_clcmd("say_team /votegag", "clcmd_VoteGag") + register_clcmd("votegag", "clcmd_VoteGag") } public plugin_cfg() { - g_VotingMenu = menu_create("Title", "voting_handler"); - menu_setprop(g_VotingMenu, MPROP_EXIT, MEXIT_NEVER); - menu_additem(g_VotingMenu, MSG_MENU_YES, "1"); - menu_additem(g_VotingMenu, MSG_MENU_NO, "0"); + g_VotingMenu = menu_create("Title", "voting_handler") + menu_setprop(g_VotingMenu, MPROP_EXIT, MEXIT_NEVER) + menu_additem(g_VotingMenu, MSG_MENU_YES, "1") + menu_additem(g_VotingMenu, MSG_MENU_NO, "0") } public client_disconnected(id) { - if(g_bPlayerVoted[id]) - { - g_bPlayerVoted[id] = false; - g_iPlayersVotedCount--; - } + if (g_bPlayerVoted[id]) + { + g_bPlayerVoted[id] = false + g_iPlayersVotedCount-- + } } public clcmd_VoteGag(id) { - if(g_iVotingIndex) - { - ChatColor(id, 0, MSG_VOTE_EXISTS, PREFIX); - return PLUGIN_HANDLED; - } - new time = g_iVotingLasttime + REPEAT_VOTE_MIN * 60 - get_systime(); - if(time > 0) - { - ChatColor(id, 0, MSG_VOTE_BLOCK, PREFIX, time % 60); - return PLUGIN_HANDLED; - } - - new szName[32], num[3], menu, callback; - menu = menu_create(MSG_PLMENU_TITLE, "players_handler"); - callback = menu_makecallback("players_callback"); - - menu_setprop(menu, MPROP_NEXTNAME, MSG_MENU_NEXT); - menu_setprop(menu, MPROP_BACKNAME, MSG_MENU_BACK); - menu_setprop(menu, MPROP_EXITNAME, MSG_MENU_EXIT); - - get_players(g_arrPlayers, g_iPnum, "h"); - - for(new i; i < g_iPnum; i++) - { - if(g_arrPlayers[i] == id) - continue; - - get_user_name(g_arrPlayers[i], szName, charsmax(szName)); - num_to_str(g_arrPlayers[i], num, charsmax(num)); - menu_additem(menu, szName, num, .callback = callback); - } - - menu_display(id, menu); - return PLUGIN_HANDLED; + if (g_iVotingIndex) + { + ChatColor(id, 0, MSG_VOTE_EXISTS, PREFIX) + return PLUGIN_HANDLED + } + new time = g_iVotingLasttime + REPEAT_VOTE_MIN * 60 - get_systime() + if (time > 0) + { + ChatColor(id, 0, MSG_VOTE_BLOCK, PREFIX, time % 60) + return PLUGIN_HANDLED + } + + new szName[32], num[3], menu, callback + menu = menu_create(MSG_PLMENU_TITLE, "players_handler") + callback = menu_makecallback("players_callback") + + menu_setprop(menu, MPROP_NEXTNAME, MSG_MENU_NEXT) + menu_setprop(menu, MPROP_BACKNAME, MSG_MENU_BACK) + menu_setprop(menu, MPROP_EXITNAME, MSG_MENU_EXIT) + + get_players(g_arrPlayers, g_iPnum, "h") + + for(new i; i < g_iPnum; i++) + { + if (g_arrPlayers[i] == id) + continue + + get_user_name(g_arrPlayers[i], szName, charsmax(szName)) + num_to_str(g_arrPlayers[i], num, charsmax(num)) + menu_additem(menu, szName, num, .callback = callback) + } + + menu_display(id, menu) + return PLUGIN_HANDLED } public players_callback(id, menu, item) { - new _access, item_data[3], callback; - menu_item_getinfo(menu, item, _access, item_data, charsmax(item_data), .callback = callback); - - new index = str_to_num(item_data); - if(!is_user_connected(index)) - return ITEM_DISABLED; - if(ca_has_user_gag(index)) - return ITEM_DISABLED; - if(get_user_flags(index) & IMMUNITY_FLAGS) - return ITEM_DISABLED; - - return ITEM_ENABLED; + new _access, item_data[3], callback + menu_item_getinfo(menu, item, _access, item_data, charsmax(item_data), .callback = callback) + + new index = str_to_num(item_data) + if (!is_user_connected(index)) + return ITEM_DISABLED + if (ca_has_user_gag(index)) + return ITEM_DISABLED + if (get_user_flags(index) & IMMUNITY_FLAGS) + return ITEM_DISABLED + + return ITEM_ENABLED } public players_handler(id, menu, item) { - if(item == MENU_EXIT) - { - menu_destroy(menu); - return PLUGIN_HANDLED; - } + if (item == MENU_EXIT) + { + menu_destroy(menu) + return PLUGIN_HANDLED + } - new _access, item_data[3], callback; - menu_item_getinfo(menu, item, _access, item_data, charsmax(item_data), .callback = callback); - g_iVotingIndex = str_to_num(item_data); - menu_destroy(menu); + new _access, item_data[3], callback + menu_item_getinfo(menu, item, _access, item_data, charsmax(item_data), .callback = callback) + g_iVotingIndex = str_to_num(item_data) + menu_destroy(menu) - new szTitle[128], szName[32]; - get_user_name(g_iVotingIndex, szName, charsmax(szName)); + new szTitle[128], szName[32] + get_user_name(g_iVotingIndex, szName, charsmax(szName)) - formatex(szTitle, charsmax(szTitle), MSG_VMENU_TITLE, szName); - menu_setprop(g_VotingMenu, MPROP_TITLE, szTitle); + formatex(szTitle, charsmax(szTitle), MSG_VMENU_TITLE, szName) + menu_setprop(g_VotingMenu, MPROP_TITLE, szTitle) - ChatColor(0, g_iVotingIndex, MSG_VOTE_START, PREFIX, id, g_iVotingIndex); + ChatColor(0, g_iVotingIndex, MSG_VOTE_START, PREFIX, id, g_iVotingIndex) - for(new i; i < g_iPnum; i++) - { - if(g_arrPlayers[i] == g_iVotingIndex) - continue; + for(new i; i < g_iPnum; i++) + { + if (g_arrPlayers[i] == g_iVotingIndex) + continue - if(is_user_connected(g_arrPlayers[i])) - menu_display(g_arrPlayers[i], g_VotingMenu); - } + if (is_user_connected(g_arrPlayers[i])) + menu_display(g_arrPlayers[i], g_VotingMenu) + } - set_task(CHECK_VOTE_TIME, "task__CheckVotes", id); - return PLUGIN_HANDLED; + set_task(CHECK_VOTE_TIME, "task__CheckVotes", id) + return PLUGIN_HANDLED } public voting_handler(id, menu, item) { - if(item == MENU_EXIT) - return PLUGIN_HANDLED; - - new _access, item_data[3], callback; - menu_item_getinfo(menu, item, _access, item_data, charsmax(item_data), .callback = callback); - - if(str_to_num(item_data)) - { - g_iPlayersVotedCount++; - g_bPlayerVoted[id] = true; - } - return PLUGIN_HANDLED; + if (item == MENU_EXIT) + return PLUGIN_HANDLED + + new _access, item_data[3], callback + menu_item_getinfo(menu, item, _access, item_data, charsmax(item_data), .callback = callback) + + if (str_to_num(item_data)) + { + g_iPlayersVotedCount++ + g_bPlayerVoted[id] = true + } + return PLUGIN_HANDLED } public task__CheckVotes(id) { - for(new i; i < g_iPnum; i++) - { - if(is_user_connected(g_arrPlayers[i])) - show_menu(g_arrPlayers[i], 0, "^n"); - } - - new iVoteCount = floatround(g_iPnum * PERCENT_VOTE_OK / 100.0); - - if(g_iPlayersVotedCount >= iVoteCount) - { - if(is_user_connected(g_iVotingIndex)) - { - ca_set_user_gag(g_iVotingIndex, PREFIX, BLOCK_TIME_MIN, (gagFlag_Say | gagFlag_SayTeam | gagFlag_Voice)); - - new szName[32]; - get_user_name(g_iVotingIndex, szName, charsmax(szName)); - ChatColor(0, g_iVotingIndex, MSG_VOTING_OK_ALL, PREFIX, szName, BLOCK_TIME_MIN); - ChatColor(g_iVotingIndex, 0, MSG_VOTING_OK_PL, PREFIX, BLOCK_TIME_MIN); - } - else ChatColor(id, 0, MSG_VOTING_DISC, PREFIX); - } - else ChatColor(0, g_iVotingIndex, MSG_VOTING_FAIL, PREFIX, g_iPlayersVotedCount, iVoteCount); - - arrayset(g_bPlayerVoted, false, sizeof g_bPlayerVoted); - g_iPlayersVotedCount = 0; - g_iVotingIndex = 0; - g_iVotingLasttime = get_systime(); + for(new i; i < g_iPnum; i++) + { + if (is_user_connected(g_arrPlayers[i])) + show_menu(g_arrPlayers[i], 0, "^n") + } + + new iVoteCount = floatround(g_iPnum * PERCENT_VOTE_OK / 100.0) + + if (g_iPlayersVotedCount >= iVoteCount) + { + if (is_user_connected(g_iVotingIndex)) + { + ca_set_user_gag(g_iVotingIndex, PREFIX, BLOCK_TIME_MIN, (gagFlag_Say | gagFlag_SayTeam | gagFlag_Voice)) + + new szName[32] + get_user_name(g_iVotingIndex, szName, charsmax(szName)) + ChatColor(0, g_iVotingIndex, MSG_VOTING_OK_ALL, PREFIX, szName, BLOCK_TIME_MIN) + ChatColor(g_iVotingIndex, 0, MSG_VOTING_OK_PL, PREFIX, BLOCK_TIME_MIN) + } + else ChatColor(id, 0, MSG_VOTING_DISC, PREFIX) + } + else ChatColor(0, g_iVotingIndex, MSG_VOTING_FAIL, PREFIX, g_iPlayersVotedCount, iVoteCount) + + arrayset(g_bPlayerVoted, false, sizeof g_bPlayerVoted) + g_iPlayersVotedCount = 0 + g_iVotingIndex = 0 + g_iVotingLasttime = get_systime() } stock ChatColor(id, id2, const szMessage[], any:...) { - new szMsg[190]; - vformat(szMsg, charsmax(szMsg), szMessage, 4); - - if(id) - { - client_print_color(id, print_team_default, szMsg); - } - else - { - new players[32], pnum; - get_players(players, pnum, "c"); - for(new i; i < pnum; ++i) - { - if(players[i] != id2) - { - client_print_color(players[i], print_team_default, szMsg); - } - } - } + new szMsg[190] + vformat(szMsg, charsmax(szMsg), szMessage, 4) + + if (id) + { + client_print_color(id, print_team_default, szMsg) + } + else + { + new players[32], pnum + get_players(players, pnum, "c") + for(new i; i < pnum; ++i) + { + if (players[i] != id2) + { + client_print_color(players[i], print_team_default, szMsg) + } + } + } } diff --git a/cstrike/addons/amxmodx/scripting/CA_AntiFlood.sma b/cstrike/addons/amxmodx/scripting/CA_AntiFlood.sma index 21347e4..f65a9ef 100644 --- a/cstrike/addons/amxmodx/scripting/CA_AntiFlood.sma +++ b/cstrike/addons/amxmodx/scripting/CA_AntiFlood.sma @@ -1,102 +1,100 @@ #include <amxmodx> #include <ChatAdditions> -#pragma ctrlchar '\' -#pragma tabsize 2 +#pragma tabsize 4 new g_OldMessage[MAX_PLAYERS + 1][CA_MAX_MESSAGE_SIZE] new Float: ca_anti_flood_time, - ca_equal_messages + ca_equal_messages -public stock const PluginName[] = "CA: Anti Flood" -public stock const PluginVersion[] = CA_VERSION -public stock const PluginAuthor[] = "Nordic Warrior" -public stock const PluginURL[] = "https://github.com/ChatAdditions/" -public stock const PluginDescription[] = "Antiflood for text chat" +public stock const PluginName[] = "CA: Anti Flood" +public stock const PluginVersion[] = CA_VERSION +public stock const PluginAuthor[] = "Nordic Warrior" +public stock const PluginURL[] = "https://github.com/ChatAdditions/" +public stock const PluginDescription[] = "Antiflood for text chat" public plugin_init() { - register_plugin(PluginName, PluginVersion, PluginAuthor) + register_plugin(PluginName, PluginVersion, PluginAuthor) - register_dictionary("CA_AntiFlood.txt") + register_dictionary("CA_AntiFlood.txt") - Create_CVars() + Create_CVars() - AutoExecConfig(true, "CA_AntiFlood", "ChatAdditions") + AutoExecConfig(true, "CA_AntiFlood", "ChatAdditions") } public plugin_cfg() { - if(find_plugin_byfile("antiflood.amxx") != INVALID_PLUGIN_ID) { - log_amx("Default plugin <antiflood.amxx> was found. It has been stopped.") - pause("acd", "antiflood.amxx") - } + if (find_plugin_byfile("antiflood.amxx") != INVALID_PLUGIN_ID) { + log_amx("Default plugin <antiflood.amxx> was found. It has been stopped.") + pause("acd", "antiflood.amxx") + } } public CA_Client_Say(id, const bool: isTeamMessage, const message[]) { - return CheckMessage(id, message) + return CheckMessage(id, message) } CheckMessage(id, const message[]) { - if(message[0] == '/') { - return CA_CONTINUE - } + if (message[0] == '/') { + return CA_CONTINUE + } - static Float:nextMessage[MAX_PLAYERS + 1] - static equalMessage[MAX_PLAYERS + 1] + static Float:nextMessage[MAX_PLAYERS + 1] + static equalMessage[MAX_PLAYERS + 1] - new Float:nextSay = get_gametime() + new Float:nextSay = get_gametime() - if(nextMessage[id] > nextSay) { - client_print_color(id, print_team_red, "%L %L", id, "CA_ANTIFLOOD_CHAT_PREFIX", id, "CA_ANTIFLOOD_CHAT_STOP_FLOODING") - nextMessage[id] = nextSay + ca_anti_flood_time + if (nextMessage[id] > nextSay) { + client_print_color(id, print_team_red, "%L %L", id, "CA_ANTIFLOOD_CHAT_PREFIX", id, "CA_ANTIFLOOD_CHAT_STOP_FLOODING") + nextMessage[id] = nextSay + ca_anti_flood_time - return CA_SUPERCEDE - } + return CA_SUPERCEDE + } - if(strcmp(message, g_OldMessage[id], true) == 0) { - if(++equalMessage[id] >= ca_equal_messages) { - client_print_color(id, print_team_red, "%L %L", id, "CA_ANTIFLOOD_CHAT_PREFIX", id, "CA_ANTIFLOOD_CHAT_EQUAL_MESSAGE") + if (strcmp(message, g_OldMessage[id], true) == 0) { + if (++equalMessage[id] >= ca_equal_messages) { + client_print_color(id, print_team_red, "%L %L", id, "CA_ANTIFLOOD_CHAT_PREFIX", id, "CA_ANTIFLOOD_CHAT_EQUAL_MESSAGE") - return CA_SUPERCEDE + return CA_SUPERCEDE + } + } else { + equalMessage[id] = 0 } - } - else { - equalMessage[id] = 0 - } - nextMessage[id] = nextSay + ca_anti_flood_time - copy(g_OldMessage[id], charsmax(g_OldMessage[]), message) + nextMessage[id] = nextSay + ca_anti_flood_time + copy(g_OldMessage[id], charsmax(g_OldMessage[]), message) - return CA_CONTINUE + return CA_CONTINUE } public client_disconnected(id) { - g_OldMessage[id][0] = EOS + g_OldMessage[id][0] = EOS } Create_CVars() { - bind_pcvar_float( - create_cvar( - .name = "ca_anti_flood_time", - .string = "0.75", - .description = "Time between messages\n 0.0 - no limit", - .has_min = true, - .min_val = 0.0 - ), - - ca_anti_flood_time - ) - - bind_pcvar_num( - create_cvar( - .name = "ca_equal_messages", - .string = "2", - .description = "How many identical messages can be written in a row\n 0 - no limit", - .has_min = true, - .min_val = 0.0 - ), - - ca_equal_messages - ) + bind_pcvar_float( + create_cvar( + .name = "ca_anti_flood_time", + .string = "0.75", + .description = "Time between messages^n 0.0 - no limit", + .has_min = true, + .min_val = 0.0 + ), + + ca_anti_flood_time + ) + + bind_pcvar_num( + create_cvar( + .name = "ca_equal_messages", + .string = "2", + .description = "How many identical messages can be written in a row^n 0 - no limit", + .has_min = true, + .min_val = 0.0 + ), + + ca_equal_messages + ) } diff --git a/cstrike/addons/amxmodx/scripting/CA_Gag.sma b/cstrike/addons/amxmodx/scripting/CA_Gag.sma index 668602d..1709cbb 100644 --- a/cstrike/addons/amxmodx/scripting/CA_Gag.sma +++ b/cstrike/addons/amxmodx/scripting/CA_Gag.sma @@ -6,14 +6,13 @@ #include <CA_GAG_API> #include <CA_StorageAPI> -#pragma ctrlchar '\' #pragma dynamic 524288 -#pragma tabsize 2 +#pragma tabsize 4 - /* ----- START SETTINGS ----- */ + /* ----- START SETTINGS ----- */ const Float: GAG_THINKER_FREQ = 3.0 - /* ----- END OF SETTINGS ----- */ + /* ----- END OF SETTINGS ----- */ static g_currentGags[MAX_PLAYERS + 1][gagData_s] static g_adminTempData[MAX_PLAYERS + 1][gagData_s] @@ -24,245 +23,245 @@ static Array: g_gagTimeTemplates, g_gagTimeTemplates_size static Array: g_chatWhitelistCmds, g_chatWhitelistCmds_size new ca_gag_times[64], - ca_gag_immunity_flags[16], - ca_gag_access_flags[16], - ca_gag_access_flags_own_reason[16], - ca_gag_access_flags_own_time[16], - ca_gag_access_flags_high[16], - ca_gag_remove_only_own_gag, - ca_gag_sound_ok[128], - ca_gag_sound_error[128], - bool: ca_gag_block_nickname_change, - bool: ca_gag_block_admin_chat, - bool: ca_gag_common_chat_block, - ca_gag_own_reason_enabled + ca_gag_immunity_flags[16], + ca_gag_access_flags[16], + ca_gag_access_flags_own_reason[16], + ca_gag_access_flags_own_time[16], + ca_gag_access_flags_high[16], + ca_gag_remove_only_own_gag, + ca_gag_sound_ok[128], + ca_gag_sound_error[128], + bool: ca_gag_block_nickname_change, + bool: ca_gag_block_admin_chat, + bool: ca_gag_common_chat_block, + ca_gag_own_reason_enabled new g_dummy, g_itemInfo[64], g_itemName[128] enum { - ITEM_ENTER_GAG_REASON = -1, - ITEM_ENTER_GAG_TIME = -2, - ITEM_CONFIRM = -3, - ITEM_REASON = -4, + ITEM_ENTER_GAG_REASON = -1, + ITEM_ENTER_GAG_TIME = -2, + ITEM_CONFIRM = -3, + ITEM_REASON = -4, } new g_fwd_gag_setted, - g_fwd_gag_removed, - g_ret + g_fwd_gag_removed, + g_ret new const g_adminChatCmds[][] = { - "amx_say", "amx_asay", "amx_chat", "amx_psay", - "amx_teamsay", "amx_bsay", "amx_bsay2", "amx_csay", - "amx_csay2", "amx_rsay", "amx_rsay2", "amx_tsay", - "amx_tsay2" + "amx_say", "amx_asay", "amx_chat", "amx_psay", + "amx_teamsay", "amx_bsay", "amx_bsay2", "amx_csay", + "amx_csay2", "amx_rsay", "amx_rsay2", "amx_tsay", + "amx_tsay2" } new const g_gagCmd[] = "gag" new const g_unGagCmd[] = "ungag" -public stock const PluginName[] = "CA: Gag" -public stock const PluginVersion[] = CA_VERSION -public stock const PluginAuthor[] = "Sergey Shorokhov" -public stock const PluginURL[] = "https://github.com/ChatAdditions/" -public stock const PluginDescription[] = "Manage player chats for the admin." +public stock const PluginName[] = "CA: Gag" +public stock const PluginVersion[] = CA_VERSION +public stock const PluginAuthor[] = "Sergey Shorokhov" +public stock const PluginURL[] = "https://github.com/ChatAdditions/" +public stock const PluginDescription[] = "Manage player chats for the admin." public plugin_precache() { - register_plugin(PluginName, PluginVersion, PluginAuthor) + register_plugin(PluginName, PluginVersion, PluginAuthor) - register_dictionary("CA_Gag.txt") - register_dictionary("common.txt") - register_dictionary("time.txt") + register_dictionary("CA_Gag.txt") + register_dictionary("common.txt") + register_dictionary("time.txt") - register_srvcmd("ca_gag_add_reason", "SrvCmd_AddReason") - register_srvcmd("ca_gag_show_templates", "SrvCmd_ShowTemplates") - register_srvcmd("ca_gag_add_chat_whitelist_cmd", "SrvCmd_AddWhitelistCmd") - register_srvcmd("ca_gag_reload_config", "SrvCmd_ReloadConfig") + register_srvcmd("ca_gag_add_reason", "SrvCmd_AddReason") + register_srvcmd("ca_gag_show_templates", "SrvCmd_ShowTemplates") + register_srvcmd("ca_gag_add_chat_whitelist_cmd", "SrvCmd_AddWhitelistCmd") + register_srvcmd("ca_gag_reload_config", "SrvCmd_ReloadConfig") - Create_CVars() + Create_CVars() - g_gagReasonsTemplates = ArrayCreate(reason_s) - g_gagTimeTemplates = ArrayCreate() - g_chatWhitelistCmds = ArrayCreate(MAX_WHITELIST_CMD_LEN) + g_gagReasonsTemplates = ArrayCreate(reason_s) + g_gagTimeTemplates = ArrayCreate() + g_chatWhitelistCmds = ArrayCreate(MAX_WHITELIST_CMD_LEN) - LoadConfig() + LoadConfig() - if(ca_gag_sound_ok[0] != EOS && file_exists(fmt("sounds/%s", ca_gag_sound_ok))) { - precache_sound(ca_gag_sound_ok) - } + if (ca_gag_sound_ok[0] != EOS && file_exists(fmt("sounds/%s", ca_gag_sound_ok))) { + precache_sound(ca_gag_sound_ok) + } - if(ca_gag_sound_error[0] != EOS && file_exists(fmt("sounds/%s", ca_gag_sound_error))) { - precache_sound(ca_gag_sound_error) - } + if (ca_gag_sound_error[0] != EOS && file_exists(fmt("sounds/%s", ca_gag_sound_error))) { + precache_sound(ca_gag_sound_error) + } } public plugin_init() { - set_task_ex(GAG_THINKER_FREQ, "Gags_Thinker", .flags = SetTask_Repeat) + set_task_ex(GAG_THINKER_FREQ, "Gags_Thinker", .flags = SetTask_Repeat) - new accessFlagsHigh = read_flags(ca_gag_access_flags_high) - new accessFlags = read_flags(ca_gag_access_flags) - new accessFlagsOwnReason = read_flags(ca_gag_access_flags_own_reason) - new accessFlagsOwnTime = read_flags(ca_gag_access_flags_own_time) + new accessFlagsHigh = read_flags(ca_gag_access_flags_high) + new accessFlags = read_flags(ca_gag_access_flags) + new accessFlagsOwnReason = read_flags(ca_gag_access_flags_own_reason) + new accessFlagsOwnTime = read_flags(ca_gag_access_flags_own_time) - register_clcmd("enter_GagReason", "ClCmd_EnterGagReason", (accessFlagsHigh | accessFlagsOwnReason), .FlagManager = false) - register_clcmd("enter_GagTime", "ClCmd_EnterGagTime", (accessFlagsHigh | accessFlagsOwnTime), .FlagManager = false) + register_clcmd("enter_GagReason", "ClCmd_EnterGagReason", (accessFlagsHigh | accessFlagsOwnReason), .FlagManager = false) + register_clcmd("enter_GagTime", "ClCmd_EnterGagTime", (accessFlagsHigh | accessFlagsOwnTime), .FlagManager = false) - register_concmd("amx_gag", "ConCmd_amx_gag", accessFlagsHigh, "Usage: amx_gag [nickname | STEAM_ID | userID | IP] <reason> <time> <flags>", .FlagManager = false) + register_concmd("amx_gag", "ConCmd_amx_gag", accessFlagsHigh, "Usage: amx_gag [nickname | STEAM_ID | userID | IP] <reason> <time> <flags>", .FlagManager = false) - new const CMDS_GAG[][] = { "gag" } + new const CMDS_GAG[][] = { "gag" } - for(new i; i < sizeof(CMDS_GAG); i++) { - register_trigger_clcmd(CMDS_GAG[i], "ClCmd_Gag", (accessFlags | accessFlagsHigh), .FlagManager = false) - } + for(new i; i < sizeof(CMDS_GAG); i++) { + register_trigger_clcmd(CMDS_GAG[i], "ClCmd_Gag", (accessFlags | accessFlagsHigh), .FlagManager = false) + } - register_clcmd("amx_gagmenu", "ClCmd_Gag", (accessFlags | accessFlagsHigh), .FlagManager = false) + register_clcmd("amx_gagmenu", "ClCmd_Gag", (accessFlags | accessFlagsHigh), .FlagManager = false) - for(new i; i < sizeof g_adminChatCmds; i++) - register_clcmd(g_adminChatCmds[i], "ClCmd_adminSay", ADMIN_CHAT, .FlagManager = false) + for(new i; i < sizeof g_adminChatCmds; i++) + register_clcmd(g_adminChatCmds[i], "ClCmd_adminSay", ADMIN_CHAT, .FlagManager = false) - CA_Log(logLevel_Debug, "[CA]: Gag initialized!") + CA_Log(logLevel_Debug, "[CA]: Gag initialized!") - Register_Forwards() + Register_Forwards() } public plugin_end() { - DestroyForward(g_fwd_gag_setted) - DestroyForward(g_fwd_gag_removed) + DestroyForward(g_fwd_gag_setted) + DestroyForward(g_fwd_gag_removed) } Create_CVars() { - bind_pcvar_string(create_cvar("ca_gag_times", "1i, 5i, 10i, 30i, 1h, 1d, 1w, 1m", - .description = "Gag time values for choose\n \ - format: 1 = 1 second, 1i = 1 minute, 1h = 1 hour, 1d = 1 day, 1w = 1 week, 1m = 1 month, 1y = 1 year\n \ - NOTE: Changes will be applied only after reloading the map (or command `ca_gag_reload_config`)" - ), - ca_gag_times, charsmax(ca_gag_times) - ) - - bind_pcvar_string(create_cvar("ca_gag_immunity_flags", "a", - .description = "User immunity flag\n users with this flag can't be gagged\n \ - NOTE: `ca_gag_access_flags_high` can gag this users" - ), - ca_gag_immunity_flags, charsmax(ca_gag_immunity_flags) - ) - - bind_pcvar_string(create_cvar("ca_gag_access_flags", "c", - .description = "Admin flag\n \ - users with this flag can gag users with flag `z`, but can't with flag `ca_gag_immunity_flags`\n \ - users with this flag can't be gagged by same flags users (immunity)\n \ - NOTE: `ca_gag_access_flags_high` can gag this users" - ), - ca_gag_access_flags, charsmax(ca_gag_access_flags) - ) - - bind_pcvar_string(create_cvar("ca_gag_access_flags_own_reason", "d", - .description = "Admin flag\n \ - users with this flag can enter their own gag reason" - ), - ca_gag_access_flags_own_reason, charsmax(ca_gag_access_flags_own_reason) - ) - - bind_pcvar_string(create_cvar("ca_gag_access_flags_own_time", "e", - .description = "Admin flag\n \ - users with this flag can enter their own gag time" - ), - ca_gag_access_flags_own_time, charsmax(ca_gag_access_flags_own_time) - ) - - bind_pcvar_string(create_cvar("ca_gag_access_flags_high", "l", - .description = "High admin flag\n \ - users with this flag can everyone\n \ - users with this flag can't be gagged\n \ - NOTE: `ca_gag_access_flags_high` can gag this users" - ), - ca_gag_access_flags_high, charsmax(ca_gag_access_flags_high) - ) - - bind_pcvar_num(create_cvar("ca_gag_remove_only_own_gag", "1", - .description = "Remove gag access control\n \ - 1 = remove only own gags\n \ - 0 = no restrictions\n \ - NOTE: `ca_gag_access_flags_high` can remove every gag" - ), - ca_gag_remove_only_own_gag - ) - - get_pcvar_string(create_cvar("ca_gag_sound_ok", "buttons/blip2.wav", - .description = "Sound for success action\n \ - NOTE: Changes will be applied only after reloading the map" - ), - ca_gag_sound_ok, charsmax(ca_gag_sound_ok) - ) - - get_pcvar_string(create_cvar("ca_gag_sound_error", "buttons/button2.wav", - .description = "Sound for error action\n \ - NOTE: Changes will be applied only after reloading the map" - ), - ca_gag_sound_error, charsmax(ca_gag_sound_error) - ) - - bind_pcvar_num(create_cvar("ca_gag_block_nickname_change", "1", - .description = "Block nickname change for gagged player\n \ - 0 = no restrictions" - ), - ca_gag_block_nickname_change - ) - - bind_pcvar_num(create_cvar("ca_gag_block_admin_chat", "1", - .description = "Also block adminchat if admin gagged\n \ - 0 = no restrictions" - ), - ca_gag_block_admin_chat - ) - - bind_pcvar_num(create_cvar("ca_gag_common_chat_block", "1", - .description = "Don't separate `say` & `say_team` chats\n \ - 0 = disabled" - ), - ca_gag_common_chat_block - ) - - bind_pcvar_num(create_cvar("ca_gag_own_reason_enabled", "1", - .description = "Enable own gag reason\n \ - 0 = disabled (excluding when there are no reasons)\n \ - 1 = enabled, at first position in reasons list\n \ - 2 = enabled, at last position in reasons list" - ), - ca_gag_own_reason_enabled - ) + bind_pcvar_string(create_cvar("ca_gag_times", "1i, 5i, 10i, 30i, 1h, 1d, 1w, 1m", + .description = "Gag time values for choose^n \ + format: 1 = 1 second, 1i = 1 minute, 1h = 1 hour, 1d = 1 day, 1w = 1 week, 1m = 1 month, 1y = 1 year^n \ + NOTE: Changes will be applied only after reloading the map (or command `ca_gag_reload_config`)" + ), + ca_gag_times, charsmax(ca_gag_times) + ) + + bind_pcvar_string(create_cvar("ca_gag_immunity_flags", "a", + .description = "User immunity flag^n users with this flag can't be gagged^n \ + NOTE: `ca_gag_access_flags_high` can gag this users" + ), + ca_gag_immunity_flags, charsmax(ca_gag_immunity_flags) + ) + + bind_pcvar_string(create_cvar("ca_gag_access_flags", "c", + .description = "Admin flag^n \ + users with this flag can gag users with flag `z`, but can't with flag `ca_gag_immunity_flags`^n \ + users with this flag can't be gagged by same flags users (immunity)^n \ + NOTE: `ca_gag_access_flags_high` can gag this users" + ), + ca_gag_access_flags, charsmax(ca_gag_access_flags) + ) + + bind_pcvar_string(create_cvar("ca_gag_access_flags_own_reason", "d", + .description = "Admin flag^n \ + users with this flag can enter their own gag reason" + ), + ca_gag_access_flags_own_reason, charsmax(ca_gag_access_flags_own_reason) + ) + + bind_pcvar_string(create_cvar("ca_gag_access_flags_own_time", "e", + .description = "Admin flag^n \ + users with this flag can enter their own gag time" + ), + ca_gag_access_flags_own_time, charsmax(ca_gag_access_flags_own_time) + ) + + bind_pcvar_string(create_cvar("ca_gag_access_flags_high", "l", + .description = "High admin flag^n \ + users with this flag can everyone^n \ + users with this flag can't be gagged^n \ + NOTE: `ca_gag_access_flags_high` can gag this users" + ), + ca_gag_access_flags_high, charsmax(ca_gag_access_flags_high) + ) + + bind_pcvar_num(create_cvar("ca_gag_remove_only_own_gag", "1", + .description = "Remove gag access control^n \ + 1 = remove only own gags^n \ + 0 = no restrictions^n \ + NOTE: `ca_gag_access_flags_high` can remove every gag" + ), + ca_gag_remove_only_own_gag + ) + + get_pcvar_string(create_cvar("ca_gag_sound_ok", "buttons/blip2.wav", + .description = "Sound for success action^n \ + NOTE: Changes will be applied only after reloading the map" + ), + ca_gag_sound_ok, charsmax(ca_gag_sound_ok) + ) + + get_pcvar_string(create_cvar("ca_gag_sound_error", "buttons/button2.wav", + .description = "Sound for error action^n \ + NOTE: Changes will be applied only after reloading the map" + ), + ca_gag_sound_error, charsmax(ca_gag_sound_error) + ) + + bind_pcvar_num(create_cvar("ca_gag_block_nickname_change", "1", + .description = "Block nickname change for gagged player^n \ + 0 = no restrictions" + ), + ca_gag_block_nickname_change + ) + + bind_pcvar_num(create_cvar("ca_gag_block_admin_chat", "1", + .description = "Also block adminchat if admin gagged^n \ + 0 = no restrictions" + ), + ca_gag_block_admin_chat + ) + + bind_pcvar_num(create_cvar("ca_gag_common_chat_block", "1", + .description = "Don't separate `say` & `say_team` chats^n \ + 0 = disabled" + ), + ca_gag_common_chat_block + ) + + bind_pcvar_num(create_cvar("ca_gag_own_reason_enabled", "1", + .description = "Enable own gag reason^n \ + 0 = disabled (excluding when there are no reasons)^n \ + 1 = enabled, at first position in reasons list^n \ + 2 = enabled, at last position in reasons list" + ), + ca_gag_own_reason_enabled + ) } public client_putinserver(id) { - if(is_user_bot(id) || is_user_hltv(id)) { - return - } + if (is_user_bot(id) || is_user_hltv(id)) { + return + } - new authID[MAX_AUTHID_LENGTH]; get_user_authid(id, authID, charsmax(authID)) - CA_Storage_Load(authID) + new authID[MAX_AUTHID_LENGTH]; get_user_authid(id, authID, charsmax(authID)) + CA_Storage_Load(authID) } public client_disconnected(id) { - GagData_Reset(g_adminTempData[id]) - GagData_Reset(g_currentGags[id]) + GagData_Reset(g_adminTempData[id]) + GagData_Reset(g_currentGags[id]) - g_inEditMenu[id] = false + g_inEditMenu[id] = false } public Gags_Thinker() { - static players[MAX_PLAYERS], count - get_players_ex(players, count, .flags = (GetPlayers_ExcludeBots | GetPlayers_ExcludeHLTV)) + static players[MAX_PLAYERS], count + get_players_ex(players, count, .flags = (GetPlayers_ExcludeBots | GetPlayers_ExcludeHLTV)) - static currentTime; currentTime = get_systime() + static currentTime; currentTime = get_systime() - for(new i; i < count; i++) { - new id = players[i] + for(new i; i < count; i++) { + new id = players[i] - new expireAt = g_currentGags[id][gd_expireAt] - new bool: hasGag = (expireAt != 0) + new expireAt = g_currentGags[id][gd_expireAt] + new bool: hasGag = (expireAt != 0) - if(hasGag && expireAt < currentTime) { - Gag_Expired(id) + if (hasGag && expireAt < currentTime) { + Gag_Expired(id) + } } - } } @@ -272,788 +271,788 @@ public Gags_Thinker() { // Players list menu static MenuShow_PlayersList(const id, const nickname[] = "") { - GagData_Reset(g_adminTempData[id]) + GagData_Reset(g_adminTempData[id]) - g_inEditMenu[id] = false + g_inEditMenu[id] = false - if(!is_user_connected(id)) { - return - } + if (!is_user_connected(id)) { + return + } - new nameLen - new GetPlayersFlags: flags = (GetPlayers_ExcludeHLTV | GetPlayers_ExcludeBots) + new nameLen + new GetPlayersFlags: flags = (GetPlayers_ExcludeHLTV | GetPlayers_ExcludeBots) - if(nickname[0] != EOS) { - flags |= (GetPlayers_MatchNameSubstring | GetPlayers_CaseInsensitive) - nameLen = strlen(nickname) - } + if (nickname[0] != EOS) { + flags |= (GetPlayers_MatchNameSubstring | GetPlayers_CaseInsensitive) + nameLen = strlen(nickname) + } - new players[MAX_PLAYERS], count - get_players_ex(players, count, flags, nickname) + new players[MAX_PLAYERS], count + get_players_ex(players, count, flags, nickname) - if(count == 0) { - UTIL_SendAudio(id, ca_gag_sound_error) - client_print_color(id, print_team_red, "%L %L", id, "Gag_prefix", id, "Gag_PlayerNotConnected") - return - } + if (count == 0) { + UTIL_SendAudio(id, ca_gag_sound_error) + client_print_color(id, print_team_red, "%L %L", id, "Gag_prefix", id, "Gag_PlayerNotConnected") + return + } - new menu = menu_create(fmt("%L \\r%s\\y", id, "Gag_MenuTitle_PlayersList", nickname), "MenuHandler_PlayersList") + new menu = menu_create(fmt("%L \r%s\y", id, "Gag_MenuTitle_PlayersList", nickname), "MenuHandler_PlayersList") - static callback + static callback - if(!callback) { - callback = menu_makecallback("MenuCallback_PlayersList") - } + if (!callback) { + callback = menu_makecallback("MenuCallback_PlayersList") + } - for(new i; i < count; i++) { - new target = players[i] + for(new i; i < count; i++) { + new target = players[i] - if(target == id) { - continue - } + if (target == id) { + continue + } - new name[MAX_NAME_LENGTH + 16] - get_user_name(target, name, charsmax(name)) + new name[MAX_NAME_LENGTH + 16] + get_user_name(target, name, charsmax(name)) - if(nameLen > 0) { - new found = strfind(name, nickname, true) + if (nameLen > 0) { + new found = strfind(name, nickname, true) - if(found != -1) { - replace_stringex(name, charsmax(name), - nickname, fmt("\\r%s\\w", nickname), - .caseSensitive = false - ) - } - } + if (found != -1) { + replace_stringex(name, charsmax(name), + nickname, fmt("\r%s\w", nickname), + .caseSensitive = false + ) + } + } - new bool: hasImmunity = IsTargetHasImmunity(id, target) - menu_additem(menu, fmt("%s %s", name, Get_PlayerPostfix(id, target, hasImmunity)), fmt("%i", get_user_userid(target)), .callback = callback) - } + new bool: hasImmunity = IsTargetHasImmunity(id, target) + menu_additem(menu, fmt("%s %s", name, Get_PlayerPostfix(id, target, hasImmunity)), fmt("%i", get_user_userid(target)), .callback = callback) + } - menu_setprop(menu, MPROP_SHOWPAGE, false) + menu_setprop(menu, MPROP_SHOWPAGE, false) - menu_setprop(menu, MPROP_BACKNAME, fmt("%L", id, "BACK")) - menu_setprop(menu, MPROP_NEXTNAME, fmt("%L", id, "MORE")) - menu_setprop(menu, MPROP_EXITNAME, fmt("%L", id, "EXIT")) + menu_setprop(menu, MPROP_BACKNAME, fmt("%L", id, "BACK")) + menu_setprop(menu, MPROP_NEXTNAME, fmt("%L", id, "MORE")) + menu_setprop(menu, MPROP_EXITNAME, fmt("%L", id, "EXIT")) - menu_display(id, menu) + menu_display(id, menu) } public MenuCallback_PlayersList(const id, const menu, const item) { - menu_item_getinfo(menu, item, g_dummy, g_itemInfo, charsmax(g_itemInfo), g_itemName, charsmax(g_itemName), g_dummy) + menu_item_getinfo(menu, item, g_dummy, g_itemInfo, charsmax(g_itemInfo), g_itemName, charsmax(g_itemName), g_dummy) - new userID = strtol(g_itemInfo) + new userID = strtol(g_itemInfo) - new target = find_player_ex((FindPlayer_MatchUserId | FindPlayer_ExcludeBots), userID) + new target = find_player_ex((FindPlayer_MatchUserId | FindPlayer_ExcludeBots), userID) - if(target == 0) { - return ITEM_DISABLED - } + if (target == 0) { + return ITEM_DISABLED + } - new bool: hasImmunity = IsTargetHasImmunity(id, target) + new bool: hasImmunity = IsTargetHasImmunity(id, target) - if(hasImmunity) { - return ITEM_DISABLED - } + if (hasImmunity) { + return ITEM_DISABLED + } - return ITEM_ENABLED + return ITEM_ENABLED } public MenuHandler_PlayersList(const id, const menu, const item) { - if(item == MENU_EXIT || item < 0) { - menu_destroy(menu) - return PLUGIN_HANDLED - } + if (item == MENU_EXIT || item < 0) { + menu_destroy(menu) + return PLUGIN_HANDLED + } - menu_item_getinfo(menu, item, g_dummy, g_itemInfo, charsmax(g_itemInfo), g_itemName, charsmax(g_itemName), g_dummy) - menu_destroy(menu) + menu_item_getinfo(menu, item, g_dummy, g_itemInfo, charsmax(g_itemInfo), g_itemName, charsmax(g_itemName), g_dummy) + menu_destroy(menu) - new userID = strtol(g_itemInfo) + new userID = strtol(g_itemInfo) - new target = find_player_ex((FindPlayer_MatchUserId | FindPlayer_ExcludeBots), userID) + new target = find_player_ex((FindPlayer_MatchUserId | FindPlayer_ExcludeBots), userID) - if(target == 0) { - UTIL_SendAudio(id, ca_gag_sound_error) - client_print_color(id, print_team_red, "%L %L", id, "Gag_prefix", id, "Gag_PlayerNotConnected") + if (target == 0) { + UTIL_SendAudio(id, ca_gag_sound_error) + client_print_color(id, print_team_red, "%L %L", id, "Gag_prefix", id, "Gag_PlayerNotConnected") - MenuShow_PlayersList(id) - return PLUGIN_HANDLED - } + MenuShow_PlayersList(id) + return PLUGIN_HANDLED + } - // Remove already gagged player - if(g_currentGags[target][gd_reason][r_flags] != gagFlag_Removed) { - GagData_Copy(g_adminTempData[id], g_currentGags[target]) + // Remove already gagged player + if (g_currentGags[target][gd_reason][r_flags] != gagFlag_Removed) { + GagData_Copy(g_adminTempData[id], g_currentGags[target]) - g_adminTempData[id][gd_target] = target + g_adminTempData[id][gd_target] = target - MenuShow_ShowGag(id) - return PLUGIN_HANDLED - } + MenuShow_ShowGag(id) + return PLUGIN_HANDLED + } - // Setup gag for target player - GagData_GetPersonalData(id, target, g_adminTempData[id]) + // Setup gag for target player + GagData_GetPersonalData(id, target, g_adminTempData[id]) - MenuShow_SelectReason(id) - return PLUGIN_HANDLED + MenuShow_SelectReason(id) + return PLUGIN_HANDLED } // Reason choose menu static MenuShow_SelectReason(const id) { - if(!is_user_connected(id)) { - return PLUGIN_HANDLED - } + if (!is_user_connected(id)) { + return PLUGIN_HANDLED + } - new target = g_adminTempData[id][gd_target] - if(!is_user_connected(target)) { - UTIL_SendAudio(id, ca_gag_sound_error) - client_print_color(id, print_team_red, "%L %L", id, "Gag_prefix", id, "Gag_PlayerNotConnected") + new target = g_adminTempData[id][gd_target] + if (!is_user_connected(target)) { + UTIL_SendAudio(id, ca_gag_sound_error) + client_print_color(id, print_team_red, "%L %L", id, "Gag_prefix", id, "Gag_PlayerNotConnected") - MenuShow_PlayersList(id) - return PLUGIN_HANDLED - } + MenuShow_PlayersList(id) + return PLUGIN_HANDLED + } - new menu = menu_create(fmt("%L [\\r%s\\y]", id, "Gag_MenuTitle_SelectReason", g_adminTempData[id][gd_name]), "MenuHandler_SelectReason") + new menu = menu_create(fmt("%L [\r%s\y]", id, "Gag_MenuTitle_SelectReason", g_adminTempData[id][gd_name]), "MenuHandler_SelectReason") - new playerFlags = get_user_flags(id) - new accessFlagsHigh = read_flags(ca_gag_access_flags_high) - new accessFlagsOwnReason = read_flags(ca_gag_access_flags_own_reason) + new playerFlags = get_user_flags(id) + new accessFlagsHigh = read_flags(ca_gag_access_flags_high) + new accessFlagsOwnReason = read_flags(ca_gag_access_flags_own_reason) - new bool: hasReasonsTemplates = bool: (g_gagReasonsTemplates_size != 0) + new bool: hasReasonsTemplates = bool: (g_gagReasonsTemplates_size != 0) - if(ca_gag_own_reason_enabled == 1 && playerFlags & (accessFlagsHigh | accessFlagsOwnReason) || !hasReasonsTemplates) { - menu_additem(menu, fmt("%L\n", id, "Gag_EnterReason"), fmt("%i", ITEM_ENTER_GAG_REASON)) - } + if (ca_gag_own_reason_enabled == 1 && playerFlags & (accessFlagsHigh | accessFlagsOwnReason) || !hasReasonsTemplates) { + menu_additem(menu, fmt("%L^n", id, "Gag_EnterReason"), fmt("%i", ITEM_ENTER_GAG_REASON)) + } - if(hasReasonsTemplates) { - for(new i; i < g_gagReasonsTemplates_size; i++) { - new reason[reason_s] - ArrayGetArray(g_gagReasonsTemplates, i, reason) + if (hasReasonsTemplates) { + for(new i; i < g_gagReasonsTemplates_size; i++) { + new reason[reason_s] + ArrayGetArray(g_gagReasonsTemplates, i, reason) - new buffer[2048] - formatex(buffer, charsmax(buffer), reason[r_name]) + new buffer[2048] + formatex(buffer, charsmax(buffer), reason[r_name]) - new bool: reasonHasTime, bool: reasonHasFlags + new bool: reasonHasTime, bool: reasonHasFlags - if(reason[r_time] > 0) { - reasonHasTime = true - } + if (reason[r_time] > 0) { + reasonHasTime = true + } - if(reason[r_flags] != gagFlag_Removed) { - reasonHasFlags = true - } + if (reason[r_flags] != gagFlag_Removed) { + reasonHasFlags = true + } - if(reasonHasTime) { - strcat(buffer, fmt(" (\\y%s", Get_TimeString_seconds(id, reason[r_time])), charsmax(buffer)) - } + if (reasonHasTime) { + strcat(buffer, fmt(" (\y%s", Get_TimeString_seconds(id, reason[r_time])), charsmax(buffer)) + } - if(reasonHasFlags) { - strcat(buffer, fmt("%s%s", reasonHasTime ? ", " : " \\y(", bits_to_flags(reason[r_flags])), charsmax(buffer)) - } + if (reasonHasFlags) { + strcat(buffer, fmt("%s%s", reasonHasTime ? ", " : " \y(", bits_to_flags(reason[r_flags])), charsmax(buffer)) + } - if(reasonHasTime || reasonHasFlags) { - strcat(buffer, "\\w)", charsmax(buffer)) - } + if (reasonHasTime || reasonHasFlags) { + strcat(buffer, "\w)", charsmax(buffer)) + } - menu_additem(menu, buffer, fmt("%i", i)) - } + menu_additem(menu, buffer, fmt("%i", i)) + } - if(ca_gag_own_reason_enabled == 2 && playerFlags & (accessFlagsHigh | accessFlagsOwnReason)) { - menu_additem(menu, fmt("%L\n", id, "Gag_EnterReason"), fmt("%i", ITEM_ENTER_GAG_REASON)) + if (ca_gag_own_reason_enabled == 2 && playerFlags & (accessFlagsHigh | accessFlagsOwnReason)) { + menu_additem(menu, fmt("%L^n", id, "Gag_EnterReason"), fmt("%i", ITEM_ENTER_GAG_REASON)) + } + } else { + menu_addtext(menu, fmt("\d %L", id, "Gag_NoTemplatesAvailable_Reasons"), .slot = false) } - } else { - menu_addtext(menu, fmt("\\d %L", id, "Gag_NoTemplatesAvailable_Reasons"), .slot = false) - } - menu_setprop(menu, MPROP_SHOWPAGE, false) + menu_setprop(menu, MPROP_SHOWPAGE, false) - menu_setprop(menu, MPROP_BACKNAME, fmt("%L", id, "BACK")) - menu_setprop(menu, MPROP_NEXTNAME, fmt("%L", id, "MORE")) - menu_setprop(menu, MPROP_EXITNAME, fmt("%L", id, "Gag_BackToPlayersMenu")) + menu_setprop(menu, MPROP_BACKNAME, fmt("%L", id, "BACK")) + menu_setprop(menu, MPROP_NEXTNAME, fmt("%L", id, "MORE")) + menu_setprop(menu, MPROP_EXITNAME, fmt("%L", id, "Gag_BackToPlayersMenu")) - menu_display(id, menu) - return PLUGIN_HANDLED + menu_display(id, menu) + return PLUGIN_HANDLED } public MenuHandler_SelectReason(const id, const menu, const item) { - if(item == MENU_EXIT || item < 0) { - // Return to prev menu - MenuShow_PlayersList(id) + if (item == MENU_EXIT || item < 0) { + // Return to prev menu + MenuShow_PlayersList(id) - menu_destroy(menu) - return PLUGIN_HANDLED - } + menu_destroy(menu) + return PLUGIN_HANDLED + } - new target = g_adminTempData[id][gd_target] + new target = g_adminTempData[id][gd_target] - if(!is_user_connected(target)) { - UTIL_SendAudio(id, ca_gag_sound_error) - client_print_color(id, print_team_red, "%L %L", id, "Gag_prefix", id, "Gag_PlayerNotConnected") + if (!is_user_connected(target)) { + UTIL_SendAudio(id, ca_gag_sound_error) + client_print_color(id, print_team_red, "%L %L", id, "Gag_prefix", id, "Gag_PlayerNotConnected") - MenuShow_PlayersList(id) - menu_destroy(menu) - return PLUGIN_HANDLED - } + MenuShow_PlayersList(id) + menu_destroy(menu) + return PLUGIN_HANDLED + } - menu_item_getinfo(menu, item, g_dummy, g_itemInfo, charsmax(g_itemInfo), g_itemName, charsmax(g_itemName), g_dummy) - menu_destroy(menu) + menu_item_getinfo(menu, item, g_dummy, g_itemInfo, charsmax(g_itemInfo), g_itemName, charsmax(g_itemName), g_dummy) + menu_destroy(menu) - new reasonID = strtol(g_itemInfo) + new reasonID = strtol(g_itemInfo) - if(reasonID == ITEM_ENTER_GAG_REASON) { - client_cmd(id, "messagemode enter_GagReason") - return PLUGIN_HANDLED - } + if (reasonID == ITEM_ENTER_GAG_REASON) { + client_cmd(id, "messagemode enter_GagReason") + return PLUGIN_HANDLED + } - new reason[reason_s] - ArrayGetArray(g_gagReasonsTemplates, reasonID, reason) + new reason[reason_s] + ArrayGetArray(g_gagReasonsTemplates, reasonID, reason) - // Get predefined reason params - g_adminTempData[id][gd_reason] = reason + // Get predefined reason params + g_adminTempData[id][gd_reason] = reason - // Time not set - if(reason[r_time] == 0) { - MenuShow_SelectTime(id) - return PLUGIN_HANDLED - } + // Time not set + if (reason[r_time] == 0) { + MenuShow_SelectTime(id) + return PLUGIN_HANDLED + } - if(g_inEditMenu[id]) { - MenuShow_EditGag(id) - return PLUGIN_HANDLED - } + if (g_inEditMenu[id]) { + MenuShow_EditGag(id) + return PLUGIN_HANDLED + } - if(reason[r_flags] == gagFlag_Removed) { - MenuShow_SelectFlags(id) - return PLUGIN_HANDLED - } + if (reason[r_flags] == gagFlag_Removed) { + MenuShow_SelectFlags(id) + return PLUGIN_HANDLED + } - Gag_Save(id, target, reason[r_time], reason[r_flags]) - GagData_Reset(g_adminTempData[id]) + Gag_Save(id, target, reason[r_time], reason[r_flags]) + GagData_Reset(g_adminTempData[id]) - return PLUGIN_HANDLED + return PLUGIN_HANDLED } // Time choose menu static MenuShow_SelectTime(const id) { - if(!is_user_connected(id)) { - return PLUGIN_HANDLED - } + if (!is_user_connected(id)) { + return PLUGIN_HANDLED + } - new target = g_adminTempData[id][gd_target] + new target = g_adminTempData[id][gd_target] - if(!is_user_connected(target)) { - UTIL_SendAudio(id, ca_gag_sound_error) - client_print_color(id, print_team_red, "%L %L", id, "Gag_prefix", id, "Gag_PlayerNotConnected") + if (!is_user_connected(target)) { + UTIL_SendAudio(id, ca_gag_sound_error) + client_print_color(id, print_team_red, "%L %L", id, "Gag_prefix", id, "Gag_PlayerNotConnected") - MenuShow_PlayersList(id) - return PLUGIN_HANDLED - } + MenuShow_PlayersList(id) + return PLUGIN_HANDLED + } - new menu = menu_create(fmt("%L", id, "Gag_MenuTitle_SelectTime"), "MenuHandler_SelectTime") + new menu = menu_create(fmt("%L", id, "Gag_MenuTitle_SelectTime"), "MenuHandler_SelectTime") - new playerFlags = get_user_flags(id) - new accessFlagsHigh = read_flags(ca_gag_access_flags_high) - new accessFlagsOwnTime = read_flags(ca_gag_access_flags_own_time) + new playerFlags = get_user_flags(id) + new accessFlagsHigh = read_flags(ca_gag_access_flags_high) + new accessFlagsOwnTime = read_flags(ca_gag_access_flags_own_time) - if(playerFlags & (accessFlagsHigh | accessFlagsOwnTime)) { - menu_additem(menu, fmt("%L", id, "Gag_EnterTime"), fmt("%i", ITEM_ENTER_GAG_TIME)) - menu_addblank(menu, .slot = false) - } + if (playerFlags & (accessFlagsHigh | accessFlagsOwnTime)) { + menu_additem(menu, fmt("%L", id, "Gag_EnterTime"), fmt("%i", ITEM_ENTER_GAG_TIME)) + menu_addblank(menu, .slot = false) + } - if(g_gagTimeTemplates_size) { - for(new i; i < g_gagTimeTemplates_size; i++) { - new time = ArrayGetCell(g_gagTimeTemplates, i) + if (g_gagTimeTemplates_size) { + for(new i; i < g_gagTimeTemplates_size; i++) { + new time = ArrayGetCell(g_gagTimeTemplates, i) - menu_additem(menu, fmt("%s", Get_TimeString_seconds(id, time)), fmt("%i", i)) + menu_additem(menu, fmt("%s", Get_TimeString_seconds(id, time)), fmt("%i", i)) + } + } else { + menu_addtext(menu, fmt("\d %L", id, "Gag_NoTemplatesAvailable_Times"), .slot = false) } - } else { - menu_addtext(menu, fmt("\\d %L", id, "Gag_NoTemplatesAvailable_Times"), .slot = false) - } - menu_setprop(menu, MPROP_SHOWPAGE, false) + menu_setprop(menu, MPROP_SHOWPAGE, false) - menu_setprop(menu, MPROP_BACKNAME, fmt("%L", id, "BACK")) - menu_setprop(menu, MPROP_NEXTNAME, fmt("%L", id, "MORE")) - menu_setprop(menu, MPROP_EXITNAME, fmt("%L", id, "EXIT")) + menu_setprop(menu, MPROP_BACKNAME, fmt("%L", id, "BACK")) + menu_setprop(menu, MPROP_NEXTNAME, fmt("%L", id, "MORE")) + menu_setprop(menu, MPROP_EXITNAME, fmt("%L", id, "EXIT")) - menu_display(id, menu) - return PLUGIN_HANDLED + menu_display(id, menu) + return PLUGIN_HANDLED } public MenuHandler_SelectTime(const id, const menu, const item) { - if(item == MENU_EXIT || item < 0) { - MenuShow_PlayersList(id) + if (item == MENU_EXIT || item < 0) { + MenuShow_PlayersList(id) - menu_destroy(menu) - return PLUGIN_HANDLED - } + menu_destroy(menu) + return PLUGIN_HANDLED + } - new target = g_adminTempData[id][gd_target] + new target = g_adminTempData[id][gd_target] - if(!is_user_connected(target)) { - UTIL_SendAudio(id, ca_gag_sound_error) - client_print_color(id, print_team_red, "%L %L", id, "Gag_prefix", id, "Gag_PlayerNotConnected") + if (!is_user_connected(target)) { + UTIL_SendAudio(id, ca_gag_sound_error) + client_print_color(id, print_team_red, "%L %L", id, "Gag_prefix", id, "Gag_PlayerNotConnected") - MenuShow_PlayersList(id) + MenuShow_PlayersList(id) + menu_destroy(menu) + return PLUGIN_HANDLED + } + + menu_item_getinfo(menu, item, g_dummy, g_itemInfo, charsmax(g_itemInfo), g_itemName, charsmax(g_itemName), g_dummy) menu_destroy(menu) - return PLUGIN_HANDLED - } - menu_item_getinfo(menu, item, g_dummy, g_itemInfo, charsmax(g_itemInfo), g_itemName, charsmax(g_itemName), g_dummy) - menu_destroy(menu) + new timeID = strtol(g_itemInfo) - new timeID = strtol(g_itemInfo) + if (timeID == ITEM_ENTER_GAG_TIME) { + client_cmd(id, "messagemode enter_GagTime") + return PLUGIN_HANDLED + } - if(timeID == ITEM_ENTER_GAG_TIME) { - client_cmd(id, "messagemode enter_GagTime") - return PLUGIN_HANDLED - } + new time = ArrayGetCell(g_gagTimeTemplates, timeID) + g_adminTempData[id][gd_reason][r_time] = time - new time = ArrayGetCell(g_gagTimeTemplates, timeID) - g_adminTempData[id][gd_reason][r_time] = time + if (g_inEditMenu[id]) { + MenuShow_EditGag(id) + return PLUGIN_HANDLED + } - if(g_inEditMenu[id]) { - MenuShow_EditGag(id) + MenuShow_SelectFlags(id) return PLUGIN_HANDLED - } - - MenuShow_SelectFlags(id) - return PLUGIN_HANDLED } // Select flags menu static MenuShow_SelectFlags(const id) { - if(!is_user_connected(id)) { - return PLUGIN_HANDLED - } + if (!is_user_connected(id)) { + return PLUGIN_HANDLED + } - new target = g_adminTempData[id][gd_target] + new target = g_adminTempData[id][gd_target] - if(!is_user_connected(target)) { - UTIL_SendAudio(id, ca_gag_sound_error) - client_print_color(id, print_team_red, "%L %L", id, "Gag_prefix", id, "Gag_PlayerNotConnected") + if (!is_user_connected(target)) { + UTIL_SendAudio(id, ca_gag_sound_error) + client_print_color(id, print_team_red, "%L %L", id, "Gag_prefix", id, "Gag_PlayerNotConnected") - MenuShow_PlayersList(id) - return PLUGIN_HANDLED - } + MenuShow_PlayersList(id) + return PLUGIN_HANDLED + } - new menu = menu_create(fmt("%L", id, "Gag_SelectFlags", target), "MenuHandler_SelectFlags") + new menu = menu_create(fmt("%L", id, "Gag_SelectFlags", target), "MenuHandler_SelectFlags") - static callback + static callback - if(!callback) { - callback = menu_makecallback("MenuCallback_SelectFlags") - } + if (!callback) { + callback = menu_makecallback("MenuCallback_SelectFlags") + } - new gag_flags_s: gagFlags = g_adminTempData[id][gd_reason][r_flags] + new gag_flags_s: gagFlags = g_adminTempData[id][gd_reason][r_flags] - menu_additem(menu, fmt("%L [ %s ]", id, "Gag_MenuItem_PropSay", - (gagFlags & gagFlag_Say) ? " \\r+\\w " : "-"), - fmt("%i", gagFlag_Say) - ) - if(!ca_gag_common_chat_block) { - menu_additem(menu, fmt("%L [ %s ]", id, "Gag_MenuItem_PropSayTeam", - (gagFlags & gagFlag_SayTeam) ? " \\r+\\w " : "-"), - fmt("%i", gagFlag_SayTeam) + menu_additem(menu, fmt("%L [ %s ]", id, "Gag_MenuItem_PropSay", + (gagFlags & gagFlag_Say) ? " \r+\w " : "-"), + fmt("%i", gagFlag_Say) + ) + if (!ca_gag_common_chat_block) { + menu_additem(menu, fmt("%L [ %s ]", id, "Gag_MenuItem_PropSayTeam", + (gagFlags & gagFlag_SayTeam) ? " \r+\w " : "-"), + fmt("%i", gagFlag_SayTeam) + ) + } + menu_additem(menu, fmt("%L [ %s ]", id, "Gag_MenuItem_PropVoice", + (gagFlags & gagFlag_Voice) ? " \r+\w " : "-"), + fmt("%i", gagFlag_Voice) ) - } - menu_additem(menu, fmt("%L [ %s ]", id, "Gag_MenuItem_PropVoice", - (gagFlags & gagFlag_Voice) ? " \\r+\\w " : "-"), - fmt("%i", gagFlag_Voice) - ) - menu_addblank(menu, .slot = false) + menu_addblank(menu, .slot = false) - menu_additem(menu, fmt("%L", id, "Gag_MenuItem_Confirm"), fmt("%i", ITEM_CONFIRM), .callback = callback) + menu_additem(menu, fmt("%L", id, "Gag_MenuItem_Confirm"), fmt("%i", ITEM_CONFIRM), .callback = callback) - menu_addtext(menu, fmt("\n%L", id, "Gag_MenuItem_Resolution", - Get_TimeString_seconds(id, g_adminTempData[id][gd_reason][r_time]), - Get_GagString_reason(id, target)), false - ) + menu_addtext(menu, fmt("^n%L", id, "Gag_MenuItem_Resolution", + Get_TimeString_seconds(id, g_adminTempData[id][gd_reason][r_time]), + Get_GagString_reason(id, target)), false + ) - menu_addblank2(menu) - menu_addblank2(menu) - menu_addblank2(menu) - menu_addblank2(menu) - menu_addblank2(menu) + menu_addblank2(menu) + menu_addblank2(menu) + menu_addblank2(menu) + menu_addblank2(menu) + menu_addblank2(menu) - menu_setprop(menu, MPROP_PERPAGE, 0) - menu_setprop(menu, MPROP_EXIT, MEXIT_FORCE) - menu_setprop(menu, MPROP_EXITNAME, fmt("%L", id, "EXIT")) + menu_setprop(menu, MPROP_PERPAGE, 0) + menu_setprop(menu, MPROP_EXIT, MEXIT_FORCE) + menu_setprop(menu, MPROP_EXITNAME, fmt("%L", id, "EXIT")) - menu_display(id, menu) - return PLUGIN_HANDLED + menu_display(id, menu) + return PLUGIN_HANDLED } public MenuCallback_SelectFlags(const id, const menu, const item) { - menu_item_getinfo(menu, item, g_dummy, g_itemInfo, charsmax(g_itemInfo), g_itemName, charsmax(g_itemName), g_dummy) + menu_item_getinfo(menu, item, g_dummy, g_itemInfo, charsmax(g_itemInfo), g_itemName, charsmax(g_itemName), g_dummy) - new itemIndex = strtol(g_itemInfo) + new itemIndex = strtol(g_itemInfo) - new bool: isReadyToGag = (g_adminTempData[id][gd_reason][r_flags] != gagFlag_Removed) + new bool: isReadyToGag = (g_adminTempData[id][gd_reason][r_flags] != gagFlag_Removed) - new target = g_adminTempData[id][gd_target] + new target = g_adminTempData[id][gd_target] - new bool: alreadyHasGag = (g_currentGags[target][gd_reason][r_flags] != gagFlag_Removed) - new bool: hasChanges = !GagData_IsEqual(g_currentGags[target], g_adminTempData[id]) + new bool: alreadyHasGag = (g_currentGags[target][gd_reason][r_flags] != gagFlag_Removed) + new bool: hasChanges = !GagData_IsEqual(g_currentGags[target], g_adminTempData[id]) - if((itemIndex == ITEM_CONFIRM)) { - if(!isReadyToGag) { - return ITEM_DISABLED - } + if ((itemIndex == ITEM_CONFIRM)) { + if (!isReadyToGag) { + return ITEM_DISABLED + } - if(alreadyHasGag && !hasChanges) { - return ITEM_DISABLED + if (alreadyHasGag && !hasChanges) { + return ITEM_DISABLED + } } - } - return ITEM_ENABLED + return ITEM_ENABLED } public MenuHandler_SelectFlags(const id, const menu, const item) { - if(item == MENU_EXIT || item < 0) { - MenuShow_PlayersList(id) + if (item == MENU_EXIT || item < 0) { + MenuShow_PlayersList(id) - menu_destroy(menu) - return PLUGIN_HANDLED - } + menu_destroy(menu) + return PLUGIN_HANDLED + } - new target = g_adminTempData[id][gd_target] + new target = g_adminTempData[id][gd_target] - if(!is_user_connected(target)) { - UTIL_SendAudio(id, ca_gag_sound_error) - client_print_color(id, print_team_red, "%L %L", id, "Gag_prefix", id, "Gag_PlayerNotConnected") + if (!is_user_connected(target)) { + UTIL_SendAudio(id, ca_gag_sound_error) + client_print_color(id, print_team_red, "%L %L", id, "Gag_prefix", id, "Gag_PlayerNotConnected") - MenuShow_PlayersList(id) - menu_destroy(menu) - return PLUGIN_HANDLED - } + MenuShow_PlayersList(id) + menu_destroy(menu) + return PLUGIN_HANDLED + } - menu_item_getinfo(menu, item, g_dummy, g_itemInfo, charsmax(g_itemInfo), g_itemName, charsmax(g_itemName), g_dummy) - menu_destroy(menu) + menu_item_getinfo(menu, item, g_dummy, g_itemInfo, charsmax(g_itemInfo), g_itemName, charsmax(g_itemName), g_dummy) + menu_destroy(menu) - new itemIndex = strtol(g_itemInfo) + new itemIndex = strtol(g_itemInfo) - switch(itemIndex) { - case gagFlag_Say: { - g_adminTempData[id][gd_reason][r_flags] ^= (!ca_gag_common_chat_block ? gagFlag_Say : (gagFlag_Say | gagFlag_SayTeam)) - } - case gagFlag_SayTeam: g_adminTempData[id][gd_reason][r_flags] ^= gagFlag_SayTeam - case gagFlag_Voice: g_adminTempData[id][gd_reason][r_flags] ^= gagFlag_Voice + switch (itemIndex) { + case gagFlag_Say: { + g_adminTempData[id][gd_reason][r_flags] ^= (!ca_gag_common_chat_block ? gagFlag_Say : (gagFlag_Say | gagFlag_SayTeam)) + } + case gagFlag_SayTeam: g_adminTempData[id][gd_reason][r_flags] ^= gagFlag_SayTeam + case gagFlag_Voice: g_adminTempData[id][gd_reason][r_flags] ^= gagFlag_Voice - case ITEM_CONFIRM: { - new time = g_adminTempData[id][gd_reason][r_time] - new flags = g_adminTempData[id][gd_reason][r_flags] - new expireAt = g_adminTempData[id][gd_expireAt] + case ITEM_CONFIRM: { + new time = g_adminTempData[id][gd_reason][r_time] + new flags = g_adminTempData[id][gd_reason][r_flags] + new expireAt = g_adminTempData[id][gd_expireAt] - Gag_Save(id, target, time, flags, expireAt) - GagData_Reset(g_adminTempData[id]) + Gag_Save(id, target, time, flags, expireAt) + GagData_Reset(g_adminTempData[id]) - return PLUGIN_HANDLED + return PLUGIN_HANDLED + } } - } - MenuShow_SelectFlags(id) - return PLUGIN_HANDLED + MenuShow_SelectFlags(id) + return PLUGIN_HANDLED } // Show gag menu static MenuShow_ShowGag(const id) { - if(!is_user_connected(id)) { - return - } + if (!is_user_connected(id)) { + return + } - new menu = menu_create(fmt("%L", id, "Gag_MenuItem_ShowGag", g_adminTempData[id][gd_name]), "MenuHandler_ShowGag") + new menu = menu_create(fmt("%L", id, "Gag_MenuItem_ShowGag", g_adminTempData[id][gd_name]), "MenuHandler_ShowGag") - static callback + static callback - if(!callback) { - callback = menu_makecallback("MenuCallback_ShowGag") - } + if (!callback) { + callback = menu_makecallback("MenuCallback_ShowGag") + } - menu_additem(menu, fmt("%L", id, "Gag_MenuItem_RemoveGag"), .info = g_adminTempData[id][gd_adminAuthID], .callback = callback) - menu_additem(menu, fmt("%L", id, "Gag_MenuItem_EditGag"), .info = g_adminTempData[id][gd_adminAuthID], .callback = callback) + menu_additem(menu, fmt("%L", id, "Gag_MenuItem_RemoveGag"), .info = g_adminTempData[id][gd_adminAuthID], .callback = callback) + menu_additem(menu, fmt("%L", id, "Gag_MenuItem_EditGag"), .info = g_adminTempData[id][gd_adminAuthID], .callback = callback) - menu_addtext(menu, fmt("\n \\d%L \\w%s", id, "Gag_MenuItem_Admin", - g_adminTempData[id][gd_adminName] + menu_addtext(menu, fmt("^n \d%L \w%s", id, "Gag_MenuItem_Admin", + g_adminTempData[id][gd_adminName] + ) ) - ) - menu_addtext(menu, fmt(" \\d%L \\w%s", id, "Gag_MenuItem_Reason", - Get_GagString_reason(id, g_adminTempData[id][gd_target]) + menu_addtext(menu, fmt(" \d%L \w%s", id, "Gag_MenuItem_Reason", + Get_GagString_reason(id, g_adminTempData[id][gd_target]) + ) ) - ) - menu_addtext(menu, fmt(" \\d%L \\w%s", id, "Gag_MenuItem_Type", - Get_GagFlags_Names(gag_flags_s: g_adminTempData[id][gd_reason][r_flags]) + menu_addtext(menu, fmt(" \d%L \w%s", id, "Gag_MenuItem_Type", + Get_GagFlags_Names(gag_flags_s: g_adminTempData[id][gd_reason][r_flags]) + ) ) - ) - menu_addtext(menu, fmt(" \\d%L \\w%s", id, "Gag_MenuItem_Length", - Get_TimeString_seconds(id, g_adminTempData[id][gd_reason][r_time]) - ) - ) - - new hoursLeft = (g_adminTempData[id][gd_expireAt] - get_systime()) / SECONDS_IN_HOUR - if(hoursLeft > 5) { - new timeStr[32]; format_time(timeStr, charsmax(timeStr), "%d/%m/%Y (%H:%M)", g_adminTempData[id][gd_expireAt]) - menu_addtext(menu, fmt(" \\d%L \\w%s", id, "Gag_MenuItem_Expire", - timeStr - ) + menu_addtext(menu, fmt(" \d%L \w%s", id, "Gag_MenuItem_Length", + Get_TimeString_seconds(id, g_adminTempData[id][gd_reason][r_time]) + ) ) - } else { - new expireLeft = g_adminTempData[id][gd_expireAt] - get_systime() - new expireLeftStr[128]; get_time_length(id, expireLeft, timeunit_seconds, expireLeftStr, charsmax(expireLeftStr)) - menu_addtext(menu, fmt(" \\d%L \\w%s", id, "Gag_MenuItem_Left", - expireLeftStr - ) - ) - } + new hoursLeft = (g_adminTempData[id][gd_expireAt] - get_systime()) / SECONDS_IN_HOUR + if (hoursLeft > 5) { + new timeStr[32]; format_time(timeStr, charsmax(timeStr), "%d/%m/%Y (%H:%M)", g_adminTempData[id][gd_expireAt]) + menu_addtext(menu, fmt(" \d%L \w%s", id, "Gag_MenuItem_Expire", + timeStr + ) + ) + } else { + new expireLeft = g_adminTempData[id][gd_expireAt] - get_systime() + new expireLeftStr[128]; get_time_length(id, expireLeft, timeunit_seconds, expireLeftStr, charsmax(expireLeftStr)) - menu_addblank(menu, .slot = false) - menu_addblank(menu, .slot = false) + menu_addtext(menu, fmt(" \d%L \w%s", id, "Gag_MenuItem_Left", + expireLeftStr + ) + ) + } + + menu_addblank(menu, .slot = false) + menu_addblank(menu, .slot = false) - menu_setprop(menu, MPROP_PERPAGE, 0) - menu_setprop(menu, MPROP_EXIT, MEXIT_FORCE) - menu_setprop(menu, MPROP_EXITNAME, fmt("%L", id, "EXIT")) + menu_setprop(menu, MPROP_PERPAGE, 0) + menu_setprop(menu, MPROP_EXIT, MEXIT_FORCE) + menu_setprop(menu, MPROP_EXITNAME, fmt("%L", id, "EXIT")) - menu_display(id, menu) + menu_display(id, menu) } public MenuCallback_ShowGag(const id, const menu, const item) { - if(!ca_gag_remove_only_own_gag) { - return ITEM_ENABLED - } + if (!ca_gag_remove_only_own_gag) { + return ITEM_ENABLED + } - new flags = get_user_flags(id) + new flags = get_user_flags(id) - if(flags & read_flags(ca_gag_access_flags_high)) { - return ITEM_ENABLED - } + if (flags & read_flags(ca_gag_access_flags_high)) { + return ITEM_ENABLED + } - menu_item_getinfo(menu, item, g_dummy, g_itemInfo, charsmax(g_itemInfo), g_itemName, charsmax(g_itemName), g_dummy) + menu_item_getinfo(menu, item, g_dummy, g_itemInfo, charsmax(g_itemInfo), g_itemName, charsmax(g_itemName), g_dummy) - new authID[MAX_AUTHID_LENGTH]; get_user_authid(id, authID, charsmax(authID)) - new bool: isOwnGag = (strcmp(authID, g_itemInfo) == 0) + new authID[MAX_AUTHID_LENGTH]; get_user_authid(id, authID, charsmax(authID)) + new bool: isOwnGag = (strcmp(authID, g_itemInfo) == 0) - if(isOwnGag) { - return ITEM_ENABLED - } + if (isOwnGag) { + return ITEM_ENABLED + } - return ITEM_DISABLED + return ITEM_DISABLED } public MenuHandler_ShowGag(const id, const menu, const item) { - enum { menu_ComfirmRemove, menu_EditGagProperties } + enum { menu_ComfirmRemove, menu_EditGagProperties } - menu_destroy(menu) + menu_destroy(menu) - if(item == MENU_EXIT || item < 0) { - MenuShow_PlayersList(id) - return PLUGIN_HANDLED - } + if (item == MENU_EXIT || item < 0) { + MenuShow_PlayersList(id) + return PLUGIN_HANDLED + } - new target = g_adminTempData[id][gd_target] + new target = g_adminTempData[id][gd_target] - if(!is_user_connected(target)) { - UTIL_SendAudio(id, ca_gag_sound_error) - client_print_color(id, print_team_red, "%L %L", id, "Gag_prefix", id, "Gag_PlayerNotConnected") + if (!is_user_connected(target)) { + UTIL_SendAudio(id, ca_gag_sound_error) + client_print_color(id, print_team_red, "%L %L", id, "Gag_prefix", id, "Gag_PlayerNotConnected") - MenuShow_PlayersList(id) - return PLUGIN_HANDLED - } + MenuShow_PlayersList(id) + return PLUGIN_HANDLED + } - // Remove player gag and exit from menu - if(item == menu_ComfirmRemove) { - Gag_Remove(id, target) + // Remove player gag and exit from menu + if (item == menu_ComfirmRemove) { + Gag_Remove(id, target) - MenuShow_PlayersList(id) - return PLUGIN_HANDLED - } + MenuShow_PlayersList(id) + return PLUGIN_HANDLED + } - // Edit player gag properties - if(item == menu_EditGagProperties) { - new gagData[gagData_s]; { - // Copy already used gag data - GagData_Copy(gagData, g_currentGags[target]) + // Edit player gag properties + if (item == menu_EditGagProperties) { + new gagData[gagData_s]; { + // Copy already used gag data + GagData_Copy(gagData, g_currentGags[target]) - // Get updated player data like IP, nickname etc. - GagData_GetPersonalData(id, target, gagData) - } + // Get updated player data like IP, nickname etc. + GagData_GetPersonalData(id, target, gagData) + } - GagData_Copy(g_adminTempData[id], gagData) + GagData_Copy(g_adminTempData[id], gagData) - g_inEditMenu[id] = true + g_inEditMenu[id] = true - MenuShow_EditGag(id) - return PLUGIN_HANDLED - } + MenuShow_EditGag(id) + return PLUGIN_HANDLED + } - MenuShow_PlayersList(id) - return PLUGIN_HANDLED + MenuShow_PlayersList(id) + return PLUGIN_HANDLED } // Edit gag menu static MenuShow_EditGag(const id) { - if(!is_user_connected(id)) { - return - } + if (!is_user_connected(id)) { + return + } - new target = g_adminTempData[id][gd_target] + new target = g_adminTempData[id][gd_target] - if(!is_user_connected(target)) { - UTIL_SendAudio(id, ca_gag_sound_error) - client_print_color(id, print_team_red, "%L %L", id, "Gag_prefix", id, "Gag_PlayerNotConnected") + if (!is_user_connected(target)) { + UTIL_SendAudio(id, ca_gag_sound_error) + client_print_color(id, print_team_red, "%L %L", id, "Gag_prefix", id, "Gag_PlayerNotConnected") - MenuShow_PlayersList(id) - return - } + MenuShow_PlayersList(id) + return + } - new menu = menu_create(fmt("%L [\\r%s\\y]", id, "Gag_MenuItem_EditGag", g_adminTempData[id][gd_name]), "MenuHandler_EditGag") + new menu = menu_create(fmt("%L [\r%s\y]", id, "Gag_MenuItem_EditGag", g_adminTempData[id][gd_name]), "MenuHandler_EditGag") - static callback + static callback - if(!callback) { - callback = menu_makecallback("MenuCallback_EditGag") - } + if (!callback) { + callback = menu_makecallback("MenuCallback_EditGag") + } + + new gag_flags_s: gagFlags = g_adminTempData[id][gd_reason][r_flags] - new gag_flags_s: gagFlags = g_adminTempData[id][gd_reason][r_flags] + menu_additem(menu, fmt("%L [ %s ]", id, "Gag_MenuItem_PropSay", + (gagFlags & gagFlag_Say) ? " \r+\w " : "-" + ), + fmt("%i", gagFlag_Say) + ) - menu_additem(menu, fmt("%L [ %s ]", id, "Gag_MenuItem_PropSay", - (gagFlags & gagFlag_Say) ? " \\r+\\w " : "-" - ), - fmt("%i", gagFlag_Say) - ) + if (!ca_gag_common_chat_block) { + menu_additem(menu, fmt("%L [ %s ]", id, "Gag_MenuItem_PropSayTeam", + (gagFlags & gagFlag_SayTeam) ? " \r+\w " : "-" + ), + fmt("%i", gagFlag_SayTeam) + ) + } - if(!ca_gag_common_chat_block) { - menu_additem(menu, fmt("%L [ %s ]", id, "Gag_MenuItem_PropSayTeam", - (gagFlags & gagFlag_SayTeam) ? " \\r+\\w " : "-" - ), - fmt("%i", gagFlag_SayTeam) + menu_additem(menu, fmt("%L [ %s ]", id, "Gag_MenuItem_PropVoice", + (gagFlags & gagFlag_Voice) ? " \r+\w " : "-" + ), + fmt("%i", gagFlag_Voice) ) - } - - menu_additem(menu, fmt("%L [ %s ]", id, "Gag_MenuItem_PropVoice", - (gagFlags & gagFlag_Voice) ? " \\r+\\w " : "-" - ), - fmt("%i", gagFlag_Voice) - ) - - menu_addblank(menu, .slot = false) - - menu_additem(menu, fmt("%L [ \\r%s\\w ]", id, "Gag_MenuItem_Reason", - Get_GagString_reason(id, target) - ), - fmt("%i", ITEM_REASON) - ) - menu_addtext(menu, fmt(" %L [ \\r%s\\w ]", id, "Gag_MenuItem_Time", - Get_TimeString_seconds(id, g_adminTempData[id][gd_reason][r_time]) - ), .slot = false - ) - - menu_addblank(menu, .slot = false) - - menu_addblank2(menu) - menu_addblank2(menu) - menu_addblank2(menu) - menu_addblank2(menu) - - if(ca_gag_common_chat_block) { + + menu_addblank(menu, .slot = false) + + menu_additem(menu, fmt("%L [ \r%s\w ]", id, "Gag_MenuItem_Reason", + Get_GagString_reason(id, target) + ), + fmt("%i", ITEM_REASON) + ) + menu_addtext(menu, fmt(" %L [ \r%s\w ]", id, "Gag_MenuItem_Time", + Get_TimeString_seconds(id, g_adminTempData[id][gd_reason][r_time]) + ), .slot = false + ) + + menu_addblank(menu, .slot = false) + + menu_addblank2(menu) + menu_addblank2(menu) + menu_addblank2(menu) menu_addblank2(menu) - } - menu_additem(menu, fmt("%L", id, "Gag_MenuItem_Confirm"), fmt("%i", ITEM_CONFIRM), .callback = callback) + if (ca_gag_common_chat_block) { + menu_addblank2(menu) + } + + menu_additem(menu, fmt("%L", id, "Gag_MenuItem_Confirm"), fmt("%i", ITEM_CONFIRM), .callback = callback) - menu_setprop(menu, MPROP_PERPAGE, 0) - menu_setprop(menu, MPROP_EXIT, MEXIT_FORCE) - menu_setprop(menu, MPROP_EXITNAME, fmt("%L", id, "EXIT")) + menu_setprop(menu, MPROP_PERPAGE, 0) + menu_setprop(menu, MPROP_EXIT, MEXIT_FORCE) + menu_setprop(menu, MPROP_EXITNAME, fmt("%L", id, "EXIT")) - menu_display(id, menu) + menu_display(id, menu) - g_inEditMenu[id] = true + g_inEditMenu[id] = true } public MenuCallback_EditGag(const id, const menu, const item) { - menu_item_getinfo(menu, item, g_dummy, g_itemInfo, charsmax(g_itemInfo), g_itemName, charsmax(g_itemName), g_dummy) + menu_item_getinfo(menu, item, g_dummy, g_itemInfo, charsmax(g_itemInfo), g_itemName, charsmax(g_itemName), g_dummy) - new itemIndex = strtol(g_itemInfo) + new itemIndex = strtol(g_itemInfo) - if(itemIndex != ITEM_CONFIRM) { - return ITEM_ENABLED - } + if (itemIndex != ITEM_CONFIRM) { + return ITEM_ENABLED + } - new bool: isReadyToGag = (g_adminTempData[id][gd_reason][r_flags] != gagFlag_Removed) + new bool: isReadyToGag = (g_adminTempData[id][gd_reason][r_flags] != gagFlag_Removed) - if(!isReadyToGag) { - return ITEM_DISABLED - } + if (!isReadyToGag) { + return ITEM_DISABLED + } - new target = g_adminTempData[id][gd_target] - new bool: hasChanges = !GagData_IsEqual(g_currentGags[target], g_adminTempData[id]) + new target = g_adminTempData[id][gd_target] + new bool: hasChanges = !GagData_IsEqual(g_currentGags[target], g_adminTempData[id]) - if(!hasChanges) { - return ITEM_DISABLED - } + if (!hasChanges) { + return ITEM_DISABLED + } - return ITEM_ENABLED + return ITEM_ENABLED } public MenuHandler_EditGag(const id, const menu, const item) { - if(item == MENU_EXIT || item < 0) { - MenuShow_PlayersList(id) + if (item == MENU_EXIT || item < 0) { + MenuShow_PlayersList(id) - menu_destroy(menu) - return PLUGIN_HANDLED - } + menu_destroy(menu) + return PLUGIN_HANDLED + } - new target = g_adminTempData[id][gd_target] - if(!is_user_connected(target)) { - UTIL_SendAudio(id, ca_gag_sound_error) - client_print_color(id, print_team_red, "%L %L", id, "Gag_prefix", id, "Gag_PlayerNotConnected") + new target = g_adminTempData[id][gd_target] + if (!is_user_connected(target)) { + UTIL_SendAudio(id, ca_gag_sound_error) + client_print_color(id, print_team_red, "%L %L", id, "Gag_prefix", id, "Gag_PlayerNotConnected") - MenuShow_PlayersList(id) - menu_destroy(menu) - return PLUGIN_HANDLED - } + MenuShow_PlayersList(id) + menu_destroy(menu) + return PLUGIN_HANDLED + } - menu_item_getinfo(menu, item, g_dummy, g_itemInfo, charsmax(g_itemInfo), g_itemName, charsmax(g_itemName), g_dummy) - menu_destroy(menu) + menu_item_getinfo(menu, item, g_dummy, g_itemInfo, charsmax(g_itemInfo), g_itemName, charsmax(g_itemName), g_dummy) + menu_destroy(menu) - new itemIndex = strtol(g_itemInfo) + new itemIndex = strtol(g_itemInfo) - switch(itemIndex) { - case gagFlag_Say: g_adminTempData[id][gd_reason][r_flags] ^= gagFlag_Say - case gagFlag_SayTeam: g_adminTempData[id][gd_reason][r_flags] ^= gagFlag_SayTeam - case gagFlag_Voice: g_adminTempData[id][gd_reason][r_flags] ^= gagFlag_Voice - case ITEM_REASON: { - MenuShow_SelectReason(id) - return PLUGIN_HANDLED - } - case ITEM_CONFIRM: { - new time = g_adminTempData[id][gd_reason][r_time] - new flags = g_adminTempData[id][gd_reason][r_flags] + switch (itemIndex) { + case gagFlag_Say: g_adminTempData[id][gd_reason][r_flags] ^= gagFlag_Say + case gagFlag_SayTeam: g_adminTempData[id][gd_reason][r_flags] ^= gagFlag_SayTeam + case gagFlag_Voice: g_adminTempData[id][gd_reason][r_flags] ^= gagFlag_Voice + case ITEM_REASON: { + MenuShow_SelectReason(id) + return PLUGIN_HANDLED + } + case ITEM_CONFIRM: { + new time = g_adminTempData[id][gd_reason][r_time] + new flags = g_adminTempData[id][gd_reason][r_flags] - new bool: timeChanged = (g_currentGags[target][gd_reason][r_time] != time) + new bool: timeChanged = (g_currentGags[target][gd_reason][r_time] != time) - new expireAt = timeChanged ? 0 : g_adminTempData[id][gd_expireAt] + new expireAt = timeChanged ? 0 : g_adminTempData[id][gd_expireAt] - new gagTimeStr[32]; copy(gagTimeStr, charsmax(gagTimeStr), Get_TimeString_seconds(LANG_PLAYER, time)) + new gagTimeStr[32]; copy(gagTimeStr, charsmax(gagTimeStr), Get_TimeString_seconds(LANG_PLAYER, time)) - CA_Log(logLevel_Info, "Gag: \"%s\" edit gag for \"%s\" (type:\"%s\") (time:\"%s\") (reason:\"%s\")", \ - g_adminTempData[id][gd_adminName], g_adminTempData[id][gd_name], \ - bits_to_flags(gag_flags_s: g_adminTempData[id][gd_reason][r_flags]), \ - gagTimeStr, g_adminTempData[id][gd_reason][r_name] \ - ) + CA_Log(logLevel_Info, "Gag: ^"%s^" edit gag for ^"%s^" (type:^"%s^") (time:^"%s^") (reason:^"%s^")", \ + g_adminTempData[id][gd_adminName], g_adminTempData[id][gd_name], \ + bits_to_flags(gag_flags_s: g_adminTempData[id][gd_reason][r_flags]), \ + gagTimeStr, g_adminTempData[id][gd_reason][r_name] \ + ) - Gag_Save(id, target, time, flags, expireAt) + Gag_Save(id, target, time, flags, expireAt) - GagData_Reset(g_adminTempData[id]) - g_inEditMenu[id] = false + GagData_Reset(g_adminTempData[id]) + g_inEditMenu[id] = false - return PLUGIN_HANDLED + return PLUGIN_HANDLED + } } - } - MenuShow_EditGag(id) - return PLUGIN_HANDLED + MenuShow_EditGag(id) + return PLUGIN_HANDLED } /* * @endsection Menus @@ -1064,262 +1063,262 @@ public MenuHandler_EditGag(const id, const menu, const item) { * @section user cmds handling */ public ClCmd_Gag(const id, const level, const cid) { - if(!cmd_access(id, level, cid, 1)) { - return PLUGIN_HANDLED - } + if (!cmd_access(id, level, cid, 1)) { + return PLUGIN_HANDLED + } - if(get_playersnum_ex(GetPlayers_ExcludeBots | GetPlayers_ExcludeHLTV) < 2) { - UTIL_SendAudio(id, ca_gag_sound_error) - client_print_color(id, print_team_default, "%L %L", id, "Gag_prefix", id, "Gag_NotEnoughPlayers") - return PLUGIN_HANDLED - } + if (get_playersnum_ex(GetPlayers_ExcludeBots | GetPlayers_ExcludeHLTV) < 2) { + UTIL_SendAudio(id, ca_gag_sound_error) + client_print_color(id, print_team_default, "%L %L", id, "Gag_prefix", id, "Gag_NotEnoughPlayers") + return PLUGIN_HANDLED + } - MenuShow_PlayersList(id) - return PLUGIN_HANDLED + MenuShow_PlayersList(id) + return PLUGIN_HANDLED } public ClCmd_EnterGagReason(const id, const level, const cid) { - if(!cmd_access(id, level, cid, 1)) { - return PLUGIN_HANDLED - } + if (!cmd_access(id, level, cid, 1)) { + return PLUGIN_HANDLED + } - new target = g_adminTempData[id][gd_target] + new target = g_adminTempData[id][gd_target] - if(!is_user_connected(target)) { - UTIL_SendAudio(id, ca_gag_sound_error) - client_print_color(id, print_team_red, "%L %L", id, "Gag_prefix", id, "Gag_PlayerNotConnected") + if (!is_user_connected(target)) { + UTIL_SendAudio(id, ca_gag_sound_error) + client_print_color(id, print_team_red, "%L %L", id, "Gag_prefix", id, "Gag_PlayerNotConnected") - MenuShow_PlayersList(id) - return PLUGIN_HANDLED - } + MenuShow_PlayersList(id) + return PLUGIN_HANDLED + } - static customReasonName[128] - read_argv(1, customReasonName, charsmax(customReasonName)) + static customReasonName[128] + read_argv(1, customReasonName, charsmax(customReasonName)) - if(!customReasonName[0]) { - MenuShow_SelectReason(id) - return PLUGIN_HANDLED - } + if (!customReasonName[0]) { + MenuShow_SelectReason(id) + return PLUGIN_HANDLED + } - copy(g_adminTempData[id][gd_reason][r_name], charsmax(g_adminTempData[][r_name]), customReasonName) + copy(g_adminTempData[id][gd_reason][r_name], charsmax(g_adminTempData[][r_name]), customReasonName) - client_print_color(id, print_team_red, "%L %L (%s)", id, "Gag_prefix", id, "Gag_YouSetManual_Reason", g_adminTempData[id][gd_reason][r_name]) + client_print_color(id, print_team_red, "%L %L (%s)", id, "Gag_prefix", id, "Gag_YouSetManual_Reason", g_adminTempData[id][gd_reason][r_name]) - MenuShow_SelectTime(id) - return PLUGIN_HANDLED + MenuShow_SelectTime(id) + return PLUGIN_HANDLED } public ClCmd_EnterGagTime(const id, const level, const cid) { - if(!cmd_access(id, level, cid, 1)) { - return PLUGIN_HANDLED - } + if (!cmd_access(id, level, cid, 1)) { + return PLUGIN_HANDLED + } - if(!is_user_connected(id)) { - return PLUGIN_HANDLED - } + if (!is_user_connected(id)) { + return PLUGIN_HANDLED + } - new target = g_adminTempData[id][gd_target] + new target = g_adminTempData[id][gd_target] - if(!is_user_connected(target)) { - UTIL_SendAudio(id, ca_gag_sound_error) - client_print_color(id, print_team_red, "%L %L", id, "Gag_prefix", id, "Gag_PlayerNotConnected") + if (!is_user_connected(target)) { + UTIL_SendAudio(id, ca_gag_sound_error) + client_print_color(id, print_team_red, "%L %L", id, "Gag_prefix", id, "Gag_PlayerNotConnected") - MenuShow_PlayersList(id) - return PLUGIN_HANDLED - } + MenuShow_PlayersList(id) + return PLUGIN_HANDLED + } - static timeStr[6] - read_argv(1, timeStr, charsmax(timeStr)) + static timeStr[6] + read_argv(1, timeStr, charsmax(timeStr)) - new time = strtol(timeStr) * SECONDS_IN_MINUTE + new time = strtol(timeStr) * SECONDS_IN_MINUTE - if(time <= 0) { - client_print_color(id, print_team_red, "%L %L (%s)!", id, "Gag_prefix", id, "Gag_NotValidTimeEntered", timeStr) + if (time <= 0) { + client_print_color(id, print_team_red, "%L %L (%s)!", id, "Gag_prefix", id, "Gag_NotValidTimeEntered", timeStr) - MenuShow_SelectTime(id) - return PLUGIN_HANDLED - } + MenuShow_SelectTime(id) + return PLUGIN_HANDLED + } - client_print_color(id, print_team_red, "%L %L (%s)", id, "Gag_prefix", id, "Gag_YouSetManual_Time", Get_TimeString_seconds(id, time)) + client_print_color(id, print_team_red, "%L %L (%s)", id, "Gag_prefix", id, "Gag_YouSetManual_Time", Get_TimeString_seconds(id, time)) - g_adminTempData[id][gd_reason][r_time] = time + g_adminTempData[id][gd_reason][r_time] = time - if(g_inEditMenu[id]) { - MenuShow_EditGag(id) + if (g_inEditMenu[id]) { + MenuShow_EditGag(id) - return PLUGIN_HANDLED - } + return PLUGIN_HANDLED + } - MenuShow_SelectFlags(id) - return PLUGIN_HANDLED + MenuShow_SelectFlags(id) + return PLUGIN_HANDLED } public ConCmd_amx_gag(const id, const level, const cid) { - enum amx_gag_s { /* arg_cmd, */ arg_player = 1, arg_reason, arg_time, arg_flags } + enum amx_gag_s { /* arg_cmd, */ arg_player = 1, arg_reason, arg_time, arg_flags } - if(!cmd_access(id, level, cid, 1)) { - return PLUGIN_HANDLED - } + if (!cmd_access(id, level, cid, 1)) { + return PLUGIN_HANDLED + } - new argc = read_argc() + new argc = read_argc() - if(argc == 1) { - console_print(id, "\t Usage: amx_gag [nickname | STEAM_ID | userID | IP] <reason> <time> <flags>\n") + if (argc == 1) { + console_print(id, "^t Usage: amx_gag [nickname | STEAM_ID | userID | IP] <reason> <time> <flags>^n") - return PLUGIN_HANDLED - } + return PLUGIN_HANDLED + } - new args[amx_gag_s][255] - for(new i; i < argc; i++) { - read_argv(i, args[amx_gag_s: i], charsmax(args[])) - } + new args[amx_gag_s][255] + for(new i; i < argc; i++) { + read_argv(i, args[amx_gag_s: i], charsmax(args[])) + } - new target = FindPlayerByTarget(args[arg_player]) + new target = FindPlayerByTarget(args[arg_player]) - if(!target || target == id) { - console_print(id, "Can't find player by arg=`%s`", args[arg_player]) + if (!target || target == id) { + console_print(id, "Can't find player by arg=`%s`", args[arg_player]) - return PLUGIN_HANDLED - } + return PLUGIN_HANDLED + } - if(g_currentGags[target][gd_reason][r_flags] != gagFlag_Removed) { - console_print(id, "Player '%n' has already gagged.", target) + if (g_currentGags[target][gd_reason][r_flags] != gagFlag_Removed) { + console_print(id, "Player '%n' has already gagged.", target) - return PLUGIN_HANDLED - } + return PLUGIN_HANDLED + } - trim(args[arg_reason]) + trim(args[arg_reason]) - // Setup default gag for target player - GagData_GetPersonalData(id, target, g_adminTempData[id]) + // Setup default gag for target player + GagData_GetPersonalData(id, target, g_adminTempData[id]) - g_adminTempData[id][gd_reason][r_time] = 60 * SECONDS_IN_MINUTE - g_adminTempData[id][gd_reason][r_flags] = gagFlag_Say | gagFlag_SayTeam | gagFlag_Voice + g_adminTempData[id][gd_reason][r_time] = 60 * SECONDS_IN_MINUTE + g_adminTempData[id][gd_reason][r_flags] = gagFlag_Say | gagFlag_SayTeam | gagFlag_Voice - copy(g_adminTempData[id][gd_reason][r_name], charsmax(g_adminTempData[][r_name]), "Not set") + copy(g_adminTempData[id][gd_reason][r_name], charsmax(g_adminTempData[][r_name]), "Not set") - if(args[arg_reason][0] != EOS) { - copy(g_adminTempData[id][gd_reason][r_name], charsmax(g_adminTempData[][r_name]), args[arg_reason]) - } + if (args[arg_reason][0] != EOS) { + copy(g_adminTempData[id][gd_reason][r_name], charsmax(g_adminTempData[][r_name]), args[arg_reason]) + } - if(args[arg_time][0] != EOS) { - new seconds = strtol(args[arg_time]) * SECONDS_IN_MINUTE + if (args[arg_time][0] != EOS) { + new seconds = strtol(args[arg_time]) * SECONDS_IN_MINUTE - if(seconds > 0) { - g_adminTempData[id][gd_reason][r_time] = seconds + if (seconds > 0) { + g_adminTempData[id][gd_reason][r_time] = seconds + } } - } - if(args[arg_flags][0] != EOS) { - g_adminTempData[id][gd_reason][r_flags] = flags_to_bit(args[arg_flags][0]) - } + if (args[arg_flags][0] != EOS) { + g_adminTempData[id][gd_reason][r_flags] = flags_to_bit(args[arg_flags][0]) + } - Gag_Save(id, target, g_adminTempData[id][gd_reason][r_time], g_adminTempData[id][gd_reason][r_flags]) - return PLUGIN_HANDLED + Gag_Save(id, target, g_adminTempData[id][gd_reason][r_time], g_adminTempData[id][gd_reason][r_flags]) + return PLUGIN_HANDLED } public SrvCmd_AddReason() { - enum any: args_s { arg_cmd, arg_reason, arg_flags, arg_time } + enum any: args_s { arg_cmd, arg_reason, arg_flags, arg_time } - new argCount = read_argc() - if(argCount < 2 || argCount > 4) { - server_print("\tUsage: ca_gag_add_reason <reason> [flags] [time]") - return - } + new argCount = read_argc() + if (argCount < 2 || argCount > 4) { + server_print("^tUsage: ca_gag_add_reason <reason> [flags] [time]") + return + } - new args[args_s][256] + new args[args_s][256] - for(new arg = arg_cmd; arg < sizeof(args); arg++) { - read_argv(arg, args[arg], charsmax(args[])) - } + for(new arg = arg_cmd; arg < sizeof(args); arg++) { + read_argv(arg, args[arg], charsmax(args[])) + } - new reason[reason_s] - copy(reason[r_name], charsmax(reason[r_name]), args[arg_reason]) + new reason[reason_s] + copy(reason[r_name], charsmax(reason[r_name]), args[arg_reason]) - trim(args[arg_time]) + trim(args[arg_time]) - new seconds = parseTime(args[arg_time]) + new seconds = parseTime(args[arg_time]) - reason[r_time] = seconds - reason[r_flags] = gag_flags_s: flags_to_bit(args[arg_flags]) + reason[r_time] = seconds + reason[r_flags] = gag_flags_s: flags_to_bit(args[arg_flags]) - ArrayPushArray(g_gagReasonsTemplates, reason) - g_gagReasonsTemplates_size = ArraySize(g_gagReasonsTemplates) + ArrayPushArray(g_gagReasonsTemplates, reason) + g_gagReasonsTemplates_size = ArraySize(g_gagReasonsTemplates) - CA_Log(logLevel_Debug, "ADD: Reason template[#%i]: '%s' (time='%s', flags='%s')",\ - g_gagReasonsTemplates_size, reason[r_name], args[arg_time], bits_to_flags(reason[r_flags])\ - ) + CA_Log(logLevel_Debug, "ADD: Reason template[#%i]: '%s' (time='%s', flags='%s')",\ + g_gagReasonsTemplates_size, reason[r_name], args[arg_time], bits_to_flags(reason[r_flags])\ + ) } public SrvCmd_AddWhitelistCmd() { - enum { arg_chat_cmd = 1 } + enum { arg_chat_cmd = 1 } - new argCount = read_argc() - if(argCount != 2) { - server_print("\tUsage: ca_gag_add_chat_whitelist_cmd <cmd>") - return - } + new argCount = read_argc() + if (argCount != 2) { + server_print("^tUsage: ca_gag_add_chat_whitelist_cmd <cmd>") + return + } - new whitelistCmd[MAX_WHITELIST_CMD_LEN] - read_argv(arg_chat_cmd, whitelistCmd, charsmax(whitelistCmd)) + new whitelistCmd[MAX_WHITELIST_CMD_LEN] + read_argv(arg_chat_cmd, whitelistCmd, charsmax(whitelistCmd)) - ArrayPushArray(g_chatWhitelistCmds, whitelistCmd) - g_chatWhitelistCmds_size = ArraySize(g_chatWhitelistCmds) + ArrayPushArray(g_chatWhitelistCmds, whitelistCmd) + g_chatWhitelistCmds_size = ArraySize(g_chatWhitelistCmds) - CA_Log(logLevel_Debug, "ADD: Whitelist chat cmd[#%i]: %s", g_chatWhitelistCmds_size, whitelistCmd) + CA_Log(logLevel_Debug, "ADD: Whitelist chat cmd[#%i]: %s", g_chatWhitelistCmds_size, whitelistCmd) } public SrvCmd_ShowTemplates() { - if(!g_gagReasonsTemplates_size) { - CA_Log(logLevel_Warning, "\t NO REASONS FOUNDED!") - return PLUGIN_HANDLED - } + if (!g_gagReasonsTemplates_size) { + CA_Log(logLevel_Warning, "^t NO REASONS FOUNDED!") + return PLUGIN_HANDLED + } - for(new i; i < g_gagReasonsTemplates_size; i++) { - new reason[reason_s] - ArrayGetArray(g_gagReasonsTemplates, i, reason) + for(new i; i < g_gagReasonsTemplates_size; i++) { + new reason[reason_s] + ArrayGetArray(g_gagReasonsTemplates, i, reason) - new timeStr[32]; get_time_length(LANG_SERVER, reason[r_time], timeunit_seconds, timeStr, charsmax(timeStr)) + new timeStr[32]; get_time_length(LANG_SERVER, reason[r_time], timeunit_seconds, timeStr, charsmax(timeStr)) - server_print("\t Reason[#%i]: '%s' (Flags:'%s', Time:'%s')",\ - i + 1, reason[r_name], bits_to_flags(reason[r_flags]), timeStr\ - ) - } + server_print("^t Reason[#%i]: '%s' (Flags:'%s', Time:'%s')",\ + i + 1, reason[r_name], bits_to_flags(reason[r_flags]), timeStr\ + ) + } - return PLUGIN_HANDLED + return PLUGIN_HANDLED } public SrvCmd_ReloadConfig() { - LoadConfig() + LoadConfig() - CA_Log(logLevel_Info, "Config re-loaded!") + CA_Log(logLevel_Info, "Config re-loaded!") } static Message_ChatBlocked(const target) { - new secondsLeft = g_currentGags[target][gd_expireAt] - get_systime() - new hoursLeft = secondsLeft / SECONDS_IN_HOUR - - if(hoursLeft > 5) { - new timeStr[32]; format_time(timeStr, charsmax(timeStr), "%d/%m/%Y (%H:%M)", g_currentGags[target][gd_expireAt]) - client_print_color(target, print_team_red, "%L %L %L %s", target, "Gag_prefix", target, "Gag_NotifyPlayer_BlockedChat", target, "Gag_MenuItem_Expire", timeStr) - } else { - new expireLeftStr[128]; get_time_length(target, secondsLeft, timeunit_seconds, expireLeftStr, charsmax(expireLeftStr)) - client_print_color(target, print_team_red, "%L %L %L %s", target, "Gag_prefix", target, "Gag_NotifyPlayer_BlockedChat", target, "Gag_MenuItem_Left", expireLeftStr) - } + new secondsLeft = g_currentGags[target][gd_expireAt] - get_systime() + new hoursLeft = secondsLeft / SECONDS_IN_HOUR + + if (hoursLeft > 5) { + new timeStr[32]; format_time(timeStr, charsmax(timeStr), "%d/%m/%Y (%H:%M)", g_currentGags[target][gd_expireAt]) + client_print_color(target, print_team_red, "%L %L %L %s", target, "Gag_prefix", target, "Gag_NotifyPlayer_BlockedChat", target, "Gag_MenuItem_Expire", timeStr) + } else { + new expireLeftStr[128]; get_time_length(target, secondsLeft, timeunit_seconds, expireLeftStr, charsmax(expireLeftStr)) + client_print_color(target, print_team_red, "%L %L %L %s", target, "Gag_prefix", target, "Gag_NotifyPlayer_BlockedChat", target, "Gag_MenuItem_Left", expireLeftStr) + } } static bool: IsWhitelistCmd(const message[]) { - new whitelistCmd[MAX_WHITELIST_CMD_LEN] + new whitelistCmd[MAX_WHITELIST_CMD_LEN] - for(new i; i < g_chatWhitelistCmds_size; i++) { - ArrayGetArray(g_chatWhitelistCmds, i, whitelistCmd) + for(new i; i < g_chatWhitelistCmds_size; i++) { + ArrayGetArray(g_chatWhitelistCmds, i, whitelistCmd) - if(strcmp(message, whitelistCmd) == 0) { - return true + if (strcmp(message, whitelistCmd) == 0) { + return true + } } - } - return false + return false } /* * @endsection user cmds handling @@ -1330,67 +1329,67 @@ static bool: IsWhitelistCmd(const message[]) { * @section CA:Core API handling */ public CA_Client_Voice(const listener, const sender) { - new bool: hasBlock = (g_currentGags[sender][gd_reason][r_flags] & gagFlag_Voice) + new bool: hasBlock = (g_currentGags[sender][gd_reason][r_flags] & gagFlag_Voice) - if(!hasBlock) { - return CA_CONTINUE - } + if (!hasBlock) { + return CA_CONTINUE + } - // UTIL_SendAudio(sender, ca_gag_sound_error) // TODO: implement later + // UTIL_SendAudio(sender, ca_gag_sound_error) // TODO: implement later - return CA_SUPERCEDE + return CA_SUPERCEDE } public CA_Client_Say(id, const bool: isTeamMessage, const message[]) { - if(CmdRouter(id, message)) - return CA_CONTINUE - - new bool: hasBlock - if(isTeamMessage) { - hasBlock = bool: (g_currentGags[id][gd_reason][r_flags] & (ca_gag_common_chat_block ? gagFlag_Say : gagFlag_SayTeam)) - } else { - hasBlock = bool: (g_currentGags[id][gd_reason][r_flags] & gagFlag_Say) - } + if (CmdRouter(id, message)) + return CA_CONTINUE + + new bool: hasBlock + if (isTeamMessage) { + hasBlock = bool: (g_currentGags[id][gd_reason][r_flags] & (ca_gag_common_chat_block ? gagFlag_Say : gagFlag_SayTeam)) + } else { + hasBlock = bool: (g_currentGags[id][gd_reason][r_flags] & gagFlag_Say) + } - if(!hasBlock) { - return CA_CONTINUE - } + if (!hasBlock) { + return CA_CONTINUE + } - if(IsWhitelistCmd(message)) { - return CA_CONTINUE - } + if (IsWhitelistCmd(message)) { + return CA_CONTINUE + } - UTIL_SendAudio(id, ca_gag_sound_error) - Message_ChatBlocked(id) + UTIL_SendAudio(id, ca_gag_sound_error) + Message_ChatBlocked(id) - return CA_SUPERCEDE + return CA_SUPERCEDE } public CA_Client_ChangeName(const id, const newName[]) { - if(!ca_gag_block_nickname_change) { - return CA_CONTINUE - } + if (!ca_gag_block_nickname_change) { + return CA_CONTINUE + } - new bool: hasBlock = (g_currentGags[id][gd_reason][r_flags] & gagFlag_Say) + new bool: hasBlock = (g_currentGags[id][gd_reason][r_flags] & gagFlag_Say) - if(!hasBlock) { - return CA_CONTINUE - } + if (!hasBlock) { + return CA_CONTINUE + } - return CA_SUPERCEDE + return CA_SUPERCEDE } public ClCmd_adminSay(const id) { - new bool: hasBlock = (g_currentGags[id][gd_reason][r_flags] & gagFlag_Say) + new bool: hasBlock = (g_currentGags[id][gd_reason][r_flags] & gagFlag_Say) - if(!hasBlock || !ca_gag_block_admin_chat) { - return CA_CONTINUE - } + if (!hasBlock || !ca_gag_block_admin_chat) { + return CA_CONTINUE + } - UTIL_SendAudio(id, ca_gag_sound_error) - Message_ChatBlocked(id) + UTIL_SendAudio(id, ca_gag_sound_error) + Message_ChatBlocked(id) - return CA_SUPERCEDE + return CA_SUPERCEDE } /* * @endsection CA:Core API handling @@ -1400,65 +1399,65 @@ public ClCmd_adminSay(const id) { * @section Storage handling */ public CA_Storage_Initialized( ) { - CA_Log(logLevel_Debug, "[CA]: Gag > storage initialized!") + CA_Log(logLevel_Debug, "[CA]: Gag > storage initialized!") } public CA_Storage_Saved(const name[], const authID[], const IP[], const reason[], - const adminName[], const adminAuthID[], const adminIP[], - const createdAt, const expireAt, const flags) { + const adminName[], const adminAuthID[], const adminIP[], + const createdAt, const expireAt, const flags) { - new gagTime = expireAt - createdAt - new gagTimeStr[32]; copy(gagTimeStr, charsmax(gagTimeStr), Get_TimeString_seconds(LANG_PLAYER, gagTime)) + new gagTime = expireAt - createdAt + new gagTimeStr[32]; copy(gagTimeStr, charsmax(gagTimeStr), Get_TimeString_seconds(LANG_PLAYER, gagTime)) - new admin = find_player_ex((FindPlayer_MatchAuthId | FindPlayer_ExcludeBots), adminAuthID) + new admin = find_player_ex((FindPlayer_MatchAuthId | FindPlayer_ExcludeBots), adminAuthID) - if(is_user_connected(admin)) { - UTIL_SendAudio(admin, ca_gag_sound_ok) - } + if (is_user_connected(admin)) { + UTIL_SendAudio(admin, ca_gag_sound_ok) + } - // TODO: Rework this - show_activity_ex(admin, adminName, "%l", "Gag_AdminGagPlayer", name) - client_print(0, print_chat, "%l %s, %l %s (%s)", - "Gag_MenuItem_Reason", reason, - "Gag_MenuItem_Time", gagTimeStr, - Get_GagFlags_Names(gag_flags_s: flags) - ) + // TODO: Rework this + show_activity_ex(admin, adminName, "%l", "Gag_AdminGagPlayer", name) + client_print(0, print_chat, "%l %s, %l %s (%s)", + "Gag_MenuItem_Reason", reason, + "Gag_MenuItem_Time", gagTimeStr, + Get_GagFlags_Names(gag_flags_s: flags) + ) - CA_Log(logLevel_Info, "Gag: \"%s\" add gag to \"%s\" (type:\"%s\") (time:\"%s\") (reason:\"%s\")", \ - adminName, name, bits_to_flags(gag_flags_s: flags), gagTimeStr, reason \ - ) + CA_Log(logLevel_Info, "Gag: ^"%s^" add gag to ^"%s^" (type:^"%s^") (time:^"%s^") (reason:^"%s^")", \ + adminName, name, bits_to_flags(gag_flags_s: flags), gagTimeStr, reason \ + ) } public CA_Storage_Loaded(const name[], const authID[], const IP[], const reason[], - const adminName[], const adminAuthID[], const adminIP[], - const createdAt, const expireAt, const flags) { + const adminName[], const adminAuthID[], const adminIP[], + const createdAt, const expireAt, const flags) { - new target = find_player_ex((FindPlayer_MatchAuthId | FindPlayer_ExcludeBots), authID) + new target = find_player_ex((FindPlayer_MatchAuthId | FindPlayer_ExcludeBots), authID) - if(!target) { - return - } + if (!target) { + return + } - copy(g_currentGags[target][gd_name], charsmax(g_currentGags[][gd_name]), name) + copy(g_currentGags[target][gd_name], charsmax(g_currentGags[][gd_name]), name) - // FIXME: Nickname can't change on DEAD player. - // set_user_info(target, "name", name) + // FIXME: Nickname can't change on DEAD player. + // set_user_info(target, "name", name) - copy(g_currentGags[target][gd_authID], charsmax(g_currentGags[][gd_authID]), authID) - copy(g_currentGags[target][gd_IP], charsmax(g_currentGags[][gd_IP]), IP) + copy(g_currentGags[target][gd_authID], charsmax(g_currentGags[][gd_authID]), authID) + copy(g_currentGags[target][gd_IP], charsmax(g_currentGags[][gd_IP]), IP) - copy(g_currentGags[target][gd_adminName], charsmax(g_currentGags[][gd_adminName]), adminName) - copy(g_currentGags[target][gd_adminAuthID], charsmax(g_currentGags[][gd_adminAuthID]), adminAuthID) - copy(g_currentGags[target][gd_adminIP], charsmax(g_currentGags[][gd_adminIP]), adminIP) + copy(g_currentGags[target][gd_adminName], charsmax(g_currentGags[][gd_adminName]), adminName) + copy(g_currentGags[target][gd_adminAuthID], charsmax(g_currentGags[][gd_adminAuthID]), adminAuthID) + copy(g_currentGags[target][gd_adminIP], charsmax(g_currentGags[][gd_adminIP]), adminIP) - copy(g_currentGags[target][gd_reason][r_name], charsmax(g_currentGags[][r_name]), reason) - g_currentGags[target][gd_reason][r_time] = expireAt - createdAt - g_currentGags[target][gd_reason][r_flags] = gag_flags_s: flags + copy(g_currentGags[target][gd_reason][r_name], charsmax(g_currentGags[][r_name]), reason) + g_currentGags[target][gd_reason][r_time] = expireAt - createdAt + g_currentGags[target][gd_reason][r_flags] = gag_flags_s: flags - g_currentGags[target][gd_expireAt] = expireAt + g_currentGags[target][gd_expireAt] = expireAt } public CA_Storage_Removed( ) { - // TODO + // TODO } /** * @endsection Storage handling @@ -1467,348 +1466,348 @@ public CA_Storage_Removed( ) { static LoadConfig() { - if(ArraySize(g_gagReasonsTemplates) > 0) { - ArrayClear(g_gagReasonsTemplates) - g_gagReasonsTemplates_size = 0 - } + if (ArraySize(g_gagReasonsTemplates) > 0) { + ArrayClear(g_gagReasonsTemplates) + g_gagReasonsTemplates_size = 0 + } - if(ArraySize(g_chatWhitelistCmds) > 0) { - ArrayClear(g_chatWhitelistCmds) - g_chatWhitelistCmds_size = 0 - } + if (ArraySize(g_chatWhitelistCmds) > 0) { + ArrayClear(g_chatWhitelistCmds) + g_chatWhitelistCmds_size = 0 + } - AutoExecConfig(true, "CA_Gag", "ChatAdditions") + AutoExecConfig(true, "CA_Gag", "ChatAdditions") - new configsDir[PLATFORM_MAX_PATH] - get_configsdir(configsDir, charsmax(configsDir)) + new configsDir[PLATFORM_MAX_PATH] + get_configsdir(configsDir, charsmax(configsDir)) - server_cmd("exec %s/plugins/ChatAdditions/CA_Gag.cfg", configsDir) - server_cmd("exec %s/plugins/ChatAdditions/ca_gag_reasons.cfg", configsDir) - server_cmd("exec %s/plugins/ChatAdditions/ca_gag_chat_whitelist_cmds.cfg", configsDir) - server_exec() + server_cmd("exec %s/plugins/ChatAdditions/CA_Gag.cfg", configsDir) + server_cmd("exec %s/plugins/ChatAdditions/ca_gag_reasons.cfg", configsDir) + server_cmd("exec %s/plugins/ChatAdditions/ca_gag_chat_whitelist_cmds.cfg", configsDir) + server_exec() - ParseTimes() + ParseTimes() } static ParseTimes() { - new buffer[128]; get_cvar_string("ca_gag_times", buffer, charsmax(buffer)) + new buffer[128]; get_cvar_string("ca_gag_times", buffer, charsmax(buffer)) - if(strlen(buffer) > 0) { - const MAX_TIMES_COUNT = 10 + if (strlen(buffer) > 0) { + const MAX_TIMES_COUNT = 10 - new times[MAX_TIMES_COUNT][16] + new times[MAX_TIMES_COUNT][16] - new count = explode_string(buffer, ",", times, sizeof(times), charsmax(times[])) + new count = explode_string(buffer, ",", times, sizeof(times), charsmax(times[])) - if(g_gagTimeTemplates_size) { - ArrayClear(g_gagTimeTemplates) - } + if (g_gagTimeTemplates_size) { + ArrayClear(g_gagTimeTemplates) + } - for(new i; i < count; i++) { - trim(times[i]) + for(new i; i < count; i++) { + trim(times[i]) - new time = parseTime(times[i]) - new timeStr[32]; get_time_length(LANG_SERVER, time, timeunit_seconds, timeStr, charsmax(timeStr)) + new time = parseTime(times[i]) + new timeStr[32]; get_time_length(LANG_SERVER, time, timeunit_seconds, timeStr, charsmax(timeStr)) - CA_Log(logLevel_Debug, "ADD: Time template[#%i]: %s",\ - i + 1, timeStr - ) + CA_Log(logLevel_Debug, "ADD: Time template[#%i]: %s",\ + i + 1, timeStr + ) - ArrayPushCell(g_gagTimeTemplates, time) + ArrayPushCell(g_gagTimeTemplates, time) + } } - } - g_gagTimeTemplates_size = ArraySize(g_gagTimeTemplates) + g_gagTimeTemplates_size = ArraySize(g_gagTimeTemplates) } static Get_TimeString_seconds(const id, const seconds) { - new timeStr[32] - get_time_length(id, seconds, timeunit_seconds, timeStr, charsmax(timeStr)) + new timeStr[32] + get_time_length(id, seconds, timeunit_seconds, timeStr, charsmax(timeStr)) - if(timeStr[0] == EOS) { - formatex(timeStr, charsmax(timeStr), "%L", id, "Gag_NotSet") - } + if (timeStr[0] == EOS) { + formatex(timeStr, charsmax(timeStr), "%L", id, "Gag_NotSet") + } - return timeStr + return timeStr } static Get_GagString_reason(const id, const target) { - new buffer[MAX_REASON_LEN] + new buffer[MAX_REASON_LEN] - if(id != LANG_PLAYER) { - copy(buffer, charsmax(buffer), g_adminTempData[id][gd_reason][r_name]) - } else { - copy(buffer, charsmax(buffer), g_currentGags[target][gd_reason][r_name]) - } + if (id != LANG_PLAYER) { + copy(buffer, charsmax(buffer), g_adminTempData[id][gd_reason][r_name]) + } else { + copy(buffer, charsmax(buffer), g_currentGags[target][gd_reason][r_name]) + } - if(buffer[0] == EOS) { - formatex(buffer, charsmax(buffer), "%L", id, "Gag_NotSet") - } + if (buffer[0] == EOS) { + formatex(buffer, charsmax(buffer), "%L", id, "Gag_NotSet") + } - return buffer + return buffer } static Get_PlayerPostfix(const id, const target, const hasImmunity) { - new postfix[32] + new postfix[32] - if(hasImmunity) { - formatex(postfix, charsmax(postfix), " [\\r%L\\d]", id, "Gag_Immunity") - } else if(g_currentGags[target][gd_reason][r_flags]) { - formatex(postfix, charsmax(postfix), " [\\y%L\\w]", id, "Gag_Gagged") - } + if (hasImmunity) { + formatex(postfix, charsmax(postfix), " [\r%L\d]", id, "Gag_Immunity") + } else if (g_currentGags[target][gd_reason][r_flags]) { + formatex(postfix, charsmax(postfix), " [\y%L\w]", id, "Gag_Gagged") + } - return postfix + return postfix } static bool: IsTargetHasImmunity(const id, const target) { - new accessFlagsImmunity = read_flags(ca_gag_immunity_flags) - new accessFlagsHigh = read_flags(ca_gag_access_flags_high) - new accessFlags = read_flags(ca_gag_access_flags) + new accessFlagsImmunity = read_flags(ca_gag_immunity_flags) + new accessFlagsHigh = read_flags(ca_gag_access_flags_high) + new accessFlags = read_flags(ca_gag_access_flags) - new userFlags = get_user_flags(id) - new targetFlags = get_user_flags(target) + new userFlags = get_user_flags(id) + new targetFlags = get_user_flags(target) - // main admin can gag everyone - if(userFlags & accessFlagsHigh) { - return false - } + // main admin can gag everyone + if (userFlags & accessFlagsHigh) { + return false + } - // main admin can't be gagged by admins - if(targetFlags & accessFlagsHigh) { - return true - } + // main admin can't be gagged by admins + if (targetFlags & accessFlagsHigh) { + return true + } - // target has immunity or admin flags - if(targetFlags & (accessFlags|accessFlagsImmunity)) { - return true - } + // target has immunity or admin flags + if (targetFlags & (accessFlags|accessFlagsImmunity)) { + return true + } - return false + return false } static Get_GagFlags_Names(gag_flags_s: flags) { - // TODO: ML this + // TODO: ML this - new buffer[64] - new const GAG_FLAGS_STR[][] = { - "Chat", "Team chat", "Voice" - } + new buffer[64] + new const GAG_FLAGS_STR[][] = { + "Chat", "Team chat", "Voice" + } - if(ca_gag_common_chat_block && (flags & gagFlag_SayTeam)) - flags ^= gagFlag_SayTeam + if (ca_gag_common_chat_block && (flags & gagFlag_SayTeam)) + flags ^= gagFlag_SayTeam - for(new i; i < sizeof(GAG_FLAGS_STR); i++) { - if(flags & gag_flags_s: (1 << i)) { - strcat(buffer, fmt("%s + ", GAG_FLAGS_STR[i]), charsmax(buffer)) + for(new i; i < sizeof(GAG_FLAGS_STR); i++) { + if (flags & gag_flags_s: (1 << i)) { + strcat(buffer, fmt("%s + ", GAG_FLAGS_STR[i]), charsmax(buffer)) + } } - } - if(buffer[0] != EOS) { - buffer[strlen(buffer) - 3] = EOS - } + if (buffer[0] != EOS) { + buffer[strlen(buffer) - 3] = EOS + } - return buffer + return buffer } static bool: Gag_Save(const id, const target, const time, const flags, const expireAt = 0) { - GagData_Copy(g_currentGags[target], g_adminTempData[id]) - GagData_Reset(g_adminTempData[id]) + GagData_Copy(g_currentGags[target], g_adminTempData[id]) + GagData_Reset(g_adminTempData[id]) - new gag[gagData_s] - GagData_GetPersonalData(id, target, gag); { - copy(gag[gd_reason][r_name], charsmax(gag[r_name]), Get_GagString_reason(LANG_PLAYER, target)) - gag[gd_reason][r_time] = time - gag[gd_reason][r_flags] = gag_flags_s: flags + new gag[gagData_s] + GagData_GetPersonalData(id, target, gag); { + copy(gag[gd_reason][r_name], charsmax(gag[r_name]), Get_GagString_reason(LANG_PLAYER, target)) + gag[gd_reason][r_time] = time + gag[gd_reason][r_flags] = gag_flags_s: flags - gag[gd_expireAt] = (expireAt != 0) ? (expireAt) : (time + get_systime()) - } + gag[gd_expireAt] = (expireAt != 0) ? (expireAt) : (time + get_systime()) + } - ExecuteForward(g_fwd_gag_setted, g_ret, - target, - gag[gd_name], - gag[gd_authID], - gag[gd_IP], + ExecuteForward(g_fwd_gag_setted, g_ret, + target, + gag[gd_name], + gag[gd_authID], + gag[gd_IP], - gag[gd_adminName], - gag[gd_adminAuthID], - gag[gd_adminIP], + gag[gd_adminName], + gag[gd_adminAuthID], + gag[gd_adminIP], - gag[gd_reason][r_name], - gag[gd_reason][r_time], - gag[gd_reason][r_flags], + gag[gd_reason][r_name], + gag[gd_reason][r_time], + gag[gd_reason][r_flags], - gag[gd_expireAt] - ) + gag[gd_expireAt] + ) - if(g_ret == CA_SUPERCEDE) { - return false - } + if (g_ret == CA_SUPERCEDE) { + return false + } - CA_Storage_Save( - gag[gd_name], gag[gd_authID], gag[gd_IP], gag[gd_reason][r_name], - gag[gd_adminName], gag[gd_adminAuthID], gag[gd_adminIP], - gag[gd_expireAt], gag[gd_reason][r_flags] - ) + CA_Storage_Save( + gag[gd_name], gag[gd_authID], gag[gd_IP], gag[gd_reason][r_name], + gag[gd_adminName], gag[gd_adminAuthID], gag[gd_adminIP], + gag[gd_expireAt], gag[gd_reason][r_flags] + ) - g_currentGags[target] = gag + g_currentGags[target] = gag - client_cmd(target, "-voicerecord") + client_cmd(target, "-voicerecord") - return true + return true } static bool: Gag_Remove(const id, const target) { - if(g_adminTempData[id][gd_reason][r_flags] != gagFlag_Removed) { - ExecuteForward(g_fwd_gag_removed, g_ret, - target, - g_currentGags[target][gd_reason][r_name], - g_currentGags[target][gd_reason][r_time], - g_currentGags[target][gd_reason][r_flags] - ) + if (g_adminTempData[id][gd_reason][r_flags] != gagFlag_Removed) { + ExecuteForward(g_fwd_gag_removed, g_ret, + target, + g_currentGags[target][gd_reason][r_name], + g_currentGags[target][gd_reason][r_time], + g_currentGags[target][gd_reason][r_flags] + ) - if(g_ret == CA_SUPERCEDE) { - return false - } + if (g_ret == CA_SUPERCEDE) { + return false + } - show_activity_ex(id, fmt("%n", id), "%l", "Gag_AdminUngagPlayer", g_currentGags[target][gd_name]) + show_activity_ex(id, fmt("%n", id), "%l", "Gag_AdminUngagPlayer", g_currentGags[target][gd_name]) - GagData_Reset(g_adminTempData[id]) - GagData_Reset(g_currentGags[target]) + GagData_Reset(g_adminTempData[id]) + GagData_Reset(g_currentGags[target]) - new authID[MAX_AUTHID_LENGTH]; get_user_authid(target, authID, charsmax(authID)) - CA_Storage_Remove(authID) - return true - } else { - client_print_color(id, print_team_red, "%L %L", id, "Gag_prefix", id, "Gag_PlayerAlreadyRemoved", target) - } + new authID[MAX_AUTHID_LENGTH]; get_user_authid(target, authID, charsmax(authID)) + CA_Storage_Remove(authID) + return true + } else { + client_print_color(id, print_team_red, "%L %L", id, "Gag_prefix", id, "Gag_PlayerAlreadyRemoved", target) + } - return false + return false } static Gag_Expired(const id) { - GagData_Reset(g_currentGags[id]) + GagData_Reset(g_currentGags[id]) - client_print_color(0, print_team_default, "%L %L", LANG_PLAYER, "Gag_prefix", LANG_PLAYER, "Gag_PlayerExpiredGag", id) + client_print_color(0, print_team_default, "%L %L", LANG_PLAYER, "Gag_prefix", LANG_PLAYER, "Gag_PlayerExpiredGag", id) } static bool: CmdRouter(const player, const message[]) { - if(!(get_user_flags(player) & (read_flags(ca_gag_access_flags) | read_flags(ca_gag_access_flags_high)))) - return false + if (!(get_user_flags(player) & (read_flags(ca_gag_access_flags) | read_flags(ca_gag_access_flags_high)))) + return false - new cmd[32], token[32] - strtok2(message[1], cmd, charsmax(cmd), token, charsmax(token), .trim = true) + new cmd[32], token[32] + strtok2(message[1], cmd, charsmax(cmd), token, charsmax(token), .trim = true) - if(strncmp(cmd, g_gagCmd, charsmax(g_gagCmd), true) == 0) { - MenuShow_PlayersList(player, token) - return true - } + if (strncmp(cmd, g_gagCmd, charsmax(g_gagCmd), true) == 0) { + MenuShow_PlayersList(player, token) + return true + } - if(strncmp(cmd, g_unGagCmd, charsmax(g_unGagCmd), true) == 0) { - new targetUserID = strtol(token) - if(targetUserID == 0) - return false + if (strncmp(cmd, g_unGagCmd, charsmax(g_unGagCmd), true) == 0) { + new targetUserID = strtol(token) + if (targetUserID == 0) + return false - UnGag_ByUserID(player, targetUserID) - return true - } + UnGag_ByUserID(player, targetUserID) + return true + } - return false + return false } static UnGag_ByUserID(const admin, const targetUserID) { - new target = find_player_ex(FindPlayer_MatchUserId | FindPlayer_ExcludeBots, targetUserID) - if(!is_user_connected(target)) { - client_print_color(admin, print_team_red, "%L %L", admin, "Gag_prefix", admin, "Gag_PlayerNotConnected") - return + new target = find_player_ex(FindPlayer_MatchUserId | FindPlayer_ExcludeBots, targetUserID) + if (!is_user_connected(target)) { + client_print_color(admin, print_team_red, "%L %L", admin, "Gag_prefix", admin, "Gag_PlayerNotConnected") + return + } + + new bool: hasBlock = g_currentGags[target][gd_reason][r_flags] != gagFlag_Removed + if (!hasBlock) { + client_print_color(admin, print_team_red, "%L %L", admin, "Gag_prefix", admin, "Gag_PlayerExpiredGag", target) + return } - new bool: hasBlock = g_currentGags[target][gd_reason][r_flags] != gagFlag_Removed - if(!hasBlock) { - client_print_color(admin, print_team_red, "%L %L", admin, "Gag_prefix", admin, "Gag_PlayerExpiredGag", target) - return - } - - GagData_Copy(g_adminTempData[admin], g_currentGags[target]) - g_adminTempData[admin][gd_target] = target + GagData_Copy(g_adminTempData[admin], g_currentGags[target]) + g_adminTempData[admin][gd_target] = target - Gag_Remove(admin, target) + Gag_Remove(admin, target) } Register_Forwards() { - g_fwd_gag_setted = CreateMultiForward("CA_gag_setted", ET_STOP, - FP_CELL, FP_STRING, FP_STRING, FP_STRING, - FP_STRING, FP_STRING, FP_STRING, - FP_STRING, FP_CELL, FP_CELL, - FP_CELL - ) - - g_fwd_gag_removed = CreateMultiForward("CA_gag_removed", ET_STOP, FP_CELL, FP_STRING, FP_CELL, FP_CELL) + g_fwd_gag_setted = CreateMultiForward("CA_gag_setted", ET_STOP, + FP_CELL, FP_STRING, FP_STRING, FP_STRING, + FP_STRING, FP_STRING, FP_STRING, + FP_STRING, FP_CELL, FP_CELL, + FP_CELL + ) + + g_fwd_gag_removed = CreateMultiForward("CA_gag_removed", ET_STOP, FP_CELL, FP_STRING, FP_CELL, FP_CELL) } public plugin_natives() { - register_native("ca_set_user_gag", "native_ca_set_user_gag") - register_native("ca_get_user_gag", "native_ca_get_user_gag") - register_native("ca_has_user_gag", "native_ca_has_user_gag") - register_native("ca_remove_user_gag", "native_ca_remove_user_gag") + register_native("ca_set_user_gag", "native_ca_set_user_gag") + register_native("ca_get_user_gag", "native_ca_get_user_gag") + register_native("ca_has_user_gag", "native_ca_has_user_gag") + register_native("ca_remove_user_gag", "native_ca_remove_user_gag") } public bool: native_ca_set_user_gag(const plugin_id, const argc) { - enum { arg_index = 1, arg_reason, arg_minutes, arg_flags } + enum { arg_index = 1, arg_reason, arg_minutes, arg_flags } - g_adminTempData[0][gd_target] = get_param(arg_index) + g_adminTempData[0][gd_target] = get_param(arg_index) - get_string(arg_reason, g_adminTempData[0][gd_reason][r_name], charsmax(g_adminTempData[][r_name])) + get_string(arg_reason, g_adminTempData[0][gd_reason][r_name], charsmax(g_adminTempData[][r_name])) - g_adminTempData[0][gd_reason][r_time] = get_param(arg_minutes) * SECONDS_IN_MINUTE - g_adminTempData[0][gd_reason][r_flags] = gag_flags_s: get_param(arg_flags) + g_adminTempData[0][gd_reason][r_time] = get_param(arg_minutes) * SECONDS_IN_MINUTE + g_adminTempData[0][gd_reason][r_flags] = gag_flags_s: get_param(arg_flags) - return Gag_Save(0, - g_adminTempData[0][gd_target], - g_adminTempData[0][gd_reason][r_time], - g_adminTempData[0][gd_reason][r_flags] - ) + return Gag_Save(0, + g_adminTempData[0][gd_target], + g_adminTempData[0][gd_reason][r_time], + g_adminTempData[0][gd_reason][r_flags] + ) } public bool: native_ca_get_user_gag(const plugin_id, const argc) { - enum { arg_index = 1, arg_reason, arg_minutes, arg_flags } + enum { arg_index = 1, arg_reason, arg_minutes, arg_flags } - new target = get_param(arg_index) - new gag_flags_s: flags = g_currentGags[target][gd_reason][r_flags] + new target = get_param(arg_index) + new gag_flags_s: flags = g_currentGags[target][gd_reason][r_flags] - if(!flags) { - return false - } + if (!flags) { + return false + } - set_string(arg_reason, g_currentGags[target][gd_reason][r_name], charsmax(g_adminTempData[][r_name])) - set_param_byref(arg_minutes, g_currentGags[target][gd_reason][r_time] / SECONDS_IN_MINUTE) - set_param_byref(arg_flags, flags) + set_string(arg_reason, g_currentGags[target][gd_reason][r_name], charsmax(g_adminTempData[][r_name])) + set_param_byref(arg_minutes, g_currentGags[target][gd_reason][r_time] / SECONDS_IN_MINUTE) + set_param_byref(arg_flags, flags) - return true + return true } public bool: native_ca_has_user_gag(const plugin_id, const argc) { - enum { arg_index = 1 } + enum { arg_index = 1 } - new target = get_param(arg_index) - new gag_flags_s: flags = g_currentGags[target][gd_reason][r_flags] + new target = get_param(arg_index) + new gag_flags_s: flags = g_currentGags[target][gd_reason][r_flags] - return bool: (flags != gagFlag_Removed) + return bool: (flags != gagFlag_Removed) } public bool: native_ca_remove_user_gag(const plugin_id, const argc) { - enum { arg_target = 1, arg_admin } + enum { arg_target = 1, arg_admin } - new target = get_param(arg_target) - new gag_flags_s: flags = g_currentGags[target][gd_reason][r_flags] + new target = get_param(arg_target) + new gag_flags_s: flags = g_currentGags[target][gd_reason][r_flags] - if(flags == gagFlag_Removed) { - return false - } + if (flags == gagFlag_Removed) { + return false + } - new admin = get_param(arg_admin) - GagData_Copy(g_adminTempData[admin], g_currentGags[target]) - g_adminTempData[admin][gd_target] = target + new admin = get_param(arg_admin) + GagData_Copy(g_adminTempData[admin], g_currentGags[target]) + g_adminTempData[admin][gd_target] = target - return Gag_Remove(admin, target) + return Gag_Remove(admin, target) } diff --git a/cstrike/addons/amxmodx/scripting/CA_Mute.sma b/cstrike/addons/amxmodx/scripting/CA_Mute.sma index e1d6d8b..efc51ae 100644 --- a/cstrike/addons/amxmodx/scripting/CA_Mute.sma +++ b/cstrike/addons/amxmodx/scripting/CA_Mute.sma @@ -4,12 +4,11 @@ #include <ChatAdditions> -#pragma ctrlchar '\' -#pragma tabsize 2 +#pragma tabsize 4 #pragma reqlib sqlite #if !defined AMXMODX_NOAUTOLOAD - #pragma loadlib sqlite + #pragma loadlib sqlite #endif new bool: g_playersMute[MAX_PLAYERS + 1][MAX_PLAYERS + 1] @@ -22,362 +21,362 @@ new Float: ca_mute_use_delay new g_dummy, g_itemInfo[64], g_itemName[128] enum { - ITEM_NOT_ENOUTH_PLAYERS = -2, - ITEM_MUTE_ALL = -1 + ITEM_NOT_ENOUTH_PLAYERS = -2, + ITEM_MUTE_ALL = -1 } const QUERY_LENGTH = 4096 new const g_mute_table[] = "ca_players_mute" new Handle: g_tuple = Empty_Handle -public stock const PluginName[] = "CA: Mute" -public stock const PluginVersion[] = CA_VERSION -public stock const PluginAuthor[] = "Sergey Shorokhov" -public stock const PluginURL[] = "https://github.com/ChatAdditions/" -public stock const PluginDescription[] = "Players can choose who they can hear." +public stock const PluginName[] = "CA: Mute" +public stock const PluginVersion[] = CA_VERSION +public stock const PluginAuthor[] = "Sergey Shorokhov" +public stock const PluginURL[] = "https://github.com/ChatAdditions/" +public stock const PluginDescription[] = "Players can choose who they can hear." public plugin_init() { - register_plugin(PluginName, PluginVersion, PluginAuthor) + register_plugin(PluginName, PluginVersion, PluginAuthor) - register_dictionary("CA_Mute.txt") - register_dictionary("common.txt") + register_dictionary("CA_Mute.txt") + register_dictionary("common.txt") - bind_pcvar_float(create_cvar("ca_mute_use_delay", "3", - .description = "How often players can use menu. (in seconds)", - .has_min = true, .min_val = 0.0, - .has_max = true, .max_val = 120.0 - ), - ca_mute_use_delay - ) + bind_pcvar_float(create_cvar("ca_mute_use_delay", "3", + .description = "How often players can use menu. (in seconds)", + .has_min = true, .min_val = 0.0, + .has_max = true, .max_val = 120.0 + ), + ca_mute_use_delay + ) - new const CMDS_Mute[][] = { "mute" } + new const CMDS_Mute[][] = { "mute" } - for(new i; i < sizeof(CMDS_Mute); i++) { - register_trigger_clcmd(CMDS_Mute[i], "ClCmd_Mute", ADMIN_ALL, .FlagManager = false) - } + for(new i; i < sizeof(CMDS_Mute); i++) { + register_trigger_clcmd(CMDS_Mute[i], "ClCmd_Mute", ADMIN_ALL, .FlagManager = false) + } - AutoExecConfig(true, "CA_Mute", "ChatAdditions") + AutoExecConfig(true, "CA_Mute", "ChatAdditions") - Storage_Init() + Storage_Init() - CA_Log(logLevel_Debug, "[CA]: Mute initialized!") + CA_Log(logLevel_Debug, "[CA]: Mute initialized!") } public ClCmd_Mute(const id) { - if(!is_user_connected(id)) { - return PLUGIN_CONTINUE - } + if (!is_user_connected(id)) { + return PLUGIN_CONTINUE + } - if(get_playersnum_ex(GetPlayers_ExcludeBots | GetPlayers_ExcludeHLTV) < 2) { - client_print_color(id, print_team_default, "%L %L", id, "Mute_prefix", id, "Mute_NotEnoughPlayers") - return PLUGIN_HANDLED - } + if (get_playersnum_ex(GetPlayers_ExcludeBots | GetPlayers_ExcludeHLTV) < 2) { + client_print_color(id, print_team_default, "%L %L", id, "Mute_prefix", id, "Mute_NotEnoughPlayers") + return PLUGIN_HANDLED + } - MenuShow_PlayersList(id) + MenuShow_PlayersList(id) - return PLUGIN_HANDLED + return PLUGIN_HANDLED } static MenuShow_PlayersList(const id) { - if(!is_user_connected(id)) { - return - } + if (!is_user_connected(id)) { + return + } - new menu = menu_create(fmt("%L", id, "Mute_MenuTitle"), "MenuHandler_PlayersList") + new menu = menu_create(fmt("%L", id, "Mute_MenuTitle"), "MenuHandler_PlayersList") - static callback + static callback - if(!callback) { - callback = menu_makecallback("MenuCallback_PlayersList") - } + if (!callback) { + callback = menu_makecallback("MenuCallback_PlayersList") + } - new players[MAX_PLAYERS], count - get_players_ex(players, count, .flags = (GetPlayers_ExcludeBots | GetPlayers_ExcludeHLTV)) + new players[MAX_PLAYERS], count + get_players_ex(players, count, .flags = (GetPlayers_ExcludeBots | GetPlayers_ExcludeHLTV)) - if(count < 2) { - menu_additem(menu, fmt("\\r %L", id, "Mute_NotEnoughPlayers"), fmt("%i", ITEM_NOT_ENOUTH_PLAYERS), .callback = callback) - } else { - menu_additem(menu, fmt("\\y %L %s\n", id, "Mute_MuteAll", g_globalMute[id] ? "\\w[ \\r+\\w ]" : ""), fmt("%i", ITEM_MUTE_ALL)) + if (count < 2) { + menu_additem(menu, fmt("\r %L", id, "Mute_NotEnoughPlayers"), fmt("%i", ITEM_NOT_ENOUTH_PLAYERS), .callback = callback) + } else { + menu_additem(menu, fmt("\y %L %s^n", id, "Mute_MuteAll", g_globalMute[id] ? "\w[ \r+\w ]" : ""), fmt("%i", ITEM_MUTE_ALL)) - new name[128] - for(new i; i < count; i++) { - new target = players[i] + new name[128] + for(new i; i < count; i++) { + new target = players[i] - if(target == id) { - continue - } + if (target == id) { + continue + } - get_user_name(target, name, charsmax(name)) + get_user_name(target, name, charsmax(name)) - if(g_playersMute[id][target] || CA_PlayerHasBlockedPlayer(id, target)) { - strcat(name, " \\d[ \\r+\\d ]", charsmax(name)) - } + if (g_playersMute[id][target] || CA_PlayerHasBlockedPlayer(id, target)) { + strcat(name, " \d[ \r+\d ]", charsmax(name)) + } - if(g_globalMute[target] || g_playersMute[target][id] || CA_PlayerHasBlockedPlayer(target, id)) { - strcat(name, fmt(" \\d(\\y%L\\d)", id, "Mute_PlayerMutedYou"), charsmax(name)) - } + if (g_globalMute[target] || g_playersMute[target][id] || CA_PlayerHasBlockedPlayer(target, id)) { + strcat(name, fmt(" \d(\y%L\d)", id, "Mute_PlayerMutedYou"), charsmax(name)) + } - menu_additem(menu, name, fmt("%i", get_user_userid(target)), .callback = callback) + menu_additem(menu, name, fmt("%i", get_user_userid(target)), .callback = callback) + } } - } - menu_setprop(menu, MPROP_BACKNAME, fmt("%L", id, "BACK")) - menu_setprop(menu, MPROP_NEXTNAME, fmt("%L", id, "MORE")) - menu_setprop(menu, MPROP_EXITNAME, fmt("%L", id, "EXIT")) + menu_setprop(menu, MPROP_BACKNAME, fmt("%L", id, "BACK")) + menu_setprop(menu, MPROP_NEXTNAME, fmt("%L", id, "MORE")) + menu_setprop(menu, MPROP_EXITNAME, fmt("%L", id, "EXIT")) - menu_display(id, menu) + menu_display(id, menu) } public MenuCallback_PlayersList(const id, const menu, const item) { - menu_item_getinfo(menu, item, g_dummy, g_itemInfo, charsmax(g_itemInfo), g_itemName, charsmax(g_itemName), g_dummy) + menu_item_getinfo(menu, item, g_dummy, g_itemInfo, charsmax(g_itemInfo), g_itemName, charsmax(g_itemName), g_dummy) - new userID = strtol(g_itemInfo) + new userID = strtol(g_itemInfo) - if(userID == ITEM_NOT_ENOUTH_PLAYERS) { - return ITEM_DISABLED - } + if (userID == ITEM_NOT_ENOUTH_PLAYERS) { + return ITEM_DISABLED + } - // Disable all players in menu when local user muted all - if(userID != ITEM_MUTE_ALL && g_globalMute[id]) { - return ITEM_DISABLED - } + // Disable all players in menu when local user muted all + if (userID != ITEM_MUTE_ALL && g_globalMute[id]) { + return ITEM_DISABLED + } - new target = find_player_ex((FindPlayer_MatchUserId | FindPlayer_ExcludeBots), userID) + new target = find_player_ex((FindPlayer_MatchUserId | FindPlayer_ExcludeBots), userID) - if(CA_PlayerHasBlockedPlayer(id, target)) { - return ITEM_DISABLED - } + if (CA_PlayerHasBlockedPlayer(id, target)) { + return ITEM_DISABLED + } - return ITEM_ENABLED + return ITEM_ENABLED } public MenuHandler_PlayersList(const id, const menu, const item) { - if(item == MENU_EXIT || item < 0) { - menu_destroy(menu) - return PLUGIN_HANDLED - } + if (item == MENU_EXIT || item < 0) { + menu_destroy(menu) + return PLUGIN_HANDLED + } - menu_item_getinfo(menu, item, g_dummy, g_itemInfo, charsmax(g_itemInfo), g_itemName, charsmax(g_itemName), g_dummy) - menu_destroy(menu) + menu_item_getinfo(menu, item, g_dummy, g_itemInfo, charsmax(g_itemInfo), g_itemName, charsmax(g_itemName), g_dummy) + menu_destroy(menu) - new Float: gametime = get_gametime() + new Float: gametime = get_gametime() - if(g_nextUse[id] > gametime) { - client_print_color(id, print_team_red, "%L %L", id, "Mute_prefix", id, "Mute_UseTooOften") - MenuShow_PlayersList(id) - return PLUGIN_HANDLED - } + if (g_nextUse[id] > gametime) { + client_print_color(id, print_team_red, "%L %L", id, "Mute_prefix", id, "Mute_UseTooOften") + MenuShow_PlayersList(id) + return PLUGIN_HANDLED + } - g_nextUse[id] = gametime + ca_mute_use_delay + g_nextUse[id] = gametime + ca_mute_use_delay - new userID = strtol(g_itemInfo) + new userID = strtol(g_itemInfo) - if(userID == ITEM_MUTE_ALL) { - g_globalMute[id] ^= true - Storage_Update(id, ITEM_MUTE_ALL) + if (userID == ITEM_MUTE_ALL) { + g_globalMute[id] ^= true + Storage_Update(id, ITEM_MUTE_ALL) - client_print_color(0, print_team_default, "%L \3%n\1 %L ", id, "Mute_prefix", - id, LANG_PLAYER, g_globalMute[id] ? "Mute_PlayerNowMutedAll" : "Mute_PlayerNowUnmutedAll" - ) + client_print_color(0, print_team_default, "%L ^3%n^1 %L ", id, "Mute_prefix", + id, LANG_PLAYER, g_globalMute[id] ? "Mute_PlayerNowMutedAll" : "Mute_PlayerNowUnmutedAll" + ) - CA_Log(logLevel_Info, "Mute: \"%N\" %sMuted everyone", id, g_globalMute[id] ? "" : "Un") - MenuShow_PlayersList(id) - return PLUGIN_HANDLED - } + CA_Log(logLevel_Info, "Mute: ^"%N^" %sMuted everyone", id, g_globalMute[id] ? "" : "Un") + MenuShow_PlayersList(id) + return PLUGIN_HANDLED + } - new player = find_player_ex((FindPlayer_MatchUserId | FindPlayer_ExcludeBots), userID) + new player = find_player_ex((FindPlayer_MatchUserId | FindPlayer_ExcludeBots), userID) - if(player == 0) { - client_print_color(id, print_team_red, "%L %L", id, "Mute_prefix", id, "Mute_PlayerNotConnected") - MenuShow_PlayersList(id) - return PLUGIN_HANDLED - } + if (player == 0) { + client_print_color(id, print_team_red, "%L %L", id, "Mute_prefix", id, "Mute_PlayerNotConnected") + MenuShow_PlayersList(id) + return PLUGIN_HANDLED + } - g_playersMute[id][player] ^= true - Storage_Update(id, player) + g_playersMute[id][player] ^= true + Storage_Update(id, player) - client_print_color(id, print_team_default, "%L %L \3%n\1", id, "Mute_prefix", - id, g_playersMute[id][player] ? "Mute_YouMutePlayer" : "Mute_YouUnmutePlayer", player - ) + client_print_color(id, print_team_default, "%L %L ^3%n^1", id, "Mute_prefix", + id, g_playersMute[id][player] ? "Mute_YouMutePlayer" : "Mute_YouUnmutePlayer", player + ) - client_print_color(player, print_team_default, "%L \3%n\1 %L ", id, "Mute_prefix", - id, player, g_playersMute[id][player] ? "Mute_PlayerNowMutedYou" : "Mute_PlayerNowUnmutedYou" - ) + client_print_color(player, print_team_default, "%L ^3%n^1 %L ", id, "Mute_prefix", + id, player, g_playersMute[id][player] ? "Mute_PlayerNowMutedYou" : "Mute_PlayerNowUnmutedYou" + ) - CA_Log(logLevel_Info, "Mute: '%N' %smuted '%N'", id, g_playersMute[id][player] ? "" : "Un", player) - MenuShow_PlayersList(id) - return PLUGIN_HANDLED + CA_Log(logLevel_Info, "Mute: '%N' %smuted '%N'", id, g_playersMute[id][player] ? "" : "Un", player) + MenuShow_PlayersList(id) + return PLUGIN_HANDLED } public client_disconnected(id) { - arrayset(g_playersMute[id], false, sizeof(g_playersMute[])) - g_globalMute[id] = false - g_nextUse[id] = 0.0 + arrayset(g_playersMute[id], false, sizeof(g_playersMute[])) + g_globalMute[id] = false + g_nextUse[id] = 0.0 - for(new i; i < sizeof(g_playersMute[]); i++) { - if (!g_playersMute[i][id]) - continue + for(new i; i < sizeof(g_playersMute[]); i++) { + if (!g_playersMute[i][id]) + continue - g_playersMute[i][id] = false - } + g_playersMute[i][id] = false + } } public CA_Client_Voice(const listener, const sender) { - if(g_globalMute[listener]) { - return CA_SUPERCEDE - } + if (g_globalMute[listener]) { + return CA_SUPERCEDE + } - if(g_globalMute[sender]) { - return CA_SUPERCEDE - } + if (g_globalMute[sender]) { + return CA_SUPERCEDE + } - if(g_playersMute[listener][sender] == true) { - return CA_SUPERCEDE - } + if (g_playersMute[listener][sender] == true) { + return CA_SUPERCEDE + } - return CA_CONTINUE + return CA_CONTINUE } Storage_Init() { - if(!SQL_SetAffinity("sqlite")) { - set_fail_state("Can't user 'SQLite'. Check modules.ini") - } + if (!SQL_SetAffinity("sqlite")) { + set_fail_state("Can't user 'SQLite'. Check modules.ini") + } - g_tuple = SQL_MakeDbTuple("", "", "", g_mute_table) + g_tuple = SQL_MakeDbTuple("", "", "", g_mute_table) - Storage_Create() + Storage_Create() } Storage_Create() { - new query[QUERY_LENGTH / 2] + new query[QUERY_LENGTH / 2] - formatex(query, charsmax(query), "CREATE TABLE IF NOT EXISTS %s", g_mute_table); { - strcat(query, " ( id INTEGER PRIMARY KEY AUTOINCREMENT,", charsmax(query)) - strcat(query, "authid VARCHAR NOT NULL,", charsmax(query)) - strcat(query, "authid_target VARCHAR NOT NULL); ", charsmax(query)) - strcat(query, fmt("CREATE UNIQUE INDEX IF NOT EXISTS authid_target_idx1 ON %s (authid, authid_target)", g_mute_table), charsmax(query)) - } + formatex(query, charsmax(query), "CREATE TABLE IF NOT EXISTS %s", g_mute_table); { + strcat(query, " ( id INTEGER PRIMARY KEY AUTOINCREMENT,", charsmax(query)) + strcat(query, "authid VARCHAR NOT NULL,", charsmax(query)) + strcat(query, "authid_target VARCHAR NOT NULL); ", charsmax(query)) + strcat(query, fmt("CREATE UNIQUE INDEX IF NOT EXISTS authid_target_idx1 ON %s (authid, authid_target)", g_mute_table), charsmax(query)) + } - SQL_ThreadQuery(g_tuple, "handle_StorageCreated", query) + SQL_ThreadQuery(g_tuple, "handle_StorageCreated", query) } public handle_StorageCreated(failstate, Handle: query, error[], errnum, data[], size, Float: queuetime) { - if(IsSQLQueryFailed(failstate, query, error, errnum)) { - return - } + if (IsSQLQueryFailed(failstate, query, error, errnum)) { + return + } - CA_Log(logLevel_Debug, "Table '%s' created! (queryTime: '%.3f' sec)", g_mute_table, queuetime) + CA_Log(logLevel_Debug, "Table '%s' created! (queryTime: '%.3f' sec)", g_mute_table, queuetime) } public client_putinserver(player) { - Storage_Load(player) + Storage_Load(player) } Storage_Update(const player, const target) { - new query[QUERY_LENGTH / 2] + new query[QUERY_LENGTH / 2] + + new authId[MAX_AUTHID_LENGTH] + get_user_authid(player, authId, charsmax(authId)) + + if (target == ITEM_MUTE_ALL) { + if (g_globalMute[player]) { + formatex(query, charsmax(query), "INSERT INTO %s (authid, authid_target)", g_mute_table) + strcat(query, fmt(" VALUES ('%s', '%s') ON CONFLICT DO NOTHING", authId, "GLOBAL"), charsmax(query)) + } else { + formatex(query, charsmax(query), "DELETE FROM %s", g_mute_table) + strcat(query, fmt(" WHERE authid='%s' AND authid_target = '%s'", authId, "GLOBAL"), charsmax(query)) + } + + SQL_ThreadQuery(g_tuple, "handle_Saved", query) + return + } - new authId[MAX_AUTHID_LENGTH] - get_user_authid(player, authId, charsmax(authId)) + new authId_target[MAX_AUTHID_LENGTH] + get_user_authid(target, authId_target, charsmax(authId_target)) - if(target == ITEM_MUTE_ALL) { - if(g_globalMute[player]) { - formatex(query, charsmax(query), "INSERT INTO %s (authid, authid_target)", g_mute_table) - strcat(query, fmt(" VALUES ('%s', '%s') ON CONFLICT DO NOTHING", authId, "GLOBAL"), charsmax(query)) + if (g_playersMute[player][target]) { + formatex(query, charsmax(query), "INSERT INTO %s (authid, authid_target)", g_mute_table) + strcat(query, fmt(" VALUES ('%s', '%s') ON CONFLICT DO NOTHING", authId, authId_target), charsmax(query)) } else { - formatex(query, charsmax(query), "DELETE FROM %s", g_mute_table) - strcat(query, fmt(" WHERE authid='%s' AND authid_target = '%s'", authId, "GLOBAL"), charsmax(query)) + formatex(query, charsmax(query), "DELETE FROM %s", g_mute_table) + strcat(query, fmt(" WHERE authid ='%s' AND authid_target = '%s'", authId, authId_target), charsmax(query)) } SQL_ThreadQuery(g_tuple, "handle_Saved", query) - return - } - - new authId_target[MAX_AUTHID_LENGTH] - get_user_authid(target, authId_target, charsmax(authId_target)) - - if(g_playersMute[player][target]) { - formatex(query, charsmax(query), "INSERT INTO %s (authid, authid_target)", g_mute_table) - strcat(query, fmt(" VALUES ('%s', '%s') ON CONFLICT DO NOTHING", authId, authId_target), charsmax(query)) - } else { - formatex(query, charsmax(query), "DELETE FROM %s", g_mute_table) - strcat(query, fmt(" WHERE authid ='%s' AND authid_target = '%s'", authId, authId_target), charsmax(query)) - } - - SQL_ThreadQuery(g_tuple, "handle_Saved", query) } public handle_Saved(failstate, Handle: query, error[], errnum, data[], size, Float: queuetime) { - if(IsSQLQueryFailed(failstate, query, error, errnum)) { - return - } + if (IsSQLQueryFailed(failstate, query, error, errnum)) { + return + } } Storage_Load(const player) { - new authId[MAX_AUTHID_LENGTH] - get_user_authid(player, authId, charsmax(authId)) + new authId[MAX_AUTHID_LENGTH] + get_user_authid(player, authId, charsmax(authId)) - new query[QUERY_LENGTH / 2] - formatex(query, charsmax(query), "SELECT authid, authid_target FROM %s", g_mute_table) - strcat(query, fmt(" WHERE authid ='%s' OR authid_target = '%s'", authId, authId), charsmax(query)) + new query[QUERY_LENGTH / 2] + formatex(query, charsmax(query), "SELECT authid, authid_target FROM %s", g_mute_table) + strcat(query, fmt(" WHERE authid ='%s' OR authid_target = '%s'", authId, authId), charsmax(query)) - SQL_ThreadQuery(g_tuple, "handle_LoadedMute", query) + SQL_ThreadQuery(g_tuple, "handle_LoadedMute", query) } public handle_LoadedMute(failstate, Handle: query, error[], errnum, data[], size, Float: queuetime) { - if(IsSQLQueryFailed(failstate, query, error, errnum)) { - return - } - - if(!SQL_NumResults(query)) - return - - while(SQL_MoreResults(query)) { - new authId[MAX_AUTHID_LENGTH], authId_target[MAX_AUTHID_LENGTH] - SQL_ReadResult(query, 0, authId, charsmax(authId)) - SQL_ReadResult(query, 1, authId_target, charsmax(authId_target)) - - new player = find_player_ex(FindPlayer_MatchAuthId, authId) - if(player == 0) { - goto next - } - - if(strcmp(authId_target, "GLOBAL") == 0) { - g_globalMute[player] = true - goto next + if (IsSQLQueryFailed(failstate, query, error, errnum)) { + return } - new target = find_player_ex(FindPlayer_MatchAuthId, authId_target) - if (target == 0) { - goto next + if (!SQL_NumResults(query)) + return + + while (SQL_MoreResults(query)) { + new authId[MAX_AUTHID_LENGTH], authId_target[MAX_AUTHID_LENGTH] + SQL_ReadResult(query, 0, authId, charsmax(authId)) + SQL_ReadResult(query, 1, authId_target, charsmax(authId_target)) + + new player = find_player_ex(FindPlayer_MatchAuthId, authId) + if (player == 0) { + goto next + } + + if (strcmp(authId_target, "GLOBAL") == 0) { + g_globalMute[player] = true + goto next + } + + new target = find_player_ex(FindPlayer_MatchAuthId, authId_target) + if (target == 0) { + goto next + } + + g_playersMute[player][target] = true + + next: + SQL_NextRow(query) } - - g_playersMute[player][target] = true - - next: - SQL_NextRow(query) - } } static stock bool: IsSQLQueryFailed(const failstate, const Handle: query, const error[], const errNum) { - switch(failstate) { - case TQUERY_CONNECT_FAILED: { - log_amx("SQL: connection failed [%i] `%s`", errNum, error) - return true - } - case TQUERY_QUERY_FAILED: { - log_amx("SQL: query failed [%i] %s", errNum, error); - - server_print("^n^n ===> Query:") - new buffer[1024]; SQL_GetQueryString(query, buffer, charsmax(buffer)); - for(new i, len = strlen(buffer); i < len; i+=255) { - server_print(fmt("%-255s", buffer[i])); - } - - return true + switch (failstate) { + case TQUERY_CONNECT_FAILED: { + log_amx("SQL: connection failed [%i] `%s`", errNum, error) + return true + } + case TQUERY_QUERY_FAILED: { + log_amx("SQL: query failed [%i] %s", errNum, error) + + server_print("^n^n ===> Query:") + new buffer[1024]; SQL_GetQueryString(query, buffer, charsmax(buffer)) + for(new i, len = strlen(buffer); i < len; i+=255) { + server_print(fmt("%-255s", buffer[i])) + } + + return true + } } - } - return false + return false } diff --git a/cstrike/addons/amxmodx/scripting/CA_Storage_CSBans.sma b/cstrike/addons/amxmodx/scripting/CA_Storage_CSBans.sma index 699b7b8..b32b990 100644 --- a/cstrike/addons/amxmodx/scripting/CA_Storage_CSBans.sma +++ b/cstrike/addons/amxmodx/scripting/CA_Storage_CSBans.sma @@ -8,13 +8,12 @@ #include <CA_StorageAPI_endpoint> #include <CA_GAG_API> -#pragma ctrlchar '\' #pragma dynamic 131072 -#pragma tabsize 2 +#pragma tabsize 4 #pragma reqlib mysql #if !defined AMXMODX_NOAUTOLOAD - #pragma loadlib mysql + #pragma loadlib mysql #endif new const SQL_TBL_GAGS[] = "chatadditions_gags" @@ -25,346 +24,346 @@ new g_query[QUERY_LENGTH] new Handle: g_tuple = Empty_Handle new Queue: g_queueLoad = Invalid_Queue, - Queue: g_queueSave = Invalid_Queue + Queue: g_queueSave = Invalid_Queue new ca_storage_host[64], - ca_storage_user[128], - ca_storage_pass[128], - ca_storage_dbname[128] + ca_storage_user[128], + ca_storage_pass[128], + ca_storage_dbname[128] -public stock const PluginName[] = "ChatAdditions: CSBans storage" -public stock const PluginVersion[] = CA_VERSION -public stock const PluginAuthor[] = "Sergey Shorokhov" -public stock const PluginURL[] = "https://github.com/ChatAdditions/" -public stock const PluginDescription[] = "CSBans (MySQL) storage provider for ChatAdditions" +public stock const PluginName[] = "ChatAdditions: CSBans storage" +public stock const PluginVersion[] = CA_VERSION +public stock const PluginAuthor[] = "Sergey Shorokhov" +public stock const PluginURL[] = "https://github.com/ChatAdditions/" +public stock const PluginDescription[] = "CSBans (MySQL) storage provider for ChatAdditions" public plugin_init() { - register_plugin(PluginName, PluginVersion, PluginAuthor) + register_plugin(PluginName, PluginVersion, PluginAuthor) - if(!SQL_SetAffinity("mysql")) { - set_fail_state("Can't user 'MySQL'. Check modules.ini") - } + if (!SQL_SetAffinity("mysql")) { + set_fail_state("Can't user 'MySQL'. Check modules.ini") + } - Create_CVars() + Create_CVars() - AutoExecConfig(true, "CA_Storage_CSBans", "ChatAdditions") + AutoExecConfig(true, "CA_Storage_CSBans", "ChatAdditions") - g_queueLoad = QueueCreate(MAX_AUTHID_LENGTH) - g_queueSave = QueueCreate(gagData_s) + g_queueLoad = QueueCreate(MAX_AUTHID_LENGTH) + g_queueSave = QueueCreate(gagData_s) - set_task_ex(6.274, "_OnConfigsExecuted") + set_task_ex(6.274, "_OnConfigsExecuted") } public _OnConfigsExecuted() { - g_tuple = SQL_MakeDbTuple(ca_storage_host, ca_storage_user, ca_storage_pass, ca_storage_dbname) + g_tuple = SQL_MakeDbTuple(ca_storage_host, ca_storage_user, ca_storage_pass, ca_storage_dbname) - Storage_Create() + Storage_Create() } public plugin_end() { - if(g_tuple != Empty_Handle) { - SQL_FreeHandle(g_tuple) - } + if (g_tuple != Empty_Handle) { + SQL_FreeHandle(g_tuple) + } - QueueDestroy(g_queueLoad) - QueueDestroy(g_queueSave) + QueueDestroy(g_queueLoad) + QueueDestroy(g_queueSave) } public plugin_natives() { - RegisterNatives() + RegisterNatives() } public plugin_cfg() { - RegisterForwards() + RegisterForwards() } Create_CVars() { - bind_pcvar_string(create_cvar("ca_storage_host", "127.0.0.1", FCVAR_PROTECTED, - .description = "CSBans MySQL database host address" - ), - ca_storage_host, charsmax(ca_storage_host) - ) - - bind_pcvar_string(create_cvar("ca_storage_user", "root", FCVAR_PROTECTED, - .description = "CSBans MySQL database user" - ), - ca_storage_user, charsmax(ca_storage_user) - ) - - bind_pcvar_string(create_cvar("ca_storage_pass", "", FCVAR_PROTECTED, - .description = "CSBans MySQL database host password" - ), - ca_storage_pass, charsmax(ca_storage_pass) - ) - - bind_pcvar_string(create_cvar("ca_storage_dbname", "players_gags", FCVAR_PROTECTED, - .description = "CSBans MySQL database name (not recommended to change)" - ), - ca_storage_dbname, charsmax(ca_storage_dbname) - ) + bind_pcvar_string(create_cvar("ca_storage_host", "127.0.0.1", FCVAR_PROTECTED, + .description = "CSBans MySQL database host address" + ), + ca_storage_host, charsmax(ca_storage_host) + ) + + bind_pcvar_string(create_cvar("ca_storage_user", "root", FCVAR_PROTECTED, + .description = "CSBans MySQL database user" + ), + ca_storage_user, charsmax(ca_storage_user) + ) + + bind_pcvar_string(create_cvar("ca_storage_pass", "", FCVAR_PROTECTED, + .description = "CSBans MySQL database host password" + ), + ca_storage_pass, charsmax(ca_storage_pass) + ) + + bind_pcvar_string(create_cvar("ca_storage_dbname", "players_gags", FCVAR_PROTECTED, + .description = "CSBans MySQL database name (not recommended to change)" + ), + ca_storage_dbname, charsmax(ca_storage_dbname) + ) } Storage_Create() { - formatex(g_query, charsmax(g_query), "CREATE TABLE IF NOT EXISTS %s ", SQL_TBL_GAGS); { - strcat(g_query, "( id INTEGER PRIMARY KEY AUTO_INCREMENT,", charsmax(g_query)) - strcat(g_query, "name VARCHAR(32) NOT NULL,", charsmax(g_query)) - strcat(g_query, "authid VARCHAR(64) NOT NULL,", charsmax(g_query)) - strcat(g_query, "ip VARCHAR(22) NOT NULL,", charsmax(g_query)) - strcat(g_query, "reason VARCHAR(256) NOT NULL,", charsmax(g_query)) - strcat(g_query, "admin_name VARCHAR(32) NOT NULL,", charsmax(g_query)) - strcat(g_query, "admin_authid VARCHAR(64) NOT NULL,", charsmax(g_query)) - strcat(g_query, "admin_ip VARCHAR(22) NOT NULL,", charsmax(g_query)) - strcat(g_query, "created_at DATETIME NOT NULL,", charsmax(g_query)) - strcat(g_query, "expire_at DATETIME NOT NULL,", charsmax(g_query)) - strcat(g_query, "flags INTEGER NOT NULL,", charsmax(g_query)) - strcat(g_query, "UNIQUE INDEX authid_unique_idx (authid)", charsmax(g_query)) - strcat(g_query, ") CHARACTER SET utf8 COLLATE utf8_general_ci;", charsmax(g_query)) - } - - SQL_ThreadQuery(g_tuple, "handle_StorageCreated", g_query) + formatex(g_query, charsmax(g_query), "CREATE TABLE IF NOT EXISTS %s ", SQL_TBL_GAGS); { + strcat(g_query, "( id INTEGER PRIMARY KEY AUTO_INCREMENT,", charsmax(g_query)) + strcat(g_query, "name VARCHAR(32) NOT NULL,", charsmax(g_query)) + strcat(g_query, "authid VARCHAR(64) NOT NULL,", charsmax(g_query)) + strcat(g_query, "ip VARCHAR(22) NOT NULL,", charsmax(g_query)) + strcat(g_query, "reason VARCHAR(256) NOT NULL,", charsmax(g_query)) + strcat(g_query, "admin_name VARCHAR(32) NOT NULL,", charsmax(g_query)) + strcat(g_query, "admin_authid VARCHAR(64) NOT NULL,", charsmax(g_query)) + strcat(g_query, "admin_ip VARCHAR(22) NOT NULL,", charsmax(g_query)) + strcat(g_query, "created_at DATETIME NOT NULL,", charsmax(g_query)) + strcat(g_query, "expire_at DATETIME NOT NULL,", charsmax(g_query)) + strcat(g_query, "flags INTEGER NOT NULL,", charsmax(g_query)) + strcat(g_query, "UNIQUE INDEX authid_unique_idx (authid)", charsmax(g_query)) + strcat(g_query, ") CHARACTER SET utf8 COLLATE utf8_general_ci;", charsmax(g_query)) + } + + SQL_ThreadQuery(g_tuple, "handle_StorageCreated", g_query) } public handle_StorageCreated(failstate, Handle: query, error[], errnum, data[], size, Float: queuetime) { - if(IsSQLQueryFailed(failstate, query, error, errnum)) { - return - } + if (IsSQLQueryFailed(failstate, query, error, errnum)) { + return + } - CA_Log(logLevel_Debug, "Table '%s' created! (queryTime: '%.3f' sec)", SQL_TBL_GAGS, queuetime) + CA_Log(logLevel_Debug, "Table '%s' created! (queryTime: '%.3f' sec)", SQL_TBL_GAGS, queuetime) - g_storageInitialized = true - ExecuteForward(g_fwd_StorageInitialized, g_ret) + g_storageInitialized = true + ExecuteForward(g_fwd_StorageInitialized, g_ret) - // Load prepared data from storage - new queueCounter + // Load prepared data from storage + new queueCounter - for(new i, len = QueueSize(g_queueLoad); i < len; i++) { - new authID[MAX_AUTHID_LENGTH]; QueuePopString(g_queueLoad, authID, charsmax(authID)) - Storage_Load(authID) + for(new i, len = QueueSize(g_queueLoad); i < len; i++) { + new authID[MAX_AUTHID_LENGTH]; QueuePopString(g_queueLoad, authID, charsmax(authID)) + Storage_Load(authID) - ++queueCounter - } + ++queueCounter + } - if(queueCounter) { - CA_Log(logLevel_Warning, "Loaded %i queue gags from DB (slow DB connection issue)", queueCounter) - queueCounter = 0 - } + if (queueCounter) { + CA_Log(logLevel_Warning, "Loaded %i queue gags from DB (slow DB connection issue)", queueCounter) + queueCounter = 0 + } - // Save prepared data to storage - for(new i, len = QueueSize(g_queueSave); i < len; i++) { - new gagData[gagData_s]; QueuePopArray(g_queueSave, gagData, sizeof(gagData)) + // Save prepared data to storage + for(new i, len = QueueSize(g_queueSave); i < len; i++) { + new gagData[gagData_s]; QueuePopArray(g_queueSave, gagData, sizeof(gagData)) - Storage_Save(gagData[gd_name], gagData[gd_authID], gagData[gd_IP], - gagData[gd_reason][r_name], gagData[gd_adminName], gagData[gd_adminAuthID], - gagData[gd_adminIP], gagData[gd_expireAt], gagData[gd_reason][r_flags] - ) + Storage_Save(gagData[gd_name], gagData[gd_authID], gagData[gd_IP], + gagData[gd_reason][r_name], gagData[gd_adminName], gagData[gd_adminAuthID], + gagData[gd_adminIP], gagData[gd_expireAt], gagData[gd_reason][r_flags] + ) - ++queueCounter - } + ++queueCounter + } - if(queueCounter) { - CA_Log(logLevel_Warning, "Saved %i queue gags to DB (slow DB connection issue)", queueCounter) - queueCounter = 0 - } + if (queueCounter) { + CA_Log(logLevel_Warning, "Saved %i queue gags to DB (slow DB connection issue)", queueCounter) + queueCounter = 0 + } } Storage_Save(const name[], const authID[], const IP[], - const reason[], const adminName[], const adminAuthID[], - const adminIP[], const expireAt, const flags) { + const reason[], const adminName[], const adminAuthID[], + const adminIP[], const expireAt, const flags) { + + if (!g_storageInitialized) { + new gagData[gagData_s]; { + copy(gagData[gd_name], charsmax(gagData[gd_name]), name) + copy(gagData[gd_authID], charsmax(gagData[gd_authID]), authID) + copy(gagData[gd_IP], charsmax(gagData[gd_IP]), IP) - if(!g_storageInitialized) { - new gagData[gagData_s]; { - copy(gagData[gd_name], charsmax(gagData[gd_name]), name) - copy(gagData[gd_authID], charsmax(gagData[gd_authID]), authID) - copy(gagData[gd_IP], charsmax(gagData[gd_IP]), IP) + copy(gagData[gd_adminName], charsmax(gagData[gd_adminName]), adminName) + copy(gagData[gd_adminAuthID], charsmax(gagData[gd_adminAuthID]), adminAuthID) + copy(gagData[gd_adminIP], charsmax(gagData[gd_adminIP]), adminIP) - copy(gagData[gd_adminName], charsmax(gagData[gd_adminName]), adminName) - copy(gagData[gd_adminAuthID], charsmax(gagData[gd_adminAuthID]), adminAuthID) - copy(gagData[gd_adminIP], charsmax(gagData[gd_adminIP]), adminIP) + copy(gagData[gd_reason][r_name], charsmax(gagData[r_name]), reason) + gagData[gd_reason][r_flags] = gag_flags_s: flags - copy(gagData[gd_reason][r_name], charsmax(gagData[r_name]), reason) - gagData[gd_reason][r_flags] = gag_flags_s: flags + gagData[gd_expireAt] = expireAt + } + + QueuePushArray(g_queueSave, gagData) + + return + } - gagData[gd_expireAt] = expireAt + new name_safe[MAX_NAME_LENGTH * 2] + SQL_QuoteString(Empty_Handle, name_safe, charsmax(name_safe), name) + + new reason_safe[MAX_REASON_LENGTH * 2] + SQL_QuoteString(Empty_Handle, reason_safe, charsmax(reason_safe), reason) + + new adminName_safe[MAX_NAME_LENGTH * 2] + SQL_QuoteString(Empty_Handle, adminName_safe, charsmax(adminName_safe), adminName) + + // TODO: Optimize this EPIC QUERY + formatex(g_query, charsmax(g_query), "INSERT INTO %s ", SQL_TBL_GAGS); { + strcat(g_query, "( name,authid,ip,", charsmax(g_query)) + strcat(g_query, "reason,admin_name,admin_authid,", charsmax(g_query)) + strcat(g_query, "admin_ip,created_at,expire_at,flags )", charsmax(g_query)) + + strcat(g_query, fmt(" VALUES ( '%s',", name_safe), charsmax(g_query)) + strcat(g_query, fmt("'%s',", authID), charsmax(g_query)) + strcat(g_query, fmt("'%s',", IP), charsmax(g_query)) + strcat(g_query, fmt("'%s',", reason_safe), charsmax(g_query)) + strcat(g_query, fmt("'%s',", adminName_safe), charsmax(g_query)) + strcat(g_query, fmt("'%s',", adminAuthID), charsmax(g_query)) + strcat(g_query, fmt("'%s',", adminIP), charsmax(g_query)) + strcat(g_query, fmt("NOW(),"), charsmax(g_query)) + strcat(g_query, fmt("FROM_UNIXTIME(%i),", expireAt), charsmax(g_query)) + strcat(g_query, fmt("%i ) ", flags), charsmax(g_query)) + strcat(g_query, "ON DUPLICATE KEY UPDATE ", charsmax(g_query)) + strcat(g_query, fmt("name='%s',", name_safe), charsmax(g_query)) + strcat(g_query, fmt("ip='%s',", IP), charsmax(g_query)) + strcat(g_query, fmt("reason='%s',", reason_safe), charsmax(g_query)) + strcat(g_query, fmt("admin_name='%s',", adminName_safe), charsmax(g_query)) + strcat(g_query, fmt("admin_authid='%s',", adminAuthID), charsmax(g_query)) + strcat(g_query, fmt("admin_ip='%s',", adminIP), charsmax(g_query)) + strcat(g_query, "created_at=NOW(),", charsmax(g_query)) + strcat(g_query, fmt("expire_at=FROM_UNIXTIME(%i),", expireAt), charsmax(g_query)) + strcat(g_query, fmt("flags=%i; ", flags), charsmax(g_query)) } - QueuePushArray(g_queueSave, gagData) - - return - } - - new name_safe[MAX_NAME_LENGTH * 2] - SQL_QuoteString(Empty_Handle, name_safe, charsmax(name_safe), name) - - new reason_safe[MAX_REASON_LENGTH * 2] - SQL_QuoteString(Empty_Handle, reason_safe, charsmax(reason_safe), reason) - - new adminName_safe[MAX_NAME_LENGTH * 2] - SQL_QuoteString(Empty_Handle, adminName_safe, charsmax(adminName_safe), adminName) - - // TODO: Optimize this EPIC QUERY - formatex(g_query, charsmax(g_query), "INSERT INTO %s ", SQL_TBL_GAGS); { - strcat(g_query, "( name,authid,ip,", charsmax(g_query)) - strcat(g_query, "reason,admin_name,admin_authid,", charsmax(g_query)) - strcat(g_query, "admin_ip,created_at,expire_at,flags )", charsmax(g_query)) - - strcat(g_query, fmt(" VALUES ( '%s',", name_safe), charsmax(g_query)) - strcat(g_query, fmt("'%s',", authID), charsmax(g_query)) - strcat(g_query, fmt("'%s',", IP), charsmax(g_query)) - strcat(g_query, fmt("'%s',", reason_safe), charsmax(g_query)) - strcat(g_query, fmt("'%s',", adminName_safe), charsmax(g_query)) - strcat(g_query, fmt("'%s',", adminAuthID), charsmax(g_query)) - strcat(g_query, fmt("'%s',", adminIP), charsmax(g_query)) - strcat(g_query, fmt("NOW(),"), charsmax(g_query)) - strcat(g_query, fmt("FROM_UNIXTIME(%i),", expireAt), charsmax(g_query)) - strcat(g_query, fmt("%i ) ", flags), charsmax(g_query)) - strcat(g_query, "ON DUPLICATE KEY UPDATE ", charsmax(g_query)) - strcat(g_query, fmt("name='%s',", name_safe), charsmax(g_query)) - strcat(g_query, fmt("ip='%s',", IP), charsmax(g_query)) - strcat(g_query, fmt("reason='%s',", reason_safe), charsmax(g_query)) - strcat(g_query, fmt("admin_name='%s',", adminName_safe), charsmax(g_query)) - strcat(g_query, fmt("admin_authid='%s',", adminAuthID), charsmax(g_query)) - strcat(g_query, fmt("admin_ip='%s',", adminIP), charsmax(g_query)) - strcat(g_query, "created_at=NOW(),", charsmax(g_query)) - strcat(g_query, fmt("expire_at=FROM_UNIXTIME(%i),", expireAt), charsmax(g_query)) - strcat(g_query, fmt("flags=%i; ", flags), charsmax(g_query)) - } - - SQL_ThreadQuery(g_tuple, "handle_Saved", g_query) + SQL_ThreadQuery(g_tuple, "handle_Saved", g_query) } public handle_Saved(failstate, Handle: query, error[], errnum, data[], size, Float: queuetime) { - if(IsSQLQueryFailed(failstate, query, error, errnum)) { - return - } - - formatex(g_query, charsmax(g_query), "SELECT \ - name,authid,ip,reason,\ - admin_name,admin_authid,admin_ip,\ - UNIX_TIMESTAMP(created_at),UNIX_TIMESTAMP(expire_at),flags") - strcat(g_query, fmt(" FROM %s", SQL_TBL_GAGS), charsmax(g_query)) - strcat(g_query, fmt(" WHERE id=%i;", SQL_GetInsertId(query)), charsmax(g_query)) - - SQL_ThreadQuery(g_tuple, "handle_SavedResult", g_query) + if (IsSQLQueryFailed(failstate, query, error, errnum)) { + return + } + + formatex(g_query, charsmax(g_query), "SELECT \ + name,authid,ip,reason,\ + admin_name,admin_authid,admin_ip,\ + UNIX_TIMESTAMP(created_at),UNIX_TIMESTAMP(expire_at),flags") + strcat(g_query, fmt(" FROM %s", SQL_TBL_GAGS), charsmax(g_query)) + strcat(g_query, fmt(" WHERE id=%i;", SQL_GetInsertId(query)), charsmax(g_query)) + + SQL_ThreadQuery(g_tuple, "handle_SavedResult", g_query) } public handle_SavedResult(failstate, Handle: query, error[], errnum, data[], size, Float: queuetime) { - if(IsSQLQueryFailed(failstate, query, error, errnum)) { - return - } - - enum { res_name, res_authid, res_ip, res_reason, - res_admin_name, res_admin_authid, res_admin_ip, - res_created_at, res_expire_at, res_flags - } - - new name[MAX_NAME_LENGTH]; SQL_ReadResult(query, res_name, name, charsmax(name)) - new authID[MAX_AUTHID_LENGTH]; SQL_ReadResult(query, res_authid, authID, charsmax(authID)) - new IP[MAX_IP_LENGTH]; SQL_ReadResult(query, res_ip, IP, charsmax(IP)) - new reason[MAX_REASON_LENGTH]; SQL_ReadResult(query, res_reason, reason, charsmax(reason)) - - new adminName[MAX_NAME_LENGTH]; SQL_ReadResult(query, res_admin_name, adminName, charsmax(adminName)) - new adminAuthID[MAX_AUTHID_LENGTH]; SQL_ReadResult(query, res_admin_authid, adminAuthID, charsmax(adminAuthID)) - new adminIP[MAX_IP_LENGTH]; SQL_ReadResult(query, res_admin_ip, adminIP, charsmax(adminIP)) - - new createdAt = SQL_ReadResult(query, res_created_at) - new expireAt = SQL_ReadResult(query, res_expire_at) - new flags = SQL_ReadResult(query, res_flags) - - CA_Log(logLevel_Debug, "Player gag saved {'%s', '%s', '%s', '%s', '%s', '%s', '%s', %i, %i, %i} (queryTime: '%.3f' sec)", \ - name, authID, IP, reason, adminName, adminAuthID, adminIP, createdAt, expireAt, flags,\ - queuetime \ - ) - - ExecuteForward(g_fwd_StorageSaved, g_ret, - name, authID, IP, reason, - adminName, adminAuthID, adminIP, - createdAt, expireAt, flags - ) + if (IsSQLQueryFailed(failstate, query, error, errnum)) { + return + } + + enum { res_name, res_authid, res_ip, res_reason, + res_admin_name, res_admin_authid, res_admin_ip, + res_created_at, res_expire_at, res_flags + } + + new name[MAX_NAME_LENGTH]; SQL_ReadResult(query, res_name, name, charsmax(name)) + new authID[MAX_AUTHID_LENGTH]; SQL_ReadResult(query, res_authid, authID, charsmax(authID)) + new IP[MAX_IP_LENGTH]; SQL_ReadResult(query, res_ip, IP, charsmax(IP)) + new reason[MAX_REASON_LENGTH]; SQL_ReadResult(query, res_reason, reason, charsmax(reason)) + + new adminName[MAX_NAME_LENGTH]; SQL_ReadResult(query, res_admin_name, adminName, charsmax(adminName)) + new adminAuthID[MAX_AUTHID_LENGTH]; SQL_ReadResult(query, res_admin_authid, adminAuthID, charsmax(adminAuthID)) + new adminIP[MAX_IP_LENGTH]; SQL_ReadResult(query, res_admin_ip, adminIP, charsmax(adminIP)) + + new createdAt = SQL_ReadResult(query, res_created_at) + new expireAt = SQL_ReadResult(query, res_expire_at) + new flags = SQL_ReadResult(query, res_flags) + + CA_Log(logLevel_Debug, "Player gag saved {'%s', '%s', '%s', '%s', '%s', '%s', '%s', %i, %i, %i} (queryTime: '%.3f' sec)", \ + name, authID, IP, reason, adminName, adminAuthID, adminIP, createdAt, expireAt, flags,\ + queuetime \ + ) + + ExecuteForward(g_fwd_StorageSaved, g_ret, + name, authID, IP, reason, + adminName, adminAuthID, adminIP, + createdAt, expireAt, flags + ) } Storage_Load(const authID[]) { - if(!g_storageInitialized) { - QueuePushString(g_queueLoad, authID) + if (!g_storageInitialized) { + QueuePushString(g_queueLoad, authID) - return - } + return + } - formatex(g_query, charsmax(g_query), "SELECT name, authid, ip, reason,\ - admin_name, admin_authid, admin_ip, \ - UNIX_TIMESTAMP(created_at), UNIX_TIMESTAMP(expire_at), flags FROM %s", SQL_TBL_GAGS); { - strcat(g_query, fmt(" WHERE (authid = '%s')", authID), charsmax(g_query)) - strcat(g_query, " AND ( expire_at = FROM_UNIXTIME(9999999999) OR (expire_at > NOW()) ) LIMIT 1", charsmax(g_query)) - } + formatex(g_query, charsmax(g_query), "SELECT name, authid, ip, reason,\ + admin_name, admin_authid, admin_ip, \ + UNIX_TIMESTAMP(created_at), UNIX_TIMESTAMP(expire_at), flags FROM %s", SQL_TBL_GAGS); { + strcat(g_query, fmt(" WHERE (authid = '%s')", authID), charsmax(g_query)) + strcat(g_query, " AND ( expire_at = FROM_UNIXTIME(9999999999) OR (expire_at > NOW()) ) LIMIT 1", charsmax(g_query)) + } - SQL_ThreadQuery(g_tuple, "handle_Loaded", g_query) + SQL_ThreadQuery(g_tuple, "handle_Loaded", g_query) } public handle_Loaded(failstate, Handle: query, error[], errnum, data[], size, Float: queuetime) { - if(IsSQLQueryFailed(failstate, query, error, errnum)) { - return - } - - enum { res_name, res_authid, res_ip, res_reason, - res_admin_name, res_admin_authid, res_admin_ip, - res_created_at, res_expire_at, res_flags - } - - new bool: found = (SQL_NumResults(query) != 0) - - if(!found) { - return - } - - new name[MAX_NAME_LENGTH]; SQL_ReadResult(query, res_name, name, charsmax(name)) - new authID[MAX_AUTHID_LENGTH]; SQL_ReadResult(query, res_authid, authID, charsmax(authID)) - new IP[MAX_IP_LENGTH]; SQL_ReadResult(query, res_ip, IP, charsmax(IP)) - new reason[MAX_REASON_LENGTH]; SQL_ReadResult(query, res_reason, reason, charsmax(reason)) - - new adminName[MAX_NAME_LENGTH]; SQL_ReadResult(query, res_admin_name, adminName, charsmax(adminName)) - new adminAuthID[MAX_AUTHID_LENGTH]; SQL_ReadResult(query, res_admin_authid, adminAuthID, charsmax(adminAuthID)) - new adminIP[MAX_IP_LENGTH]; SQL_ReadResult(query, res_admin_ip, adminIP, charsmax(adminIP)) - - new createdAt = SQL_ReadResult(query, res_created_at) - new expireAt = SQL_ReadResult(query, res_expire_at) - new flags = SQL_ReadResult(query, res_flags) - - CA_Log(logLevel_Debug, "Player gag loaded {'%s', '%s', '%s', '%s', '%s', '%s', '%s', %i, %i, %i} (queryTime: '%.3f' sec)", \ - name, authID, IP, reason, adminName, adminAuthID, adminIP, createdAt, expireAt, flags,\ - queuetime \ - ) - - ExecuteForward(g_fwd_StorageLoaded, g_ret, - name, authID, IP, reason, - adminName, adminAuthID, adminIP, - createdAt, expireAt, flags - ) + if (IsSQLQueryFailed(failstate, query, error, errnum)) { + return + } + + enum { res_name, res_authid, res_ip, res_reason, + res_admin_name, res_admin_authid, res_admin_ip, + res_created_at, res_expire_at, res_flags + } + + new bool: found = (SQL_NumResults(query) != 0) + + if (!found) { + return + } + + new name[MAX_NAME_LENGTH]; SQL_ReadResult(query, res_name, name, charsmax(name)) + new authID[MAX_AUTHID_LENGTH]; SQL_ReadResult(query, res_authid, authID, charsmax(authID)) + new IP[MAX_IP_LENGTH]; SQL_ReadResult(query, res_ip, IP, charsmax(IP)) + new reason[MAX_REASON_LENGTH]; SQL_ReadResult(query, res_reason, reason, charsmax(reason)) + + new adminName[MAX_NAME_LENGTH]; SQL_ReadResult(query, res_admin_name, adminName, charsmax(adminName)) + new adminAuthID[MAX_AUTHID_LENGTH]; SQL_ReadResult(query, res_admin_authid, adminAuthID, charsmax(adminAuthID)) + new adminIP[MAX_IP_LENGTH]; SQL_ReadResult(query, res_admin_ip, adminIP, charsmax(adminIP)) + + new createdAt = SQL_ReadResult(query, res_created_at) + new expireAt = SQL_ReadResult(query, res_expire_at) + new flags = SQL_ReadResult(query, res_flags) + + CA_Log(logLevel_Debug, "Player gag loaded {'%s', '%s', '%s', '%s', '%s', '%s', '%s', %i, %i, %i} (queryTime: '%.3f' sec)", \ + name, authID, IP, reason, adminName, adminAuthID, adminIP, createdAt, expireAt, flags,\ + queuetime \ + ) + + ExecuteForward(g_fwd_StorageLoaded, g_ret, + name, authID, IP, reason, + adminName, adminAuthID, adminIP, + createdAt, expireAt, flags + ) } Storage_Remove(const authID[]) { - if(!g_storageInitialized || g_tuple == Empty_Handle) { - CA_Log(logLevel_Warning, "Storage_Remove(): Storage connection not initialized. Query not executed. (g_storageInitialized=%i, g_tuple=%i)", - g_storageInitialized, g_tuple - ) + if (!g_storageInitialized || g_tuple == Empty_Handle) { + CA_Log(logLevel_Warning, "Storage_Remove(): Storage connection not initialized. Query not executed. (g_storageInitialized=%i, g_tuple=%i)", + g_storageInitialized, g_tuple + ) - return - } + return + } - formatex(g_query, charsmax(g_query), "DELETE FROM %s ", SQL_TBL_GAGS); { - strcat(g_query, fmt("WHERE (authid = '%s')", authID), charsmax(g_query)) - } + formatex(g_query, charsmax(g_query), "DELETE FROM %s ", SQL_TBL_GAGS); { + strcat(g_query, fmt("WHERE (authid = '%s')", authID), charsmax(g_query)) + } - SQL_ThreadQuery(g_tuple, "handle_Removed", g_query) + SQL_ThreadQuery(g_tuple, "handle_Removed", g_query) } public handle_Removed(failstate, Handle: query, error[], errnum, data[], size, Float: queuetime) { - if(IsSQLQueryFailed(failstate, query, error, errnum)) { - return - } + if (IsSQLQueryFailed(failstate, query, error, errnum)) { + return + } - CA_Log(logLevel_Debug, "Player gag removed { } (queryTime: '%.3f' sec)", \ - queuetime \ - ) + CA_Log(logLevel_Debug, "Player gag removed { } (queryTime: '%.3f' sec)", \ + queuetime \ + ) - ExecuteForward(g_fwd_StorageRemoved, g_ret) + ExecuteForward(g_fwd_StorageRemoved, g_ret) } diff --git a/cstrike/addons/amxmodx/scripting/CA_Storage_GameCMS.sma b/cstrike/addons/amxmodx/scripting/CA_Storage_GameCMS.sma index dab620f..a1b83b3 100644 --- a/cstrike/addons/amxmodx/scripting/CA_Storage_GameCMS.sma +++ b/cstrike/addons/amxmodx/scripting/CA_Storage_GameCMS.sma @@ -8,13 +8,12 @@ #include <CA_StorageAPI_endpoint> #include <CA_GAG_API> -#pragma ctrlchar '\' #pragma dynamic 131072 -#pragma tabsize 2 +#pragma tabsize 4 #pragma reqlib mysql #if !defined AMXMODX_NOAUTOLOAD - #pragma loadlib mysql + #pragma loadlib mysql #endif new const SQL_TBL_GAGS[] = "comms" @@ -25,515 +24,515 @@ new g_query[QUERY_LENGTH] new Handle: g_tuple = Empty_Handle new Queue: g_queueLoad = Invalid_Queue, - Queue: g_queueSave = Invalid_Queue + Queue: g_queueSave = Invalid_Queue new g_serverID = -1 new g_gamecmsAdminId[MAX_PLAYERS + 1] new ca_server_address[128], - ca_storage_host[64], - ca_storage_user[128], - ca_storage_pass[128], - ca_storage_dbname[128] + ca_storage_host[64], + ca_storage_user[128], + ca_storage_pass[128], + ca_storage_dbname[128] -public stock const PluginName[] = "ChatAdditions: GameCMS storage" -public stock const PluginVersion[] = CA_VERSION -public stock const PluginAuthor[] = "Sergey Shorokhov" -public stock const PluginURL[] = "https://github.com/ChatAdditions/" -public stock const PluginDescription[] = "GameCMS (MySQL) storage provider for ChatAdditions" +public stock const PluginName[] = "ChatAdditions: GameCMS storage" +public stock const PluginVersion[] = CA_VERSION +public stock const PluginAuthor[] = "Sergey Shorokhov" +public stock const PluginURL[] = "https://github.com/ChatAdditions/" +public stock const PluginDescription[] = "GameCMS (MySQL) storage provider for ChatAdditions" public plugin_init() { - register_plugin(PluginName, PluginVersion, PluginAuthor) + register_plugin(PluginName, PluginVersion, PluginAuthor) - if(!SQL_SetAffinity("mysql")) { - set_fail_state("Can't user 'MySQL'. Check modules.ini") - } + if (!SQL_SetAffinity("mysql")) { + set_fail_state("Can't user 'MySQL'. Check modules.ini") + } - Create_CVars() + Create_CVars() - AutoExecConfig(true, "CA_Storage_GameCMS", "ChatAdditions") + AutoExecConfig(true, "CA_Storage_GameCMS", "ChatAdditions") - g_queueLoad = QueueCreate(MAX_AUTHID_LENGTH) - g_queueSave = QueueCreate(gagData_s) + g_queueLoad = QueueCreate(MAX_AUTHID_LENGTH) + g_queueSave = QueueCreate(gagData_s) - set_task_ex(6.274, "_OnConfigsExecuted") + set_task_ex(6.274, "_OnConfigsExecuted") } public _OnConfigsExecuted() { - g_tuple = SQL_MakeDbTuple(ca_storage_host, ca_storage_user, ca_storage_pass, ca_storage_dbname) - SQL_SetCharset(g_tuple, "utf8") + g_tuple = SQL_MakeDbTuple(ca_storage_host, ca_storage_user, ca_storage_pass, ca_storage_dbname) + SQL_SetCharset(g_tuple, "utf8") - ServerAddress_Check() - Storage_Create() + ServerAddress_Check() + Storage_Create() } public plugin_end() { - if(g_tuple != Empty_Handle) { - SQL_FreeHandle(g_tuple) - } + if (g_tuple != Empty_Handle) { + SQL_FreeHandle(g_tuple) + } - QueueDestroy(g_queueLoad) - QueueDestroy(g_queueSave) + QueueDestroy(g_queueLoad) + QueueDestroy(g_queueSave) } public plugin_natives() { - RegisterNatives() + RegisterNatives() } public plugin_cfg() { - RegisterForwards() + RegisterForwards() } public client_putinserver(id) { - if(!g_storageInitialized) { - return - } + if (!g_storageInitialized) { + return + } - GameCMS_GetAdminID(id) + GameCMS_GetAdminID(id) } public client_disconnected(id) { - g_gamecmsAdminId[id] = 0 + g_gamecmsAdminId[id] = 0 } Create_CVars() { - bind_pcvar_string(create_cvar("ca_server_address", "", - .description = "Server address in the GameCMS database" - ), - ca_server_address, charsmax(ca_server_address) - ) - - bind_pcvar_string(create_cvar("ca_storage_host", "127.0.0.1", FCVAR_PROTECTED, - .description = "GameCMS MySQL database host address" - ), - ca_storage_host, charsmax(ca_storage_host) - ) - - bind_pcvar_string(create_cvar("ca_storage_user", "root", FCVAR_PROTECTED, - .description = "GameCMS MySQL database user" - ), - ca_storage_user, charsmax(ca_storage_user) - ) - - bind_pcvar_string(create_cvar("ca_storage_pass", "", FCVAR_PROTECTED, - .description = "GameCMS MySQL database host password" - ), - ca_storage_pass, charsmax(ca_storage_pass) - ) - - bind_pcvar_string(create_cvar("ca_storage_dbname", "players_gags", FCVAR_PROTECTED, - .description = "GameCMS MySQL database name (not recommended to change)" - ), - ca_storage_dbname, charsmax(ca_storage_dbname) - ) + bind_pcvar_string(create_cvar("ca_server_address", "", + .description = "Server address in the GameCMS database" + ), + ca_server_address, charsmax(ca_server_address) + ) + + bind_pcvar_string(create_cvar("ca_storage_host", "127.0.0.1", FCVAR_PROTECTED, + .description = "GameCMS MySQL database host address" + ), + ca_storage_host, charsmax(ca_storage_host) + ) + + bind_pcvar_string(create_cvar("ca_storage_user", "root", FCVAR_PROTECTED, + .description = "GameCMS MySQL database user" + ), + ca_storage_user, charsmax(ca_storage_user) + ) + + bind_pcvar_string(create_cvar("ca_storage_pass", "", FCVAR_PROTECTED, + .description = "GameCMS MySQL database host password" + ), + ca_storage_pass, charsmax(ca_storage_pass) + ) + + bind_pcvar_string(create_cvar("ca_storage_dbname", "players_gags", FCVAR_PROTECTED, + .description = "GameCMS MySQL database name (not recommended to change)" + ), + ca_storage_dbname, charsmax(ca_storage_dbname) + ) } ServerAddress_Check() { - if (ca_server_address[0] != EOS) - return + if (ca_server_address[0] != EOS) + return - get_cvar_string("net_address", ca_server_address, charsmax(ca_server_address)) + get_cvar_string("net_address", ca_server_address, charsmax(ca_server_address)) } Storage_Create() { - formatex(g_query, charsmax(g_query), "CREATE TABLE IF NOT EXISTS %s ", SQL_TBL_GAGS); { - strcat(g_query, "( bid int(6) NOT NULL AUTO_INCREMENT,", charsmax(g_query)) - strcat(g_query, "authid varchar(32) COLLATE utf8_unicode_ci NOT NULL,", charsmax(g_query)) - strcat(g_query, "name varchar(32) COLLATE utf8_unicode_ci NOT NULL,", charsmax(g_query)) - strcat(g_query, "created int(11) NOT NULL,", charsmax(g_query)) - strcat(g_query, "expired int(11) NOT NULL,", charsmax(g_query)) - strcat(g_query, "length int(10) NOT NULL,", charsmax(g_query)) - strcat(g_query, "reason varchar(64) COLLATE utf8_unicode_ci NOT NULL,", charsmax(g_query)) - strcat(g_query, "admin_id int(6) NOT NULL,", charsmax(g_query)) - strcat(g_query, "admin_nick varchar(32) COLLATE utf8_unicode_ci NOT NULL,", charsmax(g_query)) - strcat(g_query, "server_id int(6) NOT NULL,", charsmax(g_query)) - strcat(g_query, "modified_by varchar(32) COLLATE utf8_unicode_ci NOT NULL,", charsmax(g_query)) - strcat(g_query, "type int(2) NOT NULL,", charsmax(g_query)) - strcat(g_query, "PRIMARY KEY (bid),", charsmax(g_query)) - strcat(g_query, "KEY sid (server_id),", charsmax(g_query)) - strcat(g_query, "KEY type (type),", charsmax(g_query)) - strcat(g_query, "KEY authid (authid),", charsmax(g_query)) - strcat(g_query, "KEY created (created),", charsmax(g_query)) - strcat(g_query, "KEY aid (admin_id)", charsmax(g_query)) - strcat(g_query, ") ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=37 ;", charsmax(g_query)) - } - - SQL_ThreadQuery(g_tuple, "handle_StorageCreated", g_query) + formatex(g_query, charsmax(g_query), "CREATE TABLE IF NOT EXISTS %s ", SQL_TBL_GAGS); { + strcat(g_query, "( bid int(6) NOT NULL AUTO_INCREMENT,", charsmax(g_query)) + strcat(g_query, "authid varchar(32) COLLATE utf8_unicode_ci NOT NULL,", charsmax(g_query)) + strcat(g_query, "name varchar(32) COLLATE utf8_unicode_ci NOT NULL,", charsmax(g_query)) + strcat(g_query, "created int(11) NOT NULL,", charsmax(g_query)) + strcat(g_query, "expired int(11) NOT NULL,", charsmax(g_query)) + strcat(g_query, "length int(10) NOT NULL,", charsmax(g_query)) + strcat(g_query, "reason varchar(64) COLLATE utf8_unicode_ci NOT NULL,", charsmax(g_query)) + strcat(g_query, "admin_id int(6) NOT NULL,", charsmax(g_query)) + strcat(g_query, "admin_nick varchar(32) COLLATE utf8_unicode_ci NOT NULL,", charsmax(g_query)) + strcat(g_query, "server_id int(6) NOT NULL,", charsmax(g_query)) + strcat(g_query, "modified_by varchar(32) COLLATE utf8_unicode_ci NOT NULL,", charsmax(g_query)) + strcat(g_query, "type int(2) NOT NULL,", charsmax(g_query)) + strcat(g_query, "PRIMARY KEY (bid),", charsmax(g_query)) + strcat(g_query, "KEY sid (server_id),", charsmax(g_query)) + strcat(g_query, "KEY type (type),", charsmax(g_query)) + strcat(g_query, "KEY authid (authid),", charsmax(g_query)) + strcat(g_query, "KEY created (created),", charsmax(g_query)) + strcat(g_query, "KEY aid (admin_id)", charsmax(g_query)) + strcat(g_query, ") ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=37 ;", charsmax(g_query)) + } + + SQL_ThreadQuery(g_tuple, "handle_StorageCreated", g_query) } public handle_StorageCreated(failstate, Handle: query, error[], errnum, data[], size, Float: queuetime) { - if(IsSQLQueryFailed(failstate, query, error, errnum)) { - return - } + if (IsSQLQueryFailed(failstate, query, error, errnum)) { + return + } - CA_Log(logLevel_Debug, "Table '%s' created! (queryTime: '%.3f' sec)", SQL_TBL_GAGS, queuetime) - GameCMS_GetServerID() + CA_Log(logLevel_Debug, "Table '%s' created! (queryTime: '%.3f' sec)", SQL_TBL_GAGS, queuetime) + GameCMS_GetServerID() } Storage_Save(const name[], const authID[], const IP[], - const reason[], const adminName[], const adminAuthID[], - const adminIP[], const expireAt, const flags) { - - if(!g_storageInitialized) { - new gagData[gagData_s]; { - copy(gagData[gd_name], charsmax(gagData[gd_name]), name) - copy(gagData[gd_authID], charsmax(gagData[gd_authID]), authID) - copy(gagData[gd_IP], charsmax(gagData[gd_IP]), IP) - - copy(gagData[gd_adminName], charsmax(gagData[gd_adminName]), adminName) - copy(gagData[gd_adminAuthID], charsmax(gagData[gd_adminAuthID]), adminAuthID) - copy(gagData[gd_adminIP], charsmax(gagData[gd_adminIP]), adminIP) - - copy(gagData[gd_reason][r_name], charsmax(gagData[r_name]), reason) - gagData[gd_reason][r_flags] = gag_flags_s: flags - - gagData[gd_expireAt] = expireAt - } - - QueuePushArray(g_queueSave, gagData) - - return - } - - #pragma unused adminIP, IP - new name_safe[MAX_NAME_LENGTH * 2] - SQL_QuoteString(Empty_Handle, name_safe, charsmax(name_safe), name) - - new reason_safe[MAX_REASON_LENGTH * 2] - SQL_QuoteString(Empty_Handle, reason_safe, charsmax(reason_safe), reason) - - new adminName_safe[MAX_NAME_LENGTH * 2] - SQL_QuoteString(Empty_Handle, adminName_safe, charsmax(adminName_safe), adminName) - - - new admin_id = 0 - new admin = find_player_ex((FindPlayer_MatchUserId | FindPlayer_ExcludeBots), adminAuthID) - if(admin) { - admin_id = g_gamecmsAdminId[admin] - } - - // TODO: Optimize this EPIC QUERY - formatex(g_query, charsmax(g_query), "INSERT INTO %s ", SQL_TBL_GAGS); { - strcat(g_query, "( authid,name,created,", charsmax(g_query)) - strcat(g_query, "expired,length,reason,", charsmax(g_query)) - strcat(g_query, "admin_id,admin_nick,server_id,modified_by,type )", charsmax(g_query)) - - - strcat(g_query, " VALUES ( ", charsmax(g_query)) - strcat(g_query, fmt("'%s',", authID), charsmax(g_query)) - strcat(g_query, fmt("'%s',", name_safe), charsmax(g_query)) - strcat(g_query, fmt("UNIX_TIMESTAMP(NOW()),"), charsmax(g_query)) - strcat(g_query, fmt("%i,", expireAt), charsmax(g_query)) - strcat(g_query, fmt("(%i - UNIX_TIMESTAMP(NOW())) / 60,", expireAt), charsmax(g_query)) - strcat(g_query, fmt("'%s',", reason_safe), charsmax(g_query)) - strcat(g_query, fmt("'%i',", admin_id), charsmax(g_query)) - strcat(g_query, fmt("'%s',", adminName_safe), charsmax(g_query)) - strcat(g_query, fmt("'%i',", g_serverID), charsmax(g_query)) - strcat(g_query, fmt("'%s',", adminName_safe), charsmax(g_query)) - strcat(g_query, fmt("%i ) ", CAGAGFlags_to_GCMS_Flags(gag_flags_s: flags)), charsmax(g_query)) - strcat(g_query, "ON DUPLICATE KEY UPDATE ", charsmax(g_query)) - strcat(g_query, fmt("name='%s',", name_safe), charsmax(g_query)) - strcat(g_query, fmt("reason='%s',", reason_safe), charsmax(g_query)) - strcat(g_query, fmt("admin_nick='%s',", adminName_safe), charsmax(g_query)) - strcat(g_query, "created=UNIX_TIMESTAMP(NOW()),", charsmax(g_query)) - strcat(g_query, fmt("expired=%i,", expireAt), charsmax(g_query)) - strcat(g_query, fmt("type=%i; ", CAGAGFlags_to_GCMS_Flags(gag_flags_s: flags)), charsmax(g_query)) - } - - SQL_ThreadQuery(g_tuple, "handle_Saved", g_query) + const reason[], const adminName[], const adminAuthID[], + const adminIP[], const expireAt, const flags) { + + if (!g_storageInitialized) { + new gagData[gagData_s]; { + copy(gagData[gd_name], charsmax(gagData[gd_name]), name) + copy(gagData[gd_authID], charsmax(gagData[gd_authID]), authID) + copy(gagData[gd_IP], charsmax(gagData[gd_IP]), IP) + + copy(gagData[gd_adminName], charsmax(gagData[gd_adminName]), adminName) + copy(gagData[gd_adminAuthID], charsmax(gagData[gd_adminAuthID]), adminAuthID) + copy(gagData[gd_adminIP], charsmax(gagData[gd_adminIP]), adminIP) + + copy(gagData[gd_reason][r_name], charsmax(gagData[r_name]), reason) + gagData[gd_reason][r_flags] = gag_flags_s: flags + + gagData[gd_expireAt] = expireAt + } + + QueuePushArray(g_queueSave, gagData) + + return + } + + #pragma unused adminIP, IP + new name_safe[MAX_NAME_LENGTH * 2] + SQL_QuoteString(Empty_Handle, name_safe, charsmax(name_safe), name) + + new reason_safe[MAX_REASON_LENGTH * 2] + SQL_QuoteString(Empty_Handle, reason_safe, charsmax(reason_safe), reason) + + new adminName_safe[MAX_NAME_LENGTH * 2] + SQL_QuoteString(Empty_Handle, adminName_safe, charsmax(adminName_safe), adminName) + + + new admin_id = 0 + new admin = find_player_ex((FindPlayer_MatchUserId | FindPlayer_ExcludeBots), adminAuthID) + if (admin) { + admin_id = g_gamecmsAdminId[admin] + } + + // TODO: Optimize this EPIC QUERY + formatex(g_query, charsmax(g_query), "INSERT INTO %s ", SQL_TBL_GAGS); { + strcat(g_query, "( authid,name,created,", charsmax(g_query)) + strcat(g_query, "expired,length,reason,", charsmax(g_query)) + strcat(g_query, "admin_id,admin_nick,server_id,modified_by,type )", charsmax(g_query)) + + + strcat(g_query, " VALUES ( ", charsmax(g_query)) + strcat(g_query, fmt("'%s',", authID), charsmax(g_query)) + strcat(g_query, fmt("'%s',", name_safe), charsmax(g_query)) + strcat(g_query, fmt("UNIX_TIMESTAMP(NOW()),"), charsmax(g_query)) + strcat(g_query, fmt("%i,", expireAt), charsmax(g_query)) + strcat(g_query, fmt("(%i - UNIX_TIMESTAMP(NOW())) / 60,", expireAt), charsmax(g_query)) + strcat(g_query, fmt("'%s',", reason_safe), charsmax(g_query)) + strcat(g_query, fmt("'%i',", admin_id), charsmax(g_query)) + strcat(g_query, fmt("'%s',", adminName_safe), charsmax(g_query)) + strcat(g_query, fmt("'%i',", g_serverID), charsmax(g_query)) + strcat(g_query, fmt("'%s',", adminName_safe), charsmax(g_query)) + strcat(g_query, fmt("%i ) ", CAGAGFlags_to_GCMS_Flags(gag_flags_s: flags)), charsmax(g_query)) + strcat(g_query, "ON DUPLICATE KEY UPDATE ", charsmax(g_query)) + strcat(g_query, fmt("name='%s',", name_safe), charsmax(g_query)) + strcat(g_query, fmt("reason='%s',", reason_safe), charsmax(g_query)) + strcat(g_query, fmt("admin_nick='%s',", adminName_safe), charsmax(g_query)) + strcat(g_query, "created=UNIX_TIMESTAMP(NOW()),", charsmax(g_query)) + strcat(g_query, fmt("expired=%i,", expireAt), charsmax(g_query)) + strcat(g_query, fmt("type=%i; ", CAGAGFlags_to_GCMS_Flags(gag_flags_s: flags)), charsmax(g_query)) + } + + SQL_ThreadQuery(g_tuple, "handle_Saved", g_query) } public handle_Saved(failstate, Handle: query, error[], errnum, data[], size, Float: queuetime) { - if(IsSQLQueryFailed(failstate, query, error, errnum)) { - return - } + if (IsSQLQueryFailed(failstate, query, error, errnum)) { + return + } - formatex(g_query, charsmax(g_query), "SELECT \ - name,authid,reason,\ - admin_nick,\ - created,expired,type") + formatex(g_query, charsmax(g_query), "SELECT \ + name,authid,reason,\ + admin_nick,\ + created,expired,type") - strcat(g_query, fmt(" FROM %s", SQL_TBL_GAGS), charsmax(g_query)) - strcat(g_query, fmt(" WHERE bid=%i;", SQL_GetInsertId(query)), charsmax(g_query)) + strcat(g_query, fmt(" FROM %s", SQL_TBL_GAGS), charsmax(g_query)) + strcat(g_query, fmt(" WHERE bid=%i;", SQL_GetInsertId(query)), charsmax(g_query)) - SQL_ThreadQuery(g_tuple, "handle_SavedResult", g_query) + SQL_ThreadQuery(g_tuple, "handle_SavedResult", g_query) } public handle_SavedResult(failstate, Handle: query, error[], errnum, data[], size, Float: queuetime) { - if(IsSQLQueryFailed(failstate, query, error, errnum)) { - return - } - - enum { res_name, res_authid, /* res_ip, */ res_reason, - res_admin_name, /* res_admin_authid, res_admin_ip, */ - res_created_at, res_expire_at, res_flags - } - - new name[MAX_NAME_LENGTH]; SQL_ReadResult(query, res_name, name, charsmax(name)) - new authID[MAX_AUTHID_LENGTH]; SQL_ReadResult(query, res_authid, authID, charsmax(authID)) - new IP[MAX_IP_LENGTH]; /* SQL_ReadResult(query, res_ip, IP, charsmax(IP)) */ - new reason[MAX_REASON_LENGTH]; SQL_ReadResult(query, res_reason, reason, charsmax(reason)) - - new adminName[MAX_NAME_LENGTH]; SQL_ReadResult(query, res_admin_name, adminName, charsmax(adminName)) - new adminAuthID[MAX_AUTHID_LENGTH]; /* SQL_ReadResult(query, res_admin_authid, adminAuthID, charsmax(adminAuthID)) */ - new adminIP[MAX_IP_LENGTH]; /* SQL_ReadResult(query, res_admin_ip, adminIP, charsmax(adminIP)) */ - - // HACK: for bad DB struct - new target = find_player_ex((FindPlayer_MatchAuthId | FindPlayer_ExcludeBots), authID) - if(target) - get_user_ip(target, IP, charsmax(IP), true) - - new admin = find_player_ex((FindPlayer_MatchName | FindPlayer_ExcludeBots), adminName) - if(admin) { - get_user_authid(admin, adminAuthID, charsmax(adminAuthID)) - get_user_ip(admin, adminIP, charsmax(adminIP), true) - } - - new createdAt = SQL_ReadResult(query, res_created_at) - new expireAt = SQL_ReadResult(query, res_expire_at) - new flags = GCMS_FlagsTo_CAGAGFlags(SQL_ReadResult(query, res_flags)) - - CA_Log(logLevel_Debug, "Player gag saved {'%s', '%s', '%s', '%s', '%s', '%s', '%s', %i, %i, %i} (queryTime: '%.3f' sec)", \ - name, authID, IP, reason, adminName, adminAuthID, adminIP, createdAt, expireAt, flags,\ - queuetime \ - ) - - ExecuteForward(g_fwd_StorageSaved, g_ret, - name, authID, IP, reason, - adminName, adminAuthID, adminIP, - createdAt, expireAt, flags - ) + if (IsSQLQueryFailed(failstate, query, error, errnum)) { + return + } + + enum { res_name, res_authid, /* res_ip, */ res_reason, + res_admin_name, /* res_admin_authid, res_admin_ip, */ + res_created_at, res_expire_at, res_flags + } + + new name[MAX_NAME_LENGTH]; SQL_ReadResult(query, res_name, name, charsmax(name)) + new authID[MAX_AUTHID_LENGTH]; SQL_ReadResult(query, res_authid, authID, charsmax(authID)) + new IP[MAX_IP_LENGTH]; /* SQL_ReadResult(query, res_ip, IP, charsmax(IP)) */ + new reason[MAX_REASON_LENGTH]; SQL_ReadResult(query, res_reason, reason, charsmax(reason)) + + new adminName[MAX_NAME_LENGTH]; SQL_ReadResult(query, res_admin_name, adminName, charsmax(adminName)) + new adminAuthID[MAX_AUTHID_LENGTH]; /* SQL_ReadResult(query, res_admin_authid, adminAuthID, charsmax(adminAuthID)) */ + new adminIP[MAX_IP_LENGTH]; /* SQL_ReadResult(query, res_admin_ip, adminIP, charsmax(adminIP)) */ + + // HACK: for bad DB struct + new target = find_player_ex((FindPlayer_MatchAuthId | FindPlayer_ExcludeBots), authID) + if (target) + get_user_ip(target, IP, charsmax(IP), true) + + new admin = find_player_ex((FindPlayer_MatchName | FindPlayer_ExcludeBots), adminName) + if (admin) { + get_user_authid(admin, adminAuthID, charsmax(adminAuthID)) + get_user_ip(admin, adminIP, charsmax(adminIP), true) + } + + new createdAt = SQL_ReadResult(query, res_created_at) + new expireAt = SQL_ReadResult(query, res_expire_at) + new flags = GCMS_FlagsTo_CAGAGFlags(SQL_ReadResult(query, res_flags)) + + CA_Log(logLevel_Debug, "Player gag saved {'%s', '%s', '%s', '%s', '%s', '%s', '%s', %i, %i, %i} (queryTime: '%.3f' sec)", \ + name, authID, IP, reason, adminName, adminAuthID, adminIP, createdAt, expireAt, flags,\ + queuetime \ + ) + + ExecuteForward(g_fwd_StorageSaved, g_ret, + name, authID, IP, reason, + adminName, adminAuthID, adminIP, + createdAt, expireAt, flags + ) } Storage_Load(const authID[]) { - if(!g_storageInitialized) { - QueuePushString(g_queueLoad, authID) + if (!g_storageInitialized) { + QueuePushString(g_queueLoad, authID) - return - } + return + } - formatex(g_query, charsmax(g_query), "SELECT name, authid, reason,\ - admin_nick, \ - created, expired, type FROM %s", SQL_TBL_GAGS); { - strcat(g_query, fmt(" WHERE (authid = '%s')", authID), charsmax(g_query)) - strcat(g_query, " AND (expired > UNIX_TIMESTAMP(NOW())) LIMIT 1;", charsmax(g_query)) - } + formatex(g_query, charsmax(g_query), "SELECT name, authid, reason,\ + admin_nick, \ + created, expired, type FROM %s", SQL_TBL_GAGS); { + strcat(g_query, fmt(" WHERE (authid = '%s')", authID), charsmax(g_query)) + strcat(g_query, " AND (expired > UNIX_TIMESTAMP(NOW())) LIMIT 1;", charsmax(g_query)) + } - SQL_ThreadQuery(g_tuple, "handle_Loaded", g_query) + SQL_ThreadQuery(g_tuple, "handle_Loaded", g_query) } public handle_Loaded(failstate, Handle: query, error[], errnum, data[], size, Float: queuetime) { - if(IsSQLQueryFailed(failstate, query, error, errnum)) { - return - } - - enum { res_name, res_authid, /* res_ip, */res_reason, - res_admin_name, /* res_admin_authid, res_admin_ip, */ - res_created_at, res_expire_at, res_flags - } - - new bool: found = (SQL_NumResults(query) != 0) - - if(!found) { - return - } - - new name[MAX_NAME_LENGTH]; SQL_ReadResult(query, res_name, name, charsmax(name)) - new authID[MAX_AUTHID_LENGTH]; SQL_ReadResult(query, res_authid, authID, charsmax(authID)) - new IP[MAX_IP_LENGTH]; /* SQL_ReadResult(query, res_ip, IP, charsmax(IP)) */ - new reason[MAX_REASON_LENGTH]; SQL_ReadResult(query, res_reason, reason, charsmax(reason)) - - new adminName[MAX_NAME_LENGTH]; SQL_ReadResult(query, res_admin_name, adminName, charsmax(adminName)) - new adminAuthID[MAX_AUTHID_LENGTH]; /* SQL_ReadResult(query, res_admin_authid, adminAuthID, charsmax(adminAuthID)) */ - new adminIP[MAX_IP_LENGTH]; /* SQL_ReadResult(query, res_admin_ip, adminIP, charsmax(adminIP)) */ - - // HACK: for bad DB struct - new target = find_player_ex((FindPlayer_MatchAuthId | FindPlayer_ExcludeBots), authID) - if(target) - get_user_ip(target, IP, charsmax(IP), true) - - new admin = find_player_ex((FindPlayer_MatchName | FindPlayer_ExcludeBots), adminName) - if(admin) { - get_user_authid(admin, adminAuthID, charsmax(adminAuthID)) - get_user_ip(admin, adminIP, charsmax(adminIP), true) - } - - new createdAt = SQL_ReadResult(query, res_created_at) - new expireAt = SQL_ReadResult(query, res_expire_at) - new flags = GCMS_FlagsTo_CAGAGFlags(SQL_ReadResult(query, res_flags)) - - CA_Log(logLevel_Debug, "Player gag loaded {'%s', '%s', '%s', '%s', '%s', '%s', '%s', %i, %i, %i} (queryTime: '%.3f' sec)", \ - name, authID, IP, reason, adminName, adminAuthID, adminIP, createdAt, expireAt, flags,\ - queuetime \ - ) - - ExecuteForward(g_fwd_StorageLoaded, g_ret, - name, authID, IP, reason, - adminName, adminAuthID, adminIP, - createdAt, expireAt, flags - ) + if (IsSQLQueryFailed(failstate, query, error, errnum)) { + return + } + + enum { res_name, res_authid, /* res_ip, */res_reason, + res_admin_name, /* res_admin_authid, res_admin_ip, */ + res_created_at, res_expire_at, res_flags + } + + new bool: found = (SQL_NumResults(query) != 0) + + if (!found) { + return + } + + new name[MAX_NAME_LENGTH]; SQL_ReadResult(query, res_name, name, charsmax(name)) + new authID[MAX_AUTHID_LENGTH]; SQL_ReadResult(query, res_authid, authID, charsmax(authID)) + new IP[MAX_IP_LENGTH]; /* SQL_ReadResult(query, res_ip, IP, charsmax(IP)) */ + new reason[MAX_REASON_LENGTH]; SQL_ReadResult(query, res_reason, reason, charsmax(reason)) + + new adminName[MAX_NAME_LENGTH]; SQL_ReadResult(query, res_admin_name, adminName, charsmax(adminName)) + new adminAuthID[MAX_AUTHID_LENGTH]; /* SQL_ReadResult(query, res_admin_authid, adminAuthID, charsmax(adminAuthID)) */ + new adminIP[MAX_IP_LENGTH]; /* SQL_ReadResult(query, res_admin_ip, adminIP, charsmax(adminIP)) */ + + // HACK: for bad DB struct + new target = find_player_ex((FindPlayer_MatchAuthId | FindPlayer_ExcludeBots), authID) + if (target) + get_user_ip(target, IP, charsmax(IP), true) + + new admin = find_player_ex((FindPlayer_MatchName | FindPlayer_ExcludeBots), adminName) + if (admin) { + get_user_authid(admin, adminAuthID, charsmax(adminAuthID)) + get_user_ip(admin, adminIP, charsmax(adminIP), true) + } + + new createdAt = SQL_ReadResult(query, res_created_at) + new expireAt = SQL_ReadResult(query, res_expire_at) + new flags = GCMS_FlagsTo_CAGAGFlags(SQL_ReadResult(query, res_flags)) + + CA_Log(logLevel_Debug, "Player gag loaded {'%s', '%s', '%s', '%s', '%s', '%s', '%s', %i, %i, %i} (queryTime: '%.3f' sec)", \ + name, authID, IP, reason, adminName, adminAuthID, adminIP, createdAt, expireAt, flags,\ + queuetime \ + ) + + ExecuteForward(g_fwd_StorageLoaded, g_ret, + name, authID, IP, reason, + adminName, adminAuthID, adminIP, + createdAt, expireAt, flags + ) } Storage_Remove(const authID[]) { - if(!g_storageInitialized || g_tuple == Empty_Handle) { - CA_Log(logLevel_Warning, "Storage_Remove(): Storage connection not initialized. Query not executed. (g_storageInitialized=%i, g_tuple=%i)", - g_storageInitialized, g_tuple - ) + if (!g_storageInitialized || g_tuple == Empty_Handle) { + CA_Log(logLevel_Warning, "Storage_Remove(): Storage connection not initialized. Query not executed. (g_storageInitialized=%i, g_tuple=%i)", + g_storageInitialized, g_tuple + ) - return - } + return + } - formatex(g_query, charsmax(g_query), "DELETE FROM %s ", SQL_TBL_GAGS); { - strcat(g_query, fmt("WHERE (authid = '%s')", authID), charsmax(g_query)) - } + formatex(g_query, charsmax(g_query), "DELETE FROM %s ", SQL_TBL_GAGS); { + strcat(g_query, fmt("WHERE (authid = '%s')", authID), charsmax(g_query)) + } - SQL_ThreadQuery(g_tuple, "handle_Removed", g_query) + SQL_ThreadQuery(g_tuple, "handle_Removed", g_query) } public handle_Removed(failstate, Handle: query, error[], errnum, data[], size, Float: queuetime) { - if(IsSQLQueryFailed(failstate, query, error, errnum)) { - return - } + if (IsSQLQueryFailed(failstate, query, error, errnum)) { + return + } - CA_Log(logLevel_Debug, "Player gag removed { } (queryTime: '%.3f' sec)", \ - queuetime \ - ) + CA_Log(logLevel_Debug, "Player gag removed { } (queryTime: '%.3f' sec)", \ + queuetime \ + ) - ExecuteForward(g_fwd_StorageRemoved, g_ret) + ExecuteForward(g_fwd_StorageRemoved, g_ret) } GameCMS_GetServerID() { - new serverAddress[2][128] - explode_string(ca_server_address, ":", serverAddress, sizeof(serverAddress), charsmax(serverAddress[])) + new serverAddress[2][128] + explode_string(ca_server_address, ":", serverAddress, sizeof(serverAddress), charsmax(serverAddress[])) - formatex(g_query, charsmax(g_query), "SELECT id FROM servers WHERE servers.ip = '%s' AND servers.port = '%s' LIMIT 1;", - serverAddress[0], serverAddress[1] - ) + formatex(g_query, charsmax(g_query), "SELECT id FROM servers WHERE servers.ip = '%s' AND servers.port = '%s' LIMIT 1;", + serverAddress[0], serverAddress[1] + ) - SQL_ThreadQuery(g_tuple, "handle_GetServerID", g_query) + SQL_ThreadQuery(g_tuple, "handle_GetServerID", g_query) } public handle_GetServerID(failstate, Handle: query, error[], errnum, data[], size, Float: queuetime) { - if(IsSQLQueryFailed(failstate, query, error, errnum)) { - return - } + if (IsSQLQueryFailed(failstate, query, error, errnum)) { + return + } - new bool: found = bool: (SQL_NumResults(query) != 0) + new bool: found = bool: (SQL_NumResults(query) != 0) - if(!found) { - set_fail_state("Server `%s` not found on db.", ca_server_address) + if (!found) { + set_fail_state("Server `%s` not found on db.", ca_server_address) - return - } + return + } - g_serverID = SQL_ReadResult(query, 0) - CA_Log(logLevel_Debug, "Found server `%s` in db. ServerID=%i", ca_server_address, g_serverID) + g_serverID = SQL_ReadResult(query, 0) + CA_Log(logLevel_Debug, "Found server `%s` in db. ServerID=%i", ca_server_address, g_serverID) - g_storageInitialized = true - ExecuteForward(g_fwd_StorageInitialized, g_ret) + g_storageInitialized = true + ExecuteForward(g_fwd_StorageInitialized, g_ret) - // Load prepared data from storage - new queueCounter + // Load prepared data from storage + new queueCounter - for(new i, len = QueueSize(g_queueLoad); i < len; i++) { - new authID[MAX_AUTHID_LENGTH]; QueuePopString(g_queueLoad, authID, charsmax(authID)) - Storage_Load(authID) + for(new i, len = QueueSize(g_queueLoad); i < len; i++) { + new authID[MAX_AUTHID_LENGTH]; QueuePopString(g_queueLoad, authID, charsmax(authID)) + Storage_Load(authID) - ++queueCounter - } + ++queueCounter + } - if(queueCounter) { - CA_Log(logLevel_Warning, "Loaded %i queue gags from DB (slow DB connection issue)", queueCounter) - queueCounter = 0 - } + if (queueCounter) { + CA_Log(logLevel_Warning, "Loaded %i queue gags from DB (slow DB connection issue)", queueCounter) + queueCounter = 0 + } - // Save prepared data to storage - for(new i, len = QueueSize(g_queueSave); i < len; i++) { - new gagData[gagData_s]; QueuePopArray(g_queueSave, gagData, sizeof(gagData)) + // Save prepared data to storage + for(new i, len = QueueSize(g_queueSave); i < len; i++) { + new gagData[gagData_s]; QueuePopArray(g_queueSave, gagData, sizeof(gagData)) - Storage_Save(gagData[gd_name], gagData[gd_authID], gagData[gd_IP], - gagData[gd_reason][r_name], gagData[gd_adminName], gagData[gd_adminAuthID], - gagData[gd_adminIP], gagData[gd_expireAt], gagData[gd_reason][r_flags] - ) + Storage_Save(gagData[gd_name], gagData[gd_authID], gagData[gd_IP], + gagData[gd_reason][r_name], gagData[gd_adminName], gagData[gd_adminAuthID], + gagData[gd_adminIP], gagData[gd_expireAt], gagData[gd_reason][r_flags] + ) - ++queueCounter - } + ++queueCounter + } - if(queueCounter) { - CA_Log(logLevel_Warning, "Saved %i queue gags to DB (slow DB connection issue)", queueCounter) - queueCounter = 0 - } + if (queueCounter) { + CA_Log(logLevel_Warning, "Saved %i queue gags to DB (slow DB connection issue)", queueCounter) + queueCounter = 0 + } - new players[MAX_PLAYERS], count - get_players_ex(players, count, .flags = (GetPlayers_ExcludeBots | GetPlayers_ExcludeHLTV)) + new players[MAX_PLAYERS], count + get_players_ex(players, count, .flags = (GetPlayers_ExcludeBots | GetPlayers_ExcludeHLTV)) - for(new i; i < count; i++) { - GameCMS_GetAdminID(players[i]) - } + for(new i; i < count; i++) { + GameCMS_GetAdminID(players[i]) + } } enum { - GCMS_FLAG_NONE = -1, - GCMS_FLAG_ALL, - GCMS_FLAG_CHAT, - GCMS_FLAG_VOICE + GCMS_FLAG_NONE = -1, + GCMS_FLAG_ALL, + GCMS_FLAG_CHAT, + GCMS_FLAG_VOICE } static stock gag_flags_s: GCMS_FlagsTo_CAGAGFlags(const flag) { - switch(flag) { - case GCMS_FLAG_NONE: return (gagFlag_Removed) - case GCMS_FLAG_ALL: return (gagFlag_Say | gagFlag_SayTeam | gagFlag_Voice) - case GCMS_FLAG_CHAT: return (gagFlag_Say | gagFlag_SayTeam) - case GCMS_FLAG_VOICE: return (gagFlag_Voice) - } - - CA_Log(logLevel_Warning, "[WARN]: GCMS_FlagsTo_CAGAGFlags() => Undefinded flag:%i", flag) - return gagFlag_Removed + switch (flag) { + case GCMS_FLAG_NONE: return (gagFlag_Removed) + case GCMS_FLAG_ALL: return (gagFlag_Say | gagFlag_SayTeam | gagFlag_Voice) + case GCMS_FLAG_CHAT: return (gagFlag_Say | gagFlag_SayTeam) + case GCMS_FLAG_VOICE: return (gagFlag_Voice) + } + + CA_Log(logLevel_Warning, "[WARN]: GCMS_FlagsTo_CAGAGFlags() => Undefinded flag:%i", flag) + return gagFlag_Removed } static stock CAGAGFlags_to_GCMS_Flags(const gag_flags_s: flags) { - if(flags == gagFlag_Voice) { - return GCMS_FLAG_VOICE - } - if(flags == (gagFlag_Say | gagFlag_SayTeam | gagFlag_Voice)) { - return GCMS_FLAG_ALL - } - if(flags & (gagFlag_Say | gagFlag_SayTeam)) { - return GCMS_FLAG_CHAT - } - - return GCMS_FLAG_NONE + if (flags == gagFlag_Voice) { + return GCMS_FLAG_VOICE + } + if (flags == (gagFlag_Say | gagFlag_SayTeam | gagFlag_Voice)) { + return GCMS_FLAG_ALL + } + if (flags & (gagFlag_Say | gagFlag_SayTeam)) { + return GCMS_FLAG_CHAT + } + + return GCMS_FLAG_NONE } GameCMS_GetAdminID(const id) { - new authID[MAX_AUTHID_LENGTH], name[MAX_NAME_LENGTH] - get_user_authid(id, authID, charsmax(authID)) - get_user_name(id, name, charsmax(name)) + new authID[MAX_AUTHID_LENGTH], name[MAX_NAME_LENGTH] + get_user_authid(id, authID, charsmax(authID)) + get_user_name(id, name, charsmax(name)) - new name_safe[MAX_NAME_LENGTH * 2] - SQL_QuoteString(Empty_Handle, name_safe, charsmax(name_safe), name) + new name_safe[MAX_NAME_LENGTH * 2] + SQL_QuoteString(Empty_Handle, name_safe, charsmax(name_safe), name) - formatex(g_query, charsmax(g_query), "SELECT id FROM admins WHERE (name = '%s' or name = \"%s\") LIMIT 1;", - authID, name_safe - ) + formatex(g_query, charsmax(g_query), "SELECT id FROM admins WHERE (name = '%s' or name = ^"%s^") LIMIT 1;", + authID, name_safe + ) - new data[1]; data[0] = id - SQL_ThreadQuery(g_tuple, "handle_GetAdminID", g_query, data, sizeof(data)) + new data[1]; data[0] = id + SQL_ThreadQuery(g_tuple, "handle_GetAdminID", g_query, data, sizeof(data)) } public handle_GetAdminID(failstate, Handle: query, error[], errnum, data[], size, Float: queuetime) { - enum { col_id } + enum { col_id } - if(IsSQLQueryFailed(failstate, query, error, errnum)) { - return - } + if (IsSQLQueryFailed(failstate, query, error, errnum)) { + return + } - new bool: found = bool: (SQL_NumResults(query) != 0) - if(!found) { - return - } + new bool: found = bool: (SQL_NumResults(query) != 0) + if (!found) { + return + } - g_gamecmsAdminId[data[0]] = SQL_ReadResult(query, col_id) - CA_Log(logLevel_Debug, "Found admin `%N` in gameCMS DB. admins.id=%i", data[0], g_gamecmsAdminId[data[0]]) + g_gamecmsAdminId[data[0]] = SQL_ReadResult(query, col_id) + CA_Log(logLevel_Debug, "Found admin `%N` in gameCMS DB. admins.id=%i", data[0], g_gamecmsAdminId[data[0]]) } diff --git a/cstrike/addons/amxmodx/scripting/CA_Storage_PGBans.sma b/cstrike/addons/amxmodx/scripting/CA_Storage_PGBans.sma index ddcea8a..f5a2005 100644 --- a/cstrike/addons/amxmodx/scripting/CA_Storage_PGBans.sma +++ b/cstrike/addons/amxmodx/scripting/CA_Storage_PGBans.sma @@ -8,13 +8,12 @@ #include <CA_StorageAPI_endpoint> #include <CA_GAG_API> -#pragma ctrlchar '\' #pragma dynamic 131072 -#pragma tabsize 2 +#pragma tabsize 4 #pragma reqlib mysql #if !defined AMXMODX_NOAUTOLOAD - #pragma loadlib mysql + #pragma loadlib mysql #endif new const SQL_TBL_GAGS[] = "pgb_comms" @@ -25,346 +24,346 @@ new g_query[QUERY_LENGTH] new Handle: g_tuple = Empty_Handle new Queue: g_queueLoad = Invalid_Queue, - Queue: g_queueSave = Invalid_Queue + Queue: g_queueSave = Invalid_Queue new pgb_storage_host[33], - pgb_storage_user[33], - pgb_storage_pass[64], - pgb_storage_dbname[33] + pgb_storage_user[33], + pgb_storage_pass[64], + pgb_storage_dbname[33] -public stock const PluginName[] = "ChatAdditions: PGBans storage" -public stock const PluginVersion[] = CA_VERSION -public stock const PluginAuthor[] = "Sergey Shorokhov" -public stock const PluginURL[] = "https://github.com/ChatAdditions/" -public stock const PluginDesc[] = "PGBans (MySQL) storage provider for ChatAdditions" +public stock const PluginName[] = "ChatAdditions: PGBans storage" +public stock const PluginVersion[] = CA_VERSION +public stock const PluginAuthor[] = "Sergey Shorokhov" +public stock const PluginURL[] = "https://github.com/ChatAdditions/" +public stock const PluginDescription[] = "PGBans (MySQL) storage provider for ChatAdditions" public plugin_init() { - register_plugin(PluginName, PluginVersion, PluginAuthor) + register_plugin(PluginName, PluginVersion, PluginAuthor) - if(!SQL_SetAffinity("mysql")) { - set_fail_state("Can't user 'MySQL'. Check modules.ini") - } + if (!SQL_SetAffinity("mysql")) { + set_fail_state("Can't user 'MySQL'. Check modules.ini") + } - Create_CVars() + Create_CVars() - AutoExecConfig(true, "CA_Storage_PGBans", "ChatAdditions") + AutoExecConfig(true, "CA_Storage_PGBans", "ChatAdditions") - g_queueLoad = QueueCreate(MAX_AUTHID_LENGTH) - g_queueSave = QueueCreate(gagData_s) + g_queueLoad = QueueCreate(MAX_AUTHID_LENGTH) + g_queueSave = QueueCreate(gagData_s) - set_task_ex(6.274, "_OnConfigsExecuted") + set_task_ex(6.274, "_OnConfigsExecuted") } public _OnConfigsExecuted() { - g_tuple = SQL_MakeDbTuple(pgb_storage_host, pgb_storage_user, pgb_storage_pass, pgb_storage_dbname) + g_tuple = SQL_MakeDbTuple(pgb_storage_host, pgb_storage_user, pgb_storage_pass, pgb_storage_dbname) - Storage_Create() + Storage_Create() } public plugin_end() { - if(g_tuple != Empty_Handle) { - SQL_FreeHandle(g_tuple) - } + if (g_tuple != Empty_Handle) { + SQL_FreeHandle(g_tuple) + } - QueueDestroy(g_queueLoad) - QueueDestroy(g_queueSave) + QueueDestroy(g_queueLoad) + QueueDestroy(g_queueSave) } public plugin_natives() { - RegisterNatives() + RegisterNatives() } public plugin_cfg() { - RegisterForwards() + RegisterForwards() } Create_CVars() { - bind_pcvar_string(create_cvar("pgb_storage_host", "127.0.0.1", FCVAR_PROTECTED, - .description = "PGBans MySQL database host address" - ), - pgb_storage_host, charsmax(pgb_storage_host) - ) - - bind_pcvar_string(create_cvar("pgb_storage_user", "root", FCVAR_PROTECTED, - .description = "PGBans MySQL database user" - ), - pgb_storage_user, charsmax(pgb_storage_user) - ) - - bind_pcvar_string(create_cvar("pgb_storage_pass", "pass", FCVAR_PROTECTED, - .description = "PGBans MySQL database host password" - ), - pgb_storage_pass, charsmax(pgb_storage_pass) - ) - - bind_pcvar_string(create_cvar("pgb_storage_dbname", "db", FCVAR_PROTECTED, - .description = "PGBans MySQL database name" - ), - pgb_storage_dbname, charsmax(pgb_storage_dbname) - ) + bind_pcvar_string(create_cvar("pgb_storage_host", "127.0.0.1", FCVAR_PROTECTED, + .description = "PGBans MySQL database host address" + ), + pgb_storage_host, charsmax(pgb_storage_host) + ) + + bind_pcvar_string(create_cvar("pgb_storage_user", "root", FCVAR_PROTECTED, + .description = "PGBans MySQL database user" + ), + pgb_storage_user, charsmax(pgb_storage_user) + ) + + bind_pcvar_string(create_cvar("pgb_storage_pass", "pass", FCVAR_PROTECTED, + .description = "PGBans MySQL database host password" + ), + pgb_storage_pass, charsmax(pgb_storage_pass) + ) + + bind_pcvar_string(create_cvar("pgb_storage_dbname", "db", FCVAR_PROTECTED, + .description = "PGBans MySQL database name" + ), + pgb_storage_dbname, charsmax(pgb_storage_dbname) + ) } Storage_Create() { - formatex(g_query, charsmax(g_query), "CREATE TABLE IF NOT EXISTS %s ", SQL_TBL_GAGS); { - strcat(g_query, "( id INTEGER PRIMARY KEY AUTO_INCREMENT,", charsmax(g_query)) - strcat(g_query, "name VARCHAR(32) NOT NULL,", charsmax(g_query)) - strcat(g_query, "authid VARCHAR(64) NOT NULL,", charsmax(g_query)) - strcat(g_query, "ip VARCHAR(22) NOT NULL,", charsmax(g_query)) - strcat(g_query, "reason VARCHAR(256) NOT NULL,", charsmax(g_query)) - strcat(g_query, "admin_name VARCHAR(32) NOT NULL,", charsmax(g_query)) - strcat(g_query, "admin_authid VARCHAR(64) NOT NULL,", charsmax(g_query)) - strcat(g_query, "admin_ip VARCHAR(22) NOT NULL,", charsmax(g_query)) - strcat(g_query, "created_at DATETIME NOT NULL,", charsmax(g_query)) - strcat(g_query, "expire_at DATETIME NOT NULL,", charsmax(g_query)) - strcat(g_query, "flags INTEGER NOT NULL,", charsmax(g_query)) - strcat(g_query, "UNIQUE INDEX authid_unique_idx (authid)", charsmax(g_query)) - strcat(g_query, ") CHARACTER SET utf8 COLLATE utf8_general_ci;", charsmax(g_query)) - } - - SQL_ThreadQuery(g_tuple, "handle_StorageCreated", g_query) + formatex(g_query, charsmax(g_query), "CREATE TABLE IF NOT EXISTS %s ", SQL_TBL_GAGS); { + strcat(g_query, "( id INTEGER PRIMARY KEY AUTO_INCREMENT,", charsmax(g_query)) + strcat(g_query, "name VARCHAR(32) NOT NULL,", charsmax(g_query)) + strcat(g_query, "authid VARCHAR(64) NOT NULL,", charsmax(g_query)) + strcat(g_query, "ip VARCHAR(22) NOT NULL,", charsmax(g_query)) + strcat(g_query, "reason VARCHAR(256) NOT NULL,", charsmax(g_query)) + strcat(g_query, "admin_name VARCHAR(32) NOT NULL,", charsmax(g_query)) + strcat(g_query, "admin_authid VARCHAR(64) NOT NULL,", charsmax(g_query)) + strcat(g_query, "admin_ip VARCHAR(22) NOT NULL,", charsmax(g_query)) + strcat(g_query, "created_at DATETIME NOT NULL,", charsmax(g_query)) + strcat(g_query, "expire_at DATETIME NOT NULL,", charsmax(g_query)) + strcat(g_query, "flags INTEGER NOT NULL,", charsmax(g_query)) + strcat(g_query, "UNIQUE INDEX authid_unique_idx (authid)", charsmax(g_query)) + strcat(g_query, ") CHARACTER SET utf8 COLLATE utf8_general_ci;", charsmax(g_query)) + } + + SQL_ThreadQuery(g_tuple, "handle_StorageCreated", g_query) } public handle_StorageCreated(failstate, Handle: query, error[], errnum, data[], size, Float:queuetime) { - if(IsSQLQueryFailed(failstate, query, error, errnum)) { - return - } + if (IsSQLQueryFailed(failstate, query, error, errnum)) { + return + } - CA_Log(logLevel_Debug, "Table '%s' created! (queryTime: '%.3f' sec)", SQL_TBL_GAGS, queuetime) + CA_Log(logLevel_Debug, "Table '%s' created! (queryTime: '%.3f' sec)", SQL_TBL_GAGS, queuetime) - g_storageInitialized = true - ExecuteForward(g_fwd_StorageInitialized, g_ret) + g_storageInitialized = true + ExecuteForward(g_fwd_StorageInitialized, g_ret) - // Load prepared data from storage - new queueCounter + // Load prepared data from storage + new queueCounter - for(new i, len = QueueSize(g_queueLoad); i < len; i++) { - new authID[MAX_AUTHID_LENGTH]; QueuePopString(g_queueLoad, authID, charsmax(authID)) - Storage_Load(authID) + for(new i, len = QueueSize(g_queueLoad); i < len; i++) { + new authID[MAX_AUTHID_LENGTH]; QueuePopString(g_queueLoad, authID, charsmax(authID)) + Storage_Load(authID) - ++queueCounter - } + ++queueCounter + } - if(queueCounter) { - CA_Log(logLevel_Info, "Loaded %i queue gags from DB (slow DB connection issue)", queueCounter) - queueCounter = 0 - } + if (queueCounter) { + CA_Log(logLevel_Info, "Loaded %i queue gags from DB (slow DB connection issue)", queueCounter) + queueCounter = 0 + } - // Save prepared data to storage - for(new i, len = QueueSize(g_queueSave); i < len; i++) { - new gagData[gagData_s]; QueuePopArray(g_queueSave, gagData, sizeof(gagData)) + // Save prepared data to storage + for(new i, len = QueueSize(g_queueSave); i < len; i++) { + new gagData[gagData_s]; QueuePopArray(g_queueSave, gagData, sizeof(gagData)) - Storage_Save(gagData[gd_name], gagData[gd_authID], gagData[gd_IP], - gagData[gd_reason][r_name], gagData[gd_adminName], gagData[gd_adminAuthID], - gagData[gd_adminIP], gagData[gd_expireAt], gagData[gd_reason][r_flags] - ) + Storage_Save(gagData[gd_name], gagData[gd_authID], gagData[gd_IP], + gagData[gd_reason][r_name], gagData[gd_adminName], gagData[gd_adminAuthID], + gagData[gd_adminIP], gagData[gd_expireAt], gagData[gd_reason][r_flags] + ) - ++queueCounter - } + ++queueCounter + } - if(queueCounter) { - CA_Log(logLevel_Info, "Saved %i queue gags to DB (slow DB connection issue)", queueCounter) - queueCounter = 0 - } + if (queueCounter) { + CA_Log(logLevel_Info, "Saved %i queue gags to DB (slow DB connection issue)", queueCounter) + queueCounter = 0 + } } Storage_Save(const name[], const authID[], const IP[], - const reason[], const adminName[], const adminAuthID[], - const adminIP[], const expireAt, const flags) { + const reason[], const adminName[], const adminAuthID[], + const adminIP[], const expireAt, const flags) { + + if (!g_storageInitialized) { + new gagData[gagData_s]; { + copy(gagData[gd_name], charsmax(gagData[gd_name]), name) + copy(gagData[gd_authID], charsmax(gagData[gd_authID]), authID) + copy(gagData[gd_IP], charsmax(gagData[gd_IP]), IP) - if(!g_storageInitialized) { - new gagData[gagData_s]; { - copy(gagData[gd_name], charsmax(gagData[gd_name]), name) - copy(gagData[gd_authID], charsmax(gagData[gd_authID]), authID) - copy(gagData[gd_IP], charsmax(gagData[gd_IP]), IP) + copy(gagData[gd_adminName], charsmax(gagData[gd_adminName]), adminName) + copy(gagData[gd_adminAuthID], charsmax(gagData[gd_adminAuthID]), adminAuthID) + copy(gagData[gd_adminIP], charsmax(gagData[gd_adminIP]), adminIP) - copy(gagData[gd_adminName], charsmax(gagData[gd_adminName]), adminName) - copy(gagData[gd_adminAuthID], charsmax(gagData[gd_adminAuthID]), adminAuthID) - copy(gagData[gd_adminIP], charsmax(gagData[gd_adminIP]), adminIP) + copy(gagData[gd_reason][r_name], charsmax(gagData[r_name]), reason) + gagData[gd_reason][r_flags] = gag_flags_s: flags - copy(gagData[gd_reason][r_name], charsmax(gagData[r_name]), reason) - gagData[gd_reason][r_flags] = gag_flags_s: flags + gagData[gd_expireAt] = expireAt + } + + QueuePushArray(g_queueSave, gagData) + + return + } - gagData[gd_expireAt] = expireAt + new name_safe[MAX_NAME_LENGTH * 2] + SQL_QuoteString(Empty_Handle, name_safe, charsmax(name_safe), name) + + new reason_safe[MAX_REASON_LENGTH * 2] + SQL_QuoteString(Empty_Handle, reason_safe, charsmax(reason_safe), reason) + + new adminName_safe[MAX_NAME_LENGTH * 2] + SQL_QuoteString(Empty_Handle, adminName_safe, charsmax(adminName_safe), adminName) + + // TODO: Optimize this EPIC QUERY + formatex(g_query, charsmax(g_query), "INSERT INTO %s ", SQL_TBL_GAGS); { + strcat(g_query, "( name,authid,ip,", charsmax(g_query)) + strcat(g_query, "reason,admin_name,admin_authid,", charsmax(g_query)) + strcat(g_query, "admin_ip,created_at,expire_at,flags )", charsmax(g_query)) + + strcat(g_query, fmt(" VALUES ( '%s',", name_safe), charsmax(g_query)) + strcat(g_query, fmt("'%s',", authID), charsmax(g_query)) + strcat(g_query, fmt("'%s',", IP), charsmax(g_query)) + strcat(g_query, fmt("'%s',", reason_safe), charsmax(g_query)) + strcat(g_query, fmt("'%s',", adminName_safe), charsmax(g_query)) + strcat(g_query, fmt("'%s',", adminAuthID), charsmax(g_query)) + strcat(g_query, fmt("'%s',", adminIP), charsmax(g_query)) + strcat(g_query, fmt("NOW(),"), charsmax(g_query)) + strcat(g_query, fmt("FROM_UNIXTIME(%i),", expireAt), charsmax(g_query)) + strcat(g_query, fmt("%i ) ", flags), charsmax(g_query)) + strcat(g_query, "ON DUPLICATE KEY UPDATE ", charsmax(g_query)) + strcat(g_query, fmt("name='%s',", name_safe), charsmax(g_query)) + strcat(g_query, fmt("ip='%s',", IP), charsmax(g_query)) + strcat(g_query, fmt("reason='%s',", reason_safe), charsmax(g_query)) + strcat(g_query, fmt("admin_name='%s',", adminName_safe), charsmax(g_query)) + strcat(g_query, fmt("admin_authid='%s',", adminAuthID), charsmax(g_query)) + strcat(g_query, fmt("admin_ip='%s',", adminIP), charsmax(g_query)) + strcat(g_query, "created_at=NOW(),", charsmax(g_query)) + strcat(g_query, fmt("expire_at=FROM_UNIXTIME(%i),", expireAt), charsmax(g_query)) + strcat(g_query, fmt("flags=%i;", flags), charsmax(g_query)) } - QueuePushArray(g_queueSave, gagData) - - return - } - - new name_safe[MAX_NAME_LENGTH * 2] - SQL_QuoteString(Empty_Handle, name_safe, charsmax(name_safe), name) - - new reason_safe[MAX_REASON_LENGTH * 2] - SQL_QuoteString(Empty_Handle, reason_safe, charsmax(reason_safe), reason) - - new adminName_safe[MAX_NAME_LENGTH * 2] - SQL_QuoteString(Empty_Handle, adminName_safe, charsmax(adminName_safe), adminName) - - // TODO: Optimize this EPIC QUERY - formatex(g_query, charsmax(g_query), "INSERT INTO %s ", SQL_TBL_GAGS); { - strcat(g_query, "( name,authid,ip,", charsmax(g_query)) - strcat(g_query, "reason,admin_name,admin_authid,", charsmax(g_query)) - strcat(g_query, "admin_ip,created_at,expire_at,flags )", charsmax(g_query)) - - strcat(g_query, fmt(" VALUES ( '%s',", name_safe), charsmax(g_query)) - strcat(g_query, fmt("'%s',", authID), charsmax(g_query)) - strcat(g_query, fmt("'%s',", IP), charsmax(g_query)) - strcat(g_query, fmt("'%s',", reason_safe), charsmax(g_query)) - strcat(g_query, fmt("'%s',", adminName_safe), charsmax(g_query)) - strcat(g_query, fmt("'%s',", adminAuthID), charsmax(g_query)) - strcat(g_query, fmt("'%s',", adminIP), charsmax(g_query)) - strcat(g_query, fmt("NOW(),"), charsmax(g_query)) - strcat(g_query, fmt("FROM_UNIXTIME(%i),", expireAt), charsmax(g_query)) - strcat(g_query, fmt("%i ) ", flags), charsmax(g_query)) - strcat(g_query, "ON DUPLICATE KEY UPDATE ", charsmax(g_query)) - strcat(g_query, fmt("name='%s',", name_safe), charsmax(g_query)) - strcat(g_query, fmt("ip='%s',", IP), charsmax(g_query)) - strcat(g_query, fmt("reason='%s',", reason_safe), charsmax(g_query)) - strcat(g_query, fmt("admin_name='%s',", adminName_safe), charsmax(g_query)) - strcat(g_query, fmt("admin_authid='%s',", adminAuthID), charsmax(g_query)) - strcat(g_query, fmt("admin_ip='%s',", adminIP), charsmax(g_query)) - strcat(g_query, "created_at=NOW(),", charsmax(g_query)) - strcat(g_query, fmt("expire_at=FROM_UNIXTIME(%i),", expireAt), charsmax(g_query)) - strcat(g_query, fmt("flags=%i;", flags), charsmax(g_query)) - } - - SQL_ThreadQuery(g_tuple, "handle_Saved", g_query) + SQL_ThreadQuery(g_tuple, "handle_Saved", g_query) } public handle_Saved(failstate, Handle: query, error[], errnum, data[], size, Float: queuetime) { - if(IsSQLQueryFailed(failstate, query, error, errnum)) { - return - } - - formatex(g_query, charsmax(g_query), "SELECT \ - name,authid,ip,reason,\ - admin_name,admin_authid,admin_ip,\ - UNIX_TIMESTAMP(created_at),UNIX_TIMESTAMP(expire_at),flags") - strcat(g_query, fmt(" FROM %s", SQL_TBL_GAGS), charsmax(g_query)) - strcat(g_query, fmt(" WHERE id=%i;", SQL_GetInsertId(query)), charsmax(g_query)) - - SQL_ThreadQuery(g_tuple, "handle_SavedResult", g_query) + if (IsSQLQueryFailed(failstate, query, error, errnum)) { + return + } + + formatex(g_query, charsmax(g_query), "SELECT \ + name,authid,ip,reason,\ + admin_name,admin_authid,admin_ip,\ + UNIX_TIMESTAMP(created_at),UNIX_TIMESTAMP(expire_at),flags") + strcat(g_query, fmt(" FROM %s", SQL_TBL_GAGS), charsmax(g_query)) + strcat(g_query, fmt(" WHERE id=%i;", SQL_GetInsertId(query)), charsmax(g_query)) + + SQL_ThreadQuery(g_tuple, "handle_SavedResult", g_query) } public handle_SavedResult(failstate, Handle: query, error[], errnum, data[], size, Float: queuetime) { - if(IsSQLQueryFailed(failstate, query, error, errnum)) { - return - } - - enum { res_name, res_authid, res_ip, res_reason, - res_admin_name, res_admin_authid, res_admin_ip, - res_created_at, res_expire_at, res_flags - } - - new name[MAX_NAME_LENGTH]; SQL_ReadResult(query, res_name, name, charsmax(name)) - new authID[MAX_AUTHID_LENGTH]; SQL_ReadResult(query, res_authid, authID, charsmax(authID)) - new IP[MAX_IP_LENGTH]; SQL_ReadResult(query, res_ip, IP, charsmax(IP)) - new reason[MAX_REASON_LENGTH]; SQL_ReadResult(query, res_reason, reason, charsmax(reason)) - - new adminName[MAX_NAME_LENGTH]; SQL_ReadResult(query, res_admin_name, adminName, charsmax(adminName)) - new adminAuthID[MAX_AUTHID_LENGTH]; SQL_ReadResult(query, res_admin_authid, adminAuthID, charsmax(adminAuthID)) - new adminIP[MAX_IP_LENGTH]; SQL_ReadResult(query, res_admin_ip, adminIP, charsmax(adminIP)) - - new createdAt = SQL_ReadResult(query, res_created_at) - new expireAt = SQL_ReadResult(query, res_expire_at) - new flags = SQL_ReadResult(query, res_flags) - - CA_Log(logLevel_Debug, "Player gag saved {'%s', '%s', '%s', '%s', '%s', '%s', '%s', %i, %i, %i} (queryTime: '%.3f' sec)", \ - name, authID, IP, reason, adminName, adminAuthID, adminIP, createdAt, expireAt, flags,\ - queuetime \ - ) - - ExecuteForward(g_fwd_StorageSaved, g_ret, - name, authID, IP, reason, - adminName, adminAuthID, adminIP, - createdAt, expireAt, flags - ) + if (IsSQLQueryFailed(failstate, query, error, errnum)) { + return + } + + enum { res_name, res_authid, res_ip, res_reason, + res_admin_name, res_admin_authid, res_admin_ip, + res_created_at, res_expire_at, res_flags + } + + new name[MAX_NAME_LENGTH]; SQL_ReadResult(query, res_name, name, charsmax(name)) + new authID[MAX_AUTHID_LENGTH]; SQL_ReadResult(query, res_authid, authID, charsmax(authID)) + new IP[MAX_IP_LENGTH]; SQL_ReadResult(query, res_ip, IP, charsmax(IP)) + new reason[MAX_REASON_LENGTH]; SQL_ReadResult(query, res_reason, reason, charsmax(reason)) + + new adminName[MAX_NAME_LENGTH]; SQL_ReadResult(query, res_admin_name, adminName, charsmax(adminName)) + new adminAuthID[MAX_AUTHID_LENGTH]; SQL_ReadResult(query, res_admin_authid, adminAuthID, charsmax(adminAuthID)) + new adminIP[MAX_IP_LENGTH]; SQL_ReadResult(query, res_admin_ip, adminIP, charsmax(adminIP)) + + new createdAt = SQL_ReadResult(query, res_created_at) + new expireAt = SQL_ReadResult(query, res_expire_at) + new flags = SQL_ReadResult(query, res_flags) + + CA_Log(logLevel_Debug, "Player gag saved {'%s', '%s', '%s', '%s', '%s', '%s', '%s', %i, %i, %i} (queryTime: '%.3f' sec)", \ + name, authID, IP, reason, adminName, adminAuthID, adminIP, createdAt, expireAt, flags,\ + queuetime \ + ) + + ExecuteForward(g_fwd_StorageSaved, g_ret, + name, authID, IP, reason, + adminName, adminAuthID, adminIP, + createdAt, expireAt, flags + ) } Storage_Load(const authID[]) { - if(!g_storageInitialized) { - QueuePushString(g_queueLoad, authID) + if (!g_storageInitialized) { + QueuePushString(g_queueLoad, authID) - return - } + return + } - formatex(g_query, charsmax(g_query), "SELECT name, authid, ip, reason,\ - admin_name, admin_authid, admin_ip, \ - UNIX_TIMESTAMP(created_at), UNIX_TIMESTAMP(expire_at), flags FROM %s", SQL_TBL_GAGS); { - strcat(g_query, fmt(" WHERE (authid = '%s')", authID), charsmax(g_query)) - strcat(g_query, " AND ( expire_at = FROM_UNIXTIME(9999999999) OR (expire_at > NOW())) LIMIT 1", charsmax(g_query)) - } + formatex(g_query, charsmax(g_query), "SELECT name, authid, ip, reason,\ + admin_name, admin_authid, admin_ip, \ + UNIX_TIMESTAMP(created_at), UNIX_TIMESTAMP(expire_at), flags FROM %s", SQL_TBL_GAGS); { + strcat(g_query, fmt(" WHERE (authid = '%s')", authID), charsmax(g_query)) + strcat(g_query, " AND ( expire_at = FROM_UNIXTIME(9999999999) OR (expire_at > NOW())) LIMIT 1", charsmax(g_query)) + } - SQL_ThreadQuery(g_tuple, "handle_Loaded", g_query) + SQL_ThreadQuery(g_tuple, "handle_Loaded", g_query) } public handle_Loaded(failstate, Handle: query, error[], errnum, data[], size, Float:queuetime) { - if(IsSQLQueryFailed(failstate, query, error, errnum)) { - return - } - - enum { res_name, res_authid, res_ip, res_reason, - res_admin_name, res_admin_authid, res_admin_ip, - res_created_at, res_expire_at, res_flags - } - - new bool: found = (SQL_NumResults(query) != 0) - - if(!found) { - return - } - - new name[MAX_NAME_LENGTH]; SQL_ReadResult(query, res_name, name, charsmax(name)) - new authID[MAX_AUTHID_LENGTH]; SQL_ReadResult(query, res_authid, authID, charsmax(authID)) - new IP[MAX_IP_LENGTH]; SQL_ReadResult(query, res_ip, IP, charsmax(IP)) - new reason[MAX_REASON_LENGTH]; SQL_ReadResult(query, res_reason, reason, charsmax(reason)) - - new adminName[MAX_NAME_LENGTH]; SQL_ReadResult(query, res_admin_name, adminName, charsmax(adminName)) - new adminAuthID[MAX_AUTHID_LENGTH]; SQL_ReadResult(query, res_admin_authid, adminAuthID, charsmax(adminAuthID)) - new adminIP[MAX_IP_LENGTH]; SQL_ReadResult(query, res_admin_ip, adminIP, charsmax(adminIP)) - - new createdAt = SQL_ReadResult(query, res_created_at) - new expireAt = SQL_ReadResult(query, res_expire_at) - new flags = SQL_ReadResult(query, res_flags) - - CA_Log(logLevel_Debug, "Player gag loaded {'%s', '%s', '%s', '%s', '%s', '%s', '%s', %i, %i, %i} (queryTime: '%.3f' sec)", \ - name, authID, IP, reason, adminName, adminAuthID, adminIP, createdAt, expireAt, flags, \ - queuetime \ - ) - - ExecuteForward(g_fwd_StorageLoaded, g_ret, - name, authID, IP, reason, - adminName, adminAuthID, adminIP, - createdAt, expireAt, flags - ) + if (IsSQLQueryFailed(failstate, query, error, errnum)) { + return + } + + enum { res_name, res_authid, res_ip, res_reason, + res_admin_name, res_admin_authid, res_admin_ip, + res_created_at, res_expire_at, res_flags + } + + new bool: found = (SQL_NumResults(query) != 0) + + if (!found) { + return + } + + new name[MAX_NAME_LENGTH]; SQL_ReadResult(query, res_name, name, charsmax(name)) + new authID[MAX_AUTHID_LENGTH]; SQL_ReadResult(query, res_authid, authID, charsmax(authID)) + new IP[MAX_IP_LENGTH]; SQL_ReadResult(query, res_ip, IP, charsmax(IP)) + new reason[MAX_REASON_LENGTH]; SQL_ReadResult(query, res_reason, reason, charsmax(reason)) + + new adminName[MAX_NAME_LENGTH]; SQL_ReadResult(query, res_admin_name, adminName, charsmax(adminName)) + new adminAuthID[MAX_AUTHID_LENGTH]; SQL_ReadResult(query, res_admin_authid, adminAuthID, charsmax(adminAuthID)) + new adminIP[MAX_IP_LENGTH]; SQL_ReadResult(query, res_admin_ip, adminIP, charsmax(adminIP)) + + new createdAt = SQL_ReadResult(query, res_created_at) + new expireAt = SQL_ReadResult(query, res_expire_at) + new flags = SQL_ReadResult(query, res_flags) + + CA_Log(logLevel_Debug, "Player gag loaded {'%s', '%s', '%s', '%s', '%s', '%s', '%s', %i, %i, %i} (queryTime: '%.3f' sec)", \ + name, authID, IP, reason, adminName, adminAuthID, adminIP, createdAt, expireAt, flags, \ + queuetime \ + ) + + ExecuteForward(g_fwd_StorageLoaded, g_ret, + name, authID, IP, reason, + adminName, adminAuthID, adminIP, + createdAt, expireAt, flags + ) } Storage_Remove(const authID[]) { - if(!g_storageInitialized || g_tuple == Empty_Handle) { - CA_Log(logLevel_Warning, "Storage_Remove(): Storage connection not initialized. Query not executed. (g_storageInitialized=%i, g_tuple=%i)", - g_storageInitialized, g_tuple - ) + if (!g_storageInitialized || g_tuple == Empty_Handle) { + CA_Log(logLevel_Warning, "Storage_Remove(): Storage connection not initialized. Query not executed. (g_storageInitialized=%i, g_tuple=%i)", + g_storageInitialized, g_tuple + ) - return - } + return + } - formatex(g_query, charsmax(g_query), "DELETE FROM %s ", SQL_TBL_GAGS); { - strcat(g_query, fmt("WHERE (authid = '%s')", authID), charsmax(g_query)) - } + formatex(g_query, charsmax(g_query), "DELETE FROM %s ", SQL_TBL_GAGS); { + strcat(g_query, fmt("WHERE (authid = '%s')", authID), charsmax(g_query)) + } - SQL_ThreadQuery(g_tuple, "handle_Removed", g_query) + SQL_ThreadQuery(g_tuple, "handle_Removed", g_query) } public handle_Removed(failstate, Handle: query, error[], errnum, data[], size, Float: queuetime) { - if(IsSQLQueryFailed(failstate, query, error, errnum)) { - return - } + if (IsSQLQueryFailed(failstate, query, error, errnum)) { + return + } - CA_Log(logLevel_Debug, "Player gag removed { } (queryTime: '%.3f' sec)", \ - queuetime \ - ) + CA_Log(logLevel_Debug, "Player gag removed { } (queryTime: '%.3f' sec)", \ + queuetime \ + ) - ExecuteForward(g_fwd_StorageRemoved, g_ret) + ExecuteForward(g_fwd_StorageRemoved, g_ret) } diff --git a/cstrike/addons/amxmodx/scripting/CA_Storage_SQLite.sma b/cstrike/addons/amxmodx/scripting/CA_Storage_SQLite.sma index c70fb50..70a25cb 100644 --- a/cstrike/addons/amxmodx/scripting/CA_Storage_SQLite.sma +++ b/cstrike/addons/amxmodx/scripting/CA_Storage_SQLite.sma @@ -4,13 +4,12 @@ #include <ChatAdditions> #include <CA_StorageAPI_endpoint> -#pragma ctrlchar '\' #pragma dynamic 131072 -#pragma tabsize 2 +#pragma tabsize 4 #pragma reqlib sqlite #if !defined AMXMODX_NOAUTOLOAD - #pragma loadlib sqlite + #pragma loadlib sqlite #endif new const SQL_DBNAME[] = "ChatAdditions" @@ -21,216 +20,216 @@ const MAX_REASON_LENGTH = 256 new Handle: g_tuple = Empty_Handle -public stock const PluginName[] = "ChatAdditions: SQLite storage" -public stock const PluginVersion[] = CA_VERSION -public stock const PluginAuthor[] = "Sergey Shorokhov" -public stock const PluginURL[] = "https://github.com/ChatAdditions/" -public stock const PluginDescription[] = "SQLite storage provider for ChatAdditions" +public stock const PluginName[] = "ChatAdditions: SQLite storage" +public stock const PluginVersion[] = CA_VERSION +public stock const PluginAuthor[] = "Sergey Shorokhov" +public stock const PluginURL[] = "https://github.com/ChatAdditions/" +public stock const PluginDescription[] = "SQLite storage provider for ChatAdditions" public plugin_init() { - register_plugin(PluginName, PluginVersion, PluginAuthor) + register_plugin(PluginName, PluginVersion, PluginAuthor) - if(!SQL_SetAffinity("sqlite")) { - set_fail_state("Can't user 'SQLite'. Check modules.ini") - } + if (!SQL_SetAffinity("sqlite")) { + set_fail_state("Can't user 'SQLite'. Check modules.ini") + } - g_tuple = SQL_MakeDbTuple("", "", "", SQL_DBNAME) + g_tuple = SQL_MakeDbTuple("", "", "", SQL_DBNAME) - Storage_Create() + Storage_Create() } public plugin_end() { - if(g_tuple != Empty_Handle) { - SQL_FreeHandle(g_tuple) - } + if (g_tuple != Empty_Handle) { + SQL_FreeHandle(g_tuple) + } } public plugin_natives() { - RegisterNatives() + RegisterNatives() } public plugin_cfg() { - RegisterForwards() + RegisterForwards() } Storage_Create() { - new query[QUERY_LENGTH] - - formatex(query, charsmax(query), "CREATE TABLE IF NOT EXISTS %s ", SQL_TBL_GAGS); { - strcat(query, "( id INTEGER PRIMARY KEY AUTOINCREMENT,", charsmax(query)) - strcat(query, "name VARCHAR NOT NULL,", charsmax(query)) - strcat(query, "authid VARCHAR NOT NULL,", charsmax(query)) - strcat(query, "ip VARCHAR NOT NULL,", charsmax(query)) - strcat(query, "reason VARCHAR NOT NULL,", charsmax(query)) - strcat(query, "admin_name VARCHAR NOT NULL,", charsmax(query)) - strcat(query, "admin_authid VARCHAR NOT NULL,", charsmax(query)) - strcat(query, "admin_ip VARCHAR NOT NULL,", charsmax(query)) - strcat(query, "created_at DATETIME NOT NULL,", charsmax(query)) - strcat(query, "expire_at DATETIME NOT NULL,", charsmax(query)) - strcat(query, "flags INTEGER NOT NULL", charsmax(query)) - strcat(query, ");", charsmax(query)) - } - strcat(query, fmt("CREATE UNIQUE INDEX IF NOT EXISTS authid_unique_idx ON %s (authid)", SQL_TBL_GAGS), charsmax(query)) - - SQL_ThreadQuery(g_tuple, "handle_StorageCreated", query) + new query[QUERY_LENGTH] + + formatex(query, charsmax(query), "CREATE TABLE IF NOT EXISTS %s ", SQL_TBL_GAGS); { + strcat(query, "( id INTEGER PRIMARY KEY AUTOINCREMENT,", charsmax(query)) + strcat(query, "name VARCHAR NOT NULL,", charsmax(query)) + strcat(query, "authid VARCHAR NOT NULL,", charsmax(query)) + strcat(query, "ip VARCHAR NOT NULL,", charsmax(query)) + strcat(query, "reason VARCHAR NOT NULL,", charsmax(query)) + strcat(query, "admin_name VARCHAR NOT NULL,", charsmax(query)) + strcat(query, "admin_authid VARCHAR NOT NULL,", charsmax(query)) + strcat(query, "admin_ip VARCHAR NOT NULL,", charsmax(query)) + strcat(query, "created_at DATETIME NOT NULL,", charsmax(query)) + strcat(query, "expire_at DATETIME NOT NULL,", charsmax(query)) + strcat(query, "flags INTEGER NOT NULL", charsmax(query)) + strcat(query, ");", charsmax(query)) + } + strcat(query, fmt("CREATE UNIQUE INDEX IF NOT EXISTS authid_unique_idx ON %s (authid)", SQL_TBL_GAGS), charsmax(query)) + + SQL_ThreadQuery(g_tuple, "handle_StorageCreated", query) } public handle_StorageCreated(failstate, Handle: query, error[], errnum, data[], size, Float: queuetime) { - if(IsSQLQueryFailed(failstate, query, error, errnum)) { - return - } + if (IsSQLQueryFailed(failstate, query, error, errnum)) { + return + } - CA_Log(logLevel_Debug, "Table '%s' created! (queryTime: '%.3f' sec)", SQL_TBL_GAGS, queuetime) + CA_Log(logLevel_Debug, "Table '%s' created! (queryTime: '%.3f' sec)", SQL_TBL_GAGS, queuetime) - ExecuteForward(g_fwd_StorageInitialized, g_ret) + ExecuteForward(g_fwd_StorageInitialized, g_ret) } Storage_Save(const name[], const authID[], const IP[], - const reason[], const adminName[], const adminAuthID[], - const adminIP[], const expireAt, const flags) { - - new name_safe[MAX_NAME_LENGTH * 2] - SQL_QuoteString(Empty_Handle, name_safe, charsmax(name_safe), name) - - new reason_safe[MAX_REASON_LENGTH * 2] - SQL_QuoteString(Empty_Handle, reason_safe, charsmax(reason_safe), reason) - - new adminName_safe[MAX_NAME_LENGTH * 2] - SQL_QuoteString(Empty_Handle, adminName_safe, charsmax(adminName_safe), adminName) - - new query[QUERY_LENGTH] - formatex(query, charsmax(query), "INSERT OR REPLACE INTO %s ", SQL_TBL_GAGS); { - strcat(query, "( name,authid,ip,", charsmax(query)) - strcat(query, "reason,admin_name,admin_authid,", charsmax(query)) - strcat(query, "admin_ip,created_at,expire_at,flags )", charsmax(query)) - - strcat(query, fmt("VALUES ( '%s',", name_safe), charsmax(query)) - strcat(query, fmt("'%s',", authID), charsmax(query)) - strcat(query, fmt("'%s',", IP), charsmax(query)) - strcat(query, fmt("'%s',", reason_safe), charsmax(query)) - strcat(query, fmt("'%s',", adminName_safe), charsmax(query)) - strcat(query, fmt("'%s',", adminAuthID), charsmax(query)) - strcat(query, fmt("'%s',", adminIP), charsmax(query)) - strcat(query, fmt("DateTime('now'),"), charsmax(query)) - strcat(query, fmt("DateTime(%i, 'unixepoch'),", expireAt), charsmax(query)) - strcat(query, fmt("%i ); ", flags), charsmax(query)) - } - - strcat(query, "SELECT \ - name,authid,ip,reason,\ - admin_name,admin_authid,admin_ip,\ - strftime('%s',created_at),strftime('%s',expire_at),flags", charsmax(query)) - strcat(query, fmt(" FROM %s", SQL_TBL_GAGS), charsmax(query)) - strcat(query, fmt(" WHERE authid='%s'", authID), charsmax(query)) - - SQL_ThreadQuery(g_tuple, "handle_Saved", query) + const reason[], const adminName[], const adminAuthID[], + const adminIP[], const expireAt, const flags) { + + new name_safe[MAX_NAME_LENGTH * 2] + SQL_QuoteString(Empty_Handle, name_safe, charsmax(name_safe), name) + + new reason_safe[MAX_REASON_LENGTH * 2] + SQL_QuoteString(Empty_Handle, reason_safe, charsmax(reason_safe), reason) + + new adminName_safe[MAX_NAME_LENGTH * 2] + SQL_QuoteString(Empty_Handle, adminName_safe, charsmax(adminName_safe), adminName) + + new query[QUERY_LENGTH] + formatex(query, charsmax(query), "INSERT OR REPLACE INTO %s ", SQL_TBL_GAGS); { + strcat(query, "( name,authid,ip,", charsmax(query)) + strcat(query, "reason,admin_name,admin_authid,", charsmax(query)) + strcat(query, "admin_ip,created_at,expire_at,flags )", charsmax(query)) + + strcat(query, fmt("VALUES ( '%s',", name_safe), charsmax(query)) + strcat(query, fmt("'%s',", authID), charsmax(query)) + strcat(query, fmt("'%s',", IP), charsmax(query)) + strcat(query, fmt("'%s',", reason_safe), charsmax(query)) + strcat(query, fmt("'%s',", adminName_safe), charsmax(query)) + strcat(query, fmt("'%s',", adminAuthID), charsmax(query)) + strcat(query, fmt("'%s',", adminIP), charsmax(query)) + strcat(query, fmt("DateTime('now'),"), charsmax(query)) + strcat(query, fmt("DateTime(%i, 'unixepoch'),", expireAt), charsmax(query)) + strcat(query, fmt("%i ); ", flags), charsmax(query)) + } + + strcat(query, "SELECT \ + name,authid,ip,reason,\ + admin_name,admin_authid,admin_ip,\ + strftime('%s',created_at),strftime('%s',expire_at),flags", charsmax(query)) + strcat(query, fmt(" FROM %s", SQL_TBL_GAGS), charsmax(query)) + strcat(query, fmt(" WHERE authid='%s'", authID), charsmax(query)) + + SQL_ThreadQuery(g_tuple, "handle_Saved", query) } public handle_Saved(failstate, Handle: query, error[], errnum, data[], size, Float: queuetime) { - if(IsSQLQueryFailed(failstate, query, error, errnum)) { - return - } - - enum { res_name, res_authid, res_ip, res_reason, - res_admin_name, res_admin_authid, res_admin_ip, - res_created_at, res_expire_at, res_flags - } - - new name[MAX_NAME_LENGTH]; SQL_ReadResult(query, res_name, name, charsmax(name)) - new authID[MAX_AUTHID_LENGTH]; SQL_ReadResult(query, res_authid, authID, charsmax(authID)) - new IP[MAX_IP_LENGTH]; SQL_ReadResult(query, res_ip, IP, charsmax(IP)) - new reason[MAX_REASON_LENGTH]; SQL_ReadResult(query, res_reason, reason, charsmax(reason)) - - new adminName[MAX_NAME_LENGTH]; SQL_ReadResult(query, res_admin_name, adminName, charsmax(adminName)) - new adminAuthID[MAX_AUTHID_LENGTH]; SQL_ReadResult(query, res_admin_authid, adminAuthID, charsmax(adminAuthID)) - new adminIP[MAX_IP_LENGTH]; SQL_ReadResult(query, res_admin_ip, adminIP, charsmax(adminIP)) - - new createdAt = SQL_ReadResult(query, res_created_at) - new expireAt = SQL_ReadResult(query, res_expire_at) - new flags = SQL_ReadResult(query, res_flags) - - CA_Log(logLevel_Debug, "Player gag saved {'%s', '%s', '%s', '%s', '%s', '%s', '%s', %i, %i, %i} (queryTime: '%.3f' sec)", \ - name, authID, IP, reason, adminName, adminAuthID, adminIP, createdAt, expireAt, flags,\ - queuetime \ - ) - - ExecuteForward(g_fwd_StorageSaved, g_ret, - name, authID, IP, reason, - adminName, adminAuthID, adminIP, - createdAt, expireAt, flags - ) + if (IsSQLQueryFailed(failstate, query, error, errnum)) { + return + } + + enum { res_name, res_authid, res_ip, res_reason, + res_admin_name, res_admin_authid, res_admin_ip, + res_created_at, res_expire_at, res_flags + } + + new name[MAX_NAME_LENGTH]; SQL_ReadResult(query, res_name, name, charsmax(name)) + new authID[MAX_AUTHID_LENGTH]; SQL_ReadResult(query, res_authid, authID, charsmax(authID)) + new IP[MAX_IP_LENGTH]; SQL_ReadResult(query, res_ip, IP, charsmax(IP)) + new reason[MAX_REASON_LENGTH]; SQL_ReadResult(query, res_reason, reason, charsmax(reason)) + + new adminName[MAX_NAME_LENGTH]; SQL_ReadResult(query, res_admin_name, adminName, charsmax(adminName)) + new adminAuthID[MAX_AUTHID_LENGTH]; SQL_ReadResult(query, res_admin_authid, adminAuthID, charsmax(adminAuthID)) + new adminIP[MAX_IP_LENGTH]; SQL_ReadResult(query, res_admin_ip, adminIP, charsmax(adminIP)) + + new createdAt = SQL_ReadResult(query, res_created_at) + new expireAt = SQL_ReadResult(query, res_expire_at) + new flags = SQL_ReadResult(query, res_flags) + + CA_Log(logLevel_Debug, "Player gag saved {'%s', '%s', '%s', '%s', '%s', '%s', '%s', %i, %i, %i} (queryTime: '%.3f' sec)", \ + name, authID, IP, reason, adminName, adminAuthID, adminIP, createdAt, expireAt, flags,\ + queuetime \ + ) + + ExecuteForward(g_fwd_StorageSaved, g_ret, + name, authID, IP, reason, + adminName, adminAuthID, adminIP, + createdAt, expireAt, flags + ) } Storage_Load(const authID[]) { - new query[QUERY_LENGTH] - formatex(query, charsmax(query), "SELECT name, authid, ip, reason,\ - admin_name, admin_authid, admin_ip, \ - strftime('%%s', created_at), strftime('%%s', expire_at), flags FROM %s", SQL_TBL_GAGS); { - strcat(query, fmt(" WHERE (authid = '%s')", authID), charsmax(query)) - strcat(query, " AND ( expire_at = DateTime(9999999999, 'unixepoch') OR (expire_at > DateTime('now')) ) LIMIT 1", charsmax(query)) - } - - SQL_ThreadQuery(g_tuple, "handle_Loaded", query) + new query[QUERY_LENGTH] + formatex(query, charsmax(query), "SELECT name, authid, ip, reason,\ + admin_name, admin_authid, admin_ip, \ + strftime('%%s', created_at), strftime('%%s', expire_at), flags FROM %s", SQL_TBL_GAGS); { + strcat(query, fmt(" WHERE (authid = '%s')", authID), charsmax(query)) + strcat(query, " AND ( expire_at = DateTime(9999999999, 'unixepoch') OR (expire_at > DateTime('now')) ) LIMIT 1", charsmax(query)) + } + + SQL_ThreadQuery(g_tuple, "handle_Loaded", query) } public handle_Loaded(failstate, Handle: query, error[], errnum, data[], size, Float: queuetime) { - if(IsSQLQueryFailed(failstate, query, error, errnum)) { - return - } - - enum { res_name, res_authid, res_ip, res_reason, - res_admin_name, res_admin_authid, res_admin_ip, - res_created_at, res_expire_at, res_flags - } - - new bool: found = (SQL_NumResults(query) != 0) - - if(!found) { - return - } - - new name[MAX_NAME_LENGTH]; SQL_ReadResult(query, res_name, name, charsmax(name)) - new authID[MAX_AUTHID_LENGTH]; SQL_ReadResult(query, res_authid, authID, charsmax(authID)) - new IP[MAX_IP_LENGTH]; SQL_ReadResult(query, res_ip, IP, charsmax(IP)) - new reason[MAX_REASON_LENGTH]; SQL_ReadResult(query, res_reason, reason, charsmax(reason)) - - new adminName[MAX_NAME_LENGTH]; SQL_ReadResult(query, res_admin_name, adminName, charsmax(adminName)) - new adminAuthID[MAX_AUTHID_LENGTH]; SQL_ReadResult(query, res_admin_authid, adminAuthID, charsmax(adminAuthID)) - new adminIP[MAX_IP_LENGTH]; SQL_ReadResult(query, res_admin_ip, adminIP, charsmax(adminIP)) - - new createdAt = SQL_ReadResult(query, res_created_at) - new expireAt = SQL_ReadResult(query, res_expire_at) - new flags = SQL_ReadResult(query, res_flags) - - CA_Log(logLevel_Debug, "Player gag loaded {'%s', '%s', '%s', '%s', '%s', '%s', '%s', %i, %i, %i} (queryTime: '%.3f' sec)", \ - name, authID, IP, reason, adminName, adminAuthID, adminIP, createdAt, expireAt, flags,\ - queuetime \ - ) - - ExecuteForward(g_fwd_StorageLoaded, g_ret, - name, authID, IP, reason, - adminName, adminAuthID, adminIP, - createdAt, expireAt, flags - ) + if (IsSQLQueryFailed(failstate, query, error, errnum)) { + return + } + + enum { res_name, res_authid, res_ip, res_reason, + res_admin_name, res_admin_authid, res_admin_ip, + res_created_at, res_expire_at, res_flags + } + + new bool: found = (SQL_NumResults(query) != 0) + + if (!found) { + return + } + + new name[MAX_NAME_LENGTH]; SQL_ReadResult(query, res_name, name, charsmax(name)) + new authID[MAX_AUTHID_LENGTH]; SQL_ReadResult(query, res_authid, authID, charsmax(authID)) + new IP[MAX_IP_LENGTH]; SQL_ReadResult(query, res_ip, IP, charsmax(IP)) + new reason[MAX_REASON_LENGTH]; SQL_ReadResult(query, res_reason, reason, charsmax(reason)) + + new adminName[MAX_NAME_LENGTH]; SQL_ReadResult(query, res_admin_name, adminName, charsmax(adminName)) + new adminAuthID[MAX_AUTHID_LENGTH]; SQL_ReadResult(query, res_admin_authid, adminAuthID, charsmax(adminAuthID)) + new adminIP[MAX_IP_LENGTH]; SQL_ReadResult(query, res_admin_ip, adminIP, charsmax(adminIP)) + + new createdAt = SQL_ReadResult(query, res_created_at) + new expireAt = SQL_ReadResult(query, res_expire_at) + new flags = SQL_ReadResult(query, res_flags) + + CA_Log(logLevel_Debug, "Player gag loaded {'%s', '%s', '%s', '%s', '%s', '%s', '%s', %i, %i, %i} (queryTime: '%.3f' sec)", \ + name, authID, IP, reason, adminName, adminAuthID, adminIP, createdAt, expireAt, flags,\ + queuetime \ + ) + + ExecuteForward(g_fwd_StorageLoaded, g_ret, + name, authID, IP, reason, + adminName, adminAuthID, adminIP, + createdAt, expireAt, flags + ) } Storage_Remove(const authID[]) { - new query[QUERY_LENGTH] - formatex(query, charsmax(query), "DELETE FROM %s ", SQL_TBL_GAGS); { - strcat(query, fmt("WHERE (authid = '%s')", authID), charsmax(query)) - } + new query[QUERY_LENGTH] + formatex(query, charsmax(query), "DELETE FROM %s ", SQL_TBL_GAGS); { + strcat(query, fmt("WHERE (authid = '%s')", authID), charsmax(query)) + } - SQL_ThreadQuery(g_tuple, "handle_Removed", query) + SQL_ThreadQuery(g_tuple, "handle_Removed", query) } public handle_Removed(failstate, Handle: query, error[], errnum, data[], size, Float: queuetime) { - if(IsSQLQueryFailed(failstate, query, error, errnum)) { - return - } + if (IsSQLQueryFailed(failstate, query, error, errnum)) { + return + } - CA_Log(logLevel_Debug, "Player gag removed { } (queryTime: '%.3f' sec)", \ - queuetime \ - ) + CA_Log(logLevel_Debug, "Player gag removed { } (queryTime: '%.3f' sec)", \ + queuetime \ + ) - ExecuteForward(g_fwd_StorageRemoved, g_ret) + ExecuteForward(g_fwd_StorageRemoved, g_ret) } diff --git a/cstrike/addons/amxmodx/scripting/ChatAdditions_Core.sma b/cstrike/addons/amxmodx/scripting/ChatAdditions_Core.sma index 2ad2b97..c3e6c63 100644 --- a/cstrike/addons/amxmodx/scripting/ChatAdditions_Core.sma +++ b/cstrike/addons/amxmodx/scripting/ChatAdditions_Core.sma @@ -5,29 +5,28 @@ #include <grip> #include <ChatAdditions> -#pragma ctrlchar '\' -#pragma tabsize 2 +#pragma tabsize 4 #pragma dynamic (8192 + 4096) enum logType_s { - _Default, - _LogToDir, - _LogToDirSilent + _Default, + _LogToDir, + _LogToDirSilent } new logType_s: ca_log_type, - logLevel_s: ca_log_level = logLevel_Debug, - g_logsPath[PLATFORM_MAX_PATH], - bool: ca_update_notify, - ca_log_autodelete_time + logLevel_s: ca_log_level = logLevel_Debug, + g_logsPath[PLATFORM_MAX_PATH], + bool: ca_update_notify, + ca_log_autodelete_time new const LOG_FOLDER[] = "ChatAdditions" new g_fwdClientSay, - g_fwdClientVoice, - g_fwdClientChangeName, - g_retVal + g_fwdClientVoice, + g_fwdClientChangeName, + g_retVal // FROM https://github.com/s1lentq/ReGameDLL_CS/blob/master/regamedll/game_shared/voice_gamemgr.cpp @@ -40,443 +39,443 @@ new bool: g_PlayerModEnable[MAX_PLAYERS + 1] new g_BanMasks[MAX_PLAYERS + 1] new const g_versionLink[] = "https://api.github.com/repos/" - + "ChatAdditions/ChatAdditions_AMXX" - + "/releases/latest" + + "ChatAdditions/ChatAdditions_AMXX" + + "/releases/latest" -public stock const PluginName[] = "ChatAdditions: Core" -public stock const PluginVersion[] = CA_VERSION -public stock const PluginAuthor[] = "Sergey Shorokhov" -public stock const PluginURL[] = "https://github.com/ChatAdditions/" -public stock const PluginDescription[] = "A core plugin for control different types of chat." +public stock const PluginName[] = "ChatAdditions: Core" +public stock const PluginVersion[] = CA_VERSION +public stock const PluginAuthor[] = "Sergey Shorokhov" +public stock const PluginURL[] = "https://github.com/ChatAdditions/" +public stock const PluginDescription[] = "A core plugin for control different types of chat." public plugin_precache() { - register_plugin(PluginName, PluginVersion, PluginAuthor) + register_plugin(PluginName, PluginVersion, PluginAuthor) - create_cvar("ChatAdditions_version", PluginVersion, (FCVAR_SERVER | FCVAR_SPONLY | FCVAR_UNLOGGED)) + create_cvar("ChatAdditions_version", PluginVersion, (FCVAR_SERVER | FCVAR_SPONLY | FCVAR_UNLOGGED)) - GetLogsFilePath(g_logsPath, .dir = LOG_FOLDER) + GetLogsFilePath(g_logsPath, .dir = LOG_FOLDER) - Create_CVars() + Create_CVars() - AutoExecConfig(true, "ChatAdditions_core", "ChatAdditions") + AutoExecConfig(true, "ChatAdditions_core", "ChatAdditions") } public plugin_init() { - register_clcmd("say", "ClCmd_Say", ADMIN_ALL) - register_clcmd("say_team", "ClCmd_Say", ADMIN_ALL) + register_clcmd("say", "ClCmd_Say", ADMIN_ALL) + register_clcmd("say_team", "ClCmd_Say", ADMIN_ALL) - register_forward(FM_Voice_SetClientListening, "Voice_SetClientListening_Pre", ._post = false) - register_forward(FM_ClientUserInfoChanged, "ClientUserInfoChanged_Pre", ._post = false) + register_forward(FM_Voice_SetClientListening, "Voice_SetClientListening_Pre", ._post = false) + register_forward(FM_ClientUserInfoChanged, "ClientUserInfoChanged_Pre", ._post = false) - register_clcmd("VModEnable", "ClCmd_VModEnable", ADMIN_ALL, .FlagManager = false) - register_clcmd("vban", "ClCmd_vban", ADMIN_ALL, .FlagManager = false) + register_clcmd("VModEnable", "ClCmd_VModEnable", ADMIN_ALL, .FlagManager = false) + register_clcmd("vban", "ClCmd_vban", ADMIN_ALL, .FlagManager = false) - g_fwdClientSay = CreateMultiForward("CA_Client_Say", ET_STOP, FP_CELL, FP_CELL, FP_STRING) - g_fwdClientVoice = CreateMultiForward("CA_Client_Voice", ET_STOP, FP_CELL, FP_CELL) - g_fwdClientChangeName = CreateMultiForward("CA_Client_ChangeName", ET_STOP, FP_CELL, FP_STRING) + g_fwdClientSay = CreateMultiForward("CA_Client_Say", ET_STOP, FP_CELL, FP_CELL, FP_STRING) + g_fwdClientVoice = CreateMultiForward("CA_Client_Voice", ET_STOP, FP_CELL, FP_CELL) + g_fwdClientChangeName = CreateMultiForward("CA_Client_ChangeName", ET_STOP, FP_CELL, FP_STRING) - CheckAutoDelete() + CheckAutoDelete() - CA_Log(logLevel_Debug, "Chat Additions: Core initialized!") + CA_Log(logLevel_Debug, "Chat Additions: Core initialized!") - set_task_ex(6.274, "_OnConfigsExecuted") + set_task_ex(6.274, "_OnConfigsExecuted") } public plugin_end() { - DestroyForward(g_fwdClientSay) - DestroyForward(g_fwdClientVoice) - DestroyForward(g_fwdClientChangeName) + DestroyForward(g_fwdClientSay) + DestroyForward(g_fwdClientVoice) + DestroyForward(g_fwdClientChangeName) } public _OnConfigsExecuted() { - CheckUpdate() + CheckUpdate() } CheckAutoDelete() { - if(ca_log_autodelete_time > 0) { - if(dir_exists(g_logsPath)) { - new logFile[PLATFORM_MAX_PATH] - new dirHandle - new subDirectory[PLATFORM_MAX_PATH] - new deleteTime + if (ca_log_autodelete_time > 0) { + if (dir_exists(g_logsPath)) { + new logFile[PLATFORM_MAX_PATH] + new dirHandle + new subDirectory[PLATFORM_MAX_PATH] + new deleteTime - deleteTime = get_systime() - (ca_log_autodelete_time * 60 * 60 * 24) + deleteTime = get_systime() - (ca_log_autodelete_time * 60 * 60 * 24) - dirHandle = open_dir(g_logsPath, logFile, charsmax(logFile)) + dirHandle = open_dir(g_logsPath, logFile, charsmax(logFile)) - if(dirHandle) { - while(next_file(dirHandle, logFile, charsmax(logFile))) { - if(logFile[0] == '.') - continue + if (dirHandle) { + while (next_file(dirHandle, logFile, charsmax(logFile))) { + if (logFile[0] == '.') + continue - if(containi(logFile, ".log") == -1) { - formatex(subDirectory, charsmax(subDirectory), "%s/%s", g_logsPath, logFile) + if (containi(logFile, ".log") == -1) { + formatex(subDirectory, charsmax(subDirectory), "%s/%s", g_logsPath, logFile) - ReadFolder(deleteTime, subDirectory) + ReadFolder(deleteTime, subDirectory) - continue - } + continue + } + } + close_dir(dirHandle) + } } - close_dir(dirHandle) - } } - } } ReadFolder(deleteTime, logPath[]) { - new logFile[PLATFORM_MAX_PATH] - new dirHandle = open_dir(logPath, logFile, charsmax(logFile)) - new fileTime - - if(dirHandle) { - do - { - if(logFile[0] == '.') { - continue - } - - if(containi(logFile, ".log") != -1) { - fileTime = 0 - format(logFile, charsmax(logFile), "%s/%s", logPath, logFile) - - fileTime = GetFileTime(logFile, FileTime_Created) - if(fileTime < deleteTime) { - unlink(logFile) - } - } - } while(next_file(dirHandle, logFile, charsmax(logFile))) - } - close_dir(dirHandle) + new logFile[PLATFORM_MAX_PATH] + new dirHandle = open_dir(logPath, logFile, charsmax(logFile)) + new fileTime + + if (dirHandle) { + do + { + if (logFile[0] == '.') { + continue + } + + if (containi(logFile, ".log") != -1) { + fileTime = 0 + format(logFile, charsmax(logFile), "%s/%s", logPath, logFile) + + fileTime = GetFileTime(logFile, FileTime_Created) + if (fileTime < deleteTime) { + unlink(logFile) + } + } + } while (next_file(dirHandle, logFile, charsmax(logFile))) + } + close_dir(dirHandle) } Create_CVars() { - bind_pcvar_num(create_cvar("ca_log_type", "1", - .description = fmt("Log file type\n \ - 0 = log to common amxx log file (logs/L*.log)\n \ - 1 = log to plugins folder (logs/%s/[plugin name]/L*.log)\n \ - 2 = silent log to plugins folder (logs/%s/[plugin name]/L*.log)", LOG_FOLDER, LOG_FOLDER), - .has_min = true, .min_val = 0.0, - .has_max = true, .max_val = float(_LogToDirSilent) - ), - ca_log_type - ) - - bind_pcvar_num(create_cvar("ca_log_level", "1", - .description = "Log level\n 0 = disable logs\n 1 = add info messages logs\n 2 = add warinigs info\n 3 = add debug messages", - .has_min = true, .min_val = 0.0, - .has_max = true, .max_val = float(logLevel_Debug) - ), - ca_log_level - ) - - bind_pcvar_num(create_cvar("ca_update_notify", "1", - .description = "Enable update check?\n 0 = disable update checks", - .has_min = true, .min_val = 0.0, - .has_max = true, .max_val = 1.0 - ), - ca_update_notify - ) - - bind_pcvar_num(create_cvar("ca_log_autodelete_time", "7", - .description = "The time in days after which the log files should be deleted.\n \ - 0 - The logs won't be deleted.\n \ - > 0 - The logs will be deleted at the time inserted.", - .has_min = true, .min_val = 0.0 - ), - ca_log_autodelete_time - ) + bind_pcvar_num(create_cvar("ca_log_type", "1", + .description = fmt("Log file type^n \ + 0 = log to common amxx log file (logs/L*.log)^n \ + 1 = log to plugins folder (logs/%s/[plugin name]/L*.log)^n \ + 2 = silent log to plugins folder (logs/%s/[plugin name]/L*.log)", LOG_FOLDER, LOG_FOLDER), + .has_min = true, .min_val = 0.0, + .has_max = true, .max_val = float(_LogToDirSilent) + ), + ca_log_type + ) + + bind_pcvar_num(create_cvar("ca_log_level", "1", + .description = "Log level^n 0 = disable logs^n 1 = add info messages logs^n 2 = add warinigs info^n 3 = add debug messages", + .has_min = true, .min_val = 0.0, + .has_max = true, .max_val = float(logLevel_Debug) + ), + ca_log_level + ) + + bind_pcvar_num(create_cvar("ca_update_notify", "1", + .description = "Enable update check?^n 0 = disable update checks", + .has_min = true, .min_val = 0.0, + .has_max = true, .max_val = 1.0 + ), + ca_update_notify + ) + + bind_pcvar_num(create_cvar("ca_log_autodelete_time", "7", + .description = "The time in days after which the log files should be deleted.^n \ + 0 - The logs won't be deleted.^n \ + > 0 - The logs will be deleted at the time inserted.", + .has_min = true, .min_val = 0.0 + ), + ca_log_autodelete_time + ) } public plugin_natives() { - register_library("ChatAdditions_Core") + register_library("ChatAdditions_Core") - set_module_filter("ModuleFilter") - set_native_filter("NativeFilter") + set_module_filter("ModuleFilter") + set_native_filter("NativeFilter") - register_native("CA_Log", "native_CA_Log") - register_native("CA_PlayerHasBlockedPlayer", "native_CA_PlayerHasBlockedPlayer") + register_native("CA_Log", "native_CA_Log") + register_native("CA_PlayerHasBlockedPlayer", "native_CA_PlayerHasBlockedPlayer") } public ModuleFilter(const library[], LibType: type) { - return strcmp("grip", library) == 0 ? PLUGIN_HANDLED : PLUGIN_CONTINUE + return strcmp("grip", library) == 0 ? PLUGIN_HANDLED : PLUGIN_CONTINUE } public NativeFilter(const nativeName[], index, trap) { - return strncmp(nativeName, "grip_", 5) == 0 ? PLUGIN_HANDLED : PLUGIN_CONTINUE + return strncmp(nativeName, "grip_", 5) == 0 ? PLUGIN_HANDLED : PLUGIN_CONTINUE } public ClCmd_Say(const id) { - static message[CA_MAX_MESSAGE_SIZE] - read_argv(0, message, charsmax(message)) - new isTeamMessage = (message[3] == '_') - read_args(message, charsmax(message)) - remove_quotes(message) + static message[CA_MAX_MESSAGE_SIZE] + read_argv(0, message, charsmax(message)) + new isTeamMessage = (message[3] == '_') + read_args(message, charsmax(message)) + remove_quotes(message) - ExecuteForward(g_fwdClientSay, g_retVal, id, isTeamMessage, message) + ExecuteForward(g_fwdClientSay, g_retVal, id, isTeamMessage, message) - return (g_retVal == CA_SUPERCEDE) ? PLUGIN_HANDLED : PLUGIN_CONTINUE + return (g_retVal == CA_SUPERCEDE) ? PLUGIN_HANDLED : PLUGIN_CONTINUE } public Voice_SetClientListening_Pre(const receiver, const sender, bool: canListen) { - if(receiver == sender) - return FMRES_IGNORED + if (receiver == sender) + return FMRES_IGNORED - if(!g_PlayerModEnable[receiver]) - return FMRES_IGNORED + if (!g_PlayerModEnable[receiver]) + return FMRES_IGNORED - if (!is_user_connected(receiver) || !is_user_connected(sender)) - return FMRES_IGNORED + if (!is_user_connected(receiver) || !is_user_connected(sender)) + return FMRES_IGNORED - ExecuteForward(g_fwdClientVoice, g_retVal, receiver, sender) - if(g_retVal != CA_SUPERCEDE) - return FMRES_IGNORED + ExecuteForward(g_fwdClientVoice, g_retVal, receiver, sender) + if (g_retVal != CA_SUPERCEDE) + return FMRES_IGNORED - // Block voice - engfunc(EngFunc_SetClientListening, receiver, sender, (canListen = false)) - return FMRES_SUPERCEDE + // Block voice + engfunc(EngFunc_SetClientListening, receiver, sender, (canListen = false)) + return FMRES_SUPERCEDE } public ClientUserInfoChanged_Pre(const player, const infobuffer) { - new currentName[32] - get_user_name(player, currentName, charsmax(currentName)) + new currentName[32] + get_user_name(player, currentName, charsmax(currentName)) - new newName[32] - engfunc(EngFunc_InfoKeyValue, infobuffer, "name", newName, charsmax(newName)) + new newName[32] + engfunc(EngFunc_InfoKeyValue, infobuffer, "name", newName, charsmax(newName)) - if(strcmp(currentName, newName) == 0) - return + if (strcmp(currentName, newName) == 0) + return - ExecuteForward(g_fwdClientChangeName, g_retVal, player, newName) - if(g_retVal != CA_SUPERCEDE) - return + ExecuteForward(g_fwdClientChangeName, g_retVal, player, newName) + if (g_retVal != CA_SUPERCEDE) + return - // Change back name - engfunc(EngFunc_SetClientKeyValue, player, infobuffer, "name", currentName) + // Change back name + engfunc(EngFunc_SetClientKeyValue, player, infobuffer, "name", currentName) } public ClCmd_VModEnable(const id) { - if(read_argc() < 2) { - return - } + if (read_argc() < 2) { + return + } - new arg[32]; read_argv(1, arg, charsmax(arg)) - g_PlayerModEnable[id] = bool: (strtol(arg) != 0) + new arg[32]; read_argv(1, arg, charsmax(arg)) + g_PlayerModEnable[id] = bool: (strtol(arg) != 0) } public ClCmd_vban(const id) { - if(read_argc() < 2) { - return - } + if (read_argc() < 2) { + return + } - new arg[32]; read_argv(1, arg, charsmax(arg)) - g_BanMasks[id] = strtol(arg, .base = 16) + new arg[32]; read_argv(1, arg, charsmax(arg)) + g_BanMasks[id] = strtol(arg, .base = 16) } public bool: native_CA_Log(const plugin_id, const argc) { - enum { arg_level = 1, arg_msg, arg_format } + enum { arg_level = 1, arg_msg, arg_format } - new logLevel_s: level = logLevel_s: get_param(arg_level) + new logLevel_s: level = logLevel_s: get_param(arg_level) - if(ca_log_level < level) { - return false - } + if (ca_log_level < level) { + return false + } - new msg[2048] - vdformat(msg, charsmax(msg), arg_msg, arg_format) + new msg[2048] + vdformat(msg, charsmax(msg), arg_msg, arg_format) - new logsFile[PLATFORM_MAX_PATH] + new logsFile[PLATFORM_MAX_PATH] - if(ca_log_type > _Default) - { - new pluginName[32] - get_plugin(plugin_id, pluginName, charsmax(pluginName)) + if (ca_log_type > _Default) + { + new pluginName[32] + get_plugin(plugin_id, pluginName, charsmax(pluginName)) - replace(pluginName, charsmax(pluginName), ".amxx", "") + replace(pluginName, charsmax(pluginName), ".amxx", "") - new logsPath[PLATFORM_MAX_PATH] - formatex(logsPath, charsmax(logsPath), "%s/%s", g_logsPath, pluginName) + new logsPath[PLATFORM_MAX_PATH] + formatex(logsPath, charsmax(logsPath), "%s/%s", g_logsPath, pluginName) - if(!dir_exists(logsPath)) { - mkdir(logsPath) - } + if (!dir_exists(logsPath)) { + mkdir(logsPath) + } - new year, month, day - date(year, month, day) + new year, month, day + date(year, month, day) - formatex(logsFile, charsmax(logsFile), "%s/%s__%i-%02i-%02i.log", logsPath, pluginName, year, month, day) - } + formatex(logsFile, charsmax(logsFile), "%s/%s__%i-%02i-%02i.log", logsPath, pluginName, year, month, day) + } - switch(ca_log_type) { - case _LogToDir: log_to_file(logsFile, msg) - case _Default: log_amx(msg) - case _LogToDirSilent: log_to_file_ex(logsFile, msg) - } + switch (ca_log_type) { + case _LogToDir: log_to_file(logsFile, msg) + case _Default: log_amx(msg) + case _LogToDirSilent: log_to_file_ex(logsFile, msg) + } - return true + return true } public bool: native_CA_PlayerHasBlockedPlayer(const plugin_id, const argc) { - enum { arg_receiver = 1, arg_sender } + enum { arg_receiver = 1, arg_sender } - new receiver = get_param(arg_receiver) - new sender = get_param(arg_sender) + new receiver = get_param(arg_receiver) + new sender = get_param(arg_sender) - if(CVoiceGameMgr__PlayerHasBlockedPlayer(receiver, sender)) { - return true - } + if (CVoiceGameMgr__PlayerHasBlockedPlayer(receiver, sender)) { + return true + } - return false + return false } static GetLogsFilePath(buffer[], len = PLATFORM_MAX_PATH, const dir[] = "ChatAdditions") { - get_localinfo("amxx_logs", buffer, len) - strcat(buffer, fmt("/%s", dir), len) + get_localinfo("amxx_logs", buffer, len) + strcat(buffer, fmt("/%s", dir), len) - if(!dir_exists(buffer) && mkdir(buffer) == -1) { - set_fail_state("[Core API] Can't create folder! (%s)", buffer) - } + if (!dir_exists(buffer) && mkdir(buffer) == -1) { + set_fail_state("[Core API] Can't create folder! (%s)", buffer) + } } static bool: CVoiceGameMgr__PlayerHasBlockedPlayer(const receiver, const sender) { - #define CanPlayerHearPlayer(%0,%1) ( ~g_BanMasks[%0] & ( 1 << (%1 - 1) ) ) + #define CanPlayerHearPlayer(%0,%1) ( ~g_BanMasks[%0] & ( 1 << (%1 - 1) ) ) - if(receiver <= 0 || receiver > MaxClients || sender <= 0 || sender > MaxClients) { - return false - } + if (receiver <= 0 || receiver > MaxClients || sender <= 0 || sender > MaxClients) { + return false + } - return bool: !CanPlayerHearPlayer(receiver, sender) + return bool: !CanPlayerHearPlayer(receiver, sender) } static CheckUpdate() { - if(!ca_update_notify) - return + if (!ca_update_notify) + return - if(strcmp(CA_VERSION, "CA_VERSION") == 0 || contain(CA_VERSION, ".") == -1) // ignore custom builds - return + if (strcmp(CA_VERSION, "CA_VERSION") == 0 || contain(CA_VERSION, ".") == -1) // ignore custom builds + return - if(is_module_loaded("grip") == -1) { - CA_Log(logLevel_Warning, "The `GRip` module is not loaded! The new version cannot be verified.") - CA_Log(logLevel_Warning, "Please install GRip: `https://github.com/In-line/grip` or disable update checks (`ca_update_notify `0`).") + if (is_module_loaded("grip") == -1) { + CA_Log(logLevel_Warning, "The `GRip` module is not loaded! The new version cannot be verified.") + CA_Log(logLevel_Warning, "Please install GRip: `https://github.com/In-line/grip` or disable update checks (`ca_update_notify `0`).") - return - } + return + } - RequestNewVersion(g_versionLink) + RequestNewVersion(g_versionLink) } static RequestNewVersion(const link[]) { - new GripRequestOptions: options = grip_create_default_options() - new GripBody: body = grip_body_from_string("") - - grip_request( - link, - body, - GripRequestTypeGet, - "@RequestHandler", - options - ) - - grip_destroy_body(body) - grip_destroy_options(options) + new GripRequestOptions: options = grip_create_default_options() + new GripBody: body = grip_body_from_string("") + + grip_request( + link, + body, + GripRequestTypeGet, + "@RequestHandler", + options + ) + + grip_destroy_body(body) + grip_destroy_options(options) } @RequestHandler() { - new response[8192] - grip_get_response_body_string(response, charsmax(response)) + new response[8192] + grip_get_response_body_string(response, charsmax(response)) - if(contain(response, "tag_name") == -1) { - CA_Log(logLevel_Warning, " > Wrong response! (don't contain `tag_name`). res=`%s`", response) - return - } + if (contain(response, "tag_name") == -1) { + CA_Log(logLevel_Warning, " > Wrong response! (don't contain `tag_name`). res=`%s`", response) + return + } - static errorBuffer[1024] - new GripJSONValue: json = grip_json_parse_string(response, errorBuffer, charsmax(errorBuffer)) + static errorBuffer[1024] + new GripJSONValue: json = grip_json_parse_string(response, errorBuffer, charsmax(errorBuffer)) - if(json == Invalid_GripJSONValue) { - CA_Log(logLevel_Warning, " > Can't parse response JSON! (error=`%s`)", errorBuffer) - goto END - } + if (json == Invalid_GripJSONValue) { + CA_Log(logLevel_Warning, " > Can't parse response JSON! (error=`%s`)", errorBuffer) + goto END + } - new tag_name[32] - grip_json_object_get_string(json, "tag_name", tag_name, charsmax(tag_name)) + new tag_name[32] + grip_json_object_get_string(json, "tag_name", tag_name, charsmax(tag_name)) - if(CmpVersions(CA_VERSION, tag_name) >= 0) - goto END + if (CmpVersions(CA_VERSION, tag_name) >= 0) + goto END - new html_url[256] - grip_json_object_get_string(json, "html_url", html_url, charsmax(html_url)) + new html_url[256] + grip_json_object_get_string(json, "html_url", html_url, charsmax(html_url)) - NotifyUpdate(tag_name, html_url) + NotifyUpdate(tag_name, html_url) - END: - grip_destroy_json_value(json) + END: + grip_destroy_json_value(json) } static NotifyUpdate(const newVersion[], const URL[]) { - CA_Log(logLevel_Info, "\n\t ChatAdditions (%s) has update! New version `%s`.\n\ - Download link: `%s`", CA_VERSION, newVersion, URL - ) + CA_Log(logLevel_Info, "^n^t ChatAdditions (%s) has update! New version `%s`.^n\ + Download link: `%s`", CA_VERSION, newVersion, URL + ) } static stock CmpVersions(const a[], const b[]) { - new segmentsA[32][32] - new segmentsB[32][32] - - new countA = explode_string( - a[!isdigit(a[0]) ? 1 : 0], - ".", - segmentsA, sizeof segmentsA, charsmax(segmentsA[]) - ) - - new countB = explode_string( - b[!isdigit(b[0]) ? 1 : 0], - ".", - segmentsB, sizeof segmentsB, charsmax(segmentsB[]) - ) - - for(new i, l = min(countA, countB); i < l; i++) { - new diff = strtol(segmentsA[i]) - strtol(segmentsB[i]) - if(diff) - return diff - } - - return countA - countB + new segmentsA[32][32] + new segmentsB[32][32] + + new countA = explode_string( + a[!isdigit(a[0]) ? 1 : 0], + ".", + segmentsA, sizeof segmentsA, charsmax(segmentsA[]) + ) + + new countB = explode_string( + b[!isdigit(b[0]) ? 1 : 0], + ".", + segmentsB, sizeof segmentsB, charsmax(segmentsB[]) + ) + + for(new i, l = min(countA, countB); i < l; i++) { + new diff = strtol(segmentsA[i]) - strtol(segmentsB[i]) + if (diff) + return diff + } + + return countA - countB } stock log_to_file_ex(const filePath[], message[]) { - new file - new bool:firstTime = true - new date[32] + new file + new bool:firstTime = true + new date[32] - format_time(date, charsmax(date), "%m/%d/%Y - %H:%M:%S") - static modName[15], amxVersion[15] + format_time(date, charsmax(date), "%m/%d/%Y - %H:%M:%S") + static modName[15], amxVersion[15] - if(!modName[0]) { - get_modname(modName, charsmax(modName)) - } + if (!modName[0]) { + get_modname(modName, charsmax(modName)) + } - if(!amxVersion[0]) { - get_amxx_verstring(amxVersion, charsmax(amxVersion)) - } + if (!amxVersion[0]) { + get_amxx_verstring(amxVersion, charsmax(amxVersion)) + } - if((file = fopen(filePath, "r"))) { - firstTime = false - fclose(file) - } + if ((file = fopen(filePath, "r"))) { + firstTime = false + fclose(file) + } - if(!(file = fopen(filePath, "at"))) { - log_error(AMX_ERR_GENERAL, "Can't open \"%s\" file for writing.", filePath) - return PLUGIN_CONTINUE - } + if (!(file = fopen(filePath, "at"))) { + log_error(AMX_ERR_GENERAL, "Can't open ^"%s^" file for writing.", filePath) + return PLUGIN_CONTINUE + } - if(firstTime) { - fprintf(file, "L %s: Log file started (file \"%s\") (game \"%s\") (amx \"%s\")\n", date, filePath, modName, amxVersion) - } + if (firstTime) { + fprintf(file, "L %s: Log file started (file ^"%s^") (game ^"%s^") (amx ^"%s^")^n", date, filePath, modName, amxVersion) + } - fprintf(file, "L %s: %s\n", date, message) + fprintf(file, "L %s: %s^n", date, message) - fclose(file) + fclose(file) - return PLUGIN_HANDLED + return PLUGIN_HANDLED } diff --git a/cstrike/addons/amxmodx/scripting/include/CA_GAG_API.inc b/cstrike/addons/amxmodx/scripting/include/CA_GAG_API.inc index 20ac22d..fcc0ddd 100644 --- a/cstrike/addons/amxmodx/scripting/include/CA_GAG_API.inc +++ b/cstrike/addons/amxmodx/scripting/include/CA_GAG_API.inc @@ -5,125 +5,125 @@ */ #if defined _CA_GAG_API_included - #endinput + #endinput #endif #define _CA_GAG_API_included enum any: gag_flags_s ( <<=1 ) { - gagFlag_Removed = 0, - gagFlag_Say = 1, // a - gagFlag_SayTeam, // b - gagFlag_Voice // c + gagFlag_Removed = 0, + gagFlag_Say = 1, // a + gagFlag_SayTeam, // b + gagFlag_Voice // c } -const MAX_REASON_LEN = 128; -const MAX_WHITELIST_CMD_LEN = 32; +const MAX_REASON_LEN = 128 +const MAX_WHITELIST_CMD_LEN = 32 enum reason_s { - r_name[MAX_REASON_LEN], - r_time, - gag_flags_s: r_flags + r_name[MAX_REASON_LEN], + r_time, + gag_flags_s: r_flags } enum gagData_s { - gd_target, - gd_name[MAX_NAME_LENGTH], - gd_authID[MAX_AUTHID_LENGTH], - gd_IP[MAX_IP_LENGTH], - - gd_admin, - gd_adminName[MAX_NAME_LENGTH], - gd_adminAuthID[MAX_AUTHID_LENGTH], - gd_adminIP[MAX_IP_LENGTH], - - gd_reason[reason_s], - gd_expireAt + gd_target, + gd_name[MAX_NAME_LENGTH], + gd_authID[MAX_AUTHID_LENGTH], + gd_IP[MAX_IP_LENGTH], + + gd_admin, + gd_adminName[MAX_NAME_LENGTH], + gd_adminAuthID[MAX_AUTHID_LENGTH], + gd_adminIP[MAX_IP_LENGTH], + + gd_reason[reason_s], + gd_expireAt } stock gag_flags_s: flags_to_bit(const flagsStr[]) { - new gag_flags_s: bits = gagFlag_Removed; + new gag_flags_s: bits = gagFlag_Removed - if(containi(flagsStr, "a") != -1) bits |= gagFlag_Say; - if(containi(flagsStr, "b") != -1) bits |= gagFlag_SayTeam; - if(containi(flagsStr, "c") != -1) bits |= gagFlag_Voice; + if (containi(flagsStr, "a") != -1) bits |= gagFlag_Say + if (containi(flagsStr, "b") != -1) bits |= gagFlag_SayTeam + if (containi(flagsStr, "c") != -1) bits |= gagFlag_Voice - return bits; + return bits } stock bits_to_flags(const gag_flags_s: bits) { - new flagsStr[4]; - if(bits & gagFlag_Say) add(flagsStr, charsmax(flagsStr), "a"); - if(bits & gagFlag_SayTeam) add(flagsStr, charsmax(flagsStr), "b"); - if(bits & gagFlag_Voice) add(flagsStr, charsmax(flagsStr), "c"); + new flagsStr[4] + if (bits & gagFlag_Say) add(flagsStr, charsmax(flagsStr), "a") + if (bits & gagFlag_SayTeam) add(flagsStr, charsmax(flagsStr), "b") + if (bits & gagFlag_Voice) add(flagsStr, charsmax(flagsStr), "c") - return flagsStr; + return flagsStr } stock GagData_Reset(gagData[gagData_s]) { - gagData[gd_target] = 0; - gagData[gd_name][0] = EOS; - gagData[gd_authID][0] = EOS; - gagData[gd_IP][0] = EOS; + gagData[gd_target] = 0 + gagData[gd_name][0] = EOS + gagData[gd_authID][0] = EOS + gagData[gd_IP][0] = EOS - gagData[gd_admin] = 0; - gagData[gd_adminName][0] = EOS; - gagData[gd_adminAuthID][0] = EOS; - gagData[gd_adminIP][0] = EOS; + gagData[gd_admin] = 0 + gagData[gd_adminName][0] = EOS + gagData[gd_adminAuthID][0] = EOS + gagData[gd_adminIP][0] = EOS - gagData[gd_reason][r_name][0] = EOS; - gagData[gd_reason][r_time] = 0; - gagData[gd_reason][r_flags] = gagFlag_Removed; + gagData[gd_reason][r_name][0] = EOS + gagData[gd_reason][r_time] = 0 + gagData[gd_reason][r_flags] = gagFlag_Removed - gagData[gd_expireAt] = 0; + gagData[gd_expireAt] = 0 } stock GagData_Copy(to[gagData_s], const from[gagData_s]) { - to[gd_target] = from[gd_target]; - copy(to[gd_name], charsmax(to[gd_name]), from[gd_name]); - copy(to[gd_authID], charsmax(to[gd_authID]), from[gd_authID]); - copy(to[gd_IP], charsmax(to[gd_IP]), from[gd_IP]); + to[gd_target] = from[gd_target] + copy(to[gd_name], charsmax(to[gd_name]), from[gd_name]) + copy(to[gd_authID], charsmax(to[gd_authID]), from[gd_authID]) + copy(to[gd_IP], charsmax(to[gd_IP]), from[gd_IP]) - to[gd_admin] = from[gd_admin]; - copy(to[gd_adminName], charsmax(to[gd_adminName]), from[gd_adminName]); - copy(to[gd_adminAuthID], charsmax(to[gd_adminAuthID]), from[gd_adminAuthID]); - copy(to[gd_adminIP], charsmax(to[gd_adminIP]), from[gd_adminIP]); + to[gd_admin] = from[gd_admin] + copy(to[gd_adminName], charsmax(to[gd_adminName]), from[gd_adminName]) + copy(to[gd_adminAuthID], charsmax(to[gd_adminAuthID]), from[gd_adminAuthID]) + copy(to[gd_adminIP], charsmax(to[gd_adminIP]), from[gd_adminIP]) - copy(to[gd_reason][r_name], charsmax(to[r_name]), from[gd_reason][r_name]) - to[gd_reason][r_time] = from[gd_reason][r_time] - to[gd_reason][r_flags] = from[gd_reason][r_flags] + copy(to[gd_reason][r_name], charsmax(to[r_name]), from[gd_reason][r_name]) + to[gd_reason][r_time] = from[gd_reason][r_time] + to[gd_reason][r_flags] = from[gd_reason][r_flags] - to[gd_expireAt] = from[gd_expireAt]; + to[gd_expireAt] = from[gd_expireAt] } stock bool: GagData_IsEqual(const arr1[gagData_s], const arr2[gagData_s]) { - if(arr1[gd_reason][r_time] != arr2[gd_reason][r_time]) { - return false; - } + if (arr1[gd_reason][r_time] != arr2[gd_reason][r_time]) { + return false + } - if(arr1[gd_reason][r_flags] != arr2[gd_reason][r_flags]) { - return false; - } + if (arr1[gd_reason][r_flags] != arr2[gd_reason][r_flags]) { + return false + } - if(strcmp(arr1[gd_reason][r_name], arr2[gd_reason][r_name]) != 0) { - return false; - } + if (strcmp(arr1[gd_reason][r_name], arr2[gd_reason][r_name]) != 0) { + return false + } - return true; + return true } stock GagData_GetPersonalData(const admin = 0, const target, buffer[gagData_s]) { - // get's target data - buffer[gd_target] = target; - get_user_name(target, buffer[gd_name], charsmax(buffer[gd_name])); - get_user_authid(target, buffer[gd_authID], charsmax(buffer[gd_authID])); - get_user_ip(target, buffer[gd_IP], charsmax(buffer[gd_IP]), .without_port = true); - - // get's admin data - buffer[gd_admin] = admin; - get_user_name(admin, buffer[gd_adminName], charsmax(buffer[gd_adminName])); - get_user_authid(admin, buffer[gd_adminAuthID], charsmax(buffer[gd_adminAuthID])); - get_user_ip(admin, buffer[gd_adminIP], charsmax(buffer[gd_adminIP]), .without_port = true); + // get's target data + buffer[gd_target] = target + get_user_name(target, buffer[gd_name], charsmax(buffer[gd_name])) + get_user_authid(target, buffer[gd_authID], charsmax(buffer[gd_authID])) + get_user_ip(target, buffer[gd_IP], charsmax(buffer[gd_IP]), .without_port = true) + + // get's admin data + buffer[gd_admin] = admin + get_user_name(admin, buffer[gd_adminName], charsmax(buffer[gd_adminName])) + get_user_authid(admin, buffer[gd_adminAuthID], charsmax(buffer[gd_adminAuthID])) + get_user_ip(admin, buffer[gd_adminIP], charsmax(buffer[gd_adminIP]), .without_port = true) } @@ -143,7 +143,7 @@ stock GagData_GetPersonalData(const admin = 0, const target, buffer[gagData_s]) * MaxClients, or the client is not connected, an error * will be thrown. */ -native bool: ca_set_user_gag(const index, const reason[], const minutes, const gag_flags_s: flags); +native bool: ca_set_user_gag(const index, const reason[], const minutes, const gag_flags_s: flags) /** * Get client's gag data. @@ -158,7 +158,7 @@ native bool: ca_set_user_gag(const index, const reason[], const minutes, const g * MaxClients, or the client is not connected, an error * will be thrown. */ -native bool: ca_get_user_gag(const index, reason[], &minutes, &gag_flags_s: flags); +native bool: ca_get_user_gag(const index, reason[], &minutes, &gag_flags_s: flags) /** * Has client gag? @@ -170,7 +170,7 @@ native bool: ca_get_user_gag(const index, reason[], &minutes, &gag_flags_s: flag * MaxClients, or the client is not connected, an error * will be thrown. */ -native bool: ca_has_user_gag(const index); +native bool: ca_has_user_gag(const index) /** * Remove client's gag data.. @@ -183,7 +183,7 @@ native bool: ca_has_user_gag(const index); * MaxClients, or the client is not connected, an error * will be thrown. */ -native bool: ca_remove_user_gag(const target, admin = 0); +native bool: ca_remove_user_gag(const target, admin = 0) /** * Called on Gag save. @@ -203,10 +203,10 @@ native bool: ca_remove_user_gag(const target, admin = 0); * @return Return CA_SUPERCEDE for prevent Gag. */ forward CA_gag_setted( - const target, name[], authID[], IP[], - adminName[], adminAuthID[], adminIP[], - reason[], time, gag_flags_s: flags, - expireAt); + const target, name[], authID[], IP[], + adminName[], adminAuthID[], adminIP[], + reason[], time, gag_flags_s: flags, + expireAt) /** * Called on gag remove action. @@ -218,4 +218,4 @@ forward CA_gag_setted( * * @return Return CA_SUPERCEDE for prevent Gag remove. */ -forward CA_gag_removed(const target, reason[], minutes, gag_flags_s: flags); +forward CA_gag_removed(const target, reason[], minutes, gag_flags_s: flags) diff --git a/cstrike/addons/amxmodx/scripting/include/CA_StorageAPI.inc b/cstrike/addons/amxmodx/scripting/include/CA_StorageAPI.inc index 49d7572..e379f1b 100644 --- a/cstrike/addons/amxmodx/scripting/include/CA_StorageAPI.inc +++ b/cstrike/addons/amxmodx/scripting/include/CA_StorageAPI.inc @@ -1,5 +1,5 @@ #if defined _CA_STORAGE_API_included - #endinput + #endinput #endif #define _CA_STORAGE_API_included @@ -7,39 +7,39 @@ /* * */ -native CA_Storage_Save(const name[], const authID[], const IP[], const reason[], const adminName[], const adminAuthID[], const adminIP[], const expireAt, const flags); +native CA_Storage_Save(const name[], const authID[], const IP[], const reason[], const adminName[], const adminAuthID[], const adminIP[], const expireAt, const flags) /* * */ -native CA_Storage_Load(const authID[]); +native CA_Storage_Load(const authID[]) /* * */ -native CA_Storage_Remove(const authID[]); +native CA_Storage_Remove(const authID[]) /* * */ -forward CA_Storage_Initialized(); +forward CA_Storage_Initialized() /* * */ forward CA_Storage_Saved(const name[], const authID[], const IP[], const reason[], - const adminName[], const adminAuthID[], const adminIP[], - const createdAt, const expireAt, const flags); + const adminName[], const adminAuthID[], const adminIP[], + const createdAt, const expireAt, const flags) /* * */ forward CA_Storage_Loaded(const name[], const authID[], const IP[], const reason[], - const adminName[], const adminAuthID[], const adminIP[], - const createdAt, const expireAt, const flags); + const adminName[], const adminAuthID[], const adminIP[], + const createdAt, const expireAt, const flags) /* * */ -forward CA_Storage_Removed(); +forward CA_Storage_Removed() diff --git a/cstrike/addons/amxmodx/scripting/include/CA_StorageAPI_endpoint.inc b/cstrike/addons/amxmodx/scripting/include/CA_StorageAPI_endpoint.inc index 63d69ab..ec9420a 100644 --- a/cstrike/addons/amxmodx/scripting/include/CA_StorageAPI_endpoint.inc +++ b/cstrike/addons/amxmodx/scripting/include/CA_StorageAPI_endpoint.inc @@ -1,5 +1,5 @@ #if defined _CA_STORAGE_API_ENDPOINT_included - #endinput + #endinput #endif #define _CA_STORAGE_API_ENDPOINT_included @@ -9,119 +9,119 @@ new bool: g_storageInitialized stock bool: IsSQLQueryFailed(const failstate, const Handle: query, const error[], const errNum) { - switch(failstate) { - case TQUERY_CONNECT_FAILED: { - log_amx("SQL: connection failed [%i] `%s`", errNum, error) - return true + switch (failstate) { + case TQUERY_CONNECT_FAILED: { + log_amx("SQL: connection failed [%i] `%s`", errNum, error) + return true + } + case TQUERY_QUERY_FAILED: { + log_amx("SQL: query failed [%i] %s", errNum, error) + + server_print("^n^n ===> Query:") + new buffer[8192]; SQL_GetQueryString(query, buffer, charsmax(buffer)) + for(new i, len = strlen(buffer); i < len; i+=255) { + server_print(fmt("%-255s", buffer[i])) + } + + return true + } } - case TQUERY_QUERY_FAILED: { - log_amx("SQL: query failed [%i] %s", errNum, error); - server_print("^n^n ===> Query:") - new buffer[8192]; SQL_GetQueryString(query, buffer, charsmax(buffer)); - for(new i, len = strlen(buffer); i < len; i+=255) { - server_print(fmt("%-255s", buffer[i])); - } - - return true - } - } - - return false + return false } // Should be realized in each storage RegisterNatives() { - register_native("CA_Storage_Save", "native_Storage_Save"); - register_native("CA_Storage_Load", "native_Storage_Load"); - register_native("CA_Storage_Remove", "native_Storage_Remove"); - register_native("CA_Storage_IsInitialized", "native_Storage_IsInitialized"); + register_native("CA_Storage_Save", "native_Storage_Save") + register_native("CA_Storage_Load", "native_Storage_Load") + register_native("CA_Storage_Remove", "native_Storage_Remove") + register_native("CA_Storage_IsInitialized", "native_Storage_IsInitialized") } public native_Storage_Save(const plugin_id, const argc) { - enum { arg_name = 1, arg_authID, arg_IP, arg_reason, arg_adminName, arg_adminAuthID, arg_adminIP, arg_expireAt, arg_flags } - - new name[MAX_NAME_LENGTH]; get_string(arg_name, name, charsmax(name)); - new authID[MAX_AUTHID_LENGTH]; get_string(arg_authID, authID, charsmax(authID)); - new IP[MAX_IP_LENGTH]; get_string(arg_IP, IP, charsmax(IP)); - new reason[256]; get_string(arg_reason, reason, charsmax(reason)); - new adminName[MAX_NAME_LENGTH]; get_string(arg_adminName, adminName, charsmax(adminName)); - new adminAuthID[MAX_AUTHID_LENGTH]; get_string(arg_adminAuthID, adminAuthID, charsmax(adminAuthID)); - new adminIP[MAX_IP_LENGTH]; get_string(arg_adminIP, adminIP, charsmax(adminIP)); - new expireAt = get_param(arg_expireAt); - new flags = get_param(arg_flags); - - Storage_Save(name, authID, IP, reason, adminName, adminAuthID, adminIP, expireAt, flags); + enum { arg_name = 1, arg_authID, arg_IP, arg_reason, arg_adminName, arg_adminAuthID, arg_adminIP, arg_expireAt, arg_flags } + + new name[MAX_NAME_LENGTH]; get_string(arg_name, name, charsmax(name)) + new authID[MAX_AUTHID_LENGTH]; get_string(arg_authID, authID, charsmax(authID)) + new IP[MAX_IP_LENGTH]; get_string(arg_IP, IP, charsmax(IP)) + new reason[256]; get_string(arg_reason, reason, charsmax(reason)) + new adminName[MAX_NAME_LENGTH]; get_string(arg_adminName, adminName, charsmax(adminName)) + new adminAuthID[MAX_AUTHID_LENGTH]; get_string(arg_adminAuthID, adminAuthID, charsmax(adminAuthID)) + new adminIP[MAX_IP_LENGTH]; get_string(arg_adminIP, adminIP, charsmax(adminIP)) + new expireAt = get_param(arg_expireAt) + new flags = get_param(arg_flags) + + Storage_Save(name, authID, IP, reason, adminName, adminAuthID, adminIP, expireAt, flags) } public native_Storage_Load(const plugin_id, const argc) { - enum { arg_authID = 1 } + enum { arg_authID = 1 } - new authID[MAX_AUTHID_LENGTH]; get_string(arg_authID, authID, charsmax(authID)); - Storage_Load(authID); + new authID[MAX_AUTHID_LENGTH]; get_string(arg_authID, authID, charsmax(authID)) + Storage_Load(authID) } public native_Storage_Remove(const plugin_id, const argc) { - enum { arg_authID = 1 } + enum { arg_authID = 1 } - new authID[MAX_AUTHID_LENGTH]; get_string(arg_authID, authID, charsmax(authID)); - Storage_Remove(authID); + new authID[MAX_AUTHID_LENGTH]; get_string(arg_authID, authID, charsmax(authID)) + Storage_Remove(authID) } public bool: native_Storage_IsInitialized(const plugin_id, const argc) { - return g_storageInitialized; + return g_storageInitialized } // Forwards handlers -new g_fwd_StorageInitialized = INVALID_HANDLE; -new g_fwd_StorageSaved = INVALID_HANDLE; -new g_fwd_StorageLoaded = INVALID_HANDLE; -new g_fwd_StorageRemoved = INVALID_HANDLE; -new g_ret; +new g_fwd_StorageInitialized = INVALID_HANDLE +new g_fwd_StorageSaved = INVALID_HANDLE +new g_fwd_StorageLoaded = INVALID_HANDLE +new g_fwd_StorageRemoved = INVALID_HANDLE +new g_ret // Should be realized in each storage RegisterForwards() { - g_fwd_StorageInitialized = CreateMultiForward("CA_Storage_Initialized", ET_IGNORE); - g_fwd_StorageSaved = CreateMultiForward("CA_Storage_Saved", ET_IGNORE, - FP_STRING, FP_STRING, FP_STRING, FP_STRING, - FP_STRING, FP_STRING, FP_STRING, - FP_CELL, FP_CELL, FP_CELL - ); - g_fwd_StorageLoaded = CreateMultiForward("CA_Storage_Loaded", ET_IGNORE, - FP_STRING, FP_STRING, FP_STRING, FP_STRING, - FP_STRING, FP_STRING, FP_STRING, - FP_CELL, FP_CELL, FP_CELL - ); - g_fwd_StorageRemoved = CreateMultiForward("CA_Storage_Removed", ET_IGNORE); + g_fwd_StorageInitialized = CreateMultiForward("CA_Storage_Initialized", ET_IGNORE) + g_fwd_StorageSaved = CreateMultiForward("CA_Storage_Saved", ET_IGNORE, + FP_STRING, FP_STRING, FP_STRING, FP_STRING, + FP_STRING, FP_STRING, FP_STRING, + FP_CELL, FP_CELL, FP_CELL + ) + g_fwd_StorageLoaded = CreateMultiForward("CA_Storage_Loaded", ET_IGNORE, + FP_STRING, FP_STRING, FP_STRING, FP_STRING, + FP_STRING, FP_STRING, FP_STRING, + FP_CELL, FP_CELL, FP_CELL + ) + g_fwd_StorageRemoved = CreateMultiForward("CA_Storage_Removed", ET_IGNORE) } /* TEST - public CA_Storage_Initialized() { - new name[] = "Some safe name" - new authID[] = "0:1:2345678" - new IP[] = "123.123.123.123" - new reason[] = "Some safe reason" - new adminName[] = "Some safe admin name" - new adminAuthID[] = "Some safe admin authID" - new adminIP[] = "Some safe admin IP" - new expireAt = 1624232019 - new flags = 3 - - CA_Storage_Save(name, authID, IP, reason, adminName, adminAuthID, adminIP, expireAt, flags) - } - public CA_Storage_Saved() { - new authID[] = "0:1:2345678" - CA_Storage_Load(authID) - } - public CA_Storage_Loaded(const name[], const authID[], const IP[], const reason[], - const adminName[], const adminAuthID[], const adminIP[], - const createdAt, const expireAt, const flags) { - log_amx(" > CA_Storage_Loaded{`%s`,`%s`,%s`,`%s`,`%s`,`%s`,`%s`,%i,%i,%i}", - name, authID, reason, IP, - adminName, adminAuthID, adminIP, - createdAt, expireAt, flags) - CA_Storage_Remove(authID) - } - public CA_Storage_Removed() { - - } + public CA_Storage_Initialized() { + new name[] = "Some safe name" + new authID[] = "0:1:2345678" + new IP[] = "123.123.123.123" + new reason[] = "Some safe reason" + new adminName[] = "Some safe admin name" + new adminAuthID[] = "Some safe admin authID" + new adminIP[] = "Some safe admin IP" + new expireAt = 1624232019 + new flags = 3 + + CA_Storage_Save(name, authID, IP, reason, adminName, adminAuthID, adminIP, expireAt, flags) + } + public CA_Storage_Saved() { + new authID[] = "0:1:2345678" + CA_Storage_Load(authID) + } + public CA_Storage_Loaded(const name[], const authID[], const IP[], const reason[], + const adminName[], const adminAuthID[], const adminIP[], + const createdAt, const expireAt, const flags) { + log_amx(" > CA_Storage_Loaded{`%s`,`%s`,%s`,`%s`,`%s`,`%s`,`%s`,%i,%i,%i}", + name, authID, reason, IP, + adminName, adminAuthID, adminIP, + createdAt, expireAt, flags) + CA_Storage_Remove(authID) + } + public CA_Storage_Removed() { + + } */ diff --git a/cstrike/addons/amxmodx/scripting/include/ChatAdditions.inc b/cstrike/addons/amxmodx/scripting/include/ChatAdditions.inc index c94deac..f38c724 100644 --- a/cstrike/addons/amxmodx/scripting/include/ChatAdditions.inc +++ b/cstrike/addons/amxmodx/scripting/include/ChatAdditions.inc @@ -5,18 +5,18 @@ */ #if defined _CA_API_included - #endinput + #endinput #endif #define _CA_API_included #pragma reqlib ChatAdditions_Core #if !defined AMXMODX_NOAUTOLOAD - #pragma loadlib ChatAdditions_Core + #pragma loadlib ChatAdditions_Core #endif #if !defined CA_VERSION - #define CA_VERSION "%CA_VERSION%" + #define CA_VERSION "%CA_VERSION%" #endif const CA_MAX_MESSAGE_SIZE = 188 @@ -26,188 +26,188 @@ const CA_MAX_MESSAGE_SIZE = 188 */ enum { - CA_CONTINUE = 0, // Plugin didn't take any action - CA_SUPERCEDE // Skip real function, use my return value -}; + CA_CONTINUE = 0, // Plugin didn't take any action + CA_SUPERCEDE // Skip real function, use my return value +} #define CHECK_NATIVE_ARGS_NUM(%1,%2,%3) \ - if (%1 < %2) { \ - log_error(AMX_ERR_NATIVE, "Invalid num of arguments %d. Expected %d", %1, %2); \ - return %3; \ - } + if (%1 < %2) { \ + log_error(AMX_ERR_NATIVE, "Invalid num of arguments %d. Expected %d", %1, %2); \ + return %3; \ + } #define CHECK_NATIVE_PLAYER(%1,%2) \ - if (!is_user_connected(%1)) { \ - log_error(AMX_ERR_NATIVE, "Invalid player %d", %1); \ - return %2; \ - } + if (!is_user_connected(%1)) { \ + log_error(AMX_ERR_NATIVE, "Invalid player %d", %1); \ + return %2; \ + } enum logLevel_s { - logLevel_Off = 0, - logLevel_Info = 1, - logLevel_Warning, - logLevel_Debug + logLevel_Off = 0, + logLevel_Info = 1, + logLevel_Warning, + logLevel_Debug } #define register_trigger_clcmd(%0,%1) \ - for (new iter = 0; iter < sizeof(BASE_CHAT_TRIGGERS); iter++) \ - { \ - register_clcmd(fmt("%s%s", BASE_CHAT_TRIGGERS[iter], %0), %1); \ - register_clcmd(fmt("say %s%s", BASE_CHAT_TRIGGERS[iter], %0), %1); \ - register_clcmd(fmt("say_team %s%s", BASE_CHAT_TRIGGERS[iter], %0), %1); \ - } + for (new iter = 0; iter < sizeof(BASE_CHAT_TRIGGERS); iter++) \ + { \ + register_clcmd(fmt("%s%s", BASE_CHAT_TRIGGERS[iter], %0), %1); \ + register_clcmd(fmt("say %s%s", BASE_CHAT_TRIGGERS[iter], %0), %1); \ + register_clcmd(fmt("say_team %s%s", BASE_CHAT_TRIGGERS[iter], %0), %1); \ + } -new stock const BASE_CHAT_TRIGGERS[][] = { /* "", */"/", "\", "!", "." }; +new stock const BASE_CHAT_TRIGGERS[][] = { /* "", */"/", "\", "!", "." } stock parseTime(const value[]) { - const _SECONDS_IN_MINUTE = 60; - const _SECONDS_IN_HOUR = 3600; - const _SECONDS_IN_DAY = 86400; - const _SECONDS_IN_WEEK = 604800; - const _SECONDS_IN_MONTH = 2592000; - const _SECONDS_IN_YEAR = 31536000; - - new t, k; - for (new i; value[i] != EOS; i++) { - switch (value[i]) { - case '0'..'9': { - t = (t * 10) + (value[i] - '0'); - } - - case 'i': { - k += t * _SECONDS_IN_MINUTE; - t = 0; - } - - case 'h': { - k += t * _SECONDS_IN_HOUR; - t = 0; - } - - case 'd': { - k += t * _SECONDS_IN_DAY; - t = 0; - } - - case 'w': { - k += t * _SECONDS_IN_WEEK; - t = 0; - } - - case 'm': { - k += t * _SECONDS_IN_MONTH; - t = 0; - } - - case 'y': { - k += t * _SECONDS_IN_YEAR; - t = 0; - } - - default: { - break; - } + const _SECONDS_IN_MINUTE = 60 + const _SECONDS_IN_HOUR = 3600 + const _SECONDS_IN_DAY = 86400 + const _SECONDS_IN_WEEK = 604800 + const _SECONDS_IN_MONTH = 2592000 + const _SECONDS_IN_YEAR = 31536000 + + new t, k + for (new i; value[i] != EOS; i++) { + switch (value[i]) { + case '0'..'9': { + t = (t * 10) + (value[i] - '0') + } + + case 'i': { + k += t * _SECONDS_IN_MINUTE + t = 0 + } + + case 'h': { + k += t * _SECONDS_IN_HOUR + t = 0 + } + + case 'd': { + k += t * _SECONDS_IN_DAY + t = 0 + } + + case 'w': { + k += t * _SECONDS_IN_WEEK + t = 0 + } + + case 'm': { + k += t * _SECONDS_IN_MONTH + t = 0 + } + + case 'y': { + k += t * _SECONDS_IN_YEAR + t = 0 + } + + default: { + break + } + } } - } - return k + t; + return k + t } stock show_activity_ex(const actorId, const actorName[], const message[], any: ...) { - enum { arg_format = 4 } + enum { arg_format = 4 } - static _amx_show_activity; - if(!_amx_show_activity) { - _amx_show_activity = get_cvar_pointer("amx_show_activity"); - if(!_amx_show_activity) { - _amx_show_activity = create_cvar("amx_show_activity", "2"); + static _amx_show_activity + if (!_amx_show_activity) { + _amx_show_activity = get_cvar_pointer("amx_show_activity") + if (!_amx_show_activity) { + _amx_show_activity = create_cvar("amx_show_activity", "2") + } } - } - - new prefix[] = "PLAYER"; - if(is_user_admin(actorId)) { - copy(prefix, charsmax(prefix), "ADMIN"); - } - static buffer[512]; - for(new i = 1; i <= MaxClients; i++) { - if(!is_user_connected(i) && !is_user_bot(i)) { - continue; + new prefix[] = "PLAYER" + if (is_user_admin(actorId)) { + copy(prefix, charsmax(prefix), "ADMIN") } - new bool: isAdmin = bool: is_user_admin(i); - SetGlobalTransTarget(i); - vformat(buffer, charsmax(buffer), message, arg_format); - - switch(get_pcvar_num(_amx_show_activity)) { - case 1: { // Hide name for all - client_print_color(i, i, "%L %s", i, prefix, buffer); - } - case 2: { // Show name to all - client_print_color(i, i, "%L %s: %s", i, prefix, actorName, buffer); - } - case 3: { // show name only to admins, hide name from normal users - client_print_color(i, i, "%L %s: %s", i, prefix, isAdmin ? actorName : "", buffer); - } - case 4: { // show name only to admins, show nothing to normal users - if(isAdmin) { - client_print_color(i, i, "%L %s: %s", i, prefix, actorName, buffer); + static buffer[512] + for(new i = 1; i <= MaxClients; i++) { + if (!is_user_connected(i) && !is_user_bot(i)) { + continue } - } - case 5: { // show only to admins without actor name - if(isAdmin) { - client_print_color(i, i, "%L: %s", i, prefix, buffer); + + new bool: isAdmin = bool: is_user_admin(i) + SetGlobalTransTarget(i) + vformat(buffer, charsmax(buffer), message, arg_format) + + switch (get_pcvar_num(_amx_show_activity)) { + case 1: { // Hide name for all + client_print_color(i, i, "%L %s", i, prefix, buffer) + } + case 2: { // Show name to all + client_print_color(i, i, "%L %s: %s", i, prefix, actorName, buffer) + } + case 3: { // show name only to admins, hide name from normal users + client_print_color(i, i, "%L %s: %s", i, prefix, isAdmin ? actorName : "", buffer) + } + case 4: { // show name only to admins, show nothing to normal users + if (isAdmin) { + client_print_color(i, i, "%L %s: %s", i, prefix, actorName, buffer) + } + } + case 5: { // show only to admins without actor name + if (isAdmin) { + client_print_color(i, i, "%L: %s", i, prefix, buffer) + } + } } - } } - } } stock FindPlayerByTarget(const buffer[]) { - if(buffer[0] == '#' && buffer[1]) { - return find_player_ex(FindPlayer_MatchUserId, strtol(buffer[1])); - } + if (buffer[0] == '#' && buffer[1]) { + return find_player_ex(FindPlayer_MatchUserId, strtol(buffer[1])) + } - new result = find_player_ex(FindPlayer_MatchAuthId, buffer); - if (!result) { - result = find_player_ex(FindPlayer_MatchIP, buffer); - } + new result = find_player_ex(FindPlayer_MatchAuthId, buffer) + if (!result) { + result = find_player_ex(FindPlayer_MatchIP, buffer) + } - if (!result) { - result = find_player_ex(FindPlayer_MatchNameSubstring | FindPlayer_CaseInsensitive | FindPlayer_LastMatched, buffer); - } + if (!result) { + result = find_player_ex(FindPlayer_MatchNameSubstring | FindPlayer_CaseInsensitive | FindPlayer_LastMatched, buffer) + } - return result; + return result } stock UTIL_SendAudio(const id, const sample[]) { - if(sample[0] == EOS) { - return - } - - static msgId_SendAudio - if(!msgId_SendAudio) { - msgId_SendAudio = get_user_msgid("SendAudio") - } - - message_begin(MSG_ONE_UNRELIABLE, msgId_SendAudio, .player = id) - write_byte(id) - write_string(sample) - write_short(PITCH_NORM) - message_end() + if (sample[0] == EOS) { + return + } + + static msgId_SendAudio + if (!msgId_SendAudio) { + msgId_SendAudio = get_user_msgid("SendAudio") + } + + message_begin(MSG_ONE_UNRELIABLE, msgId_SendAudio, .player = id) + write_byte(id) + write_string(sample) + write_short(PITCH_NORM) + message_end() } stock UTIL_BarTime(const id, const time) { - static msgId_BarTime - if(!msgId_BarTime) { - msgId_BarTime = get_user_msgid("BarTime") - } - - message_begin(MSG_ONE_UNRELIABLE, msgId_BarTime, .player = id) - write_short(time) - message_end() + static msgId_BarTime + if (!msgId_BarTime) { + msgId_BarTime = get_user_msgid("BarTime") + } + + message_begin(MSG_ONE_UNRELIABLE, msgId_BarTime, .player = id) + write_short(time) + message_end() } @@ -221,7 +221,7 @@ stock UTIL_BarTime(const id, const time) { * @return True if a message logged, false otherwise. */ -native bool: CA_Log(logLevel_s: level, const message[], any:...); +native bool: CA_Log(logLevel_s: level, const message[], any:...) /** * Called to determine if the Receiver has muted (blocked) the Sender. @@ -233,7 +233,7 @@ native bool: CA_Log(logLevel_s: level, const message[], any:...); * @return Returns true if the receiver has blocked the sender */ -native bool: CA_PlayerHasBlockedPlayer(const receiver, const sender); +native bool: CA_PlayerHasBlockedPlayer(const receiver, const sender) /** * Called when player say to chat. @@ -245,7 +245,7 @@ native bool: CA_PlayerHasBlockedPlayer(const receiver, const sender); * @return CA_CONTINUE to allow send message * CA_SUPERCEDE or higher to prevent message */ -forward CA_Client_Say(index, const bool: isTeamMessage, const message[]); +forward CA_Client_Say(index, const bool: isTeamMessage, const message[]) /** @@ -259,7 +259,7 @@ forward CA_Client_Say(index, const bool: isTeamMessage, const message[]); * @return CA_CONTINUE to allow send voice * CA_SUPERCEDE or higher to prevent the voice */ -forward CA_Client_Voice(const listener, const sender); +forward CA_Client_Voice(const listener, const sender) /** @@ -273,4 +273,4 @@ forward CA_Client_Voice(const listener, const sender); * @return CA_CONTINUE to allow change nickname * CA_SUPERCEDE or higher to prevent */ -forward CA_Client_ChangeName(const id, const newName[]); +forward CA_Client_ChangeName(const id, const newName[]) diff --git a/cstrike/addons/amxmodx/scripting/include/cellqueue.inc b/cstrike/addons/amxmodx/scripting/include/cellqueue.inc index 3ca72e8..327dbd7 100644 --- a/cstrike/addons/amxmodx/scripting/include/cellqueue.inc +++ b/cstrike/addons/amxmodx/scripting/include/cellqueue.inc @@ -1,85 +1,85 @@ #include "cellarray.inc" enum Queue { - Invalid_Queue = 0 -}; + Invalid_Queue = 0 +} stock Queue: QueueCreate(const cellsize = 1) { - return Queue: ArrayCreate(cellsize); + return Queue: ArrayCreate(cellsize) } stock QueueDestroy(&Queue: which) { - return ArrayDestroy(Array: which); + return ArrayDestroy(Array: which) } stock QueueClear(const &Queue: which) { - ArrayClear(Array: which); + ArrayClear(Array: which) } stock Queue: QueueClone(const &Queue: which) { - return ArrayClone(Array: which); + return ArrayClone(Array: which) } stock QueuePushCell(const &Queue: which, const any: value) { - return ArrayPushCell(Array: which, any: value); + return ArrayPushCell(Array: which, any: value) } stock QueuePushString(const &Queue: which, const value[]) { - return ArrayPushString(Array: which, value); + return ArrayPushString(Array: which, value) } stock QueuePushArray(const &Queue: which, const any: value[], const size = -1) { - return ArrayPushArray(Array: which, value, size); + return ArrayPushArray(Array: which, value, size) } stock any: QueuePopCell(const &Queue: which) { - new any: value = ArrayGetCell(Array: which, 0); - ArrayDeleteItem(Array: which, 0); - return value; + new any: value = ArrayGetCell(Array: which, 0) + ArrayDeleteItem(Array: which, 0) + return value } stock QueuePopString(const &Queue: which, buffer[], const maxlength) { - new charCount = ArrayGetString(Array: which, 0, buffer, maxlength); - ArrayDeleteItem(Array: which, 0); - return charCount; + new charCount = ArrayGetString(Array: which, 0, buffer, maxlength) + ArrayDeleteItem(Array: which, 0) + return charCount } stock QueuePopArray(const &Queue: which, buffer[], const size) { - new cellCount = ArrayGetArray(Array: which, 0, buffer, size); - ArrayDeleteItem(Array: which, 0); - return cellCount; + new cellCount = ArrayGetArray(Array: which, 0, buffer, size) + ArrayDeleteItem(Array: which, 0) + return cellCount } stock any: QueueFrontCell(const &Queue: which) { - new any: value = ArrayGetCell(Array: which, 0); - return value; + new any: value = ArrayGetCell(Array: which, 0) + return value } stock QueueFrontString(const &Queue: which, buffer[], const maxlength) { - new charCount = ArrayGetString(Array: which, 0, buffer, maxlength); - return charCount; + new charCount = ArrayGetString(Array: which, 0, buffer, maxlength) + return charCount } stock QueueFrontArray(const &Queue: which, buffer[], const size) { - new cellCount = ArrayGetArray(Array: which, 0, buffer, size); - return cellCount; + new cellCount = ArrayGetArray(Array: which, 0, buffer, size) + return cellCount } stock any: QueueRearCell(const &Queue: which) { - new any: value = ArrayGetCell(Array: which, QueueSize(which) - 1); - return value; + new any: value = ArrayGetCell(Array: which, QueueSize(which) - 1) + return value } stock QueueRearString(const &Queue: which, buffer[], const maxlength) { - new charCount = ArrayGetString(Array: which, QueueSize(which) - 1, buffer, maxlength); - return charCount; + new charCount = ArrayGetString(Array: which, QueueSize(which) - 1, buffer, maxlength) + return charCount } stock QueueRearArray(const &Queue: which, buffer[], const size) { - new cellCount = ArrayGetArray(Array: which, QueueSize(which) - 1, buffer, size); - return cellCount; + new cellCount = ArrayGetArray(Array: which, QueueSize(which) - 1, buffer, size) + return cellCount } stock QueueSize(const &Queue: which) { - return ArraySize(Array: which); + return ArraySize(Array: which) }