https://wiki.alliedmods.net/index.php?title=Checking_Admin_Flags_(SourceMod_Scripting)&feed=atom&action=historyChecking Admin Flags (SourceMod Scripting) - Revision history2024-03-28T09:28:07ZRevision history for this page on the wikiMediaWiki 1.31.6https://wiki.alliedmods.net/index.php?title=Checking_Admin_Flags_(SourceMod_Scripting)&diff=10926&oldid=prevJoinedsenses: /* The last fallback: GetAdminFlag / GetUserFlagBits */ Update highlighting2020-03-29T23:19:45Z<p><span dir="auto"><span class="autocomment">The last fallback: GetAdminFlag / GetUserFlagBits: </span> Update highlighting</span></p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">Revision as of 23:19, 29 March 2020</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l129" >Line 129:</td>
<td colspan="2" class="diff-lineno">Line 129:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>For example, if you want to check if a user has both the Generic and Kick flags, you can do so like this:</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>For example, if you want to check if a user has both the Generic and Kick flags, you can do so like this:</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><<del class="diffchange diffchange-inline">pawn</del>>if (GetUserFlagBits(client) & (ADMFLAG_GENERIC | ADMFLAG_KICK) == (ADMFLAG_GENERIC | ADMFLAG_KICK))</div></td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><<ins class="diffchange diffchange-inline">sourcepawn</ins>>if (GetUserFlagBits(client) & (ADMFLAG_GENERIC | ADMFLAG_KICK) == (ADMFLAG_GENERIC | ADMFLAG_KICK))</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>{</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>{</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>     // User has both flags</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>     // User has both flags</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>}</<del class="diffchange diffchange-inline">pawn</del>></div></td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>}</<ins class="diffchange diffchange-inline">sourcepawn</ins>></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>If you're reading flags from a string somewhere, such as from a convar (which is a terrible idea, you should go back up and read the [[#Checking inside an existing command: CheckCommandAccess|CheckCommandAccess]] section above), you can use the [https://sm.alliedmods.net/new-api/admin/ReadFlagString ReadFlagString] section command to turn a string into a set of flag bits, which you can use in place of the flags in the previous section, such as this:</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>If you're reading flags from a string somewhere, such as from a convar (which is a terrible idea, you should go back up and read the [[#Checking inside an existing command: CheckCommandAccess|CheckCommandAccess]] section above), you can use the [https://sm.alliedmods.net/new-api/admin/ReadFlagString ReadFlagString] section command to turn a string into a set of flag bits, which you can use in place of the flags in the previous section, such as this:</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><<del class="diffchange diffchange-inline">pawn</del>>int flags = ReadFlagString(myflags);</div></td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><<ins class="diffchange diffchange-inline">sourcepawn</ins>>int flags = ReadFlagString(myflags);</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>if (GetUserFlagBits(client) & flags == flags)</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>if (GetUserFlagBits(client) & flags == flags)</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>{</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>{</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>     // User has all the flags in the myflags string.</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>     // User has all the flags in the myflags string.</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>}</<del class="diffchange diffchange-inline">pawn</del>></div></td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>}</<ins class="diffchange diffchange-inline">sourcepawn</ins>></div></td></tr>
</table>Joinedsenseshttps://wiki.alliedmods.net/index.php?title=Checking_Admin_Flags_(SourceMod_Scripting)&diff=10925&oldid=prevJoinedsenses: /* Checking inside an existing command: CheckCommandAccess */ Update highlighting2020-03-29T23:19:20Z<p><span dir="auto"><span class="autocomment">Checking inside an existing command: CheckCommandAccess: </span> Update highlighting</span></p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">Revision as of 23:19, 29 March 2020</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l107" >Line 107:</td>
<td colspan="2" class="diff-lineno">Line 107:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>To make a command have the same override as earlier, it would look like this:</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>To make a command have the same override as earlier, it would look like this:</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><<del class="diffchange diffchange-inline">pawn</del>>if (CheckCommandAccess(client, "mycommand", ADMFLAG_GENERIC))</div></td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><<ins class="diffchange diffchange-inline">sourcepawn</ins>>if (CheckCommandAccess(client, "mycommand", ADMFLAG_GENERIC))</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>{</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>{</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>     // They have the "mycommand" override or the generic admin flag if no override exists</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>     // They have the "mycommand" override or the generic admin flag if no override exists</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>}</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>}</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div></<del class="diffchange diffchange-inline">pawn</del>></div></td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div></<ins class="diffchange diffchange-inline">sourcepawn</ins>></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[https://sm.alliedmods.net/new-api/console/CheckAccess CheckAccess] is a variation of this command if you have an AdminId from an admin lookup already.</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[https://sm.alliedmods.net/new-api/console/CheckAccess CheckAccess] is a variation of this command if you have an AdminId from an admin lookup already.</div></td></tr>
</table>Joinedsenseshttps://wiki.alliedmods.net/index.php?title=Checking_Admin_Flags_(SourceMod_Scripting)&diff=10048&oldid=prevPowerlord: Fixed the argument list for CheckCommandAccess2015-10-26T21:05:07Z<p>Fixed the argument list for CheckCommandAccess</p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">Revision as of 21:05, 26 October 2015</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l98" >Line 98:</td>
<td colspan="2" class="diff-lineno">Line 98:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>CheckCommandAccess takes four arguments.</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>CheckCommandAccess takes four arguments.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>The <del class="diffchange diffchange-inline">first argument is the </del>client index who you want to check.</div></td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline"># </ins>The client index who you want to check.</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>The <del class="diffchange diffchange-inline">second argument is the </del>name of the override that this command should use.  It can either be a new override or an existing override or command name.</div></td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline"># </ins>The name of the override that this command should use.  It can either be a new override or an existing override or command name.</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>The <del class="diffchange diffchange-inline">third argument is the </del>default admin flag(s) that you want to use for this.  This flag(s) are used when no overrides are present.</div></td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline"># </ins>The default admin flag(s) that you want to use for this.  This flag(s) are used when no overrides are present.</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del class="diffchange diffchange-inline">The fourth </del>(<del class="diffchange diffchange-inline">optional</del>) <del class="diffchange diffchange-inline">argument is a </del>boolean that tells SourceMod whether it should look for a command with the override's name (false) or if it should just look for the override in the overrides table (true).  Default is '''false'''.</div></td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline"># </ins>(<ins class="diffchange diffchange-inline">Optional</ins>) <ins class="diffchange diffchange-inline">A </ins>boolean that tells SourceMod whether it should look for a command with the override's name (false) or if it should just look for the override in the overrides table (true).  Default is '''false'''.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>CheckCommandAccess returns true if the client has the appropriate permissions or false if they do not.</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>CheckCommandAccess returns true if the client has the appropriate permissions or false if they do not.</div></td></tr>
</table>Powerlordhttps://wiki.alliedmods.net/index.php?title=Checking_Admin_Flags_(SourceMod_Scripting)&diff=10047&oldid=prevPowerlord: Really dumb mistake2015-10-26T21:03:01Z<p>Really dumb mistake</p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">Revision as of 21:03, 26 October 2015</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l52" >Line 52:</td>
<td colspan="2" class="diff-lineno">Line 52:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Now, change the RegConsoleCmd to a RegAdminCmd and add the required flag(s) as the third argument:</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Now, change the RegConsoleCmd to a RegAdminCmd and add the required flag(s) as the third argument:</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><pawn><del class="diffchange diffchange-inline">RegConsoleCmd</del>("mycommand", Cmd_MyCommand, ADMFLAG_GENERIC, "This is my great command");</pawn></div></td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><pawn><ins class="diffchange diffchange-inline">RegAdminCmd</ins>("mycommand", Cmd_MyCommand, ADMFLAG_GENERIC, "This is my great command");</pawn></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Now you have a command that requires the generic admin flag!</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Now you have a command that requires the generic admin flag!</div></td></tr>
</table>Powerlordhttps://wiki.alliedmods.net/index.php?title=Checking_Admin_Flags_(SourceMod_Scripting)&diff=10046&oldid=prevPowerlord: New page for checking admin flags.2015-10-26T21:02:21Z<p>New page for checking admin flags.</p>
<p><b>New page</b></p><div>Admin flags control which users can use particular commands.<br />
<br />
They also interact with the Overrides system.<br />
<br />
There are multiple different ways to check flags. The major ones are documented below.<br />
<br />
==List of Admin Flag Bits==<br />
<br />
Most of the admin related functions in SourceMod use a bitmask of admin flag bits. As such, here is the list of constants located in admin.inc that you can use.<br />
<br />
''Note: Do not include this list of defines in your own code, just the ADMFLAG_WHATEVER name.''<br />
<br />
<pawn>/**<br />
* @section Bitwise values definitions for admin flags.<br />
*/<br />
#define ADMFLAG_RESERVATION (1<<0) /**< Convenience macro for Admin_Reservation as a FlagBit */<br />
#define ADMFLAG_GENERIC (1<<1) /**< Convenience macro for Admin_Generic as a FlagBit */<br />
#define ADMFLAG_KICK (1<<2) /**< Convenience macro for Admin_Kick as a FlagBit */<br />
#define ADMFLAG_BAN (1<<3) /**< Convenience macro for Admin_Ban as a FlagBit */<br />
#define ADMFLAG_UNBAN (1<<4) /**< Convenience macro for Admin_Unban as a FlagBit */<br />
#define ADMFLAG_SLAY (1<<5) /**< Convenience macro for Admin_Slay as a FlagBit */<br />
#define ADMFLAG_CHANGEMAP (1<<6) /**< Convenience macro for Admin_Changemap as a FlagBit */<br />
#define ADMFLAG_CONVARS (1<<7) /**< Convenience macro for Admin_Convars as a FlagBit */<br />
#define ADMFLAG_CONFIG (1<<8) /**< Convenience macro for Admin_Config as a FlagBit */<br />
#define ADMFLAG_CHAT (1<<9) /**< Convenience macro for Admin_Chat as a FlagBit */<br />
#define ADMFLAG_VOTE (1<<10) /**< Convenience macro for Admin_Vote as a FlagBit */<br />
#define ADMFLAG_PASSWORD (1<<11) /**< Convenience macro for Admin_Password as a FlagBit */<br />
#define ADMFLAG_RCON (1<<12) /**< Convenience macro for Admin_RCON as a FlagBit */<br />
#define ADMFLAG_CHEATS (1<<13) /**< Convenience macro for Admin_Cheats as a FlagBit */<br />
#define ADMFLAG_ROOT (1<<14) /**< Convenience macro for Admin_Root as a FlagBit */<br />
#define ADMFLAG_CUSTOM1 (1<<15) /**< Convenience macro for Admin_Custom1 as a FlagBit */<br />
#define ADMFLAG_CUSTOM2 (1<<16) /**< Convenience macro for Admin_Custom2 as a FlagBit */<br />
#define ADMFLAG_CUSTOM3 (1<<17) /**< Convenience macro for Admin_Custom3 as a FlagBit */<br />
#define ADMFLAG_CUSTOM4 (1<<18) /**< Convenience macro for Admin_Custom4 as a FlagBit */<br />
#define ADMFLAG_CUSTOM5 (1<<19) /**< Convenience macro for Admin_Custom5 as a FlagBit */<br />
#define ADMFLAG_CUSTOM6 (1<<20) /**< Convenience macro for Admin_Custom6 as a FlagBit */</pawn><br />
<br />
Since these are just bits, you can combine them to make a command require more than one admin flag:<br />
<br />
<pawn>ADMFLAG_GENERIC | ADMFLAG_KICK</pawn><br />
<br />
==Creating Admin Commands instead of Commands==<br />
<br />
The simplest form of flag checking is to create an admin command instead of a normal command.<br />
<br />
The standard syntax for creating a command looks something like this:<br />
<br />
<pawn>RegConsoleCmd("mycommand", Cmd_MyCommand, "This is my great command");</pawn><br />
<br />
If you want to restrict this to admin users only, first you need to select an admin flag from the above list.<br />
<br />
Now, change the RegConsoleCmd to a RegAdminCmd and add the required flag(s) as the third argument:<br />
<br />
<pawn>RegConsoleCmd("mycommand", Cmd_MyCommand, ADMFLAG_GENERIC, "This is my great command");</pawn><br />
<br />
Now you have a command that requires the generic admin flag!<br />
<br />
==Command and Group Overrides==<br />
<br />
Any normal or admin command can have a command override placed on it using either Command Overrides or Group Overrides.<br />
<br />
===Command Overrides===<br />
<br />
[[Overriding Command Access (SourceMod)|Command overrides]] are used to change the admin flag that a command checks. For example, to override the admin command created in one of the previous sections, I could open <tt>addons/sourcemod/configs/admin_overrides.cfg</tt> and put this somewhere before the last bracket:<br />
<br />
<pre>"mycommand" "a"</pre><br />
<br />
"a" can be any of the [[Adding Admins (SourceMod)#Levels|admin flags]] SourceMod uses. "a" itself is Reserved slot access.<br />
<br />
If a command is part of a Command Group, you can override the entire command group by putting the command group name with a @ before it. Only admin commands can have a command group.<br />
<br />
<pre>"@mycommandgroup" "a"</pre><br />
<br />
===Admin Group Overrides===<br />
<br />
Admin Group overrides are a bit different than Command overrides. First, they only apply to [[Adding Groups (SourceMod)|admin groups]].<br />
<br />
Second, they are listed as "allow" or "deny".<br />
<br />
For example, if I wanted to make it so that the "badgroup" cannot use "mycommand", I would do this in <tt>admin/sourcemod/configs/admin_groups.cfg</tt>:<br />
<br />
<pre> "badgroup"<br />
{<br />
Overrides<br />
{<br />
"mycommand" "deny"<br />
}<br />
}</pre><br />
<br />
and then I would assign users to this group.<br />
<br />
==Checking inside an existing command: CheckCommandAccess==<br />
<br />
Sometimes, you may want to treat a command differently if a user has a specific flag. This may even be something you enable and disable using a cvar.<br />
<br />
The best way to do this is the [https://sm.alliedmods.net/new-api/console/CheckCommandAccess CheckCommandAccess] command.<br />
<br />
CheckCommandAccess takes four arguments.<br />
<br />
The first argument is the client index who you want to check.<br />
The second argument is the name of the override that this command should use. It can either be a new override or an existing override or command name.<br />
The third argument is the default admin flag(s) that you want to use for this. This flag(s) are used when no overrides are present.<br />
The fourth (optional) argument is a boolean that tells SourceMod whether it should look for a command with the override's name (false) or if it should just look for the override in the overrides table (true). Default is '''false'''.<br />
<br />
CheckCommandAccess returns true if the client has the appropriate permissions or false if they do not.<br />
<br />
To make a command have the same override as earlier, it would look like this:<br />
<br />
<pawn>if (CheckCommandAccess(client, "mycommand", ADMFLAG_GENERIC))<br />
{<br />
// They have the "mycommand" override or the generic admin flag if no override exists<br />
}<br />
</pawn><br />
<br />
[https://sm.alliedmods.net/new-api/console/CheckAccess CheckAccess] is a variation of this command if you have an AdminId from an admin lookup already.<br />
<br />
==The last fallback: GetAdminFlag / GetUserFlagBits==<br />
<br />
'''These two commands are the brute force method and should only be used as a last resort.''' You should '''always''' use [[#Checking inside an existing command: CheckCommandAccess|CheckCommandAccess]] in preference to this.<br />
<br />
These commands '''do not''' participate in the overrides system.<br />
<br />
In order to use GetAdminFlag, you need to first get a client's AdminId. This is done using the [https://sm.alliedmods.net/new-api/clients/GetUserAdmin GetUserAdmin] command. This will return an AdminId or the value <tt>INVALID_ADMIN_ID</tt> if the user is not an admin.<br />
<br />
Then, you can use [https://sm.alliedmods.net/new-api/admin/GetAdminFlag GetAdminFlag] to see if a user has a particular AdminFlag. Note: This uses the [https://sm.alliedmods.net/new-api/admin/AdminFlag AdminFlag enum] instead of the Admin flag bits shown earlier.<br />
<br />
If you need to check for the existence of multiple flags, you can use [https://sm.alliedmods.net/new-api/clients/GetUserFlagBits GetUserFlagBits] instead. GetUserFlagBits takes a client index and will return a value that contains all the flags that a user has.<br />
<br />
For example, if you want to check if a user has both the Generic and Kick flags, you can do so like this:<br />
<br />
<pawn>if (GetUserFlagBits(client) & (ADMFLAG_GENERIC | ADMFLAG_KICK) == (ADMFLAG_GENERIC | ADMFLAG_KICK))<br />
{<br />
// User has both flags<br />
}</pawn><br />
<br />
If you're reading flags from a string somewhere, such as from a convar (which is a terrible idea, you should go back up and read the [[#Checking inside an existing command: CheckCommandAccess|CheckCommandAccess]] section above), you can use the [https://sm.alliedmods.net/new-api/admin/ReadFlagString ReadFlagString] section command to turn a string into a set of flag bits, which you can use in place of the flags in the previous section, such as this:<br />
<br />
<pawn>int flags = ReadFlagString(myflags);<br />
if (GetUserFlagBits(client) & flags == flags)<br />
{<br />
// User has all the flags in the myflags string.<br />
}</pawn></div>Powerlord