2008-10-04 22:59:11 +02:00
|
|
|
/**
|
|
|
|
* vim: set ts=4 :
|
|
|
|
* =============================================================================
|
2009-04-14 23:40:48 +02:00
|
|
|
* SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
|
2008-10-04 22:59:11 +02:00
|
|
|
* =============================================================================
|
|
|
|
*
|
|
|
|
* 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>.
|
|
|
|
*
|
2009-04-14 23:40:48 +02:00
|
|
|
* Version: $Id$
|
2008-10-04 22:59:11 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#if defined _helpers_included
|
|
|
|
#endinput
|
|
|
|
#endif
|
|
|
|
#define _helpers_included
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Formats a user's info as log text. This is usually not needed because
|
|
|
|
* %L can be used to auto-format client information into a string.
|
|
|
|
*
|
|
|
|
* @param client Client index.
|
|
|
|
* @param buffer Buffer for text.
|
|
|
|
* @param maxlength Maximum length of text.
|
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
stock void FormatUserLogText(int client, char[] buffer, int maxlength)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2016-08-23 15:34:00 +02:00
|
|
|
char auth[32];
|
|
|
|
char name[MAX_NAME_LENGTH];
|
2008-10-04 22:59:11 +02:00
|
|
|
|
2016-08-23 15:34:00 +02:00
|
|
|
int userid = GetClientUserId(client);
|
2008-10-04 22:59:11 +02:00
|
|
|
if (!GetClientAuthString(client, auth, sizeof(auth)))
|
|
|
|
{
|
|
|
|
strcopy(auth, sizeof(auth), "UNKNOWN");
|
|
|
|
}
|
|
|
|
if (!GetClientName(client, name, sizeof(name)))
|
|
|
|
{
|
|
|
|
strcopy(name, sizeof(name), "UNKNOWN");
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Currently, no team stuff ... */
|
|
|
|
|
|
|
|
Format(buffer, maxlength, "\"%s<%d><%s><>\"", name, userid, auth);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns plugin handle from plugin filename.
|
|
|
|
*
|
|
|
|
* @param filename Filename of the plugin to search for.
|
|
|
|
* @return Handle to plugin if found, INVALID_HANDLE otherwise.
|
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
stock Handle FindPluginByFile(const char[] filename)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2016-08-23 15:34:00 +02:00
|
|
|
char buffer[256];
|
2008-10-04 22:59:11 +02:00
|
|
|
|
2016-08-23 15:34:00 +02:00
|
|
|
Handle iter = GetPluginIterator();
|
|
|
|
Handle pl;
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
while (MorePlugins(iter))
|
|
|
|
{
|
|
|
|
pl = ReadPlugin(iter);
|
|
|
|
|
|
|
|
GetPluginFilename(pl, buffer, sizeof(buffer));
|
|
|
|
if (strcmp(buffer, filename, false) == 0)
|
|
|
|
{
|
|
|
|
CloseHandle(iter);
|
|
|
|
return pl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseHandle(iter);
|
|
|
|
|
|
|
|
return INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @deprecated Use FindTarget() or ProcessTargetString().
|
|
|
|
*/
|
|
|
|
#pragma deprecated Use FindTarget() or ProcessTargetString()
|
2015-03-21 15:43:24 +01:00
|
|
|
stock int SearchForClients(const char[] pattern, int[] clients, int maxClients)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2015-03-21 15:43:24 +01:00
|
|
|
int total = 0;
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
if (maxClients == 0)
|
|
|
|
return 0;
|
|
|
|
|
2015-03-21 15:43:24 +01:00
|
|
|
if (pattern[0] == '#') {
|
|
|
|
int input = StringToInt(pattern[1]);
|
|
|
|
if (!input) {
|
2016-08-23 15:34:00 +02:00
|
|
|
char name[MAX_NAME_LENGTH];
|
2015-03-21 15:43:24 +01:00
|
|
|
for (int i=1; i<=MaxClients; i++) {
|
2008-10-04 22:59:11 +02:00
|
|
|
if (!IsClientInGame(i))
|
|
|
|
continue;
|
|
|
|
GetClientName(i, name, sizeof(name));
|
2015-03-21 15:43:24 +01:00
|
|
|
if (strcmp(name, pattern, false) == 0) {
|
2008-10-04 22:59:11 +02:00
|
|
|
clients[0] = i;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2015-03-21 15:43:24 +01:00
|
|
|
int client = GetClientOfUserId(input);
|
|
|
|
if (client) {
|
2008-10-04 22:59:11 +02:00
|
|
|
clients[0] = client;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-23 15:34:00 +02:00
|
|
|
char name[MAX_NAME_LENGTH];
|
2015-03-21 15:43:24 +01:00
|
|
|
for (int i=1; i<=MaxClients; i++)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
|
|
|
if (!IsClientInGame(i))
|
|
|
|
continue;
|
|
|
|
GetClientName(i, name, sizeof(name));
|
2015-03-21 15:43:24 +01:00
|
|
|
if (StrContains(name, pattern, false) != -1) {
|
2008-10-04 22:59:11 +02:00
|
|
|
clients[total++] = i;
|
|
|
|
if (total >= maxClients)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wraps ProcessTargetString() and handles producing error messages for
|
|
|
|
* bad targets.
|
|
|
|
*
|
|
|
|
* @param client Client who issued command
|
|
|
|
* @param target Client's target argument
|
|
|
|
* @param nobots Optional. Set to true if bots should NOT be targetted
|
|
|
|
* @param immunity Optional. Set to false to ignore target immunity.
|
|
|
|
* @return Index of target client, or -1 on error.
|
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
stock int FindTarget(int client, const char[] target, bool nobots = false, bool immunity = true)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2016-08-23 15:34:00 +02:00
|
|
|
char target_name[MAX_TARGET_LENGTH];
|
|
|
|
int target_list[1], target_count;
|
|
|
|
bool tn_is_ml;
|
2008-10-04 22:59:11 +02:00
|
|
|
|
2016-08-23 15:34:00 +02:00
|
|
|
int flags = COMMAND_FILTER_NO_MULTI;
|
2008-10-04 22:59:11 +02:00
|
|
|
if (nobots)
|
|
|
|
{
|
|
|
|
flags |= COMMAND_FILTER_NO_BOTS;
|
|
|
|
}
|
|
|
|
if (!immunity)
|
|
|
|
{
|
|
|
|
flags |= COMMAND_FILTER_NO_IMMUNITY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((target_count = ProcessTargetString(
|
|
|
|
target,
|
|
|
|
client,
|
|
|
|
target_list,
|
|
|
|
1,
|
|
|
|
flags,
|
|
|
|
target_name,
|
|
|
|
sizeof(target_name),
|
|
|
|
tn_is_ml)) > 0)
|
|
|
|
{
|
|
|
|
return target_list[0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ReplyToTargetError(client, target_count);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function is no longer supported. It has been replaced with ReadMapList(),
|
|
|
|
* which uses a more unified caching and configuration mechanism. This function also
|
|
|
|
* has a bug where if the cvar contents changes, the fileTime change won't be recognized.
|
|
|
|
*
|
|
|
|
* Loads a specified array with maps. The maps will be either loaded from mapcyclefile, or if supplied
|
|
|
|
* a cvar containing a file name. If the file in the cvar is bad, it will use mapcyclefile. The fileTime
|
|
|
|
* parameter is used to store a timestamp of the file. If specified, the file will only be reloaded if it
|
|
|
|
* has changed.
|
|
|
|
*
|
|
|
|
* @param array Valid array handle, should be created with CreateArray(33) or larger.
|
|
|
|
* @param fileTime Variable containing the "last changed" time of the file. Used to avoid needless reloading.
|
|
|
|
* @param fileCvar CVAR set to the file to be loaded. Optional.
|
|
|
|
* @return Number of maps loaded or 0 if in error.
|
|
|
|
*/
|
|
|
|
#pragma deprecated Use ReadMapList() instead.
|
2016-08-23 15:34:00 +02:00
|
|
|
stock int LoadMaps(Handle array, int &fileTime = 0, Handle fileCvar = INVALID_HANDLE)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2016-08-23 15:34:00 +02:00
|
|
|
char mapPath[256], mapFile[64];
|
|
|
|
bool fileFound = false;
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
if (fileCvar != INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
GetConVarString(fileCvar, mapFile, 64);
|
|
|
|
BuildPath(Path_SM, mapPath, sizeof(mapPath), mapFile);
|
|
|
|
fileFound = FileExists(mapPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!fileFound)
|
|
|
|
{
|
2016-08-23 15:34:00 +02:00
|
|
|
Handle mapCycleFile = FindConVar("mapcyclefile");
|
2008-10-04 22:59:11 +02:00
|
|
|
GetConVarString(mapCycleFile, mapPath, sizeof(mapPath));
|
|
|
|
fileFound = FileExists(mapPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!fileFound)
|
|
|
|
{
|
|
|
|
LogError("Failed to find a file to load maps from. No maps loaded.");
|
|
|
|
ClearArray(array);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the file hasn't changed, there's no reason to reload
|
|
|
|
// all of the maps.
|
2016-08-23 15:34:00 +02:00
|
|
|
int newTime = GetFileTime(mapPath, FileTime_LastChange);
|
2008-10-04 22:59:11 +02:00
|
|
|
if (fileTime == newTime)
|
|
|
|
{
|
|
|
|
return GetArraySize(array);
|
|
|
|
}
|
|
|
|
|
|
|
|
fileTime = newTime;
|
|
|
|
|
|
|
|
ClearArray(array);
|
|
|
|
|
2015-03-21 15:43:24 +01:00
|
|
|
File file = OpenFile(mapPath, "rt");
|
|
|
|
if (!file) {
|
2008-10-04 22:59:11 +02:00
|
|
|
LogError("Could not open file: %s", mapPath);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LogMessage("Loading maps from file: %s", mapPath);
|
|
|
|
|
2015-03-21 15:43:24 +01:00
|
|
|
int len;
|
|
|
|
char buffer[64];
|
|
|
|
while (!file.EndOfFile() && file.ReadLine(buffer, sizeof(buffer)))
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
|
|
|
TrimString(buffer);
|
|
|
|
|
|
|
|
if ((len = StrContains(buffer, ".bsp", false)) != -1)
|
|
|
|
{
|
|
|
|
buffer[len] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buffer[0] == '\0' || !IsValidConVarChar(buffer[0]) || !IsMapValid(buffer))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FindStringInArray(array, buffer) != -1)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
PushArrayString(array, buffer);
|
|
|
|
}
|
|
|
|
|
2015-03-21 15:43:24 +01:00
|
|
|
file.Close();
|
2008-10-04 22:59:11 +02:00
|
|
|
return GetArraySize(array);
|
|
|
|
}
|