plugins/include/helpers.inc
author Scott Ehlert <ds@alliedmods.net>
Fri Mar 16 06:54:24 2007 +0000 (2007-03-16)
changeset 621 5a0f5014aac1
parent 475 bb11d7eaae0f
child 622 ecf5428b05b1
permissions -rw-r--r--
Dear me, I should have committed this long ago...
1) Added natives to create and manipulate global and private forward
2) Added natives to call forwards and functions
3) Added an IChanageableForward::RemoveFunction overload for convenience or something
4) Added test suite plugins for functions and forwards
5) Some random touch-ups to some include files
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     5  * ===============================================================
     6  *
     7  *  This file is part of the SourceMod/SourcePawn SDK.  This file may only be used 
     8  * or modified under the Terms and Conditions of its License Agreement, which is found 
     9  * in LICENSE.txt.  The Terms and Conditions for making SourceMod extensions/plugins 
    10  * may change at any time.  To view the latest information, see:
    11  *   http://www.sourcemod.net/license.php
    12  *
    13  * Version: $Id$
    14  */
    15  
    16 #if defined _helpers_included
    17  #endinput
    18 #endif
    19 #define _helpers_included
    20 
    21 /**
    22  * Formats a user's info as log text.
    23  *
    24  * @param client		Client index.
    25  * @param buffer		Buffer for text.
    26  * @param maxlength		Maximum length of text.
    27  */
    28 stock FormatUserLogText(client, String:buffer[], maxlength)
    29 {
    30 	decl String:auth[32];
    31 	decl String:name[40];
    32 	
    33 	new userid = GetClientUserId(client);
    34 	if (!GetClientAuthString(client, auth, sizeof(auth)))
    35 	{
    36 		StrCopy(auth, sizeof(auth), "UNKNOWN");
    37 	}
    38 	if (!GetClientName(client, name, sizeof(name)))
    39 	{
    40 		StrCopy(name, sizeof(name), "UNKNOWN");
    41 	}
    42 	
    43 	/** Currently, no team stuff ... */
    44 	
    45 	Format(buffer, maxlength, "\"%s<%d><%s><>\"", name, userid, auth);
    46 }
    47 
    48 /**
    49  * Returns plugin handle from plugin filename.
    50  *
    51  * @param filename		Filename of the plugin to search for.
    52  * @Returns				Handle to plugin if found, INVALID_HANDLE otherwise.
    53  */
    54 stock Handle:FindPluginByFile(const String:filename[])
    55 {
    56 	decl String:buffer[256];
    57 	
    58 	new Handle:iter = GetPluginIterator();
    59 	new Handle:pl;
    60 	
    61 	while (MorePlugins(iter))
    62 	{
    63 		pl = ReadPlugin(iter);
    64 		
    65 		GetPluginFilename(pl, buffer, sizeof(buffer));
    66 		if (StrCompare(buffer, filename) == 0)
    67 		{
    68 			return pl;
    69 		}
    70 	}
    71 	
    72 	return INVALID_HANDLE;
    73 }