Added feature testing functionality (bug 4021, r=pred).

This commit is contained in:
David Anderson
2009-10-28 00:37:34 -07:00
parent 084dd1c8dd
commit 2698ff1a04
11 changed files with 357 additions and 30 deletions
+5
View File
@@ -858,6 +858,8 @@ native RemoveServerTag(const String:tag[]);
*/
functag public Action:CommandListener(client, const String:command[], argc);
#define FEATURECAP_COMMANDLISTENER "command listener"
/**
* Adds a callback that will fire when a command is sent to the server.
*
@@ -866,6 +868,9 @@ functag public Action:CommandListener(client, const String:command[], argc);
* Using Reg*Cmd to intercept is in poor practice, as it physically creates a
* new command and can slow down dispatch in general.
*
* To see if this feature is available, use FeatureType_Capability and
* FEATURECAP_COMMANDLISTENER.
*
* @param callback Callback.
* @param command Command, or if not specified, a global listener.
* The command is case insensitive.
+14
View File
@@ -151,8 +151,22 @@ public Extension:__ext_core =
native VerifyCoreVersion();
/**
* Sets a native as optional, such that if it is unloaded, removed,
* or otherwise non-existent, the plugin will still work. Calling
* removed natives results in a run-time error.
*
* @param name Native name.
* @noreturn
*/
native MarkNativeAsOptional(const String:name[]);
public __ext_core_SetNTVOptional()
{
MarkNativeAsOptional("GetFeatureStatus");
MarkNativeAsOptional("RequireFeature");
MarkNativeAsOptional("AddCommandListener");
MarkNativeAsOptional("RemoveCommandListener");
VerifyCoreVersion();
}
+75 -10
View File
@@ -410,16 +410,6 @@ native GetSysTickCount();
*/
native AutoExecConfig(bool:autoCreate=true, const String:name[]="", const String:folder[]="sourcemod");
/**
* Sets a native as optional, such that if it is unloaded, removed,
* or otherwise non-existent, the plugin will still work. Calling
* removed natives results in a run-time error.
*
* @param name Native name.
* @noreturn
*/
native MarkNativeAsOptional(const String:name[]);
/**
* Registers a library name for identifying as a dependency to
* other plugins.
@@ -565,6 +555,81 @@ forward bool:OnClientFloodCheck(client);
*/
forward OnClientFloodResult(client, bool:blocked);
/**
* Feature types.
*/
enum FeatureType
{
/**
* A native function call.
*/
FeatureType_Native,
/**
* A named capability. This is distinctly different from checking for a
* native, because the underlying functionality could be enabled on-demand
* to improve loading time. Thus a native may appear to exist, but it might
* be part of a set of features that are not compatible with the current game
* or version of SourceMod.
*/
FeatureType_Capability
};
/**
* Feature statuses.
*/
enum FeatureStatus
{
/**
* Feature is available for use.
*/
FeatureStatus_Available,
/**
* Feature is not available.
*/
FeatureStatus_Unavailable,
/**
* Feature is not known at all.
*/
FeatureStatus_Unknown
};
/**
* Returns whether "GetFeatureStatus" will work. Using this native
* or this function will not cause SourceMod to fail loading on older versions,
* however, GetFeatureStatus will only work if this function returns true.
*
* @return True if GetFeatureStatus will work, false otherwise.
*/
stock bool:CanTestFeatures()
{
return LibraryExists("__CanTestFeatures__");
}
/**
* Returns whether a feature exists, and if so, whether it is usable.
*
* @param type Feature type.
* @param name Feature name.
* @return Feature status.
*/
native FeatureStatus:GetFeatureStatus(FeatureType:type, const String:name[]);
/**
* Requires that a given feature is available. If it is not, SetFailState()
* is called with the given message.
*
* @param type Feature type.
* @param name Feature name.
* @param fmt Message format string, or empty to use default.
* @param ... Message format parameters, if any.
* @noreturn
*/
native RequireFeature(FeatureType:type, const String:name[],
const String:fmt[]="", any:...);
#include <helpers>
#include <entity>
#include <entity_prop_stocks>
+33
View File
@@ -0,0 +1,33 @@
public OnPluginStart()
{
RegServerCmd("sm_test_caps1", Test_Caps1);
RegServerCmd("sm_test_caps2", Test_Caps2);
RegServerCmd("sm_test_caps3", Test_Caps3);
}
public Action:Test_Caps1(args)
{
PrintToServer("CanTestFeatures: %d", CanTestFeatures());
PrintToServer("Status PTS: %d", GetFeatureStatus(FeatureType_Native, "PrintToServer"));
PrintToServer("Status ???: %d", GetFeatureStatus(FeatureType_Native, "???"));
PrintToServer("Status CL: %d", GetFeatureStatus(FeatureType_Capability, FEATURECAP_COMMANDLISTENER));
return Plugin_Handled
}
public Action:Test_Caps2(args)
{
RequireFeature(FeatureType_Native, "VerifyCoreVersion");
RequireFeature(FeatureType_Native, "Sally ate a worm");
}
public Action:Test_Caps3(args)
{
RequireFeature(FeatureType_Native, "Sally ate a worm", "oh %s %d no", "yam", 23);
}