Example #1
0
static cell_t CanUserTarget(IPluginContext *pContext, const cell_t *params)
{
    int client = params[1];
    int target = params[2];

    if (client == 0)
    {
        return 1;
    }

    IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client);
    if (!pPlayer)
    {
        return pContext->ThrowNativeError("Client index %d is invalid", client);
    }
    else if (!pPlayer->IsConnected()) {
        return pContext->ThrowNativeError("Client %d is not connected", client);
    }

    IGamePlayer *pTarget = playerhelpers->GetGamePlayer(target);
    if (!pTarget)
    {
        return pContext->ThrowNativeError("Client index %d is invalid", target);
    }
    else if (!pTarget->IsConnected()) {
        return pContext->ThrowNativeError("Client %d is not connected", target);
    }

    return adminsys->CanAdminTarget(pPlayer->GetAdminId(), pTarget->GetAdminId()) ? 1 : 0;
}
Example #2
0
static cell_t RemoveUserFlags(IPluginContext *pContext, const cell_t *params)
{
    int client = params[1];
    IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client);
    if (!pPlayer)
    {
        return pContext->ThrowNativeError("Client index %d is invalid", client);
    }
    if (!pPlayer->IsConnected())
    {
        return pContext->ThrowNativeError("Client %d is not connected", client);
    }

    AdminId id;
    if ((id = pPlayer->GetAdminId()) == INVALID_ADMIN_ID)
    {
        return 0;
    }

    cell_t *addr;
    for (int i = 2; i <= params[0]; i++)
    {
        pContext->LocalToPhysAddr(params[i], &addr);
        adminsys->SetAdminFlag(id, (AdminFlag) *addr, false);
    }

    return 1;
}
Example #3
0
static cell_t GetUserAdmin(IPluginContext *pContext, const cell_t *params)
{
    int client = params[1];
    IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client);
    if (!pPlayer)
    {
        return pContext->ThrowNativeError("Client index %d is invalid", client);
    }
    if (!pPlayer->IsConnected())
    {
        return pContext->ThrowNativeError("Client %d is not connected", client);
    }

    return pPlayer->GetAdminId();
}
Example #4
0
static cell_t GetUserFlagBits(IPluginContext *pContext, const cell_t *params)
{
    int client = params[1];
    IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client);
    if (!pPlayer)
    {
        return pContext->ThrowNativeError("Client index %d is invalid", client);
    }
    if (!pPlayer->IsConnected())
    {
        return pContext->ThrowNativeError("Client %d is not connected", client);
    }

    AdminId id;
    if ((id = pPlayer->GetAdminId()) == INVALID_ADMIN_ID)
    {
        return 0;
    }

    return adminsys->GetAdminFlags(id, Access_Effective);
}
Example #5
0
		void Line(std::string &line, const dlib::incoming_things& incoming, dlib::outgoing_things& outgoing)
		{
			size_t posStart, posEnd, posTemp;

			// Search for "gets"
			for (posStart = line.find("ec::GET["); posStart != std::string::npos; posStart = line.find("ec::GET["))
			{
				std::string get = &line[posStart+8];
				posEnd = get.find(']');

				get = get.substr(0, posEnd);

				std::string result = incoming.queries[get];
				if (result.empty())
					result = "Unknown GET[" + get + ']';

				// Delete functioncall
				line.erase(posStart, posEnd+9);
				line.insert(posStart, result);
			}

			// Now interpret all functions
			for (posStart = line.find("ec::"); posStart != std::string::npos; posStart = line.find("ec::"))
			{
				std::vector<std::string> params;
				std::string function = &line[posStart+4], arg, result;

				posTemp = function.find('(');
				posEnd = function.find(')');

				arg = function.substr(posTemp+1, posEnd-posTemp-1);
				if (line.find(";") != std::string::npos)
					params = dlib::split(arg.c_str(), ";");
				else
					params.emplace_back(arg);
				function = function.substr(0, posTemp);

				if (function == "GetMapName")
				{
					result = gamehelpers->GetCurrentMap();
				}
				else if (function == "GetGameFolder")
				{
					result = g_pSM->GetGameFolderName();
				}
				else if (function == "GetHTMLFormatedPlayerInfo")
				{
					IGamePlayer *player = Helper::GetPlayerByIP(incoming.foreign_ip);
					if (player)
					{
						result = "<b>" + std::string(player->GetName()) + "</b>";
						result += "<br/>IP: ";
						result += player->GetIPAddress();
						result += "<br/>Auth:";
						result += player->GetAuthString();
						result += "<br/>Steam:";
						result += player->GetSteamAccountID();

						AdminId adminID = player->GetAdminId();
						if (adminID != INVALID_ADMIN_ID)
							result += "<br/>You are an admin";
						else
							result += "<br/>You are no admin";
					}
					else
					{
						result = "You are not connected!";
					}
				}
				else if (function == "GetNavHidingSpots")
				{
					if (Navigation::gNavMesh)
						result = dlib::cast_to_string(Navigation::gHidingSpotsCount);
					else
						result = "Navigation not loaded.";
				}
				else if (function == "GetNavAreas")
				{
					if (Navigation::gNavMesh && Navigation::gNavMesh->GetAreas())
						result = dlib::cast_to_string(Navigation::gNavMesh->GetAreas()->Size());
					else
						result = "Navigation not loaded.";
				}
				else if (function == "GetNavPlaces")
				{
					if (Navigation::gNavMesh && Navigation::gNavMesh->GetPlaces())
						result = dlib::cast_to_string(Navigation::gNavMesh->GetPlaces()->Size());
					else
						result = "Navigation not loaded.";
				}
				else if (function == "GetNavLadders")
				{
					if (Navigation::gNavMesh && Navigation::gNavMesh->GetLadders())
						result = dlib::cast_to_string(Navigation::gNavMesh->GetLadders()->Size());
					else
						result = "Navigation not loaded.";
				}
				else if (function == "GetNavMagicNumber")
				{
					if (Navigation::gNavMesh)
						result = dlib::cast_to_string(Navigation::gNavMesh->GetMagicNumber());
					else
						result = "Navigation not loaded.";
				}
				else if (function == "GetNavSaveBSPSize")
				{
					if (Navigation::gNavMesh)
						result = dlib::cast_to_string(Navigation::gNavMesh->GetSaveBSPSize());
					else
						result = "Navigation not loaded.";
				}
				else if (function == "GetNavVersion")
				{
					if (Navigation::gNavMesh)
						result = dlib::cast_to_string(Navigation::gNavMesh->GetVersion());
					else
						result = "Navigation not loaded.";
				}
				else if (function == "GetNavSubVersion")
				{
					if (Navigation::gNavMesh)
						result = dlib::cast_to_string(Navigation::gNavMesh->GetSubVersion());
					else
						result = "Navigation not loaded.";
				}
				else if (function == "IsLANServer")
				{
					result = gamehelpers->IsLANServer() ? "true" : "false";
				}
				else if (function == "GetMaxClients")
				{
					result = dlib::cast_to_string(playerhelpers->GetMaxClients());
				}
				else if (function == "GetPlayerCount")
				{
					result = dlib::cast_to_string(playerhelpers->GetNumPlayers());
				}
				else if (function == "GetEntityClassname")
				{
					if (params.size() == 1)
					{
						CBaseEntity *entity = gamehelpers->ReferenceToEntity(dlib::string_cast<int>(params.at(0)));
						if (entity)
							result = gamehelpers->GetEntityClassname(entity);
						else
							result = "Entity(" + params.at(0) + ") is invalid!";
					}
					else
					{
						result = "Usage:GetEntityClassname(entity)";
					}
				}
				else if (function == "ServerCommand")
				{
					if (params.size() == 1)
					{
						gamehelpers->ServerCommand(params.at(0).append("\n").c_str());
						result = "";
					}
					else
					{
						result = "Usage:ServerCommand(COMMAND)";
					}
				}
				else if (function == "ReadFile")
				{
					if (params.size() == 1)
					{
						result = HTTP::ReadFile(lastFilePath.substr(0, lastFilePath.find_last_of('/')+1) + params.at(0), incoming, outgoing);
					}
					else
					{
						result = "Usage:ReadFile(filename)";
					}
				}
				else if (function == "MostRecentVersion")
				{
					std::string newVersion;

					newVersion = LGN::get_most_recent_version();
					if (!newVersion.empty())
					{
						result = newVersion;
					}
					else
					{
						result = "Unable to receive the most recent version";
					}
				}
				else if (function == "CurrentVersion")
				{
					result = SMEXT_CONF_VERSION;
				}
				else
				{
					IGamePlayer *player = Helper::GetPlayerByIP(incoming.foreign_ip);
					if (player)
						ForwardFunction(player->GetUserId(), function, arg, result);
					else
						ForwardFunction(0, function, arg, result);
				}

				// Delete functioncallname
				line.erase(posStart, posEnd+5);

				// Insert the result
				line.insert(posStart, result);
			}
		}
Example #6
0
static cell_t FormatActivitySource(IPluginContext *pContext, const cell_t *params)
{
    int value;
    int client;
    int target;
    IGamePlayer *pTarget;
    AdminId aidTarget;
    const char *identity[2] = { "Console", "ADMIN" };

    client = params[1];
    target = params[2];

    if ((pTarget = playerhelpers->GetGamePlayer(target)) == NULL)
    {
        return pContext->ThrowNativeError("Invalid client index %d", target);
    }
    if (!pTarget->IsConnected())
    {
        return pContext->ThrowNativeError("Client %d not connected", target);
    }

    value = bridge->GetActivityFlags();

    if (client != 0)
    {
        IGamePlayer *pPlayer;

        if ((pPlayer = playerhelpers->GetGamePlayer(client)) == NULL)
        {
            return pContext->ThrowNativeError("Invalid client index %d", client);
        }
        if (!pPlayer->IsConnected())
        {
            return pContext->ThrowNativeError("Client %d not connected", client);
        }

        identity[0] = pPlayer->GetName();

        AdminId id = pPlayer->GetAdminId();
        if (id == INVALID_ADMIN_ID
                || !adminsys->GetAdminFlag(id, Admin_Generic, Access_Effective))
        {
            identity[1] = "PLAYER";
        }
    }

    int mode = 1;
    bool bShowActivity = false;

    if ((aidTarget = pTarget->GetAdminId()) == INVALID_ADMIN_ID
            || !adminsys->GetAdminFlag(aidTarget, Admin_Generic, Access_Effective))
    {
        /* Treat this as a normal user */
        if ((value & kActivityNonAdmins) || (value & kActivityNonAdminsNames))
        {
            if ((value & 2) || (target == client))
            {
                mode = 0;
            }
            bShowActivity = true;
        }
    }
    else
    {
        /* Treat this as an admin user */
        bool is_root = adminsys->GetAdminFlag(aidTarget, Admin_Root, Access_Effective);
        if ((value & kActivityAdmins)
                || (value & kActivityAdminsNames)
                || ((value & kActivityRootNames) && is_root))
        {
            if ((value & kActivityAdminsNames) || ((value & kActivityRootNames) && is_root) || (target == client))
            {
                mode = 0;
            }
            bShowActivity = true;
        }
    }

    /* Otherwise, send it back to the script. */
    pContext->StringToLocalUTF8(params[3], params[4], identity[mode], NULL);

    return bShowActivity ? 1 : 0;
}
Example #7
0
static cell_t _ShowActivity2(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";
    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";
        }

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

        /* We don't display directly to the console because the chat text
        * simply gets added to the console, so we don't want it to print
        * twice.
        */
        g_pSM->Format(message, sizeof(message), "%s%s", tag, buffer);
        gamehelpers->TextMsg(client, TEXTMSG_DEST_CHAT, message);
    }
    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()
                || 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))
                {
                    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))
                {
                    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;
}