2009-08-11 03:29:22 +02:00
|
|
|
/*
|
|
|
|
* ============================================================================
|
|
|
|
*
|
|
|
|
* Zombie:Reloaded
|
|
|
|
*
|
|
|
|
* File: admintools.inc
|
2016-02-06 00:47:47 +01:00
|
|
|
* Type: Core
|
2009-08-11 03:29:22 +02:00
|
|
|
* Description: Functions for checking extended admin privileges.
|
|
|
|
*
|
2013-01-12 08:47:36 +01:00
|
|
|
* Copyright (C) 2009-2013 Greyscale, Richard Helgeby
|
2009-08-11 03:29:22 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* ============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2009-10-26 23:17:22 +01:00
|
|
|
* @section Pre-defined SourceMod group names for authenticating players.
|
2009-08-11 03:29:22 +02:00
|
|
|
*/
|
|
|
|
#define ZR_GROUP_ADMINS "zr_admins"
|
|
|
|
#define ZR_GROUP_MODERATORS "zr_moderators"
|
|
|
|
#define ZR_GROUP_CONFIGURATORS "zr_configurators"
|
|
|
|
/**
|
|
|
|
* @endsection
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List of operation types to specify the category of a admin operation.
|
|
|
|
*/
|
|
|
|
enum OperationTypes
|
|
|
|
{
|
|
|
|
OperationType_Invalid = -1, /** Invalid operation type. */
|
|
|
|
OperationType_Generic, /** Generic events like infecting or teleporting players. */
|
|
|
|
OperationType_Configuration, /** Changing settings. */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether a player is allowed to do a certain operation or not.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
* @param operationType The operation category.
|
|
|
|
* @return True if allowed, false otherwise.
|
|
|
|
*/
|
|
|
|
stock bool:ZRIsClientPrivileged(client, OperationTypes:operationType = OperationType_Generic)
|
|
|
|
{
|
2009-10-21 01:42:47 +02:00
|
|
|
// Check if console.
|
|
|
|
if (client == 0)
|
|
|
|
{
|
|
|
|
// Console always has full access no matter what.
|
|
|
|
return true;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-08-11 03:29:22 +02:00
|
|
|
// Validate client index.
|
|
|
|
if (!ZRIsClientValid(client))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-10-26 23:17:22 +01:00
|
|
|
// Check if group authentication is used.
|
2009-08-11 03:29:22 +02:00
|
|
|
new bool:groupauth = GetConVarBool(g_hCvarsList[CVAR_PERMISSIONS_USE_GROUPS]);
|
|
|
|
if (groupauth)
|
|
|
|
{
|
|
|
|
/**********************************
|
|
|
|
* *
|
|
|
|
* GROUP BASED AUTHENTICATION *
|
|
|
|
* *
|
|
|
|
**********************************/
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-08-11 03:29:22 +02:00
|
|
|
// Check if client is full admin.
|
|
|
|
if (ZRIsClientInGroup(client, ZR_GROUP_ADMINS))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-08-11 03:29:22 +02:00
|
|
|
// Check operation type.
|
|
|
|
switch (operationType)
|
|
|
|
{
|
|
|
|
case OperationType_Generic:
|
|
|
|
{
|
|
|
|
return ZRIsClientInGroup(client, ZR_GROUP_MODERATORS);
|
|
|
|
}
|
|
|
|
case OperationType_Configuration:
|
|
|
|
{
|
|
|
|
return ZRIsClientInGroup(client, ZR_GROUP_CONFIGURATORS);
|
|
|
|
}
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-08-11 03:29:22 +02:00
|
|
|
// Invalid operation type.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*********************************
|
|
|
|
* *
|
|
|
|
* FLAG BASED AUTHENTICATION *
|
|
|
|
* *
|
|
|
|
*********************************/
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-08-11 03:29:22 +02:00
|
|
|
new AdminFlag:flag;
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-08-11 03:29:22 +02:00
|
|
|
// Check operation type.
|
|
|
|
switch (operationType)
|
|
|
|
{
|
|
|
|
case OperationType_Generic:
|
|
|
|
{
|
|
|
|
flag = Admin_Generic;
|
|
|
|
}
|
|
|
|
case OperationType_Configuration:
|
|
|
|
{
|
|
|
|
flag = Admin_Config;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
// Invalid operation type.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-08-11 03:29:22 +02:00
|
|
|
return GetAdminFlag(GetUserAdmin(client), flag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether a player is in a spesific group or not.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
* @param groupName SourceMod group name to check.
|
|
|
|
* @return True if in the group, false otherwise.
|
|
|
|
*/
|
|
|
|
stock bool:ZRIsClientInGroup(client, const String:groupName[])
|
|
|
|
{
|
|
|
|
new AdminId:id = GetUserAdmin(client);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-08-11 03:29:22 +02:00
|
|
|
// Validate id.
|
|
|
|
if (id == INVALID_ADMIN_ID)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-08-11 03:29:22 +02:00
|
|
|
// Get number of groups.
|
|
|
|
new groupnum = GetAdminGroupCount(id);
|
|
|
|
decl String:groupname[64];
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-08-11 03:29:22 +02:00
|
|
|
// Validate number of groups.
|
|
|
|
if (groupnum > 0)
|
|
|
|
{
|
|
|
|
// Loop through each group.
|
|
|
|
for (new group = 0; group < groupnum; group++)
|
|
|
|
{
|
|
|
|
// Get group name.
|
|
|
|
GetAdminGroup(id, group, groupname, sizeof(groupname));
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-08-11 03:29:22 +02:00
|
|
|
// Compare names.
|
|
|
|
if (StrEqual(groupName, groupname, false))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-08-11 03:29:22 +02:00
|
|
|
// No groups or no match.
|
|
|
|
return false;
|
|
|
|
}
|