From 877b604ce9afda33c5f2fbb97077f79be9d19478 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 7 Jun 2007 03:45:44 +0000 Subject: [PATCH] - added SearchForClients - fixed versions and some header info in base plugins --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40908 --- plugins/admin-auth.sp | 6 +-- plugins/admin-flatfile/admin-flatfile.sp | 2 +- plugins/include/helpers.inc | 67 ++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 4 deletions(-) diff --git a/plugins/admin-auth.sp b/plugins/admin-auth.sp index ae599166..7f2a5861 100644 --- a/plugins/admin-auth.sp +++ b/plugins/admin-auth.sp @@ -1,6 +1,6 @@ /** - * admin-flatfile.sp - * Manages the standard flat files for admins. This is the file to compile. + * admin-auth.sp + * Authenticates admins. * This file is part of SourceMod, Copyright (C) 2004-2007 AlliedModders LLC * * This program is free software; you can redistribute it and/or @@ -26,7 +26,7 @@ public Plugin:myinfo = name = "Admin Auth", author = "AlliedModders LLC", description = "Authenticates Admins", - version = "1.0.0.0", + version = SOURCEMOD_VERSION, url = "http://www.sourcemod.net/" }; diff --git a/plugins/admin-flatfile/admin-flatfile.sp b/plugins/admin-flatfile/admin-flatfile.sp index dc60f14e..5075aa05 100644 --- a/plugins/admin-flatfile/admin-flatfile.sp +++ b/plugins/admin-flatfile/admin-flatfile.sp @@ -30,7 +30,7 @@ public Plugin:myinfo = name = "Admin File Reader", author = "AlliedModders LLC", description = "Reads admin files", - version = "1.0.0.0", + version = SOURCEMOD_VERSION, url = "http://www.sourcemod.net/" }; diff --git a/plugins/include/helpers.inc b/plugins/include/helpers.inc index 5b7381f7..5120f358 100644 --- a/plugins/include/helpers.inc +++ b/plugins/include/helpers.inc @@ -73,3 +73,70 @@ stock Handle:FindPluginByFile(const String:filename[]) return INVALID_HANDLE; } + +/** + * Searches for clients that match an input string. + * + * Allowed patterns: + * 1) # or # + * 2) + */ +stock SearchForClients(const String:pattern[], clients[], maxClients) +{ + new maxclients = GetMaxClients(); + new total = 0; + + if (maxClients == 0) + { + return 0; + } + + if (pattern[0] == '#') + { + new input = StringToInt(pattern[1]); + if (!input) + { + decl String:name[65] + for (new i=1; i<=maxclients; i++) + { + if (!IsClientInGame(i)) + { + continue; + } + GetClientName(i, name, sizeof(name)); + if (StrEqual(name, pattern, false)) + { + clients[0] = i; + return 1; + } + } + } else { + new client = GetClientOfUserId(input); + if (client) + { + clients[0] = client; + return 1; + } + } + } + + decl String:name[65] + for (new i=1; i<=maxclients; i++) + { + if (!IsClientInGame(i)) + { + continue; + } + GetClientName(i, name, sizeof(name)); + if (StrContains(name, pattern, false) != -1) + { + clients[total++] = i; + if (total >= maxClients) + { + break; + } + } + } + + return total; +}