Поиск Spectators can read anyone's chat.

Сообщения
100
Реакции
37
Hello, I'm looking for Plugin which allows spectators to read anyone's chat, Dead, Alive, CT, T's, team_say, say chat.

Yes, ReGame has this feature but it don't have that option.

// Dead don't hear alive but spectators can hear everyone.
 

Вложения

w0w

Сообщения
1.008
Реакции
1.956
Read everyone's chat or hearing everyone?
 

w0w

Сообщения
1.008
Реакции
1.956
Do you use Chat Manager? For example, the one by Mistrick?
 

w0w

Сообщения
1.008
Реакции
1.956
Код:
#define PLAYER_CHAT_FLAGS (ALIVE_SEE_DEAD|DEAD_SEE_ALIVE)
#define ADMIN_CHAT_FLAGS (ALIVE_SEE_DEAD|DEAD_SEE_ALIVE)
By default, players see all chat.
 
Сообщения
100
Реакции
37
Код:
#define PLAYER_CHAT_FLAGS (ALIVE_SEE_DEAD|DEAD_SEE_ALIVE)
#define ADMIN_CHAT_FLAGS (ALIVE_SEE_DEAD|DEAD_SEE_ALIVE)
By default, players see all chat.
I haven't changed them, so by default, its

• Alive can see alive chat.
• Dead can see dead chat & spectators (but not spectators team chat).
• Teamates can see team mates chat (Alive see Alive Team mate chat, Dead see, Dead team mate chat and spectators can see spectator team chat).
• Spectators can see Spectators chat & Dead Chat.

For both Admins & Players.
 

w0w

Сообщения
1.008
Реакции
1.956
Do you want to do that spectators see T's and CT's team chat?
 
Сообщения
100
Реакции
37
Do you want to do that spectators see T's and CT's team chat?
Yes, I want Spectators to see all chats, since its Public server and my admin team requests, we want to see everyone's chat to avoid unfavorable environment in server so, I thought to opt this option only in spec mode, it will keep game fair too and they will be able to monitor too.
 
Последнее редактирование:
Сообщения
397
Реакции
706
Код:
#define PLAYER_CHAT_FLAGS (ALIVE_SEE_DEAD|DEAD_SEE_ALIVE)
#define ADMIN_CHAT_FLAGS (ALIVE_SEE_DEAD|DEAD_SEE_ALIVE)
+#define SPEC_CHAT_FLAGS (ALIVE_SEE_DEAD|DEAD_SEE_ALIVE|TEAM_SEE_TEAM)
Код:
is_player_alive = is_user_alive(player);
player_team = cs_get_user_team(player);
-player_flags = get_user_flags(player) & ADMIN_FLAG ? ADMIN_CHAT_FLAGS : PLAYER_CHAT_FLAGS;
+if(player_team == CS_TEAM_SPECTATOR) {
+    player_flags = SPEC_CHAT_FLAGS;
+} else {
+    player_flags = get_user_flags(player) & ADMIN_FLAG ? ADMIN_CHAT_FLAGS : PLAYER_CHAT_FLAGS;
+}
untested
 
Сообщения
100
Реакции
37
Код:
#define PLAYER_CHAT_FLAGS (ALIVE_SEE_DEAD|DEAD_SEE_ALIVE)
#define ADMIN_CHAT_FLAGS (ALIVE_SEE_DEAD|DEAD_SEE_ALIVE)
+#define SPEC_CHAT_FLAGS (ALIVE_SEE_DEAD|DEAD_SEE_ALIVE|TEAM_SEE_TEAM)
Код:
is_player_alive = is_user_alive(player);
player_team = cs_get_user_team(player);
-player_flags = get_user_flags(player) & ADMIN_FLAG ? ADMIN_CHAT_FLAGS : PLAYER_CHAT_FLAGS;
+if(player_team == CS_TEAM_SPECTATOR) {
+    player_flags = SPEC_CHAT_FLAGS;
+} else {
+    player_flags = get_user_flags(player) & ADMIN_FLAG ? ADMIN_CHAT_FLAGS : PLAYER_CHAT_FLAGS;
+}
untested

Код:
#define FUNCTION_ALL_CHAT

#if defined FUNCTION_ALL_CHAT
//Flags: ALIVE_SEE_DEAD, DEAD_SEE_ALIVE, TEAM_SEE_TEAM
//#define PLAYER_CHAT_FLAGS (ALIVE_SEE_DEAD|DEAD_SEE_ALIVE)
//#define ADMIN_CHAT_FLAGS (ALIVE_SEE_DEAD|DEAD_SEE_ALIVE)
#define SPEC_CHAT_FLAGS (ALIVE_SEE_DEAD|DEAD_SEE_ALIVE|TEAM_SEE_TEAM)
Mistrick
Compilation Error !! [SS Attached].

Yes I don't want to use these 2 features, so commented them //.
Код:
//#define PLAYER_CHAT_FLAGS (ALIVE_SEE_DEAD|DEAD_SEE_ALIVE)
//#define ADMIN_CHAT_FLAGS (ALIVE_SEE_DEAD|DEAD_SEE_ALIVE)
Just Want To Use This:
Код:
#define SPEC_CHAT_FLAGS (ALIVE_SEE_DEAD|DEAD_SEE_ALIVE|TEAM_SEE_TEAM)
Help would be Appreciated.
 

Вложения

Последнее редактирование:
Сообщения
100
Реакции
37
DrStrange, don't comment defines for all chat. Set it to 0
Код:
#define PLAYER_CHAT_FLAGS (0)
#define ADMIN_CHAT_FLAGS (0)
Mistrick Plugin compiled successfully, No Errors in Logs, But This Function not working.

#define SPEC_CHAT_FLAGS (ALIVE_SEE_DEAD|DEAD_SEE_ALIVE|TEAM_SEE_TEAM)

Код:
#define FUNCTION_ALL_CHAT

#if defined FUNCTION_ALL_CHAT
//Flags: ALIVE_SEE_DEAD, DEAD_SEE_ALIVE, TEAM_SEE_TEAM
#define PLAYER_CHAT_FLAGS (0)
#define ADMIN_CHAT_FLAGS (0)
#define SPEC_CHAT_FLAGS (ALIVE_SEE_DEAD|DEAD_SEE_ALIVE|TEAM_SEE_TEAM)
Код:
        is_player_alive = is_user_alive(player);
        player_team = cs_get_user_team(player);
        if(player_team == CS_TEAM_SPECTATOR) {
            player_flags = SPEC_CHAT_FLAGS;
        } else {
            player_flags = get_user_flags(player) & ADMIN_FLAG ? ADMIN_CHAT_FLAGS : PLAYER_CHAT_FLAGS;
        }
 
Сообщения
100
Реакции
37
Mistrick, I'm really Sorry, I made a big blunder, myself, the code works perfectly fine that you provided.
Can u add 1 more little feature in your chat manager addon? [I have provided code below, amx_reloadchataddons {Reloads, prefix_manager.ini, blacklist.ini & whitelist.ini} without map being change. (as amx_reloadadmins)]

Код:
/**
* Credits: BlackRose, Ian Cammarata, [email protected]
*/
#include <amxmodx>
#include <amxmisc>
#include <cstrike>

#define PLUGIN "Chat Manager"
#define VERSION "1.1.1-11"
#define AUTHOR "Mistrick"

#pragma semicolon 1

#define ADMIN_FLAG ADMIN_CHAT

//Colors: DEFAULT, TEAM, GREEN
#define PRETEXT_COLOR            DEFAULT
#define PLAYER_CHAT_COLOR        DEFAULT
#define ADMIN_CHAT_COLOR        DEFAULT
#define PLAYER_NAME_COLOR        TEAM
#define ADMIN_NAME_COLOR        TEAM

#define FUNCTION_ALL_CHAT

#if defined FUNCTION_ALL_CHAT
//Flags: ALIVE_SEE_DEAD, DEAD_SEE_ALIVE, TEAM_SEE_TEAM
#define PLAYER_CHAT_FLAGS (0)
#define ADMIN_CHAT_FLAGS (0)
#define SPEC_CHAT_FLAGS (ALIVE_SEE_DEAD|DEAD_SEE_ALIVE|TEAM_SEE_TEAM)
#endif

#define FUNCTION_PLAYER_PREFIX
//#define FUNCTION_ADD_TIME_CODE
//#define FUNCTION_LOG_MESSAGES
//#define FUNCTION_HIDE_SLASH
//#define FUNCTION_TRANSLITE
//#define FUNCTION_AES_TAGS
#define FUNCTION_BETA_SUPPORT

#define FUNCTION_ADD_STEAM_PREFIX

#if defined FUNCTION_ADD_STEAM_PREFIX
new const STEAM_PREFIX[] = "^1[^4STEAMER^1] ";
#endif

#define PREFIX_MAX_LENGTH 32
#define AES_MAX_LENGTH 32

//DONT CHANGE!!!
#define COLOR_BUFFER 6
#define TEXT_LENGTH 128
#define MESSAGE_LENGTH 189

#if defined FUNCTION_AES_TAGS
native aes_get_player_stats(id,data[4]);
native aes_get_level_name(lvlnum,level[],len,idLang = 0);
new const AES_TAG_FORMAT[] = "^1[^3%s^1] ";
#endif

const ALIVE_SEE_DEAD = (1 << 0);
const DEAD_SEE_ALIVE = (1 << 1);
const TEAM_SEE_TEAM = (1 << 2);

enum
{
    DEFAULT = 1,
    TEAM = 3,
    GREEN = 4
};

enum _:FLAG_PREFIX_INFO
{
    m_Flag,
    m_Prefix[PREFIX_MAX_LENGTH]
};

new const g_TextChannels[][] =
{
    "#Cstrike_Chat_All",
    "#Cstrike_Chat_AllDead",
    "#Cstrike_Chat_T",
    "#Cstrike_Chat_T_Dead",
    "#Cstrike_Chat_CT",
    "#Cstrike_Chat_CT_Dead",
    "#Cstrike_Chat_Spec",
    "#Cstrike_Chat_AllSpec"
};

new g_SayText;
new g_sMessage[MESSAGE_LENGTH];

#if defined FUNCTION_PLAYER_PREFIX
new const FILE_PREFIXES[] = "chatmanager_prefixes.ini";

new g_bCustomPrefix[33], g_sPlayerPrefix[33][PREFIX_MAX_LENGTH];
new Trie:g_tSteamPrefixes, g_iTrieSteamSize;
new Trie:g_tNamePrefixes, g_iTrieNameSize;
new Array:g_aFlagPrefixes, g_iArrayFlagSize;
#endif

#if defined FUNCTION_LOG_MESSAGES
new g_szLogFile[128];
#endif

#if defined FUNCTION_TRANSLITE
new g_bTranslite[33];
#endif

#if defined FUNCTION_ADD_STEAM_PREFIX
new g_bSteamPlayer[33];
#endif

enum Forwards
{
    SEND_MESSAGE
};

enum _:MessageReturn
{
    MESSAGE_IGNORED,
    MESSAGE_CHANGED,
    MESSAGE_BLOCKED
};

new g_iForwards[Forwards];
new g_sNewMessage[MESSAGE_LENGTH];

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR);
 
    #if defined FUNCTION_PLAYER_PREFIX
    register_concmd("cm_set_prefix", "Command_SetPrefix", ADMIN_LEVEL_C, "<name or #userid> <prefix>");
    #endif
 
    #if defined FUNCTION_TRANSLITE
    register_clcmd("say /rus", "Command_LangChange");
    register_clcmd("say /eng", "Command_LangChange");
    #endif
 
    register_clcmd("say", "Command_SayHandler");
    register_clcmd("say_team", "Command_SayHandler");
 
    register_message((g_SayText = get_user_msgid("SayText")), "Message_SayText");

    // cm_player_send_message(id, message[], team_chat);
    g_iForwards[SEND_MESSAGE] = CreateMultiForward("cm_player_send_message", ET_STOP, FP_CELL, FP_STRING, FP_CELL);
}
public plugin_cfg()
{
    #if defined FUNCTION_LOG_MESSAGES
    new szDir[] = "addons/amxmodx/logs/chatmanager";
    if(!dir_exists(szDir))
    {
        mkdir(szDir);
    }
    new szDate[16]; get_time("%Y%m%d", szDate, charsmax(szDate));
    formatex(g_szLogFile, charsmax(g_szLogFile), "%s/chatlog_%s.html", szDir, szDate);
    if(!file_exists(g_szLogFile))
    {
        write_file(g_szLogFile, "<meta charset=utf-8><title>ChatManager Log</title>");
    }
    #endif
 
    #if defined FUNCTION_PLAYER_PREFIX
    LoadPlayersPrefixes();
    #endif
 
    #if defined FUNCTION_AES_TAGS
    register_dictionary("aes.txt");
    #endif
}
#if defined FUNCTION_PLAYER_PREFIX
LoadPlayersPrefixes()
{
    new szDir[128]; get_localinfo("amxx_configsdir", szDir, charsmax(szDir));
    new szFile[128]; formatex(szFile, charsmax(szFile), "%s/%s", szDir, FILE_PREFIXES);
 
    if(!file_exists(szFile))
    {
        log_amx("Prefixes file doesn't exist!");
        return;
    }
 
    g_tSteamPrefixes = TrieCreate();
    g_tNamePrefixes = TrieCreate();
    g_aFlagPrefixes = ArrayCreate(FLAG_PREFIX_INFO);
 
    new file = fopen(szFile, "rt");
 
    if(file)
    {
        new szText[128], szType[6], szAuth[32], szPrefix[PREFIX_MAX_LENGTH + COLOR_BUFFER], eFlagPrefix[FLAG_PREFIX_INFO];
        while(!feof(file))
        {
            fgets(file, szText, charsmax(szText));
            parse(szText, szType, charsmax(szType), szAuth, charsmax(szAuth), szPrefix, charsmax(szPrefix));
         
            if(!szType[0] || szType[0] == ';' || !szAuth[0] || !szPrefix[0]) continue;
         
            replace_color_tag(szPrefix);
         
            switch(szType[0])
            {
                case 's'://steam
                {
                    TrieSetString(g_tSteamPrefixes, szAuth, szPrefix);
                    g_iTrieSteamSize++;
                }
                case 'n'://name
                {
                    TrieSetString(g_tNamePrefixes, szAuth, szPrefix);
                    g_iTrieNameSize++;
                }
                case 'f'://flag
                {
                    eFlagPrefix[m_Flag] = read_flags(szAuth);
                    copy(eFlagPrefix[m_Prefix], charsmax(eFlagPrefix[m_Prefix]), szPrefix);
                    ArrayPushArray(g_aFlagPrefixes, eFlagPrefix);
                    g_iArrayFlagSize++;
                }
            }
        }
        fclose(file);
    }
}
#endif
public plugin_natives()
{
    register_native("cm_set_player_message", "native_set_player_message");
}
public native_set_player_message(plugin, params)
{
    enum { arg_new_message = 1 };
    get_string(arg_new_message, g_sNewMessage, charsmax(g_sNewMessage));
}
public client_putinserver(id)
{
    #if defined FUNCTION_TRANSLITE
    g_bTranslite[id] = false;
    #endif
 
    #if defined FUNCTION_PLAYER_PREFIX
    g_sPlayerPrefix[id] = "";
    g_bCustomPrefix[id] = false;
 
    new szSteam[32]; get_user_authid(id, szSteam, charsmax(szSteam));
    if(g_iTrieSteamSize && TrieKeyExists(g_tSteamPrefixes, szSteam))
    {
        g_bCustomPrefix[id] = true;
        TrieGetString(g_tSteamPrefixes, szSteam, g_sPlayerPrefix[id], charsmax(g_sPlayerPrefix[]));
    }
    #endif
 
    #if defined FUNCTION_ADD_STEAM_PREFIX
    g_bSteamPlayer[id] = is_user_steam(id);
    #endif
}
#if defined FUNCTION_PLAYER_PREFIX
public Command_SetPrefix(id, level, cid)
{
    if(!cmd_access(id, level, cid, 2)) return PLUGIN_HANDLED;

    new szArg[32]; read_argv(1, szArg, charsmax(szArg));
    new player = cmd_target(id, szArg, CMDTARGET_ALLOW_SELF);
 
    if(!player) return PLUGIN_HANDLED;
 
    new szPrefix[PREFIX_MAX_LENGTH + COLOR_BUFFER]; read_argv(2, szPrefix, charsmax(szPrefix));
    replace_color_tag(szPrefix);
 
    console_print(id, "You changed player prefix from %s to %s.", g_sPlayerPrefix[player], szPrefix);
 
    copy(g_sPlayerPrefix[player], charsmax(g_sPlayerPrefix[]), szPrefix);
    g_bCustomPrefix[player] = true;
 
    return PLUGIN_HANDLED;
}
#endif
#if defined FUNCTION_TRANSLITE
public Command_LangChange(id)
{
    g_bTranslite[id] = !g_bTranslite[id];
    color_print(id, "^4[ChatManager]^1 You changed language to ^3%s^1.", g_bTranslite[id] ? "rus" : "eng");
    return PLUGIN_HANDLED;
}
#endif
public Command_SayHandler(id)
{
    if (!is_user_connected(id)) return PLUGIN_HANDLED;
 
    new message[TEXT_LENGTH];
 
    read_argv(0, message, charsmax(message));
    new is_team_msg = (message[3] == '_');
 
    read_args(message, charsmax(message));
    remove_quotes(message);
    replace_wrong_simbols(message);
    trim(message);
 
    if(!message[0]) return PLUGIN_HANDLED;
 
    #if defined FUNCTION_HIDE_SLASH
    if(message[0] == '/') return PLUGIN_HANDLED_MAIN;
    #endif
 
    new flags = get_user_flags(id);
 
    new name[32]; get_user_name(id, name, charsmax(name));
 
    #if defined FUNCTION_PLAYER_PREFIX
    if(!g_bCustomPrefix[id])
    {
        if(g_iTrieNameSize && TrieKeyExists(g_tNamePrefixes, name))
        {
            TrieGetString(g_tNamePrefixes, name, g_sPlayerPrefix[id], charsmax(g_sPlayerPrefix[]));
        }
        else if(g_iArrayFlagSize)
        {
            new eFlagPrefix[FLAG_PREFIX_INFO], bFoundPrefix = false;
            for(new i; i < g_iArrayFlagSize; i++)
            {
                ArrayGetArray(g_aFlagPrefixes, i, eFlagPrefix);
                if(check_flags(flags, eFlagPrefix[m_Flag]))
                {
                    bFoundPrefix = true;
                    copy(g_sPlayerPrefix[id], charsmax(g_sPlayerPrefix[]), eFlagPrefix[m_Prefix]);
                    break;
                }
            }
         
            if(!bFoundPrefix)
            {
                g_sPlayerPrefix[id] = "";
            }
        }
    }
    #endif
 
    #if defined FUNCTION_TRANSLITE
    if(g_bTranslite[id])
    {
        if(message[0] == '/')
        {
            copy(message, charsmax(message), message[1]);
        }
        else
        {
            new szTranslitedText[TEXT_LENGTH];
            translite_string(szTranslitedText, charsmax(szTranslitedText), message);
            copy(message, charsmax(message), szTranslitedText);
        }
    }
    #endif
 
    new ret; ExecuteForward(g_iForwards[SEND_MESSAGE], ret, id, message, is_team_msg);

    if(ret)
    {
        if(ret == MESSAGE_BLOCKED)
        {
            return PLUGIN_HANDLED;
        }
        copy(message, charsmax(message), g_sNewMessage);
    }

    if(!message[0])
    {
        return PLUGIN_HANDLED;
    }

    new name_color = flags & ADMIN_FLAG ? ADMIN_NAME_COLOR : PLAYER_NAME_COLOR;
    new chat_color = flags & ADMIN_FLAG ? ADMIN_CHAT_COLOR : PLAYER_CHAT_COLOR;
 
    new time_code[16]; get_time("[%H:%M:%S] ", time_code, charsmax(time_code));
 
    new is_sender_alive = is_user_alive(id);
    new CsTeams:sender_team = cs_get_user_team(id);
 
    new channel = get_user_text_channel(is_sender_alive, is_team_msg, sender_team);
 
    FormatMessage(id, sender_team, channel, name_color, chat_color, time_code, message);
 
    #if defined FUNCTION_ALL_CHAT
    new players[32], players_num; get_players(players, players_num, "ch");
    new player, is_player_alive, CsTeams:player_team, player_flags;
 
    for(new i; i < players_num; i++)
    {
        player = players[i];
     
        if(player == id) continue;
     
        is_player_alive = is_user_alive(player);
        player_team = cs_get_user_team(player);
        if(player_team == CS_TEAM_SPECTATOR) {
            player_flags = SPEC_CHAT_FLAGS;
        } else {
            player_flags = get_user_flags(player) & ADMIN_FLAG ? ADMIN_CHAT_FLAGS : PLAYER_CHAT_FLAGS;
        }
     
        if(player_flags & ALIVE_SEE_DEAD && !is_sender_alive && is_player_alive && (!is_team_msg || is_team_msg && sender_team == player_team) //flag ALIVE_SEE_DEAD
        || player_flags & DEAD_SEE_ALIVE && is_sender_alive && !is_player_alive && (!is_team_msg || is_team_msg && sender_team == player_team) //flag DEAD_SEE_ALIVE
        || player_flags & TEAM_SEE_TEAM && is_team_msg && sender_team != player_team) //flag TEAM_SEE_TEAM
        {
            emessage_begin(MSG_ONE, g_SayText, _, player);
            ewrite_byte(id);
            ewrite_string(g_TextChannels[channel]);
            ewrite_string("");
            ewrite_string("");
            emessage_end();
        }
    }
    #endif
 
    #if defined FUNCTION_LOG_MESSAGES
    static const szTeamColor[CsTeams][] = {"gray", "red", "blue", "gray"};
    new szLogMessage[256];
    formatex(szLogMessage, charsmax(szLogMessage), "<br><font color=black>%s %s %s <font color=%s><b>%s</b> </font>:</font><font color=%s> %s </font>", time_code, is_sender_alive ? "" : (_:sender_team == 1 || _:sender_team == 2 ? "*DEAD*" : "*SPEC*"), is_team_msg ? "(TEAM)" : "", szTeamColor[sender_team], name, chat_color == GREEN ? "green" : "#FFB41E", message);
    write_file(g_szLogFile, szLogMessage);
    #endif
 
    return PLUGIN_CONTINUE;
}
public FormatMessage(sender, CsTeams:sender_team, channel, name_color, chat_color, time_code[], message[])
{
    static const szTeamNames[CsTeams][] = {"(Spectator)", "(Terrorist)", "(Counter-Terrorist)", "(Spectator)"};
 
    new szText[MESSAGE_LENGTH], len = 1;
    szText[0] = PRETEXT_COLOR;
 
    if(channel % 2)
    {
        len += formatex(szText[len], charsmax(szText) - len, "%s", channel != 7 ? "*DEAD*" : "*SPEC*");
    }
 
    if(channel > 1 && channel < 7)
    {
        len += formatex(szText[len], charsmax(szText) - len, "%s ", szTeamNames[sender_team]);
    }
    else if(channel)
    {
        len += formatex(szText[len], charsmax(szText) - len, " ");
    }
 
    #if defined FUNCTION_ADD_TIME_CODE
    len += formatex(szText[len], charsmax(szText) - len, "%s", time_code);
    #endif
 
    #if defined FUNCTION_ADD_STEAM_PREFIX
    if(g_bSteamPlayer[sender])
    {
        len += formatex(szText[len], charsmax(szText) - len, "%s", STEAM_PREFIX);
    }
    #endif
 
    #if defined FUNCTION_AES_TAGS
    new data[4], szAesTag[AES_MAX_LENGTH]; aes_get_player_stats(sender, data); aes_get_level_name(data[1], szAesTag, charsmax(szAesTag));
    len += formatex(szText[len], charsmax(szText) - len, AES_TAG_FORMAT, szAesTag);
    #endif
 
    #if defined FUNCTION_PLAYER_PREFIX
    len += formatex(szText[len], charsmax(szText) - len, "%s", g_sPlayerPrefix[sender]);
    #endif
 
    #if defined FUNCTION_BETA_SUPPORT
    new name[32]; get_user_name(sender, name, charsmax(name));
    len += formatex(szText[len], charsmax(szText) - len, "%c%s^1 :%c %s", name_color, name, chat_color, message);
    #else
    len += formatex(szText[len], charsmax(szText) - len, "%c%%s1^1 :%c %s", name_color, chat_color, message);
    #endif
 
    copy(g_sMessage, charsmax(g_sMessage), szText);
}
public Message_SayText(msgid, dest, receiver)
{
    if(get_msg_args() != 4) return PLUGIN_CONTINUE;
 
    new str2[22]; get_msg_arg_string(2, str2, charsmax(str2));
 
    new channel = get_msg_channel(str2);
 
    if(!channel) return PLUGIN_CONTINUE;
 
    new str3[2]; get_msg_arg_string(3, str3, charsmax(str3));
 
    if(str3[0]) return PLUGIN_CONTINUE;
 
    set_msg_arg_string(2, g_sMessage);
    set_msg_arg_string(4, "");
 
    return PLUGIN_CONTINUE;
}
get_msg_channel(str[])
{
    for(new i; i < sizeof(g_TextChannels); i++)
    {
        if(equal(str, g_TextChannels[i]))
        {
            return i + 1;
        }
    }
    return 0;
}
stock get_user_text_channel(is_sender_alive, is_team_msg, CsTeams:sender_team)
{
    if (is_team_msg)
    {
        switch(sender_team)
        {
            case CS_TEAM_T:
            {
                return is_sender_alive ? 2 : 3;
            }
            case CS_TEAM_CT:
            {
                return is_sender_alive ? 4 : 5;
            }
            default:
            {
                return 6;
            }
        }
    }
    return is_sender_alive ? 0 : (sender_team == CS_TEAM_SPECTATOR ? 7 : 1);
}
stock replace_wrong_simbols(string[])
{
    new len = 0;
    for(new i; string[i] != EOS; i++)
    {
        if(string[i] == '%' || string[i] == '#' || 0x01 <= string[i] <= 0x04) continue;
        string[len++] = string[i];
    }
    string[len] = EOS;
}
#if defined FUNCTION_PLAYER_PREFIX
replace_color_tag(string[])
{
    new len = 0;
    for (new i; string[i] != EOS; i++)
    {
        if (string[i] == '!')
        {
            switch (string[++i])
            {
                case 'd': string[len++] = 0x01;
                case 't': string[len++] = 0x03;
                case 'g': string[len++] = 0x04;
                case EOS: break;
                default: string[len++] = string[i];
            }
        }
        else
        {
            string[len++] = string[i];
        }
    }
    string[len] = EOS;
}
#endif
stock translite_string(string[], size, source[])
{
    static const table[][] =
    {
        "Ð", "#", ";", "%", "?", "Ñ", "(", ")", "*", "+", "б", "-", "ÑŽ", ".", "0", "1", "2", "3", "4",
        "5", "6", "7", "8", "9", "Ж", "ж", "Б", "=", "Ю", ",", "^"", "Ф", "И", "С", "Ð’", "У", "Ð", "П",
        "Ð ", "Ш", "О", "Л", "Д", "Ь", "Т", "Щ", "З", "Й", "К", "Ы", "Е", "Г", "Ðœ", "Ц", "Ч", "Ð", "Я",
        "Ñ…", "\", "ÑŠ", ":", "_", "Ñ‘", "Ñ„", "и", "Ñ", "в", "у", "а", "п", "Ñ€", "ш", "о", "л", "д", "ÑŒ",
        "Ñ‚", "щ", "з", "й", "к", "Ñ‹", "е", "г", "м", "ц", "ч", "н", "Ñ", "Ð¥", "/", "Ъ", "Ð"
    };
 
    new len = 0;
    for (new i = 0; source[i] != EOS && len < size; i++)
    {
        new ch = source[i];
     
        if ('"' <= ch <= '~')
        {
            ch -= '"';
            string[len++] = table[ch][0];
            if (table[ch][1] != EOS)
            {
                string[len++] = table[ch][1];
            }
        }
        else
        {
            string[len++] = ch;
        }
    }
    string[len] = EOS;
 
    return len;
}
stock color_print(id, text[], any:...)
{
    new formated[190]; vformat(formated, charsmax(formated), text, 3);
    message_begin(id ? MSG_ONE : MSG_ALL, g_SayText, _, id);
    write_byte(id);
    write_string(formated);
    message_end();
}
stock check_flags(flags, need_flags)
{
    return ((flags & need_flags) == need_flags) ? 1 : 0;
}
stock is_user_steam(id)
{
    static dp_pointer;
    if(dp_pointer || (dp_pointer = get_cvar_pointer("dp_r_id_provider")))
    {
        server_cmd("dp_clientinfo %d", id); server_exec();
        return (get_pcvar_num(dp_pointer) == 2) ? true : false;
    }
    return false;
}


Код:
/**
* Credits: Subb98.
*/
#include <amxmodx>
#include <regex>

#define PLUGIN "Chat Manager: Addon"
#define VERSION "0.0.4-70"
#define AUTHOR "Mistrick"

#pragma semicolon 1

enum
{
    MESSAGE_IGNORED,
    MESSAGE_CHANGED,
    MESSAGE_BLOCKED
};

forward cm_player_send_message(id, message[], team_chat);
native cm_set_player_message(message[]);

#define FUNCTION_BLACK_LIST
//#define FUNCTION_BLOCK_IDENTICAL_MSG
#define FUNCTION_BLOCK_ADVERTISING
//#define FUNCTION_BLOCK_CAPS

// TODO: Remove this func from main plugin
//#define FUNCTION_LOG_MESSAGES

#define MAX_IDENTICAL_MESSAGES 5
#define MIN_MESSAGE_DELAY 0.1 // seconds
#define MAX_WARNINGS_TO_BLOCK_CHAT 5
#define BLOCK_CHAT_TIME 15.0 // seconds
#define MAX_CAPS_PERCENT 90

#define IP_LEN 22
#define DOMAIN_LEN 32

new Float:g_fLastMsgTime[33];
new g_iWarnings[33];
new Float:g_fBlockTime[33];

#if defined FUNCTION_BLACK_LIST
new const FILE_BLACK_LIST[] = "chatmanager_blacklist.ini";
new Array:g_aBlackList;
new g_iBlackListSize;
#endif // FUNCTION_BLACK_LIST

#if defined FUNCTION_BLOCK_IDENTICAL_MSG
new g_sLastMessage[33][128];
new g_iRepeatWarn[33];
#endif // FUNCTION_BLOCK_IDENTICAL_MSG

#if defined FUNCTION_BLOCK_ADVERTISING
new const FILE_WHITE_LIST[] = "chatmanager_whitelist.ini";
new Array:g_aWhiteListIp;
new Array:g_aWhiteListDomain;
new g_iWhiteListIpSize;
new g_iWhiteListDomainSize;
new Regex:g_rIpPattern;
new Regex:g_rDomainPattern;
#endif // FUNCTION_BLOCK_ADVERTISING

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR);
}

public plugin_cfg()
{
    #if defined FUNCTION_BLACK_LIST
    LoadBlackList();
    #endif // FUNCTION_BLACK_LIST

    #if defined FUNCTION_BLOCK_ADVERTISING
    new error[2], ret;
    g_rIpPattern = regex_compile("(?:\s*\d+\s*\.){3}", ret, error, charsmax(error));
    g_rDomainPattern = regex_compile("(?:[A-z]){2,}\.(?:[A-z]){2,}", ret, error, charsmax(error));
    LoadWhiteList();
    #endif // FUNCTION_BLOCK_ADVERTISING
}

#if defined FUNCTION_BLACK_LIST
LoadBlackList()
{
    g_aBlackList = ArrayCreate(64, 1);

    new file_path[128]; get_localinfo("amxx_configsdir", file_path, charsmax(file_path));
    format(file_path, charsmax(file_path), "%s/%s", file_path, FILE_BLACK_LIST);

    new file = fopen(file_path, "rt");

    if(file)
    {
        new buffer[64], wchar[64];
        while(!feof(file))
        {
            fgets(file, buffer, charsmax(buffer));
            trim(buffer); remove_quotes(buffer);

            if(!buffer[0] || buffer[0] == ';' || strlen(buffer) < 3) continue;

            normalize_string(buffer);
            multibyte_to_wchar(buffer, wchar);
            wchar_tolower_rus(wchar);
            wchar_to_multibyte(wchar, buffer);

            ArrayPushString(g_aBlackList, buffer);
            g_iBlackListSize++;
        }
        fclose(file);
    }
}
#endif // FUNCTION_BLACK_LIST

#if defined FUNCTION_BLOCK_ADVERTISING
LoadWhiteList()
{
    g_aWhiteListIp = ArrayCreate(IP_LEN, 1);
    g_aWhiteListDomain = ArrayCreate(DOMAIN_LEN, 1);

    new file_path[128]; get_localinfo("amxx_configsdir", file_path, charsmax(file_path));
    format(file_path, charsmax(file_path), "%s/%s", file_path, FILE_WHITE_LIST);

    new file = fopen(file_path, "rt");

    enum
    {
        READ_NON,
        READ_DOMAIN,
        READ_IP
    };

    if(file)
    {
        new buffer[64], type = READ_NON;
        while(!feof(file))
        {
            fgets(file, buffer, charsmax(buffer));
            trim(buffer); remove_quotes(buffer);

            if(!buffer[0] || buffer[0] == ';') continue;

            if(contain(buffer, "[ips]") > -1)
            {
                type = READ_IP;
                continue;
            }
            if(contain(buffer, "[domains]") > -1)
            {
                type = READ_DOMAIN;
                continue;
            }

            if(type)
            {
                ArrayPushString(type == READ_IP ? g_aWhiteListIp : g_aWhiteListDomain, buffer);
            }
        }
        fclose(file);

        g_iWhiteListIpSize = ArraySize(g_aWhiteListIp);
        g_iWhiteListDomainSize = ArraySize(g_aWhiteListDomain);
    }
}
#endif // FUNCTION_BLOCK_ADVERTISING


public client_connect(id)
{
    g_fLastMsgTime[id] = 0.0;
    g_iWarnings[id] = 0;
    g_fBlockTime[id] = 0.0;

    #if defined FUNCTION_BLOCK_IDENTICAL_MSG
    g_iRepeatWarn[id] = 0;
    #endif // FUNCTION_BLOCK_IDENTICAL_MSG
}

public cm_player_send_message(id, message[])
{
    new Float:gametime = get_gametime();

    if(gametime < g_fBlockTime[id])
    {
        return MESSAGE_BLOCKED;
    }

    if(gametime < g_fLastMsgTime[id] + MIN_MESSAGE_DELAY)
    {
        client_print(id, print_chat, "[PSL] Stop spamming!");
        add_warning(id);
        return MESSAGE_BLOCKED;
    }
    g_fLastMsgTime[id] = gametime;

    #if defined FUNCTION_BLOCK_IDENTICAL_MSG
    if(equal(message, g_sLastMessage[id]))
    {
        if(++g_iRepeatWarn[id] >= MAX_IDENTICAL_MESSAGES)
        {
            client_print(id, print_chat, "[PSL] Stop spamming! Identical msg.");
            add_warning(id);
            return MESSAGE_BLOCKED;
        }
    }
    else if(g_iRepeatWarn[id])
    {
        g_iRepeatWarn[id]--;
    }
    copy(g_sLastMessage[id], charsmax(g_sLastMessage[]), message);
    #endif // FUNCTION_BLOCK_IDENTICAL_MSG

    #if defined FUNCTION_BLOCK_CAPS
    static _wchar_msg[128];

    normalize_string(message);
    multibyte_to_wchar(message, _wchar_msg);

    new i, uppercase;
    while(_wchar_msg[i])
    {
        if(wchar_is_uppercase(_wchar_msg[i]))
            uppercase++;
        i++;
    }

    if(uppercase * 100.0 / i >= MAX_CAPS_PERCENT)
    {
        client_print(id, print_chat, "[PSL] Stop using caps!");
        add_warning(id);
        return MESSAGE_BLOCKED;
    }
    #endif // FUNCTION_BLOCK_CAPS

    #if defined FUNCTION_BLOCK_ADVERTISING
    static temp[128];
    new ret;
    // TODO: Add white list
    if(regex_match_c(message, g_rIpPattern, ret))
    {
        copy(temp, charsmax(temp), message);
        for(new i, whiteip[IP_LEN]; i < g_iWhiteListIpSize; i++)
        {
            ArrayGetString(g_aWhiteListIp, i, whiteip, charsmax(whiteip));
            while(replace(temp, charsmax(temp), whiteip, "")){}
        }

        if(regex_match_c(temp, g_rIpPattern, ret))
        {
            client_print(id, print_chat, "[PSL] Founded ip pattern!");
            add_warning(id);
            return MESSAGE_BLOCKED;
        }
    }
    if(regex_match_c(message, g_rDomainPattern, ret))
    {
        copy(temp, charsmax(temp), message);
        for(new i, whitedomain[DOMAIN_LEN]; i < g_iWhiteListDomainSize; i++)
        {
            ArrayGetString(g_aWhiteListDomain, i, whitedomain, charsmax(whitedomain));
            while(replace(temp, charsmax(temp), whitedomain, "")){}
        }

        if(regex_match_c(temp, g_rDomainPattern, ret))
        {
            client_print(id, print_chat, "[PSL] Founded domain pattern!");
            add_warning(id);
            return MESSAGE_BLOCKED;
        }
    }
    #endif // FUNCTION_BLOCK_ADVERTISING

    #if defined FUNCTION_BLACK_LIST
    static new_message[128], wchar_msg[128], low_message[128];

    new changed = false;

    copy(new_message, charsmax(new_message), message);
    copy(low_message, charsmax(low_message), message);

    normalize_string(low_message);
    multibyte_to_wchar(low_message, wchar_msg);
    wchar_tolower_rus(wchar_msg);
    wchar_to_multibyte(wchar_msg, low_message);

    for(new i, len, place, word[64]; i < g_iBlackListSize; i++)
    {
        ArrayGetString(g_aBlackList, i, word, charsmax(word));
        len = strlen(word);
        while((place = containi(low_message, word)) > -1)
        {
            changed = true;
            replace_blocked_word(new_message, strlen(new_message), place, len);
            replace_blocked_word(low_message, strlen(low_message), place, len);
        }
    }

    if(changed)
    {
        cm_set_player_message(new_message);
        return MESSAGE_CHANGED;
    }
    #endif // FUNCTION_BLACK_LIST

    return MESSAGE_IGNORED;
}

add_warning(id)
{
    if(++g_iWarnings[id] >= MAX_WARNINGS_TO_BLOCK_CHAT)
    {
        g_fBlockTime[id] = get_gametime() + BLOCK_CHAT_TIME;
        g_iWarnings[id] = 0;
        client_print(id, print_chat, "[PSL] Your chat has been blocked for %.0f seconds!", BLOCK_CHAT_TIME);
    }
    SendAudio(id, "sound/fvox/beep.wav", PITCH_NORM);
}

#if defined FUNCTION_BLACK_LIST
replace_blocked_word(string[], length, start, word_length)
{

    for(new i = start; i < start + 3; i++)
    {
        string[i] = '*';
    }
    if(length > 3)
    {
        new len = start + word_length;
        new diff = word_length - 3;
        while(len <= length)
        {
            string[len - diff] = string[len];
            len++;
        }
    }
}
#endif // FUNCTION_BLACK_LIST

stock normalize_string(str[])
{
    for (new i; str[i] != EOS; i++)
    {
        str[i] &= 0xFF;
    }
}

stock wchar_tolower_rus(str[])
{
    for (new i; str[i] != EOS; i++)
    {
        if(str[i] == 0x401)
        {
            str[i] = 0x451;
        }
        else if(0x410 <= str[i] <= 0x42F)
        {
            str[i] += 0x20;
        }
    }
}

stock wchar_is_uppercase(ch)
{
    if(0x41 <= ch <= 0x5A || ch == 0x401 || 0x410 <= ch <= 0x42F)
    {
        return true;
    }
    return false;
}

// Converts MultiByte (UTF-8) to WideChar (UTF-16, UCS-2)
// Supports only 1-byte, 2-byte and 3-byte UTF-8 (unicode chars from 0x0000 to 0xFFFF), because client can't display 2-byte UTF-16
// charsmax(wcszOutput) should be >= strlen(mbszInput)
stock multibyte_to_wchar(const mbszInput[], wcszOutput[]) {
    new nOutputChars = 0;
    for (new n = 0; mbszInput[n] != EOS; n++) {
        if (mbszInput[n] < 0x80) { // 0... 1-byte ASCII
            wcszOutput[nOutputChars] = mbszInput[n];
        } else if ((mbszInput[n] & 0xE0) == 0xC0) { // 110... 2-byte UTF-8
            wcszOutput[nOutputChars] = (mbszInput[n] & 0x1F) << 6; // Upper 5 bits
         
            if ((mbszInput[n + 1] & 0xC0) == 0x80) { // Is 10... ?
                wcszOutput[nOutputChars] |= mbszInput[++n] & 0x3F; // Lower 6 bits
            } else { // Decode error
                wcszOutput[nOutputChars] = '?';
            }
        } else if ((mbszInput[n] & 0xF0) == 0xE0) { // 1110... 3-byte UTF-8
            wcszOutput[nOutputChars] = (mbszInput[n] & 0xF) << 12; // Upper 4 bits
         
            if ((mbszInput[n + 1] & 0xC0) == 0x80) { // Is 10... ?
                wcszOutput[nOutputChars] |= (mbszInput[++n] & 0x3F) << 6; // Middle 6 bits
             
                if ((mbszInput[n + 1] & 0xC0) == 0x80) { // Is 10... ?
                    wcszOutput[nOutputChars] |= mbszInput[++n] & 0x3F; // Lower 6 bits
                } else { // Decode error
                    wcszOutput[nOutputChars] = '?';
                }
            } else { // Decode error
                wcszOutput[nOutputChars] = '?';
            }
        } else { // Decode error
            wcszOutput[nOutputChars] = '?';
        }
     
        nOutputChars++;
    }
    wcszOutput[nOutputChars] = EOS;
}

// Converts WideChar (UTF-16, UCS-2) to MultiByte (UTF-8)
// Supports only 1-byte UTF-16 (0x0000 to 0xFFFF), because client can't display 2-byte UTF-16
// charsmax(mbszOutput) should be >= wcslen(wcszInput) * 3
stock wchar_to_multibyte(const wcszInput[], mbszOutput[]) {
    new nOutputChars = 0;
    for (new n = 0; wcszInput[n] != EOS; n++) {
        if (wcszInput[n] < 0x80) {
            mbszOutput[nOutputChars++] = wcszInput[n];
        } else if (wcszInput[n] < 0x800) {
            mbszOutput[nOutputChars++] = (wcszInput[n] >> 6) | 0xC0;
            mbszOutput[nOutputChars++] = (wcszInput[n] & 0x3F) | 0x80;
        } else {
            mbszOutput[nOutputChars++] = (wcszInput[n] >> 12) | 0xE0;
            mbszOutput[nOutputChars++] = ((wcszInput[n] >> 6) & 0x3F) | 0x80;
            mbszOutput[nOutputChars++] = (wcszInput[n] & 0x3F) | 0x80;
        }
    }
    mbszOutput[nOutputChars] = EOS;
}

stock SendAudio(id, audio[], pitch)
{
    static msg_send_audio; if(!msg_send_audio) msg_send_audio = get_user_msgid("SendAudio");

    message_begin( id ? MSG_ONE_UNRELIABLE : MSG_BROADCAST, msg_send_audio, _, id);
    write_byte(id);
    write_string(audio);
    write_short(pitch);
    message_end();
}
 
Сообщения
397
Реакции
706
DrStrange, just create cmd, write ArrayDestroy or TrieDestoy for each object which used in load func and then call load func.
Prefix load example.
Код:
TrieDestroy(g_tSteamPrefixes);
TrieDestroy(g_tNamePrefixes);
ArrayDestroy(g_aFlagPrefixes);
g_iTrieSteamSize = 0; // so maybe exist some global counters, this need set to 0
g_iTrieNameSize = 0;
LoadPlayersPrefixes();
 
Сообщения
100
Реакции
37
DrStrange, just create cmd, write ArrayDestroy or TrieDestoy for each object which used in load func and then call load func.
Prefix load example.
Код:
TrieDestroy(g_tSteamPrefixes);
TrieDestroy(g_tNamePrefixes);
ArrayDestroy(g_aFlagPrefixes);
g_iTrieSteamSize = 0; // so maybe exist some global counters, this need set to 0
g_iTrieNameSize = 0;
LoadPlayersPrefixes();
But chatmanager_whitelist.ini and chatmanager_blacklist.ini don't have any object, then how can I call and load its function?

[ips]
;127.0.0.1

[domains]
;my.top.site

Edited, To Avoid Advertisement
 
Последнее редактирование:
Сообщения
397
Реакции
706
DrStrange, I mean Array or Trie objects used in load func.
Array - g_aBlackList, counter g_iBlackListSize
Arrays - g_aWhiteListIp, g_aWhiteListDomain
 
Сообщения
100
Реакции
37
Код:
public Reloadprefixes() {
    server_cmd("amx_reloadprefixes")
TrieDestroy(g_tSteamPrefixes);
TrieDestroy(g_tNamePrefixes);
ArrayDestroy(g_aFlagPrefixes);
g_iTrieSteamSize = 0; // so maybe exist some global counters, this need set to 0
g_iTrieNameSize = 0;
LoadPlayersPrefixes();
}
By the way like this? and yeah got it all the Array & Tier Objects in sma should be called and loaded.
 

Пользователи, просматривающие эту тему

Сейчас на форуме нет ни одного пользователя.
Сверху Снизу