summaryrefslogtreecommitdiff
path: root/sourcemod/scripting/include/smlib/convars.inc
blob: b7f4b23d7ee590b889d9d778065dcd704af703fa (plain)
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
#if defined _smlib_convars_included
	#endinput
#endif
#define _smlib_convars_included

#include <sourcemod>

/**
 * Checks if a ConVar has one or more flags set.
 *
 * @param	convar		ConVar Handle.
 * @param	flags		Flags to check.
 * @return				True if flags are set, false otherwise.
 */
stock bool Convar_HasFlags(ConVar convar, int flags)
{
	return convar.Flags & flags > 0;
}

/**
 * Adds one or more flags to a ConVar.
 *
 * @param	convar		ConVar Handle.
 * @param	flags		Flags to add.
 */
stock void Convar_AddFlags(ConVar convar, int flags)
{
	int newFlags = convar.Flags;
	newFlags |= flags;
	convar.Flags = newFlags;
}

/**
 * Removes one ore more flags from a ConVar.
 *
 * @param	convar		ConVar Handle.
 * @param	flags		Flags to remove
 * @noreturn
 */
stock void Convar_RemoveFlags(ConVar convar, int flags)
{
	int newFlags = convar.Flags;
	newFlags &= ~flags;
	convar.Flags = newFlags;
}

/**
 * Checks if a String is a valid ConVar or
 * Console Command name.
 *
 * @param	name		String Name.
 * @return				True if the name specified is a valid ConVar or console command name, false otherwise.
 */
stock bool Convar_IsValidName(const char[] name)
{
	if (name[0] == '\0') {
		return false;
	}

	int n=0;
	while (name[n] != '\0') {

		if (!IsValidConVarChar(name[n])) {
			return false;
		}

		n++;
	}

	return true;
}