// PsychoListen, Copyright 2002, PsychoGuard. No warranties. 
// Props to Luke Sankey for the original AdminMod plugin.
//
// Allows admins to listen to otherwise invisible conversations.
// Admins need admin level B to be able to listen.
//
// Cvars:
//   pd_listen_enabled    If set to "1" admin listen is enabled. Default: 0.

#include <amxmod>

public handle_say(id) {
    if (! get_cvar_num("pd_listen_enabled")) {
        return PLUGIN_CONTINUE;
    }

    new is_alive = is_user_alive(id);
    new team = get_user_team(id);

    new command[16];
    read_argv(0, command, 16);

    new is_team_msg = ! equal(command, "say");

    new player_count = get_playersnum();
    new players[32];

    get_players(players, player_count, "c");

    new message[128];
    read_argv(1, message, 128);

    new name[32];
    get_user_name(id, name, 32);

    for (new i = 0; i < player_count; i++) {
        if (get_user_flags(players[i]) & ADMIN_LEVEL_B) {
            if (is_alive != is_user_alive(players[i]) ||
                (is_team_msg && team != get_user_team(players[i]))) {
                client_print(players[i], print_chat, "%s :    %s", name, message);
            }
        }
    }

    return PLUGIN_CONTINUE;
}

public plugin_init() {
    register_plugin("PsychoListen", "0.5", "PsychoGuard");

    register_clcmd("say", "handle_say");
    register_clcmd("say_team", "handle_say");

    register_cvar("pd_listen_enabled", "0");

    return PLUGIN_CONTINUE;
}

