Exemple #1
0
static cell_t _ShowActivity(IPluginContext *pContext,
                            const cell_t *params,
                            const char *tag,
                            cell_t fmt_param)
{
    char message[255];
    char buffer[255];
    int value = bridge->GetActivityFlags();
    unsigned int replyto = playerhelpers->GetReplyTo();
    int client = params[1];

    const char *name = "Console";
    const char *sign = "ADMIN";
    bool display_in_chat = false;
    if (client != 0)
    {
        IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client);
        if (!pPlayer || !pPlayer->IsConnected())
        {
            return pContext->ThrowNativeError("Client index %d is invalid", client);
        }
        name = pPlayer->GetName();
        AdminId id = pPlayer->GetAdminId();
        if (id == INVALID_ADMIN_ID
                || !adminsys->GetAdminFlag(id, Admin_Generic, Access_Effective))
        {
            sign = "PLAYER";
        }

        /* Display the message to the client? */
        if (replyto == SM_REPLY_CONSOLE)
        {
            g_pSM->SetGlobalTarget(client);

            {
                DetectExceptions eh(pContext);
                g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
                if (eh.HasException())
                    return 0;
            }

            g_pSM->Format(message, sizeof(message), "%s%s\n", tag, buffer);
            pPlayer->PrintToConsole(message);
            display_in_chat = true;
        }
    }
    else
    {
        g_pSM->SetGlobalTarget(SOURCEMOD_SERVER_LANGUAGE);

        {
            DetectExceptions eh(pContext);
            g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
            if (eh.HasException())
                return 0;
        }

        g_pSM->Format(message, sizeof(message), "%s%s\n", tag, buffer);
        bridge->ConPrint(message);
    }

    if (value == kActivityNone)
    {
        return 1;
    }

    int maxClients = playerhelpers->GetMaxClients();
    for (int i = 1; i <= maxClients; i++)
    {
        IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(i);
        if (!pPlayer->IsInGame()
                || pPlayer->IsFakeClient()
                || (display_in_chat && i == client))
        {
            continue;
        }
        AdminId id = pPlayer->GetAdminId();
        g_pSM->SetGlobalTarget(i);
        if (id == INVALID_ADMIN_ID
                || !adminsys->GetAdminFlag(id, Admin_Generic, Access_Effective))
        {
            /* Treat this as a normal user */
            if ((value & kActivityNonAdmins) || (value & kActivityNonAdminsNames))
            {
                const char *newsign = sign;
                if ((value & kActivityNonAdminsNames) || (i == client))
                {
                    newsign = name;
                }

                {
                    DetectExceptions eh(pContext);
                    g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
                    if (eh.HasException())
                        return 0;
                }

                g_pSM->Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer);
                gamehelpers->TextMsg(i, TEXTMSG_DEST_CHAT, message);
            }
        }
        else
        {
            /* Treat this as an admin user */
            bool is_root = adminsys->GetAdminFlag(id, Admin_Root, Access_Effective);
            if ((value & kActivityAdmins)
                    || (value & kActivityAdminsNames)
                    || ((value & kActivityRootNames) && is_root))
            {
                const char *newsign = sign;
                if ((value & kActivityAdminsNames) || ((value & kActivityRootNames) && is_root) || (i == client))
                {
                    newsign = name;
                }

                {
                    DetectExceptions eh(pContext);
                    g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
                    if (eh.HasException())
                        return 0;
                }

                g_pSM->Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer);
                gamehelpers->TextMsg(i, TEXTMSG_DEST_CHAT, message);
            }
        }
    }

    return 1;
}