From 67e74581ccc1198a6f4d7a6c0c416c57de17684a Mon Sep 17 00:00:00 2001 From: Nicholas Hastings Date: Tue, 17 Feb 2015 06:43:07 -0800 Subject: [PATCH 1/9] Make result ptr in IForward::Execute default to NULL (which is allowed). --- public/IForwardSys.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/IForwardSys.h b/public/IForwardSys.h index 577c1ea7..3ea98739 100644 --- a/public/IForwardSys.h +++ b/public/IForwardSys.h @@ -171,7 +171,7 @@ namespace SourceMod * @param filter Do not use. * @return Error code, if any. */ - virtual int Execute(cell_t *result, IForwardFilter *filter=NULL) =0; + virtual int Execute(cell_t *result=NULL, IForwardFilter *filter=NULL) =0; /** * @brief Pushes an array of cells onto the current call. Different rules than ICallable. From 0f00a2db089a3b21eb2336ad3e7b2b0f9cfccbd7 Mon Sep 17 00:00:00 2001 From: Nicholas Hastings Date: Tue, 17 Feb 2015 06:43:49 -0800 Subject: [PATCH 2/9] Remove unused result value in OnRebuildAdminCache forward call. --- core/logic/AdminCache.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/core/logic/AdminCache.cpp b/core/logic/AdminCache.cpp index 0b997082..d3833c00 100644 --- a/core/logic/AdminCache.cpp +++ b/core/logic/AdminCache.cpp @@ -982,7 +982,6 @@ void AdminCache::DumpAdminCache(AdminCachePart part, bool rebuild) { List::iterator iter; IAdminListener *pListener; - cell_t result; if (part == AdminCache_Overrides) { @@ -996,7 +995,7 @@ void AdminCache::DumpAdminCache(AdminCachePart part, bool rebuild) pListener->OnRebuildOverrideCache(); } m_pCacheFwd->PushCell(part); - m_pCacheFwd->Execute(&result); + m_pCacheFwd->Execute(); } } else if (part == AdminCache_Groups || part == AdminCache_Admins) { if (part == AdminCache_Groups) @@ -1010,7 +1009,7 @@ void AdminCache::DumpAdminCache(AdminCachePart part, bool rebuild) pListener->OnRebuildGroupCache(); } m_pCacheFwd->PushCell(part); - m_pCacheFwd->Execute(&result); + m_pCacheFwd->Execute(); } } InvalidateAdminCache(true); @@ -1022,7 +1021,7 @@ void AdminCache::DumpAdminCache(AdminCachePart part, bool rebuild) pListener->OnRebuildAdminCache((part == AdminCache_Groups)); } m_pCacheFwd->PushCell(AdminCache_Admins); - m_pCacheFwd->Execute(&result); + m_pCacheFwd->Execute(); playerhelpers->RecheckAnyAdmins(); } } From c2d37cdff5be0127f390ff7b1d4c27d616ef499f Mon Sep 17 00:00:00 2001 From: Nicholas Hastings Date: Tue, 17 Feb 2015 07:19:56 -0800 Subject: [PATCH 3/9] Add methmodmap for AdminId. --- core/logic/smn_admin.cpp | 14 +++ plugins/include/admin.inc | 214 +++++++++++++++++++++++++++----------- 2 files changed, 169 insertions(+), 59 deletions(-) diff --git a/core/logic/smn_admin.cpp b/core/logic/smn_admin.cpp index 0d7d6ea4..dd49c046 100644 --- a/core/logic/smn_admin.cpp +++ b/core/logic/smn_admin.cpp @@ -585,6 +585,20 @@ REGISTER_NATIVES(adminNatives) {"SetAdmGroupImmunityLevel",SetAdmGroupImmunityLevel}, {"GetAdminImmunityLevel", GetAdminImmunityLevel}, {"SetAdminImmunityLevel", SetAdminImmunityLevel}, + {"AdminId.GetUsername", GetAdminUsername}, + {"AdminId.BindIdentity", BindAdminIdentity}, + {"AdminId.SetFlag", SetAdminFlag}, + {"AdminId.HasFlag", GetAdminFlag}, + {"AdminId.GetFlags", GetAdminFlags}, + {"AdminId.InheritGroup", AdminInheritGroup}, + {"AdminId.GetGroup", GetAdminGroup}, + {"AdminId.SetPassword", SetAdminPassword}, + {"AdminId.GetPassword", GetAdminPassword}, + {"AdminId.Purge", RemoveAdmin}, + {"AdminId.CanTarget", CanAdminTarget}, + {"AdminId.GroupCount.get", GetAdminGroupCount}, + {"AdminId.ImmunityLevel.get", GetAdminImmunityLevel}, + {"AdminId.ImmunityLevel.set", SetAdminImmunityLevel}, /* -------------------------------------------------- */ {NULL, NULL}, }; diff --git a/plugins/include/admin.inc b/plugins/include/admin.inc index d27b281b..d1d54241 100644 --- a/plugins/include/admin.inc +++ b/plugins/include/admin.inc @@ -168,21 +168,125 @@ enum AdminCachePart AdminCache_Admins = 2, /**< All admins */ }; +methodmap AdminId { + // Retrieves an admin's user name as made with CreateAdmin(). + // + // @note This function can return UTF-8 strings, and will safely chop UTF-8 strings. + // + // @param name String buffer to store name. + // @param maxlength Maximum size of string buffer. + // @return Number of bytes written. + public native void GetUsername(char[] name, int maxlength); + + // Binds an admin to an identity for fast lookup later on. The bind must be unique. + // + // @param authMethod Auth method to use, predefined or from RegisterAuthIdentType(). + // @param ident String containing the arbitrary, unique identity. + // @return True on success, false if the auth method was not found, + // ident was already taken, or ident invalid for auth method. + public native bool BindIdentity(const char[] authMethod, const char[] ident); + + // Sets whether or not a flag is enabled on an admin. + // + // @param flag Admin flag to use. + // @param enabled True to enable, false to disable. + public native void SetFlag(AdminFlag flag, bool enabled); + + // Returns whether or not a flag is enabled on an admin. + // + // @param flag Admin flag to use. + // @param mode Access mode to check. + // @return True if enabled, false otherwise. + public native bool HasFlag(AdminFlag flag, AdmAccessMode mode=Access_Effective); + + // Returns the bitstring of access flags on an admin. + // + // @param mode Access mode to use. + // @return A bitstring containing which flags are enabled. + public native int GetFlags(AdmAccessMode mode); + + // Adds a group to an admin's inherited group list. Any flags the group has + // will be added to the admin's effective flags. + // + // @param gid GroupId index of the group. + // @return True on success, false on invalid input or duplicate membership. + public native bool InheritGroup(GroupId gid); + + // Returns group information from an admin. + // + // @param index Group number to retrieve, from 0 to N-1, where N + // is the value of GetAdminGroupCount(id). + // @param name Buffer to store the group's name. + // Note: This will safely chop UTF-8 strings. + // @param maxlength Maximum size of the output name buffer. + // @return A GroupId index and a name pointer, or + // INVALID_GROUP_ID and NULL if an error occurred. + public native GroupId GetGroup(int index, const char[] name, int maxlength); + + // Sets a password on an admin. + // + // @param password String containing the password. + public native void SetPassword(const char[] password); + + // Gets an admin's password. + // + // @param buffer Optional buffer to store the admin's password. + // @param maxlength Maximum size of the output name buffer. + // Note: This will safely chop UTF-8 strings. + // @return True if there was a password set, false otherwise. + public native bool GetPassword(char[] buffer="", maxlength=0); + + // Purges an admin entry from the cache. + // + // @note This will remove any bindings to a specific user. + // + // @return True on success, false otherwise. + public native bool Purge(); + + // Tests whether one admin can target another. + // + // The heuristics for this check are as follows: + // 0. If the targeting AdminId is INVALID_ADMIN_ID, targeting fails. + // 1. If the targeted AdminId is INVALID_ADMIN_ID, targeting succeeds. + // 2. If the targeted AdminId is the same as the targeting AdminId, + // (self) targeting succeeds. + // 3. If the targeting admin is root, targeting succeeds. + // 4. If the targeted admin has access higher (as interpreted by + // (sm_immunity_mode) than the targeting admin, then targeting fails. + // 5. If the targeted admin has specific immunity from the + // targeting admin via group immunities, targeting fails. + // 6. Targeting succeeds. + // + // @param target Target admin (may be INVALID_ADMIN_ID). + // @return True if targetable, false if immune. + public native bool CanTarget(AdminId other); + + // The number of groups of which this admin is a member. + property int GroupCount { + public native get(); + } + + // Immunity level used for targetting. + property int ImmunityLevel { + public native get(); + public native set(int level); + } +} + /** * Called when part of the cache needs to be rebuilt. * * @param part Part of the admin cache to rebuild. */ -forward OnRebuildAdminCache(AdminCachePart:part); +forward void OnRebuildAdminCache(AdminCachePart part); /** * Tells the admin system to dump a portion of the cache. * * @param part Part of the cache to dump. Specifying groups also dumps admins. * @param rebuild If true, the rebuild forwards will fire. - * @noreturn */ -native DumpAdminCache(AdminCachePart:part, bool:rebuild); +native void DumpAdminCache(AdminCachePart part, bool rebuild); /** * Adds a global command flag override. Any command registered with this name @@ -191,9 +295,8 @@ native DumpAdminCache(AdminCachePart:part, bool:rebuild); * @param cmd String containing command name (case sensitive). * @param type Override type (specific command or group). * @param flags New admin flag. - * @noreturn */ -native AddCommandOverride(const String:cmd[], OverrideType:type, flags); +native void AddCommandOverride(const char[] cmd, OverrideType type, int flags); /** * Returns a command override. @@ -203,16 +306,15 @@ native AddCommandOverride(const String:cmd[], OverrideType:type, flags); * @param flags By-reference cell to store the flag (undefined if not found). * @return True if there is an override, false otherwise. */ -native bool:GetCommandOverride(const String:cmd[], OverrideType:type, &flags); +native bool GetCommandOverride(const char[] cmd, OverrideType type, int &flags); /** * Unsets a command override. * * @param cmd String containing command name (case sensitive). * @param type Override type (specific command or group). - * @noreturn */ -native UnsetCommandOverride(const String:cmd[], OverrideType:type); +native void UnsetCommandOverride(const char[] cmd, OverrideType type); /** * Adds a new group. Name must be unique. @@ -220,7 +322,7 @@ native UnsetCommandOverride(const String:cmd[], OverrideType:type); * @param group_name String containing the group name. * @return A new group id, INVALID_GROUP_ID if it already exists. */ -native GroupId:CreateAdmGroup(const String:group_name[]); +native GroupId CreateAdmGroup(const char[] group_name); /** * Finds a group by name. @@ -228,7 +330,7 @@ native GroupId:CreateAdmGroup(const String:group_name[]); * @param group_name String containing the group name. * @return A group id, or INVALID_GROUP_ID if not found. */ -native GroupId:FindAdmGroup(const String:group_name[]); +native GroupId FindAdmGroup(const char[] group_name); /** * Adds or removes a flag from a group's flag set. @@ -237,9 +339,8 @@ native GroupId:FindAdmGroup(const String:group_name[]); * @param id Group id. * @param flag Admin flag to toggle. * @param enabled True to set the flag, false to unset/disable. - * @noreturn */ -native SetAdmGroupAddFlag(GroupId:id, AdminFlag:flag, bool:enabled); +native void SetAdmGroupAddFlag(GroupId id, AdminFlag flag, bool enabled); /** * Gets the set value of an add flag on a group's flag set. @@ -249,7 +350,7 @@ native SetAdmGroupAddFlag(GroupId:id, AdminFlag:flag, bool:enabled); * @param flag Admin flag to retrieve. * @return True if enabled, false otherwise, */ -native bool:GetAdmGroupAddFlag(GroupId:id, AdminFlag:flag); +native bool GetAdmGroupAddFlag(GroupId id, AdminFlag flag); /** * Returns the flag set that is added to a user from their group. @@ -258,28 +359,27 @@ native bool:GetAdmGroupAddFlag(GroupId:id, AdminFlag:flag); * @param id GroupId of the group. * @return Bitstring containing the flags enabled. */ -native GetAdmGroupAddFlags(GroupId:id); +native int GetAdmGroupAddFlags(GroupId id); /** * @deprecated Functionality removed. */ #pragma deprecated Use SetAdmGroupImmunityLevel() instead. -native SetAdmGroupImmunity(GroupId:id, ImmunityType:type, bool:enabled); +native void SetAdmGroupImmunity(GroupId id, ImmunityType type, bool enabled); /** * @deprecated Functionality removed. */ #pragma deprecated Use GetAdmGroupImmunityLevel() instead. -native bool:GetAdmGroupImmunity(GroupId:id, ImmunityType:type); +native bool GetAdmGroupImmunity(GroupId id, ImmunityType type); /** * Adds immunity to a specific group. * * @param id Group id. * @param other_id Group id to receive immunity to. - * @noreturn */ -native SetAdmGroupImmuneFrom(GroupId:id, GroupId:other_id); +native void SetAdmGroupImmuneFrom(GroupId id, GroupId other_id); /** * Returns the number of specific group immunities. @@ -287,7 +387,7 @@ native SetAdmGroupImmuneFrom(GroupId:id, GroupId:other_id); * @param id Group id. * @return Number of group immunities. */ -native GetAdmGroupImmuneCount(GroupId:id); +native int GetAdmGroupImmuneCount(GroupId id); /** * Returns a group that this group is immune to given an index. @@ -296,7 +396,7 @@ native GetAdmGroupImmuneCount(GroupId:id); * @param number Index from 0 to N-1, from GetAdmGroupImmuneCount(). * @return GroupId that this group is immune to, or INVALID_GROUP_ID on failure. */ -native GroupId:GetAdmGroupImmuneFrom(GroupId:id, number); +native GroupId GetAdmGroupImmuneFrom(GroupId id, int number); /** * Adds a group-specific override type. @@ -305,9 +405,8 @@ native GroupId:GetAdmGroupImmuneFrom(GroupId:id, number); * @param name String containing command name (case sensitive). * @param type Override type (specific command or group). * @param rule Override allow/deny setting. - * @noreturn */ -native AddAdmGroupCmdOverride(GroupId:id, const String:name[], OverrideType:type, OverrideRule:rule); +native void AddAdmGroupCmdOverride(GroupId id, const char[] name, OverrideType type, OverrideRule rule); /** * Retrieves a group-specific command override. @@ -318,16 +417,15 @@ native AddAdmGroupCmdOverride(GroupId:id, const String:name[], OverrideType:type * @param rule Optional pointer to store allow/deny setting. * @return True if an override exists, false otherwise. */ -native bool:GetAdmGroupCmdOverride(GroupId:id, const String:name[], OverrideType:type, &OverrideRule:rule); +native bool GetAdmGroupCmdOverride(GroupId id, const char[] name, OverrideType type, OverrideRule &rule); /** * Registers an authentication identity type. You normally never need to call this except for * very specific systems. * * @param name Codename to use for your authentication type. - * @noreturn */ -native RegisterAuthIdentType(const String:name[]); +native void RegisterAuthIdentType(const char[] name); /** * Creates a new admin entry in the permissions cache. @@ -335,7 +433,7 @@ native RegisterAuthIdentType(const String:name[]); * @param name Name for this entry (does not have to be unique). * Specify an empty string for an anonymous admin. */ -native AdminId:CreateAdmin(const String:name[]=""); +native AdminId CreateAdmin(const char[] name=""); /** * Retrieves an admin's user name as made with CreateAdmin(). @@ -347,7 +445,7 @@ native AdminId:CreateAdmin(const String:name[]=""); * @param maxlength Maximum size of string buffer. * @return Number of bytes written. */ -native GetAdminUsername(AdminId:id, String:name[], maxlength); +native int GetAdminUsername(AdminId id, char[] name, int maxlength); /** * Binds an admin to an identity for fast lookup later on. The bind must be unique. @@ -358,7 +456,7 @@ native GetAdminUsername(AdminId:id, String:name[], maxlength); * @return True on success, false if the auth method was not found, * ident was already taken, or ident invalid for auth method. */ -native bool:BindAdminIdentity(AdminId:id, const String:auth[], const String:ident[]); +native bool BindAdminIdentity(AdminId id, const char[] auth, const char[] ident); /** * Sets whether or not a flag is enabled on an admin. @@ -366,9 +464,8 @@ native bool:BindAdminIdentity(AdminId:id, const String:auth[], const String:iden * @param id AdminId index of the admin. * @param flag Admin flag to use. * @param enabled True to enable, false to disable. - * @noreturn */ -native SetAdminFlag(AdminId:id, AdminFlag:flag, bool:enabled); +native void SetAdminFlag(AdminId id, AdminFlag flag, bool enabled); /** * Returns whether or not a flag is enabled on an admin. @@ -378,7 +475,7 @@ native SetAdminFlag(AdminId:id, AdminFlag:flag, bool:enabled); * @param mode Access mode to check. * @return True if enabled, false otherwise. */ -native bool:GetAdminFlag(AdminId:id, AdminFlag:flag, AdmAccessMode:mode=Access_Effective); +native bool GetAdminFlag(AdminId id, AdminFlag flag, AdmAccessMode mode=Access_Effective); /** * Returns the bitstring of access flags on an admin. @@ -387,7 +484,7 @@ native bool:GetAdminFlag(AdminId:id, AdminFlag:flag, AdmAccessMode:mode=Access_E * @param mode Access mode to use. * @return A bitstring containing which flags are enabled. */ -native GetAdminFlags(AdminId:id, AdmAccessMode:mode); +native int GetAdminFlags(AdminId id, AdmAccessMode mode); /** * Adds a group to an admin's inherited group list. Any flags the group has @@ -397,7 +494,7 @@ native GetAdminFlags(AdminId:id, AdmAccessMode:mode); * @param gid GroupId index of the group. * @return True on success, false on invalid input or duplicate membership. */ -native bool:AdminInheritGroup(AdminId:id, GroupId:gid); +native bool AdminInheritGroup(AdminId id, GroupId gid); /** * Returns the number of groups this admin is a member of. @@ -405,7 +502,7 @@ native bool:AdminInheritGroup(AdminId:id, GroupId:gid); * @param id AdminId index of the admin. * @return Number of groups this admin is a member of. */ -native GetAdminGroupCount(AdminId:id); +native int GetAdminGroupCount(AdminId id); /** * Returns group information from an admin. @@ -418,17 +515,16 @@ native GetAdminGroupCount(AdminId:id); * @param maxlength Maximum size of the output name buffer. * @return A GroupId index and a name pointer, or * INVALID_GROUP_ID and NULL if an error occurred. -*/ -native GroupId:GetAdminGroup(AdminId:id, index, const String:name[], maxlength); + */ +native GroupId GetAdminGroup(AdminId id, int index, const char[] name, int maxlength); /** * Sets a password on an admin. * * @param id AdminId index of the admin. * @param password String containing the password. - * @noreturn */ -native SetAdminPassword(AdminId:id, const String:password[]); +native void SetAdminPassword(AdminId id, const char[] password); /** * Gets an admin's password. @@ -439,7 +535,7 @@ native SetAdminPassword(AdminId:id, const String:password[]); * Note: This will safely chop UTF-8 strings. * @return True if there was a password set, false otherwise. */ -native bool:GetAdminPassword(AdminId:id, String:buffer[]="", maxlength=0); +native bool GetAdminPassword(AdminId id, char buffer[]="", int maxlength=0); /** * Attempts to find an admin by an auth method and an identity. @@ -448,7 +544,7 @@ native bool:GetAdminPassword(AdminId:id, String:buffer[]="", maxlength=0); * @param identity Identity string to look up. * @return An AdminId index if found, INVALID_ADMIN_ID otherwise. */ -native AdminId:FindAdminByIdentity(const String:auth[], const String:identity[]); +native AdminId FindAdminByIdentity(const char[] auth, const char[] identity); /** * Removes an admin entry from the cache. @@ -458,7 +554,7 @@ native AdminId:FindAdminByIdentity(const String:auth[], const String:identity[]) * @param id AdminId index to remove/invalidate. * @return True on success, false otherwise. */ -native bool:RemoveAdmin(AdminId:id); +native bool RemoveAdmin(AdminId id); /** * Converts a flag bit string to a bit array. @@ -468,7 +564,7 @@ native bool:RemoveAdmin(AdminId:id); * @param maxSize Maximum number of flags the array can store. * @return Number of flags written. */ -native FlagBitsToBitArray(bits, bool:array[], maxSize); +native int FlagBitsToBitArray(int bits, bool[] array, int maxSize); /** * Converts a flag array to a bit string. @@ -477,7 +573,7 @@ native FlagBitsToBitArray(bits, bool:array[], maxSize); * @param maxSize Maximum size of the flag array. * @return A bit string composed of the array bits. */ -native FlagBitArrayToBits(const bool:array[], maxSize); +native int FlagBitArrayToBits(const bool[] array, int maxSize); /** * Converts an array of flags to bits. @@ -486,7 +582,7 @@ native FlagBitArrayToBits(const bool:array[], maxSize); * @param numFlags Number of flags in the array. * @return A bit string composed of the array flags. */ -native FlagArrayToBits(const AdminFlag:array[], numFlags); +native int FlagArrayToBits(const AdminFlag[] array, int numFlags); /** * Converts a bit string to an array of flags. @@ -496,7 +592,7 @@ native FlagArrayToBits(const AdminFlag:array[], numFlags); * @param maxSize Maximum size of the flag array. * @return Number of flags written. */ -native FlagBitsToArray(bits, AdminFlag:array[], maxSize); +native int FlagBitsToArray(int bits, AdminFlag[] array, int maxSize); /** * Finds a flag by its string name. @@ -505,7 +601,7 @@ native FlagBitsToArray(bits, AdminFlag:array[], maxSize); * @param flag Variable to store flag in. * @return True on success, false if not found. */ -native bool:FindFlagByName(const String:name[], &AdminFlag:flag); +native bool FindFlagByName(const char[] name, AdminFlag &flag); /** * Finds a flag by a given character. @@ -514,7 +610,7 @@ native bool:FindFlagByName(const String:name[], &AdminFlag:flag); * @param flag Variable to store flag in. * @return True on success, false if not found. */ -native bool:FindFlagByChar(c, &AdminFlag:flag); +native bool FindFlagByChar(int c, AdminFlag &flag); /** * Finds a flag char by a gived admin flag. @@ -523,7 +619,7 @@ native bool:FindFlagByChar(c, &AdminFlag:flag); * @param c Variable to store flag char. * @return True on success, false if not found. */ -native bool:FindFlagChar(AdminFlag:flag, &c); +native bool FindFlagChar(AdminFlag flag, int &c); /** * Converts a string of flag characters to a bit string. @@ -532,7 +628,7 @@ native bool:FindFlagChar(AdminFlag:flag, &c); * @param numchars Optional variable to store the number of bytes read. * @return Bit string of ADMFLAG values. */ -native ReadFlagString(const String:flags[], &numchars=0); +native int ReadFlagString(const char[] flags, int &numchars=0); /** * Tests whether one admin can target another. @@ -553,7 +649,7 @@ native ReadFlagString(const String:flags[], &numchars=0); * @param target Target admin (may be INVALID_ADMIN_ID). * @return True if targetable, false if immune. */ -native CanAdminTarget(AdminId:admin, AdminId:target); +native bool CanAdminTarget(AdminId admin, AdminId target); /** * Creates an admin auth method. This does not need to be called more than once @@ -562,7 +658,7 @@ native CanAdminTarget(AdminId:admin, AdminId:target); * @param method Name of the authentication method. * @return True on success, false on failure. */ -native bool:CreateAuthMethod(const String:method[]); +native bool CreateAuthMethod(const char[] method); /** * Sets a group's immunity level. @@ -571,7 +667,7 @@ native bool:CreateAuthMethod(const String:method[]); * @param level Immunity level value. * @return Old immunity level value. */ -native SetAdmGroupImmunityLevel(GroupId:gid, level); +native int SetAdmGroupImmunityLevel(GroupId gid, int level); /** * Gets a group's immunity level (defaults to 0). @@ -579,7 +675,7 @@ native SetAdmGroupImmunityLevel(GroupId:gid, level); * @param gid Group Id. * @return Immunity level value. */ -native GetAdmGroupImmunityLevel(GroupId:gid); +native int GetAdmGroupImmunityLevel(GroupId gid); /** * Sets an admin's immunity level. @@ -588,7 +684,7 @@ native GetAdmGroupImmunityLevel(GroupId:gid); * @param level Immunity level value. * @return Old immunity level value. */ -native SetAdminImmunityLevel(AdminId:id, level); +native int SetAdminImmunityLevel(AdminId id, int level); /** * Gets an admin's immunity level. @@ -596,7 +692,7 @@ native SetAdminImmunityLevel(AdminId:id, level); * @param id Admin Id. * @return Immunity level value. */ -native GetAdminImmunityLevel(AdminId:id); +native int GetAdminImmunityLevel(AdminId id); /** * Converts a flag to its single bit. @@ -604,9 +700,9 @@ native GetAdminImmunityLevel(AdminId:id); * @param flag Flag to convert. * @return Bit representation of the flag. */ -stock FlagToBit(AdminFlag:flag) +stock int FlagToBit(AdminFlag flag) { - return (1<<_:flag); + return (1 << view_as(flag)); } /** @@ -616,9 +712,9 @@ stock FlagToBit(AdminFlag:flag) * @param flag Stores the converted flag by reference. * @return True on success, false otherwise. */ -stock bool:BitToFlag(bit, &AdminFlag:flag) +stock bool BitToFlag(int bit, AdminFlag &flag) { - new AdminFlag:array[1]; + AdminFlag array[1]; if (FlagBitsToArray(bit, array, 1)) { From c0729ff5e2644b631084d8ffd8b7ab391f9f9efa Mon Sep 17 00:00:00 2001 From: Nicholas Hastings Date: Tue, 17 Feb 2015 08:21:14 -0800 Subject: [PATCH 4/9] Add methodmap for GroupId. --- core/logic/smn_admin.cpp | 10 +++++++ plugins/include/admin.inc | 60 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/core/logic/smn_admin.cpp b/core/logic/smn_admin.cpp index dd49c046..24a8f35b 100644 --- a/core/logic/smn_admin.cpp +++ b/core/logic/smn_admin.cpp @@ -599,6 +599,16 @@ REGISTER_NATIVES(adminNatives) {"AdminId.GroupCount.get", GetAdminGroupCount}, {"AdminId.ImmunityLevel.get", GetAdminImmunityLevel}, {"AdminId.ImmunityLevel.set", SetAdminImmunityLevel}, + {"GroupId.HasFlag", GetAdmGroupAddFlag}, + {"GroupId.SetFlag", SetAdmGroupAddFlag}, + {"GroupId.GetFlags", GetAdmGroupAddFlags}, + {"GroupId.GetGroupImmunity", GetAdmGroupImmuneFrom}, + {"GroupId.AddGroupImmunity", SetAdmGroupImmuneFrom}, + {"GroupId.GetCommandOverride", GetAdmGroupCmdOverride}, + {"GroupId.AddCommandOverride", AddAdmGroupCmdOverride}, + {"GroupId.GroupImmunitiesCount.get", GetAdmGroupImmuneCount}, + {"GroupId.ImmunityLevel.get", GetAdmGroupImmunityLevel}, + {"GroupId.ImmunityLevel.set", SetAdmGroupImmunityLevel}, /* -------------------------------------------------- */ {NULL, NULL}, }; diff --git a/plugins/include/admin.inc b/plugins/include/admin.inc index d1d54241..afe9beeb 100644 --- a/plugins/include/admin.inc +++ b/plugins/include/admin.inc @@ -215,7 +215,7 @@ methodmap AdminId { // Returns group information from an admin. // // @param index Group number to retrieve, from 0 to N-1, where N - // is the value of GetAdminGroupCount(id). + // is the value of the GroupCount property. // @param name Buffer to store the group's name. // Note: This will safely chop UTF-8 strings. // @param maxlength Maximum size of the output name buffer. @@ -230,7 +230,7 @@ methodmap AdminId { // Gets an admin's password. // - // @param buffer Optional buffer to store the admin's password. + // @param buffer Optional buffer to store the admin's password. // @param maxlength Maximum size of the output name buffer. // Note: This will safely chop UTF-8 strings. // @return True if there was a password set, false otherwise. @@ -273,6 +273,62 @@ methodmap AdminId { } } +methodmap GroupId { + // Gets whether or not a flag is enabled on a group's flag set. + // + // @param flag Admin flag to retrieve. + // @return True if enabled, false otherwise, + public native bool HasFlag(AdminFlag flag); + + // Adds or removes a flag from a group's flag set. + // + // @param flag Admin flag to toggle. + // @param enabled True to set the flag, false to unset/disable. + public native void SetFlag(AdminFlag flag, bool enabled); + + // Returns the flag set that is added to users from this group. + // + // @return Bitstring containing the flags enabled. + public native int GetFlags(); + + // Returns a group that this group is immune to given an index. + // + // @param number Index from 0 to N-1, from GroupImmunitiesCount. + // @return GroupId that this group is immune to, or INVALID_GROUP_ID on failure. + public native GroupId GetGroupImmunity(int index); + + // Adds immunity to a specific group. + // + // @param other Group id to receive immunity to. + public native void AddGroupImmunity(GroupId other); + + // Retrieves a group-specific command override. + // + // @param name String containing command name (case sensitive). + // @param type Override type (specific command or group). + // @param rule Optional pointer to store allow/deny setting. + // @return True if an override exists, false otherwise. + public native bool GetCommandOverride(const char[] name, OverrideType type, OverrideRule &rule); + + // Adds a group-specific override type. + // + // @param name String containing command name (case sensitive). + // @param type Override type (specific command or group). + // @param rule Override allow/deny setting. + public native void AddCommandOverride(const char[] name, OverrideType type, OverrideRule rule); + + // Number of specific group immunities + property int GroupImmunitiesCount { + public native get(); + } + + // Immunity level used for targetting. + property int ImmunityLevel { + public native get(); + public native set(int level); + } +} + /** * Called when part of the cache needs to be rebuilt. * From e4ee52e1ac325da64092001f03149fa3830ebbd3 Mon Sep 17 00:00:00 2001 From: Nicholas Hastings Date: Tue, 17 Feb 2015 08:24:11 -0800 Subject: [PATCH 5/9] Convert adminhelp to newdecls. --- plugins/adminhelp.sp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/plugins/adminhelp.sp b/plugins/adminhelp.sp index eb965974..aec73480 100644 --- a/plugins/adminhelp.sp +++ b/plugins/adminhelp.sp @@ -37,7 +37,7 @@ #define COMMANDS_PER_PAGE 10 -public Plugin:myinfo = +public Plugin myinfo = { name = "Admin Help", author = "AlliedModders LLC", @@ -46,7 +46,7 @@ public Plugin:myinfo = url = "http://www.sourcemod.net/" }; -public OnPluginStart() +public void OnPluginStart() { LoadTranslations("common.phrases"); LoadTranslations("adminhelp.phrases"); @@ -54,11 +54,11 @@ public OnPluginStart() RegConsoleCmd("sm_searchcmd", HelpCmd, "Searches SourceMod commands"); } -public Action:HelpCmd(client, args) +public Action HelpCmd(int client, int args) { - decl String:arg[64], String:CmdName[20]; - new PageNum = 1; - new bool:DoSearch; + char arg[64], CmdName[20]; + int PageNum = 1; + bool DoSearch; GetCmdArg(0, CmdName, sizeof(CmdName)); @@ -76,17 +76,17 @@ public Action:HelpCmd(client, args) ReplyToCommand(client, "[SM] %t", "See console for output"); } - decl String:Name[64]; - decl String:Desc[255]; - decl String:NoDesc[128]; - new Flags; - new Handle:CmdIter = GetCommandIterator(); + char Name[64]; + char Desc[255]; + char NoDesc[128]; + int Flags; + Handle CmdIter = GetCommandIterator(); FormatEx(NoDesc, sizeof(NoDesc), "%T", "No description available", client); if (DoSearch) { - new i = 1; + int i = 1; while (ReadCommandIterator(CmdIter, Name, sizeof(Name), Flags, Desc, sizeof(Desc))) { if ((StrContains(Name, arg, false) != -1) && CheckCommandAccess(client, Name, Flags)) @@ -105,8 +105,8 @@ public Action:HelpCmd(client, args) /* Skip the first N commands if we need to */ if (PageNum > 1) { - new i; - new EndCmd = (PageNum-1) * COMMANDS_PER_PAGE - 1; + int i; + int EndCmd = (PageNum-1) * COMMANDS_PER_PAGE - 1; for (i=0; ReadCommandIterator(CmdIter, Name, sizeof(Name), Flags, Desc, sizeof(Desc)) && i Date: Tue, 17 Feb 2015 08:24:46 -0800 Subject: [PATCH 6/9] Convert admin-flatfile to use AdminId/GroupId methodmaps and newdecls. --- plugins/admin-flatfile/admin-flatfile.sp | 20 ++--- plugins/admin-flatfile/admin-groups.sp | 100 ++++++++++++---------- plugins/admin-flatfile/admin-overrides.sp | 45 +++++----- plugins/admin-flatfile/admin-simple.sp | 50 +++++------ plugins/admin-flatfile/admin-users.sp | 86 ++++++++++--------- 5 files changed, 158 insertions(+), 143 deletions(-) diff --git a/plugins/admin-flatfile/admin-flatfile.sp b/plugins/admin-flatfile/admin-flatfile.sp index 12f06711..6e9bccd0 100644 --- a/plugins/admin-flatfile/admin-flatfile.sp +++ b/plugins/admin-flatfile/admin-flatfile.sp @@ -36,7 +36,7 @@ #include -public Plugin:myinfo = +public Plugin myinfo = { name = "Admin File Reader", author = "AlliedModders LLC", @@ -46,18 +46,18 @@ public Plugin:myinfo = }; /** Various parsing globals */ -new bool:g_LoggedFileName = false; /* Whether or not the file name has been logged */ -new g_ErrorCount = 0; /* Current error count */ -new g_IgnoreLevel = 0; /* Nested ignored section count, so users can screw up files safely */ -new g_CurrentLine = 0; /* Current line we're on */ -new String:g_Filename[PLATFORM_MAX_PATH]; /* Used for error messages */ +bool g_LoggedFileName = false; /* Whether or not the file name has been logged */ +int g_ErrorCount = 0; /* Current error count */ +int g_IgnoreLevel = 0; /* Nested ignored section count, so users can screw up files safely */ +int g_CurrentLine = 0; /* Current line we're on */ +char g_Filename[PLATFORM_MAX_PATH]; /* Used for error messages */ #include "admin-overrides.sp" #include "admin-groups.sp" #include "admin-users.sp" #include "admin-simple.sp" -public OnRebuildAdminCache(AdminCachePart:part) +public void OnRebuildAdminCache(AdminCachePart part) { if (part == AdminCache_Overrides) { @@ -70,9 +70,9 @@ public OnRebuildAdminCache(AdminCachePart:part) } } -ParseError(const String:format[], any:...) +void ParseError(const char[] format, any ...) { - decl String:buffer[512]; + char buffer[512]; if (!g_LoggedFileName) { @@ -87,7 +87,7 @@ ParseError(const String:format[], any:...) g_ErrorCount++; } -InitGlobalStates() +void InitGlobalStates() { g_ErrorCount = 0; g_IgnoreLevel = 0; diff --git a/plugins/admin-flatfile/admin-groups.sp b/plugins/admin-flatfile/admin-groups.sp index 95277578..986907e6 100644 --- a/plugins/admin-flatfile/admin-groups.sp +++ b/plugins/admin-flatfile/admin-groups.sp @@ -31,18 +31,26 @@ * Version: $Id$ */ -#define GROUP_STATE_NONE 0 -#define GROUP_STATE_GROUPS 1 -#define GROUP_STATE_INGROUP 2 -#define GROUP_STATE_OVERRIDES 3 -#define GROUP_PASS_FIRST 1 -#define GROUP_PASS_SECOND 2 +enum GroupState +{ + GroupState_None, + GroupState_Groups, + GroupState_InGroup, + GroupState_Overrides, +} + +enum GroupPass +{ + GroupPass_Invalid, + GroupPass_First, + GroupPass_Second, +} static SMCParser g_hGroupParser; -static GroupId:g_CurGrp = INVALID_GROUP_ID; -static g_GroupState = GROUP_STATE_NONE; -static g_GroupPass = 0; -static bool:g_NeedReparse = false; +static GroupId g_CurGrp = INVALID_GROUP_ID; +static GroupState g_GroupState = GroupState_None; +static GroupPass g_GroupPass = GroupPass_Invalid; +static bool g_NeedReparse = false; public SMCResult ReadGroups_NewSection(SMCParser smc, const char[] name, bool opt_quotes) { @@ -52,24 +60,24 @@ public SMCResult ReadGroups_NewSection(SMCParser smc, const char[] name, bool op return SMCParse_Continue; } - if (g_GroupState == GROUP_STATE_NONE) + if (g_GroupState == GroupState_None) { if (StrEqual(name, "Groups")) { - g_GroupState = GROUP_STATE_GROUPS; + g_GroupState = GroupState_Groups; } else { g_IgnoreLevel++; } - } else if (g_GroupState == GROUP_STATE_GROUPS) { + } else if (g_GroupState == GroupState_Groups) { if ((g_CurGrp = CreateAdmGroup(name)) == INVALID_GROUP_ID) { g_CurGrp = FindAdmGroup(name); } - g_GroupState = GROUP_STATE_INGROUP; - } else if (g_GroupState == GROUP_STATE_INGROUP) { + g_GroupState = GroupState_InGroup; + } else if (g_GroupState == GroupState_InGroup) { if (StrEqual(name, "Overrides")) { - g_GroupState = GROUP_STATE_OVERRIDES; + g_GroupState = GroupState_Overrides; } else { g_IgnoreLevel++; } @@ -91,28 +99,28 @@ public SMCResult ReadGroups_KeyValue(SMCParser smc, return SMCParse_Continue; } - new AdminFlag:flag; + AdminFlag flag; - if (g_GroupPass == GROUP_PASS_FIRST) + if (g_GroupPass == GroupPass_First) { - if (g_GroupState == GROUP_STATE_INGROUP) + if (g_GroupState == GroupState_InGroup) { if (StrEqual(key, "flags")) { - new len = strlen(value); - for (new i=0; i 0) { - SetAdminImmunityLevel(admin, level); + admin.ImmunityLevel = level; if (flags[flag_idx] == ':') { flag_idx++; @@ -166,41 +166,41 @@ ReadAdminLine(const String:line[]) if (flags[flag_idx] == '@') { - new GroupId:gid = FindAdmGroup(flags[flag_idx + 1]); + GroupId gid = FindAdmGroup(flags[flag_idx + 1]); if (gid == INVALID_GROUP_ID) { ParseError("Invalid group detected: %s", flags[flag_idx + 1]); return; } - AdminInheritGroup(admin, gid); + admin.InheritGroup(gid); } else { - new len = strlen(flags[flag_idx]); - new bool:is_default = false; - for (new i=0; i Date: Tue, 17 Feb 2015 09:13:40 -0800 Subject: [PATCH 7/9] Convert admin SQL plugins to use AdminId/GroupId methodmaps, newdecls. --- plugins/admin-sql-prefetch.sp | 58 ++++++++-------- plugins/admin-sql-threaded.sp | 122 +++++++++++++++++----------------- 2 files changed, 90 insertions(+), 90 deletions(-) diff --git a/plugins/admin-sql-prefetch.sp b/plugins/admin-sql-prefetch.sp index a830204e..cdaca240 100644 --- a/plugins/admin-sql-prefetch.sp +++ b/plugins/admin-sql-prefetch.sp @@ -36,7 +36,7 @@ #include -public Plugin:myinfo = +public Plugin myinfo = { name = "SQL Admins (Prefetch)", author = "AlliedModders LLC", @@ -45,7 +45,7 @@ public Plugin:myinfo = url = "http://www.sourcemod.net/" }; -public OnRebuildAdminCache(AdminCachePart:part) +public void OnRebuildAdminCache(AdminCachePart part) { /* First try to get a database connection */ char error[255]; @@ -97,7 +97,7 @@ void FetchUsers(Database db) char name[80]; int immunity; AdminId adm; - GroupId gid; + GroupId grp; int id; /* Keep track of a mapping from admin DB IDs to internal AdminIds to @@ -120,7 +120,7 @@ void FetchUsers(Database db) if ((adm = FindAdminByIdentity(authtype, identity)) == INVALID_ADMIN_ID) { adm = CreateAdmin(name); - if (!BindAdminIdentity(adm, authtype, identity)) + if (!adm.BindIdentity(authtype, identity)) { LogError("Could not bind prefetched SQL admin (authtype \"%s\") (identity \"%s\")", authtype, identity); continue; @@ -136,22 +136,22 @@ void FetchUsers(Database db) /* See if this admin wants a password */ if (password[0] != '\0') { - SetAdminPassword(adm, password); + adm.SetPassword(password); } /* Apply each flag */ int len = strlen(flags); AdminFlag flag; - for (new i=0; i -public Plugin:myinfo = +public Plugin myinfo = { name = "SQL Admins (Threaded)", author = "AlliedModders LLC", @@ -68,15 +68,15 @@ public Plugin:myinfo = */ Database hDatabase = null; /** Database connection */ -new g_sequence = 0; /** Global unique sequence number */ -new ConnectLock = 0; /** Connect sequence number */ -new RebuildCachePart[3] = {0}; /** Cache part sequence numbers */ -new PlayerSeq[MAXPLAYERS+1]; /** Player-specific sequence numbers */ -new bool:PlayerAuth[MAXPLAYERS+1]; /** Whether a player has been "pre-authed" */ +int g_sequence = 0; /** Global unique sequence number */ +int ConnectLock = 0; /** Connect sequence number */ +int RebuildCachePart[3] = {0}; /** Cache part sequence numbers */ +int PlayerSeq[MAXPLAYERS+1]; /** Player-specific sequence numbers */ +bool PlayerAuth[MAXPLAYERS+1]; /** Whether a player has been "pre-authed" */ //#define _DEBUG -public OnMapEnd() +public void OnMapEnd() { /** * Clean up on map end just so we can start a fresh connection when we need it later. @@ -84,14 +84,14 @@ public OnMapEnd() delete hDatabase; } -public bool:OnClientConnect(client, String:rejectmsg[], maxlen) +public bool OnClientConnect(int client, char[] rejectmsg, int maxlen) { PlayerSeq[client] = 0; PlayerAuth[client] = false; return true; } -public OnClientDisconnect(client) +public void OnClientDisconnect(int client) { PlayerSeq[client] = 0; PlayerAuth[client] = false; @@ -128,22 +128,22 @@ public void OnDatabaseConnect(Database db, const char[] error, any data) /** * See if we need to get any of the cache stuff now. */ - new sequence; - if ((sequence = RebuildCachePart[_:AdminCache_Overrides]) != 0) + int sequence; + if ((sequence = RebuildCachePart[AdminCache_Overrides]) != 0) { FetchOverrides(hDatabase, sequence); } - if ((sequence = RebuildCachePart[_:AdminCache_Groups]) != 0) + if ((sequence = RebuildCachePart[AdminCache_Groups]) != 0) { FetchGroups(hDatabase, sequence); } - if ((sequence = RebuildCachePart[_:AdminCache_Admins]) != 0) + if ((sequence = RebuildCachePart[AdminCache_Admins]) != 0) { FetchUsersWeCan(hDatabase); } } -RequestDatabaseConnection() +void RequestDatabaseConnection() { ConnectLock = ++g_sequence; if (SQL_CheckConfig("admins")) @@ -154,7 +154,7 @@ RequestDatabaseConnection() } } -public OnRebuildAdminCache(AdminCachePart part) +public void OnRebuildAdminCache(AdminCachePart part) { /** * Mark this part of the cache as being rebuilt. This is used by the @@ -162,7 +162,7 @@ public OnRebuildAdminCache(AdminCachePart part) * used. */ int sequence = ++g_sequence; - RebuildCachePart[_:part] = sequence; + RebuildCachePart[part] = sequence; /** * If we don't have a database connection, we can't do any lookups just yet. @@ -189,7 +189,7 @@ public OnRebuildAdminCache(AdminCachePart part) } } -public Action OnClientPreAdminCheck(client) +public Action OnClientPreAdminCheck(int client) { PlayerAuth[client] = true; @@ -209,7 +209,7 @@ public Action OnClientPreAdminCheck(client) * the user's normal connection flow. The database will soon auth the user * normally. */ - if (RebuildCachePart[_:AdminCache_Admins] != 0) + if (RebuildCachePart[AdminCache_Admins] != 0) { return Plugin_Continue; } @@ -272,22 +272,22 @@ public void OnReceiveUserGroups(Database db, DBResultSet rs, const char[] error, } char name[80]; - GroupId gid; + GroupId grp; while (rs.FetchRow()) { rs.FetchString(0, name, sizeof(name)); - if ((gid = FindAdmGroup(name)) == INVALID_GROUP_ID) + if ((grp = FindAdmGroup(name)) == INVALID_GROUP_ID) { continue; } #if defined _DEBUG - PrintToServer("Binding user group (%d, %d, %d, %s, %d)", client, sequence, adm, name, gid); + PrintToServer("Binding user group (%d, %d, %d, %s, %d)", client, sequence, adm, name, grp); #endif - AdminInheritGroup(adm, gid); + adm.InheritGroup(grp); } /** @@ -366,18 +366,18 @@ public void OnReceiveUser(Database db, DBResultSet rs, const char[] error, any d /* For dynamic admins we clear anything already in the cache. */ if ((adm = FindAdminByIdentity(authtype, identity)) != INVALID_ADMIN_ID) { - RemoveAdmin(adm); + adm.Purge(); } adm = CreateAdmin(name); - if (!BindAdminIdentity(adm, authtype, identity)) + if (!adm.BindIdentity(authtype, identity)) { LogError("Could not bind prefetched SQL admin (authtype \"%s\") (identity \"%s\")", authtype, identity); continue; } user_lookup[total_users][0] = id; - user_lookup[total_users][1] = _:adm; + user_lookup[total_users][1] = view_as(adm); user_lookup[total_users][2] = rs.FetchInt(6); total_users++; @@ -388,21 +388,21 @@ public void OnReceiveUser(Database db, DBResultSet rs, const char[] error, any d /* See if this admin wants a password */ if (password[0] != '\0') { - SetAdminPassword(adm, password); + adm.SetPassword(password); } - SetAdminImmunityLevel(adm, immunity); + adm.ImmunityLevel = immunity; /* Apply each flag */ int len = strlen(flags); AdminFlag flag; - for (new i=0; i(adm)) { id = user_lookup[i][0]; group_count = user_lookup[i][2]; @@ -449,13 +449,13 @@ public void OnReceiveUser(Database db, DBResultSet rs, const char[] error, any d pk.Reset(); pk.WriteCell(client); pk.WriteCell(sequence); - pk.WriteCell(_:adm); + pk.WriteCell(adm); pk.WriteString(query); db.Query(OnReceiveUserGroups, query, pk, DBPrio_High); } -FetchUser(Database db, client) +void FetchUser(Database db, int client) { char name[65]; char safe_name[140]; @@ -484,7 +484,7 @@ FetchUser(Database db, client) * Construct the query using the information the user gave us. */ char query[512]; - new len = 0; + int len = 0; len += Format(query[len], sizeof(query)-len, "SELECT a.id, a.authtype, a.identity, a.password, a.flags, a.name, COUNT(ag.group_id), immunity"); len += Format(query[len], sizeof(query)-len, " FROM sm_admins a LEFT JOIN sm_admins_groups ag ON a.id = ag.admin_id WHERE "); @@ -516,7 +516,7 @@ FetchUser(Database db, client) db.Query(OnReceiveUser, query, pk, DBPrio_High); } -FetchUsersWeCan(Database db) +void FetchUsersWeCan(Database db) { for (int i=1; i<=MaxClients; i++) { @@ -529,7 +529,7 @@ FetchUsersWeCan(Database db) /** * This round of updates is done. Go in peace. */ - RebuildCachePart[_:AdminCache_Admins] = 0; + RebuildCachePart[AdminCache_Admins] = 0; } @@ -542,7 +542,7 @@ public void OnReceiveGroupImmunity(Database db, DBResultSet rs, const char[] err * Check if this is the latest result request. */ int sequence = pk.ReadCell(); - if (RebuildCachePart[_:AdminCache_Groups] != sequence) + if (RebuildCachePart[AdminCache_Groups] != sequence) { /* Discard everything, since we're out of sequence. */ delete pk; @@ -569,28 +569,28 @@ public void OnReceiveGroupImmunity(Database db, DBResultSet rs, const char[] err { char group1[80]; char group2[80]; - GroupId gid1, gid2; + GroupId grp, other; rs.FetchString(0, group1, sizeof(group1)); rs.FetchString(1, group2, sizeof(group2)); - if (((gid1 = FindAdmGroup(group1)) == INVALID_GROUP_ID) - || (gid2 = FindAdmGroup(group2)) == INVALID_GROUP_ID) + if (((grp = FindAdmGroup(group1)) == INVALID_GROUP_ID) + || (other = FindAdmGroup(group2)) == INVALID_GROUP_ID) { continue; } - SetAdmGroupImmuneFrom(gid1, gid2); + grp.AddGroupImmunity(other); #if defined _DEBUG - PrintToServer("SetAdmGroupImmuneFrom(%d, %d)", gid1, gid2); + PrintToServer("SetAdmGroupImmuneFrom(%d, %d)", grp, other); #endif } /* Clear the sequence so another connect doesn't refetch */ - RebuildCachePart[_:AdminCache_Groups] = 0; + RebuildCachePart[AdminCache_Groups] = 0; } -public OnReceiveGroupOverrides(Database db, DBResultSet rs, const char[] error, any data) +public void OnReceiveGroupOverrides(Database db, DBResultSet rs, const char[] error, any data) { DataPack pk = view_as(data); pk.Reset(); @@ -599,7 +599,7 @@ public OnReceiveGroupOverrides(Database db, DBResultSet rs, const char[] error, * Check if this is the latest result request. */ int sequence = pk.ReadCell(); - if (RebuildCachePart[_:AdminCache_Groups] != sequence) + if (RebuildCachePart[AdminCache_Groups] != sequence) { /* Discard everything, since we're out of sequence. */ delete pk; @@ -626,7 +626,7 @@ public OnReceiveGroupOverrides(Database db, DBResultSet rs, const char[] error, char type[16]; char command[64]; char access[16]; - GroupId gid; + GroupId grp; while (rs.FetchRow()) { rs.FetchString(0, name, sizeof(name)); @@ -635,7 +635,7 @@ public OnReceiveGroupOverrides(Database db, DBResultSet rs, const char[] error, rs.FetchString(3, access, sizeof(access)); /* Find the group. This is actually faster than doing the ID lookup. */ - if ((gid = FindAdmGroup(name)) == INVALID_GROUP_ID) + if ((grp = FindAdmGroup(name)) == INVALID_GROUP_ID) { /* Oh well, just ignore it. */ continue; @@ -654,10 +654,10 @@ public OnReceiveGroupOverrides(Database db, DBResultSet rs, const char[] error, } #if defined _DEBUG - PrintToServer("AddAdmGroupCmdOverride(%d, %s, %d, %d)", gid, command, o_type, o_rule); + PrintToServer("AddAdmGroupCmdOverride(%d, %s, %d, %d)", grp, command, o_type, o_rule); #endif - AddAdmGroupCmdOverride(gid, command, o_type, o_rule); + grp.AddCommandOverride(command, o_type, o_rule); } /** @@ -676,7 +676,7 @@ public OnReceiveGroupOverrides(Database db, DBResultSet rs, const char[] error, db.Query(OnReceiveGroupImmunity, query, pk, DBPrio_High); } -public OnReceiveGroups(Database db, DBResultSet rs, const char[] error, any data) +public void OnReceiveGroups(Database db, DBResultSet rs, const char[] error, any data) { DataPack pk = view_as(data); pk.Reset(); @@ -685,7 +685,7 @@ public OnReceiveGroups(Database db, DBResultSet rs, const char[] error, any data * Check if this is the latest result request. */ int sequence = pk.ReadCell(); - if (RebuildCachePart[_:AdminCache_Groups] != sequence) + if (RebuildCachePart[AdminCache_Groups] != sequence) { /* Discard everything, since we're out of sequence. */ delete pk; @@ -722,25 +722,25 @@ public OnReceiveGroups(Database db, DBResultSet rs, const char[] error, any data #endif /* Find or create the group */ - GroupId gid; - if ((gid = FindAdmGroup(name)) == INVALID_GROUP_ID) + GroupId grp; + if ((grp = FindAdmGroup(name)) == INVALID_GROUP_ID) { - gid = CreateAdmGroup(name); + grp = CreateAdmGroup(name); } /* Add flags from the database to the group */ int num_flag_chars = strlen(flags); for (int i=0; i Date: Thu, 5 Mar 2015 10:56:36 -0800 Subject: [PATCH 8/9] Purge Purge. --- core/logic/smn_admin.cpp | 1 - plugins/admin-flatfile/admin-simple.sp | 2 +- plugins/admin-sql-threaded.sp | 2 +- plugins/include/admin.inc | 7 ------- 4 files changed, 2 insertions(+), 10 deletions(-) diff --git a/core/logic/smn_admin.cpp b/core/logic/smn_admin.cpp index 24a8f35b..cac4f96b 100644 --- a/core/logic/smn_admin.cpp +++ b/core/logic/smn_admin.cpp @@ -594,7 +594,6 @@ REGISTER_NATIVES(adminNatives) {"AdminId.GetGroup", GetAdminGroup}, {"AdminId.SetPassword", SetAdminPassword}, {"AdminId.GetPassword", GetAdminPassword}, - {"AdminId.Purge", RemoveAdmin}, {"AdminId.CanTarget", CanAdminTarget}, {"AdminId.GroupCount.get", GetAdminGroupCount}, {"AdminId.ImmunityLevel.get", GetAdminImmunityLevel}, diff --git a/plugins/admin-flatfile/admin-simple.sp b/plugins/admin-flatfile/admin-simple.sp index e03757a5..57120c2a 100644 --- a/plugins/admin-flatfile/admin-simple.sp +++ b/plugins/admin-flatfile/admin-simple.sp @@ -219,7 +219,7 @@ void ReadAdminLine(const char[] line) if (!admin.BindIdentity(auth_method, auth[auth_offset])) { /* We should never reach here */ - admin.Purge(); + RemoveAdmin(admin); ParseError("Failed to bind identity %s (method %s)", auth[auth_offset], auth_method); } } diff --git a/plugins/admin-sql-threaded.sp b/plugins/admin-sql-threaded.sp index c36a1e88..36aa3ba5 100644 --- a/plugins/admin-sql-threaded.sp +++ b/plugins/admin-sql-threaded.sp @@ -366,7 +366,7 @@ public void OnReceiveUser(Database db, DBResultSet rs, const char[] error, any d /* For dynamic admins we clear anything already in the cache. */ if ((adm = FindAdminByIdentity(authtype, identity)) != INVALID_ADMIN_ID) { - adm.Purge(); + RemoveAdmin(adm); } adm = CreateAdmin(name); diff --git a/plugins/include/admin.inc b/plugins/include/admin.inc index afe9beeb..e988e58c 100644 --- a/plugins/include/admin.inc +++ b/plugins/include/admin.inc @@ -236,13 +236,6 @@ methodmap AdminId { // @return True if there was a password set, false otherwise. public native bool GetPassword(char[] buffer="", maxlength=0); - // Purges an admin entry from the cache. - // - // @note This will remove any bindings to a specific user. - // - // @return True on success, false otherwise. - public native bool Purge(); - // Tests whether one admin can target another. // // The heuristics for this check are as follows: From c39565ddb1b91714e4bb5b0c28767205a8b107ae Mon Sep 17 00:00:00 2001 From: Nicholas Hastings Date: Thu, 5 Mar 2015 10:56:54 -0800 Subject: [PATCH 9/9] Fix spacing. --- plugins/include/admin.inc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/include/admin.inc b/plugins/include/admin.inc index e988e58c..e0409d84 100644 --- a/plugins/include/admin.inc +++ b/plugins/include/admin.inc @@ -256,13 +256,13 @@ methodmap AdminId { // The number of groups of which this admin is a member. property int GroupCount { - public native get(); + public native get(); } // Immunity level used for targetting. property int ImmunityLevel { - public native get(); - public native set(int level); + public native get(); + public native set(int level); } }