Gave OnClientAuthorized() its meds.
3 * =============================================================================
4 * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
5 * =============================================================================
7 * This file is part of the SourceMod/SourcePawn SDK.
9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, version 3.0, as published by the
11 * Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 * You should have received a copy of the GNU General Public License along with
19 * this program. If not, see <http://www.gnu.org/licenses/>.
21 * As a special exception, AlliedModders LLC gives you permission to link the
22 * code of this program (as well as its derivative works) to "Half-Life 2," the
23 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
24 * by the Valve Corporation. You must obey the GNU General Public License in
25 * all respects for all other code used. Additionally, AlliedModders LLC grants
26 * this exception to all derivative works. AlliedModders LLC defines further
27 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
28 * or <http://www.sourcemod.net/license.php>.
33 #if defined _helpers_included
36 #define _helpers_included
39 * Formats a user's info as log text. This is usually not needed because
40 * %L can be used to auto-format client information into a string.
42 * @param client Client index.
43 * @param buffer Buffer for text.
44 * @param maxlength Maximum length of text.
46 stock FormatUserLogText(client, String:buffer[], maxlength)
51 new userid = GetClientUserId(client);
52 if (!GetClientAuthString(client, auth, sizeof(auth)))
54 strcopy(auth, sizeof(auth), "UNKNOWN");
56 if (!GetClientName(client, name, sizeof(name)))
58 strcopy(name, sizeof(name), "UNKNOWN");
61 /** Currently, no team stuff ... */
63 Format(buffer, maxlength, "\"%s<%d><%s><>\"", name, userid, auth);
67 * Returns plugin handle from plugin filename.
69 * @param filename Filename of the plugin to search for.
70 * @return Handle to plugin if found, INVALID_HANDLE otherwise.
72 stock Handle:FindPluginByFile(const String:filename[])
74 decl String:buffer[256];
76 new Handle:iter = GetPluginIterator();
79 while (MorePlugins(iter))
81 pl = ReadPlugin(iter);
83 GetPluginFilename(pl, buffer, sizeof(buffer));
84 if (strcmp(buffer, filename, false) == 0)
93 return INVALID_HANDLE;
97 * @deprecated Use FindTarget() or ProcessTargetString().
99 #pragma deprecated Use FindTarget() or ProcessTargetString()
100 stock SearchForClients(const String:pattern[], clients[], maxClients)
102 new maxclients = GetMaxClients();
110 if (pattern[0] == '#')
112 new input = StringToInt(pattern[1]);
116 for (new i=1; i<=maxclients; i++)
118 if (!IsClientInGame(i))
122 GetClientName(i, name, sizeof(name));
123 if (strcmp(name, pattern, false) == 0)
130 new client = GetClientOfUserId(input);
140 for (new i=1; i<=maxclients; i++)
142 if (!IsClientInGame(i))
146 GetClientName(i, name, sizeof(name));
147 if (StrContains(name, pattern, false) != -1)
149 clients[total++] = i;
150 if (total >= maxClients)
161 * Wraps ProcessTargetString() and handles producing error messages for
164 * @param client Client who issued command
165 * @param target Client's target argument
166 * @param nobots Optional. Set to true if bots should NOT be targetted
167 * @param immunity Optional. Set to false to ignore target immunity.
168 * @return Index of target client, or -1 on error.
170 stock FindTarget(client, const String:target[], bool:nobots = false, bool:immunity = true)
172 decl String:target_name[MAX_TARGET_LENGTH];
173 decl target_list[1], target_count, bool:tn_is_ml;
175 new flags = COMMAND_FILTER_NO_MULTI;
178 flags |= COMMAND_FILTER_NO_BOTS;
182 flags |= COMMAND_FILTER_NO_IMMUNITY;
185 if ((target_count = ProcessTargetString(
195 return target_list[0];
199 ReplyToTargetError(client, target_count);
205 * This function is no longer supported. It has been replaced with ReadMapList(),
206 * which uses a more unified caching and configuration mechanism. This function also
207 * has a bug where if the cvar contents changes, the fileTime change won't be recognized.
209 * Loads a specified array with maps. The maps will be either loaded from mapcyclefile, or if supplied
210 * a cvar containing a file name. If the file in the cvar is bad, it will use mapcyclefile. The fileTime
211 * parameter is used to store a timestamp of the file. If specified, the file will only be reloaded if it
214 * @param array Valid array handle, should be created with CreateArray(33) or larger.
215 * @param fileTime Variable containing the "last changed" time of the file. Used to avoid needless reloading.
216 * @param fileCvar CVAR set to the file to be loaded. Optional.
217 * @return Number of maps loaded or 0 if in error.
219 #pragma deprecated Use ReadMapList() instead.
220 stock LoadMaps(Handle:array, &fileTime = 0, Handle:fileCvar = INVALID_HANDLE)
222 decl String:mapPath[256], String:mapFile[64];
223 new bool:fileFound = false;
225 if (fileCvar != INVALID_HANDLE)
227 GetConVarString(fileCvar, mapFile, 64);
228 BuildPath(Path_SM, mapPath, sizeof(mapPath), mapFile);
229 fileFound = FileExists(mapPath);
234 new Handle:mapCycleFile = FindConVar("mapcyclefile");
235 GetConVarString(mapCycleFile, mapPath, sizeof(mapPath));
236 fileFound = FileExists(mapPath);
241 LogError("Failed to find a file to load maps from. No maps loaded.");
247 // If the file hasn't changed, there's no reason to reload
249 new newTime = GetFileTime(mapPath, FileTime_LastChange);
250 if (fileTime == newTime)
252 return GetArraySize(array);
259 new Handle:file = OpenFile(mapPath, "rt");
260 if (file == INVALID_HANDLE)
262 LogError("Could not open file: %s", mapPath);
267 LogMessage("Loading maps from file: %s", mapPath);
269 decl String:buffer[64], len;
270 while (!IsEndOfFile(file) && ReadFileLine(file, buffer, sizeof(buffer)))
274 if ((len = StrContains(buffer, ".bsp", false)) != -1)
279 if (buffer[0] == '\0' || !IsValidConVarChar(buffer[0]) || !IsMapValid(buffer))
284 if (FindStringInArray(array, buffer) != -1)
289 PushArrayString(array, buffer);
293 return GetArraySize(array);