1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
|
/**
* vim: set ts=4 :
* =============================================================================
* SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
* =============================================================================
*
* This file is part of the SourceMod/SourcePawn SDK.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* 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/>.
*
* As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>.
*
* Version: $Id$
*/
#if defined _admin_included
#endinput
#endif
#define _admin_included
/**
* Access levels (flags) for admins.
*/
enum AdminFlag
{
Admin_Reservation = 0, /**< Reserved slot */
Admin_Generic, /**< Generic admin abilities */
Admin_Kick, /**< Kick another user */
Admin_Ban, /**< Ban another user */
Admin_Unban, /**< Unban another user */
Admin_Slay, /**< Slay/kill/damage another user */
Admin_Changemap, /**< Change the map */
Admin_Convars, /**< Change basic convars */
Admin_Config, /**< Change configuration */
Admin_Chat, /**< Special chat privileges */
Admin_Vote, /**< Special vote privileges */
Admin_Password, /**< Set a server password */
Admin_RCON, /**< Use RCON */
Admin_Cheats, /**< Change sv_cheats and use its commands */
Admin_Root, /**< All access by default */
Admin_Custom1, /**< First custom flag type */
Admin_Custom2, /**< Second custom flag type */
Admin_Custom3, /**< Third custom flag type */
Admin_Custom4, /**< Fourth custom flag type */
Admin_Custom5, /**< Fifth custom flag type */
Admin_Custom6 /**< Sixth custom flag type */
};
#define AdminFlags_TOTAL 21 /**< Total number of admin flags */
/**
* @section Bitwise values definitions for admin flags.
*/
#define ADMFLAG_RESERVATION (1<<0) /**< Convenience macro for Admin_Reservation as a FlagBit */
#define ADMFLAG_GENERIC (1<<1) /**< Convenience macro for Admin_Generic as a FlagBit */
#define ADMFLAG_KICK (1<<2) /**< Convenience macro for Admin_Kick as a FlagBit */
#define ADMFLAG_BAN (1<<3) /**< Convenience macro for Admin_Ban as a FlagBit */
#define ADMFLAG_UNBAN (1<<4) /**< Convenience macro for Admin_Unban as a FlagBit */
#define ADMFLAG_SLAY (1<<5) /**< Convenience macro for Admin_Slay as a FlagBit */
#define ADMFLAG_CHANGEMAP (1<<6) /**< Convenience macro for Admin_Changemap as a FlagBit */
#define ADMFLAG_CONVARS (1<<7) /**< Convenience macro for Admin_Convars as a FlagBit */
#define ADMFLAG_CONFIG (1<<8) /**< Convenience macro for Admin_Config as a FlagBit */
#define ADMFLAG_CHAT (1<<9) /**< Convenience macro for Admin_Chat as a FlagBit */
#define ADMFLAG_VOTE (1<<10) /**< Convenience macro for Admin_Vote as a FlagBit */
#define ADMFLAG_PASSWORD (1<<11) /**< Convenience macro for Admin_Password as a FlagBit */
#define ADMFLAG_RCON (1<<12) /**< Convenience macro for Admin_RCON as a FlagBit */
#define ADMFLAG_CHEATS (1<<13) /**< Convenience macro for Admin_Cheats as a FlagBit */
#define ADMFLAG_ROOT (1<<14) /**< Convenience macro for Admin_Root as a FlagBit */
#define ADMFLAG_CUSTOM1 (1<<15) /**< Convenience macro for Admin_Custom1 as a FlagBit */
#define ADMFLAG_CUSTOM2 (1<<16) /**< Convenience macro for Admin_Custom2 as a FlagBit */
#define ADMFLAG_CUSTOM3 (1<<17) /**< Convenience macro for Admin_Custom3 as a FlagBit */
#define ADMFLAG_CUSTOM4 (1<<18) /**< Convenience macro for Admin_Custom4 as a FlagBit */
#define ADMFLAG_CUSTOM5 (1<<19) /**< Convenience macro for Admin_Custom5 as a FlagBit */
#define ADMFLAG_CUSTOM6 (1<<20) /**< Convenience macro for Admin_Custom6 as a FlagBit */
/**
* @endsection
*/
/**
* @section Hardcoded authentication methods
*/
#define AUTHMETHOD_STEAM "steam" /**< SteamID based authentication */
#define AUTHMETHOD_IP "ip" /**< IP based authentication */
#define AUTHMETHOD_NAME "name" /**< Name based authentication */
/**
* @endsection
*/
/**
* Access override types.
*/
enum OverrideType
{
Override_Command = 1, /**< Command */
Override_CommandGroup /**< Command group */
};
/**
* Access override rules.
*/
enum OverrideRule
{
Command_Deny = 0,
Command_Allow = 1
};
/**
* DEPRECATED, do not use.
*/
enum ImmunityType
{
Immunity_Default = 1, /**< Deprecated. */
Immunity_Global /**< Deprecated. */
};
/**
* Identifies a unique entry in the group permissions cache. These are not Handles.
*/
enum GroupId
{
INVALID_GROUP_ID = -1 /**< An invalid/non-existent group */
};
/**
* Identifies a unique entry in the admin permissions cache. These are not Handles.
*/
enum AdminId
{
INVALID_ADMIN_ID = -1 /**< An invalid/non-existent admin */
};
/**
* Methods of computing access permissions.
*/
enum AdmAccessMode
{
Access_Real, /**< Access the user has inherently */
Access_Effective /**< Access the user has from their groups */
};
/**
* Represents the various cache regions.
*/
enum AdminCachePart
{
AdminCache_Overrides = 0, /**< Global overrides */
AdminCache_Groups = 1, /**< All groups (automatically invalidates admins too) */
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);
// Sets multiple bitwise flags to be enabled/disabled on an admin.
//
// @param flags Bitwise admin flags (ADMFLAG_*).
// @param enabled True to set the flag, false to unset/disable.
public void SetBitFlags(int flags, bool enabled)
{
AdminFlag flagArray[AdminFlags_TOTAL];
int num = FlagBitsToArray(flags, flagArray, sizeof(flagArray));
for (int i = 0; i < num; i++)
{
this.SetFlag(flagArray[i], 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 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.
// @return A GroupId index and a name pointer, or
// INVALID_GROUP_ID and NULL if an error occurred.
public native GroupId GetGroup(int index, 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="", int maxlength=0);
// 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);
}
}
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);
// Adds or removes multiple bitwise flags from a group's flag set.
//
// @param flags Bitwise admin flags (ADMFLAG_*).
// @param enabled True to set the flag, false to unset/disable.
public void SetBitFlags(int flags, bool enabled)
{
AdminFlag flagArray[AdminFlags_TOTAL];
int num = FlagBitsToArray(flags, flagArray, sizeof(flagArray));
for (int i = 0; i < num; i++)
{
this.SetFlag(flagArray[i], 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.
*
* @param part Part of the admin cache to rebuild.
*/
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.
*/
native void DumpAdminCache(AdminCachePart part, bool rebuild);
/**
* Adds a global command flag override. Any command registered with this name
* will assume the new flag. This is applied retroactively as well.
*
* @param cmd String containing command name (case sensitive).
* @param type Override type (specific command or group).
* @param flags New admin flag.
*/
native void AddCommandOverride(const char[] cmd, OverrideType type, int flags);
/**
* Returns a command override.
*
* @param cmd String containing command name (case sensitive).
* @param type Override type (specific command or group).
* @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 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).
*/
native void UnsetCommandOverride(const char[] cmd, OverrideType type);
/**
* Adds a new group. Name must be unique.
*
* @param group_name String containing the group name.
* @return A new group id, INVALID_GROUP_ID if it already exists.
*/
native GroupId CreateAdmGroup(const char[] group_name);
/**
* Finds a group by name.
*
* @param group_name String containing the group name.
* @return A group id, or INVALID_GROUP_ID if not found.
*/
native GroupId FindAdmGroup(const char[] group_name);
/**
* Adds or removes a flag from a group's flag set.
* @note These are called "add flags" because they add to a user's flags.
*
* @param id Group id.
* @param flag Admin flag to toggle.
* @param enabled True to set the flag, false to unset/disable.
*/
native void SetAdmGroupAddFlag(GroupId id, AdminFlag flag, bool enabled);
/**
* Gets the set value of an add flag on a group's flag set.
* @note These are called "add flags" because they add to a user's flags.
*
* @param id Group id.
* @param flag Admin flag to retrieve.
* @return True if enabled, false otherwise,
*/
native bool GetAdmGroupAddFlag(GroupId id, AdminFlag flag);
/**
* Returns the flag set that is added to a user from their group.
* @note These are called "add flags" because they add to a user's flags.
*
* @param id GroupId of the group.
* @return Bitstring containing the flags enabled.
*/
native int GetAdmGroupAddFlags(GroupId id);
/**
* @deprecated Functionality removed.
*/
#pragma deprecated Use SetAdmGroupImmunityLevel() instead.
native void SetAdmGroupImmunity(GroupId id, ImmunityType type, bool enabled);
/**
* @deprecated Functionality removed.
*/
#pragma deprecated Use GetAdmGroupImmunityLevel() instead.
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.
*/
native void SetAdmGroupImmuneFrom(GroupId id, GroupId other_id);
/**
* Returns the number of specific group immunities.
*
* @param id Group id.
* @return Number of group immunities.
*/
native int GetAdmGroupImmuneCount(GroupId id);
/**
* Returns a group that this group is immune to given an index.
*
* @param id Group 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, int number);
/**
* Adds a group-specific override type.
*
* @param id Group id.
* @param name String containing command name (case sensitive).
* @param type Override type (specific command or group).
* @param rule Override allow/deny setting.
*/
native void AddAdmGroupCmdOverride(GroupId id, const char[] name, OverrideType type, OverrideRule rule);
/**
* Retrieves a group-specific command override.
*
* @param id Group id.
* @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.
*/
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.
*/
native void RegisterAuthIdentType(const char[] name);
/**
* Creates a new admin entry in the permissions cache and returns the generated AdminId index.
*
* @param name Name for this entry (does not have to be unique).
* Specify an empty string for an anonymous admin.
* @return New AdminId index or INVALID_ADMIN_ID if name is empty
*/
native AdminId CreateAdmin(const char[] name="");
/**
* 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 id AdminId of the admin.
* @param name String buffer to store name.
* @param maxlength Maximum size of string buffer.
* @return Number of bytes written.
*/
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.
*
* @param id AdminId of the admin.
* @param auth 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.
*/
native bool BindAdminIdentity(AdminId id, const char[] auth, const char[] ident);
/**
* Sets whether or not a flag is enabled on an admin.
*
* @param id AdminId index of the admin.
* @param flag Admin flag to use.
* @param enabled True to enable, false to disable.
*/
native void SetAdminFlag(AdminId id, AdminFlag flag, bool enabled);
/**
* Returns whether or not a flag is enabled on an admin.
*
* @param id AdminId index of the admin.
* @param flag Admin flag to use.
* @param mode Access mode to check.
* @return True if enabled, false otherwise.
*/
native bool GetAdminFlag(AdminId id, AdminFlag flag, AdmAccessMode mode=Access_Effective);
/**
* Returns the bitstring of access flags on an admin.
*
* @param id AdminId index of the admin.
* @param mode Access mode to use.
* @return A bitstring containing which flags are enabled.
*/
native int GetAdminFlags(AdminId id, 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 id AdminId index of the admin.
* @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);
/**
* Returns the number of groups this admin is a member of.
*
* @param id AdminId index of the admin.
* @return Number of groups this admin is a member of.
*/
native int GetAdminGroupCount(AdminId id);
/**
* Returns group information from an admin.
*
* @param id AdminId index of the 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.
*/
native GroupId GetAdminGroup(AdminId id, int index, char[] name, int maxlength);
/**
* Sets a password on an admin.
*
* @param id AdminId index of the admin.
* @param password String containing the password.
*/
native void SetAdminPassword(AdminId id, const char[] password);
/**
* Gets an admin's password.
*
* @param id AdminId index of the admin.
* @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.
*/
native bool GetAdminPassword(AdminId id, char[] buffer="", int maxlength=0);
/**
* Attempts to find an admin by an auth method and an identity.
*
* @param auth Auth method to try.
* @param identity Identity string to look up.
* @return An AdminId index if found, INVALID_ADMIN_ID otherwise.
*/
native AdminId FindAdminByIdentity(const char[] auth, const char[] identity);
/**
* Removes an admin entry from the cache.
*
* @note This will remove any bindings to a specific user.
*
* @param id AdminId index to remove/invalidate.
* @return True on success, false otherwise.
*/
native bool RemoveAdmin(AdminId id);
/**
* Converts a flag bit string to a bit array.
*
* @param bits Bit string containing the flags.
* @param array Array to write the flags to. Enabled flags will be 'true'.
* @param maxSize Maximum number of flags the array can store.
* @return Number of flags written.
*/
native int FlagBitsToBitArray(int bits, bool[] array, int maxSize);
/**
* Converts a flag array to a bit string.
*
* @param array Array containing true or false for each AdminFlag.
* @param maxSize Maximum size of the flag array.
* @return A bit string composed of the array bits.
*/
native int FlagBitArrayToBits(const bool[] array, int maxSize);
/**
* Converts an array of flags to bits.
*
* @param array Array containing flags that are enabled.
* @param numFlags Number of flags in the array.
* @return A bit string composed of the array flags.
*/
native int FlagArrayToBits(const AdminFlag[] array, int numFlags);
/**
* Converts a bit string to an array of flags.
*
* @param bits Bit string containing the flags.
* @param array Output array to write flags.
* @param maxSize Maximum size of the flag array.
* @return Number of flags written.
*/
native int FlagBitsToArray(int bits, AdminFlag[] array, int maxSize);
/**
* Finds a flag by its string name.
*
* @param name Flag name (like "kick"), case sensitive.
* @param flag Variable to store flag in.
* @return True on success, false if not found.
*/
native bool FindFlagByName(const char[] name, AdminFlag &flag);
/**
* Finds a flag by a given character.
*
* @param c Flag ASCII character/token.
* @param flag Variable to store flag in.
* @return True on success, false if not found.
*/
native bool FindFlagByChar(int c, AdminFlag &flag);
/**
* Finds the flag char for a given admin flag.
*
* @param flag Flag to look up.
* @param c Variable to store flag char.
* @return True on success, false if not found.
*/
native bool FindFlagChar(AdminFlag flag, int &c);
/**
* Converts a string of flag characters to a bit string.
*
* @param flags Flag ASCII string.
* @param numchars Optional variable to store the number of bytes read.
* @return Bit string of ADMFLAG values.
*/
native int ReadFlagString(const char[] flags, int &numchars=0);
/**
* 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 admin Admin doing the targetting (may be INVALID_ADMIN_ID).
* @param target Target admin (may be INVALID_ADMIN_ID).
* @return True if targetable, false if immune.
*/
native bool CanAdminTarget(AdminId admin, AdminId target);
/**
* Creates an admin auth method. This does not need to be called more than once
* per method, ever.
*
* @param method Name of the authentication method.
* @return True on success, false on failure.
*/
native bool CreateAuthMethod(const char[] method);
/**
* Sets a group's immunity level.
*
* @param gid Group Id.
* @param level Immunity level value.
* @return Old immunity level value.
*/
native int SetAdmGroupImmunityLevel(GroupId gid, int level);
/**
* Gets a group's immunity level (defaults to 0).
*
* @param gid Group Id.
* @return Immunity level value.
*/
native int GetAdmGroupImmunityLevel(GroupId gid);
/**
* Sets an admin's immunity level.
*
* @param id Admin Id.
* @param level Immunity level value.
* @return Old immunity level value.
*/
native int SetAdminImmunityLevel(AdminId id, int level);
/**
* Gets an admin's immunity level.
*
* @param id Admin Id.
* @return Immunity level value.
*/
native int GetAdminImmunityLevel(AdminId id);
/**
* Converts a flag to its single bit.
*
* @param flag Flag to convert.
* @return Bit representation of the flag.
*/
stock int FlagToBit(AdminFlag flag)
{
return (1 << view_as<int>(flag));
}
/**
* Converts a bit to an AdminFlag.
*
* @param bit Bit to convert.
* @param flag Stores the converted flag by reference.
* @return True on success, false otherwise.
*/
stock bool BitToFlag(int bit, AdminFlag &flag)
{
AdminFlag array[1];
if (FlagBitsToArray(bit, array, 1))
{
flag = array[0];
return true;
}
return false;
}
/**
* Converts a bit string to a string of flag characters.
*
* @param bits Bit string containing the flags.
* @param flags Output array to write a string of flag characters.
* @param maxSize Maximum size of the string array.
* @return Number of flag characters written.
*/
stock int FlagBitsToString(const int bits, char[] flags, const int maxSize)
{
AdminFlag array[AdminFlags_TOTAL];
int numFlags = FlagBitsToArray(bits, array, AdminFlags_TOTAL);
if (numFlags > maxSize)
{
numFlags = maxSize;
}
int i, c, numId = 0;
for (i = 0; i < numFlags; ++i)
{
if(FindFlagChar(array[i], c))
{
flags[numId++] = c;
}
}
flags[numId] = '\0';
return numId;
}
|