Initial commit
This commit is contained in:
157
scripting/testsuite/benchmark.sp
Normal file
157
scripting/testsuite/benchmark.sp
Normal file
@@ -0,0 +1,157 @@
|
||||
#include <sourcemod>
|
||||
#include <profiler>
|
||||
|
||||
public Plugin:myinfo =
|
||||
{
|
||||
name = "Benchmarks",
|
||||
author = "AlliedModders LLC",
|
||||
description = "Basic benchmarks",
|
||||
version = "1.0.0.0",
|
||||
url = "http://www.sourcemod.net/"
|
||||
};
|
||||
|
||||
#define MATH_INT_LOOPS 2000
|
||||
#define MATH_FLOAT_LOOPS 2000
|
||||
#define STRING_OP_LOOPS 2000
|
||||
#define STRING_FMT_LOOPS 2000
|
||||
#define STRING_ML_LOOPS 2000
|
||||
#define STRING_RPLC_LOOPS 2000
|
||||
|
||||
new Float:g_dict_time
|
||||
new Handle:g_Prof = null
|
||||
|
||||
public OnPluginStart()
|
||||
{
|
||||
RegServerCmd("bench", Benchmark);
|
||||
g_Prof = CreateProfiler();
|
||||
StartProfiling(g_Prof);
|
||||
LoadTranslations("fakedict-sourcemod.cfg");
|
||||
StopProfiling(g_Prof);
|
||||
g_dict_time = GetProfilerTime(g_Prof);
|
||||
}
|
||||
|
||||
public Action:Benchmark(args)
|
||||
{
|
||||
PrintToServer("dictionary time: %f seconds", g_dict_time);
|
||||
StringBench();
|
||||
MathBench();
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
MathBench()
|
||||
{
|
||||
StartProfiling(g_Prof);
|
||||
new iter = MATH_INT_LOOPS;
|
||||
new a, b, c;
|
||||
while(iter--)
|
||||
{
|
||||
a = iter * 7;
|
||||
b = 5 + iter;
|
||||
c = 6 / (iter + 3);
|
||||
a = 6 * (iter);
|
||||
b = a * 185;
|
||||
a = b / 25;
|
||||
c = b - a + 3;
|
||||
b = b*b;
|
||||
a = (a + c) / (b - c);
|
||||
b = 6;
|
||||
c = 1;
|
||||
b = a * 128 - c;
|
||||
c = b * (a + 16) * b;
|
||||
if (!a)
|
||||
{
|
||||
a = 5;
|
||||
}
|
||||
a = c + (28/a) - c;
|
||||
}
|
||||
StopProfiling(g_Prof);
|
||||
PrintToServer("int benchmark: %f seconds", GetProfilerTime(g_Prof));
|
||||
|
||||
StartProfiling(g_Prof);
|
||||
new Float:fa, Float:fb, Float:fc
|
||||
new int1
|
||||
iter = MATH_FLOAT_LOOPS;
|
||||
while (iter--)
|
||||
{
|
||||
fa = iter * 0.7;
|
||||
fb = 5.1 + iter;
|
||||
fc = 6.1 / (float(iter) + 2.5);
|
||||
fa = 6.1 * (iter);
|
||||
fb = fa * 185.26;
|
||||
fa = fb / 25.56;
|
||||
fc = fb - a + float(3);
|
||||
fb = fb*fb;
|
||||
fa = (fa + fc) / (fb - fc);
|
||||
fb = 6.2;
|
||||
fc = float(1);
|
||||
int1 = RoundToNearest(fa);
|
||||
fb = fa * float(128) - int1;
|
||||
fc = fb * (a + 16.85) * float(RoundToCeil(fb));
|
||||
if (fa == 0.0)
|
||||
{
|
||||
fa = 5.0;
|
||||
}
|
||||
fa = fc + (float(28)/fa) - RoundToFloor(fc);
|
||||
}
|
||||
StopProfiling(g_Prof);
|
||||
PrintToServer("float benchmark: %f seconds", GetProfilerTime(g_Prof));
|
||||
}
|
||||
|
||||
#define KEY1 "LVWANBAGVXSXUGB"
|
||||
#define KEY2 "IDYCVNWEOWNND"
|
||||
#define KEY3 "UZWTRNHY"
|
||||
#define KEY4 "EPRHAFCIUOIG"
|
||||
#define KEY5 "RMZCVWIEY"
|
||||
#define KEY6 "ZHPU"
|
||||
|
||||
StringBench()
|
||||
{
|
||||
new i = STRING_FMT_LOOPS;
|
||||
new String:buffer[255];
|
||||
|
||||
StartProfiling(g_Prof);
|
||||
new end
|
||||
while (i--)
|
||||
{
|
||||
end = 0;
|
||||
Format(buffer, sizeof(buffer), "%d", i);
|
||||
Format(buffer, sizeof(buffer), "%d %s %d %f %d %-3.4s %s", i, "gaben", 30, 10.0, 20, "hello", "What a gaben");
|
||||
end = Format(buffer, sizeof(buffer), "Well, that's just %-17.18s!", "what. this isn't a valid string! wait it is");
|
||||
end += Format(buffer[end], sizeof(buffer)-end, "There are %d in this %d", i, end);
|
||||
end += Format(buffer[end], sizeof(buffer)-end, "There are %d in this %d", i, end);
|
||||
}
|
||||
StopProfiling(g_Prof);
|
||||
PrintToServer("format() benchmark: %f seconds", GetProfilerTime(g_Prof));
|
||||
|
||||
StartProfiling(g_Prof);
|
||||
i = STRING_ML_LOOPS;
|
||||
new String:fmtbuf[2048]; /* don't change to decl, amxmodx doesn't use it */
|
||||
while (i--)
|
||||
{
|
||||
Format(fmtbuf, 2047, "%T %T %d %s %f %T", KEY1, LANG_SERVER, KEY2, LANG_SERVER, 50, "what the", 50.0, KEY3, LANG_SERVER);
|
||||
Format(fmtbuf, 2047, "%s %T %s %T %T", "gaben", KEY4, LANG_SERVER, "what TIME is it", KEY5, LANG_SERVER, KEY6, LANG_SERVER);
|
||||
}
|
||||
StopProfiling(g_Prof);
|
||||
PrintToServer("ml benchmark: %f seconds", GetProfilerTime(g_Prof));
|
||||
|
||||
StartProfiling(g_Prof);
|
||||
i = STRING_OP_LOOPS;
|
||||
while (i--)
|
||||
{
|
||||
StringToInt(fmtbuf)
|
||||
}
|
||||
StopProfiling(g_Prof);
|
||||
PrintToServer("str benchmark: %f seconds", GetProfilerTime(g_Prof));
|
||||
|
||||
StartProfiling(g_Prof);
|
||||
i = STRING_RPLC_LOOPS;
|
||||
while (i--)
|
||||
{
|
||||
strcopy(fmtbuf, 2047, "This is a test string for you.");
|
||||
ReplaceString(fmtbuf, sizeof(fmtbuf), " ", "ASDF")
|
||||
ReplaceString(fmtbuf, sizeof(fmtbuf), "SDF", "")
|
||||
ReplaceString(fmtbuf, sizeof(fmtbuf), "string", "gnirts")
|
||||
}
|
||||
StopProfiling(g_Prof);
|
||||
PrintToServer("replace benchmark: %f seconds", GetProfilerTime(g_Prof));
|
||||
}
|
31
scripting/testsuite/bug4059.sp
Normal file
31
scripting/testsuite/bug4059.sp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <sourcemod>
|
||||
|
||||
public OnPluginStart()
|
||||
{
|
||||
new Handle:hostname = FindConVar("hostname")
|
||||
HookConVarChange(hostname, OnChange)
|
||||
HookEvent("player_team", cb)
|
||||
RegServerCmd("test_bug4059", Test_Bug)
|
||||
}
|
||||
|
||||
public Action:cb(Handle:event, const String:name[], bool:dontBroadcast)
|
||||
{
|
||||
UnhookEvent(name, cb)
|
||||
PrintToServer("whee")
|
||||
HookEvent(name, cb)
|
||||
return Plugin_Handled
|
||||
}
|
||||
|
||||
public OnChange(Handle:convar, const String:oldValue[], const String:newValue[])
|
||||
{
|
||||
PrintToServer("called: %x", convar)
|
||||
UnhookConVarChange(convar, OnChange)
|
||||
ResetConVar(convar)
|
||||
HookConVarChange(convar, OnChange)
|
||||
}
|
||||
|
||||
public Action:Test_Bug(args)
|
||||
{
|
||||
ServerCommand("hostname \"bug4059\"")
|
||||
}
|
||||
|
169
scripting/testsuite/callfunctest.sp
Normal file
169
scripting/testsuite/callfunctest.sp
Normal file
@@ -0,0 +1,169 @@
|
||||
#include <sourcemod>
|
||||
|
||||
public Plugin:myinfo =
|
||||
{
|
||||
name = "Function Call Testing Lab",
|
||||
author = "AlliedModders LLC",
|
||||
description = "Tests basic function calls",
|
||||
version = "1.0.0.0",
|
||||
url = "http://www.sourcemod.net/"
|
||||
};
|
||||
|
||||
public OnPluginStart()
|
||||
{
|
||||
RegServerCmd("test_callfunc", Command_CallFunc);
|
||||
RegServerCmd("test_callfunc_reentrant", Command_ReentrantCallFunc);
|
||||
}
|
||||
|
||||
public OnCallFuncReceived(num, Float:fnum, String:str[], String:str2[], &val, &Float:fval, array[], array2[], size, hello2[1])
|
||||
{
|
||||
PrintToServer("Inside OnCallFuncReceived...");
|
||||
|
||||
PrintToServer("num = %d (expected: %d)", num, 5);
|
||||
PrintToServer("fnum = %f (expected: %f)", fnum, 7.17);
|
||||
PrintToServer("str[] = \"%s\" (expected: \"%s\")", str, "Gaben");
|
||||
PrintToServer("str2[] = \"%s\" (expected: \"%s\")", str2, ".taf si nebaG");
|
||||
|
||||
PrintToServer("val = %d (expected %d, setting to %d)", val, 62, 15);
|
||||
val = 15;
|
||||
|
||||
PrintToServer("fval = %f (expected: %f, setting to %f)", fval, 6.25, 1.5);
|
||||
fval = 1.5;
|
||||
|
||||
PrintToServer("Printing %d elements of array[] (expected: %d)", size, 6);
|
||||
for (new i = 0; i < size; i++)
|
||||
{
|
||||
PrintToServer("array[%d] = %d (expected: %d)", i, array[i], i);
|
||||
}
|
||||
for (new i = 0; i < size; i++)
|
||||
{
|
||||
PrintToServer("array2[%d] = %d (expected: %d)", i, array[i], i);
|
||||
}
|
||||
|
||||
/* This shouldn't get copied back */
|
||||
strcopy(str, strlen(str) + 1, "Yeti");
|
||||
/* This should get copied back */
|
||||
strcopy(str2, strlen(str2) + 1, "Gaben is fat.");
|
||||
|
||||
/* This should get copied back */
|
||||
array[0] = 5;
|
||||
array[1] = 6;
|
||||
/* This shouldn't get copied back */
|
||||
hello2[0] = 25;
|
||||
|
||||
return 42;
|
||||
}
|
||||
|
||||
public OnReentrantCallReceived(num, String:str[])
|
||||
{
|
||||
new err, ret;
|
||||
|
||||
PrintToServer("Inside OnReentrantCallReceived...");
|
||||
|
||||
PrintToServer("num = %d (expected: %d)", num, 7);
|
||||
PrintToServer("str[] = \"%s\" (expected: \"%s\")", str, "nana");
|
||||
|
||||
new Function:func = GetFunctionByName(null, "OnReentrantCallReceivedTwo");
|
||||
|
||||
if (func == INVALID_FUNCTION)
|
||||
{
|
||||
PrintToServer("Failed to get the function id of OnReentrantCallReceivedTwo");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PrintToServer("Calling OnReentrantCallReceivedTwo...");
|
||||
|
||||
Call_StartFunction(null, func);
|
||||
Call_PushFloat(8.0);
|
||||
err = Call_Finish(ret);
|
||||
|
||||
PrintToServer("Call to OnReentrantCallReceivedTwo has finished!");
|
||||
PrintToServer("Error code = %d (expected: %d)", err, 0);
|
||||
PrintToServer("Return value = %d (expected: %d)", ret, 707);
|
||||
|
||||
return 11;
|
||||
}
|
||||
|
||||
public OnReentrantCallReceivedTwo(Float:fnum)
|
||||
{
|
||||
PrintToServer("Inside OnReentrantCallReceivedTwo...");
|
||||
|
||||
PrintToServer("fnum = %f (expected: %f)", fnum, 8.0);
|
||||
|
||||
return 707;
|
||||
}
|
||||
|
||||
public Action:Command_CallFunc(args)
|
||||
{
|
||||
new a = 62;
|
||||
new Float:b = 6.25;
|
||||
new const String:what[] = "Gaben";
|
||||
new String:truth[] = ".taf si nebaG";
|
||||
new hello[] = {0, 1, 2, 3, 4, 5};
|
||||
new hello2[] = {9};
|
||||
new pm = 6;
|
||||
new err;
|
||||
new ret;
|
||||
|
||||
new Function:func = GetFunctionByName(null, "OnCallFuncReceived");
|
||||
|
||||
if (func == INVALID_FUNCTION)
|
||||
{
|
||||
PrintToServer("Failed to get the function id of OnCallFuncReceived");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
PrintToServer("Calling OnCallFuncReceived...");
|
||||
|
||||
Call_StartFunction(null, func);
|
||||
Call_PushCell(5);
|
||||
Call_PushFloat(7.17);
|
||||
Call_PushString(what);
|
||||
Call_PushStringEx(truth, sizeof(truth), SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK);
|
||||
Call_PushCellRef(a);
|
||||
Call_PushFloatRef(b);
|
||||
Call_PushArrayEx(hello, pm, SM_PARAM_COPYBACK);
|
||||
Call_PushArray(hello, pm);
|
||||
Call_PushCell(pm);
|
||||
Call_PushArray(hello2, 1);
|
||||
err = Call_Finish(ret);
|
||||
|
||||
PrintToServer("Call to OnCallFuncReceived has finished!");
|
||||
PrintToServer("Error code = %d (expected: %d)", err, 0);
|
||||
PrintToServer("Return value = %d (expected: %d)", ret, 42);
|
||||
|
||||
PrintToServer("a = %d (expected: %d)", a, 15);
|
||||
PrintToServer("b = %f (expected: %f)", b, 1.5);
|
||||
PrintToServer("what = \"%s\" (expected: \"%s\")", what, "Gaben");
|
||||
PrintToServer("truth = \"%s\" (expected: \"%s\")", truth, "Gaben is fat.");
|
||||
PrintToServer("hello[0] = %d (expected: %d)", hello[0], 5);
|
||||
PrintToServer("hello[1] = %d (expected: %d)", hello[1], 6);
|
||||
PrintToServer("hello2[0] = %d (expected: %d)", hello2[0], 9);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:Command_ReentrantCallFunc(args)
|
||||
{
|
||||
new err, ret;
|
||||
new Function:func = GetFunctionByName(null, "OnReentrantCallReceived");
|
||||
|
||||
if (func == INVALID_FUNCTION)
|
||||
{
|
||||
PrintToServer("Failed to get the function id of OnReentrantCallReceived");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
PrintToServer("Calling OnReentrantCallReceived...");
|
||||
|
||||
Call_StartFunction(null, func);
|
||||
Call_PushCell(7);
|
||||
Call_PushString("nana");
|
||||
err = Call_Finish(ret);
|
||||
|
||||
PrintToServer("Call to OnReentrantCallReceived has finished!");
|
||||
PrintToServer("Error code = %d (expected: %d)", err, 0);
|
||||
PrintToServer("Return value = %d (expected: %d)", ret, 11);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
33
scripting/testsuite/capstest.sp
Normal file
33
scripting/testsuite/capstest.sp
Normal 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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
63
scripting/testsuite/clientprefstest.sp
Normal file
63
scripting/testsuite/clientprefstest.sp
Normal file
@@ -0,0 +1,63 @@
|
||||
#include <sourcemod>
|
||||
#include <clientprefs>
|
||||
|
||||
#pragma semicolon 1
|
||||
#pragma newdecls required
|
||||
|
||||
Cookie g_Cookie1;
|
||||
Cookie g_Cookie2;
|
||||
Cookie g_Cookie3;
|
||||
Cookie g_Cookie4;
|
||||
Cookie g_Cookie5;
|
||||
|
||||
public void OnPluginStart()
|
||||
{
|
||||
g_Cookie1 = RegClientCookie("test-cookie'", "A basic 'testing cookie", CookieAccess_Public);
|
||||
g_Cookie2 = RegClientCookie("test-cookie2\"", "A basic \"testing cookie", CookieAccess_Protected);
|
||||
g_Cookie3 = RegClientCookie("test-cookie3", "A basic testing cookie", CookieAccess_Public);
|
||||
g_Cookie4 = RegClientCookie("test-cookie4", "A basic testing cookie", CookieAccess_Private);
|
||||
g_Cookie5 = RegClientCookie("test-cookie5", "A basic testing cookie", CookieAccess_Public);
|
||||
|
||||
g_Cookie1.SetPrefabMenu(CookieMenu_YesNo, "Cookie '1", CookieSelected, g_Cookie1);
|
||||
g_Cookie2.SetPrefabMenu(CookieMenu_YesNo_Int, "Cookie \"2");
|
||||
g_Cookie3.SetPrefabMenu(CookieMenu_OnOff, "Cookie 3");
|
||||
g_Cookie4.SetPrefabMenu(CookieMenu_OnOff_Int, "Cookie 4");
|
||||
|
||||
SetCookieMenuItem(CookieSelected, g_Cookie5, "Get Cookie 5 value");
|
||||
}
|
||||
|
||||
public void CookieSelected(int client, CookieMenuAction action, any info, char[] buffer, int maxlen)
|
||||
{
|
||||
if (action == CookieMenuAction_DisplayOption)
|
||||
{
|
||||
PrintToChat(client, "About to draw item. Current text is : %s", buffer);
|
||||
FormatEx(buffer, maxlen, "HELLLLLLLLLLO");
|
||||
}
|
||||
else
|
||||
{
|
||||
LogMessage("SELECTED!");
|
||||
|
||||
char value[100];
|
||||
GetClientCookie(client, info, value, sizeof(value));
|
||||
PrintToChat(client, "Value is : %s", value);
|
||||
}
|
||||
}
|
||||
|
||||
public bool OnClientConnect(int client, char[] rejectmsg, int maxlen)
|
||||
{
|
||||
LogMessage("Connect Cookie state: %s", AreClientCookiesCached(client) ? "YES" : "NO");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void OnClientCookiesCached(int client)
|
||||
{
|
||||
LogMessage("Loaded Cookie state: %s", AreClientCookiesCached(client) ? "YES" : "NO");
|
||||
|
||||
char value[100];
|
||||
g_Cookie1.Get(client, value, sizeof(value));
|
||||
LogMessage("Test before set: %s", value);
|
||||
g_Cookie1.Set(client, "somethingsomething'");
|
||||
g_Cookie1.Get(client, value, sizeof(value));
|
||||
LogMessage("Test after set: %s", value);
|
||||
}
|
142
scripting/testsuite/cstrike-test.sp
Normal file
142
scripting/testsuite/cstrike-test.sp
Normal file
@@ -0,0 +1,142 @@
|
||||
#include <sourcemod>
|
||||
#include <cstrike>
|
||||
#include <sdktools>
|
||||
|
||||
public OnPluginStart()
|
||||
{
|
||||
RegConsoleCmd( "get_mvps", get_mvps );
|
||||
RegConsoleCmd( "set_mvps", set_mvps );
|
||||
RegConsoleCmd( "get_score", get_score );
|
||||
RegConsoleCmd( "set_score", set_score );
|
||||
RegConsoleCmd( "get_assists", get_assists );
|
||||
RegConsoleCmd( "set_assists", set_assists );
|
||||
RegConsoleCmd( "get_clantag", get_clantag );
|
||||
RegConsoleCmd( "set_clantag", set_clantag );
|
||||
RegConsoleCmd( "get_teamscore", get_teamscore );
|
||||
RegConsoleCmd( "set_teamscore", set_teamscore );
|
||||
}
|
||||
|
||||
public Action:get_mvps( client, argc )
|
||||
{
|
||||
ReplyToCommand( client, "Your MVP count is %d", CS_GetMVPCount( client ) );
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:set_mvps( client, argc )
|
||||
{
|
||||
new count = GetCmdArgInt( 1 );
|
||||
|
||||
CS_SetMVPCount( client, count );
|
||||
ReplyToCommand( client, "Set your MVP count to %d", count );
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:get_score( client, argc )
|
||||
{
|
||||
if( GetEngineVersion() != Engine_CSGO )
|
||||
{
|
||||
ReplyToCommand( client, "This command is only intended for CS:GO" );
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
ReplyToCommand( client, "Your contribution score is %d", CS_GetClientContributionScore( client ) );
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:set_score( client, argc )
|
||||
{
|
||||
if( GetEngineVersion() != Engine_CSGO )
|
||||
{
|
||||
ReplyToCommand( client, "This command is only intended for CS:GO" );
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
new count = GetCmdArgInt( 1 );
|
||||
|
||||
CS_SetClientContributionScore( client, count );
|
||||
ReplyToCommand( client, "Set your contribution score to %d", count );
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:get_assists( client, argc )
|
||||
{
|
||||
if( GetEngineVersion() != Engine_CSGO )
|
||||
{
|
||||
ReplyToCommand( client, "This command is only intended for CS:GO" );
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
ReplyToCommand( client, "Your assist count is %d", CS_GetClientAssists( client ) );
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:set_assists( client, argc )
|
||||
{
|
||||
if( GetEngineVersion() != Engine_CSGO )
|
||||
{
|
||||
ReplyToCommand( client, "This command is only intended for CS:GO" );
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
new count = GetCmdArgInt( 1 );
|
||||
|
||||
CS_SetClientAssists( client, count );
|
||||
ReplyToCommand( client, "Set your assist count to %d", count );
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:get_clantag( client, argc )
|
||||
{
|
||||
decl String:tag[64];
|
||||
|
||||
CS_GetClientClanTag( client, tag, sizeof(tag) );
|
||||
ReplyToCommand( client, "Your clan tag is: %s", tag );
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:set_clantag( client, argc )
|
||||
{
|
||||
decl String:tag[64];
|
||||
GetCmdArg( 1, tag, sizeof(tag) );
|
||||
|
||||
CS_SetClientClanTag( client, tag );
|
||||
ReplyToCommand( client, "Set your clan tag to: %s", tag );
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:get_teamscore( client, argc )
|
||||
{
|
||||
new tscore = CS_GetTeamScore( CS_TEAM_T );
|
||||
new ctscore = CS_GetTeamScore( CS_TEAM_CT );
|
||||
|
||||
ReplyToCommand( client, "Team Scores: T = %d, CT = %d", tscore, ctscore );
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:set_teamscore( client, argc )
|
||||
{
|
||||
new team = GetCmdArgInt( 1 );
|
||||
new score = GetCmdArgInt( 2 );
|
||||
|
||||
if ( team != CS_TEAM_T && team != CS_TEAM_CT )
|
||||
{
|
||||
ReplyToCommand( client, "Team number must be %d or %d", CS_TEAM_T, CS_TEAM_CT );
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
CS_SetTeamScore( team, score );
|
||||
SetTeamScore( team, score );
|
||||
ReplyToCommand( client, "Score for team %d has been set to %d", team, score );
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
125
scripting/testsuite/entitylumptest.sp
Normal file
125
scripting/testsuite/entitylumptest.sp
Normal file
@@ -0,0 +1,125 @@
|
||||
#pragma semicolon 1
|
||||
#include <sourcemod>
|
||||
|
||||
#include <sdktools>
|
||||
#include <entitylump>
|
||||
|
||||
#pragma newdecls required
|
||||
|
||||
#define PLUGIN_VERSION "0.0.0"
|
||||
public Plugin myinfo = {
|
||||
name = "Entity Lump Core Native Test",
|
||||
author = "nosoop",
|
||||
description = "A port of the Level KeyValues entity test to the Entity Lump implementation in core SourceMod",
|
||||
}
|
||||
|
||||
#define OUTPUT_NAME "OnCapTeam2"
|
||||
|
||||
public void OnMapInit() {
|
||||
// set every area_time_to_cap value to 30
|
||||
for (int i, n = EntityLump.Length(); i < n; i++) {
|
||||
EntityLumpEntry entry = EntityLump.Get(i);
|
||||
|
||||
int ttc = entry.FindKey("area_time_to_cap");
|
||||
if (ttc != -1) {
|
||||
entry.Update(ttc, NULL_STRING, "30");
|
||||
PrintToServer("Set time to cap for item %d to 30", i);
|
||||
}
|
||||
|
||||
delete entry;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnMapStart() {
|
||||
int captureArea = FindEntityByClassname(-1, "trigger_capture_area");
|
||||
|
||||
if (!IsValidEntity(captureArea)) {
|
||||
LogMessage("---- %s", "No capture area");
|
||||
return;
|
||||
}
|
||||
|
||||
int hammerid = GetEntProp(captureArea, Prop_Data, "m_iHammerID");
|
||||
EntityLumpEntry entry = FindEntityLumpEntryByHammerID(hammerid);
|
||||
|
||||
if (!entry) {
|
||||
return;
|
||||
}
|
||||
|
||||
LogMessage("---- %s", "Found a trigger_capture_area with keys:");
|
||||
|
||||
for (int i, n = entry.Length; i < n; i++) {
|
||||
char keyBuffer[128], valueBuffer[128];
|
||||
entry.Get(i, keyBuffer, sizeof(keyBuffer), valueBuffer, sizeof(valueBuffer));
|
||||
|
||||
LogMessage("%s -> %s", keyBuffer, valueBuffer);
|
||||
}
|
||||
|
||||
LogMessage("---- %s", "List of " ... OUTPUT_NAME ... " outputs:");
|
||||
char outputString[256];
|
||||
for (int k = -1; (k = entry.GetNextKey(OUTPUT_NAME, outputString, sizeof(outputString), k)) != -1;) {
|
||||
char targetName[32], inputName[64], variantValue[32];
|
||||
float delay;
|
||||
int nFireCount;
|
||||
|
||||
ParseEntityOutputString(outputString, targetName, sizeof(targetName),
|
||||
inputName, sizeof(inputName), variantValue, sizeof(variantValue),
|
||||
delay, nFireCount);
|
||||
|
||||
LogMessage("target %s -> input %s (value %s, delay %.2f, refire %d)",
|
||||
targetName, inputName, variantValue, delay, nFireCount);
|
||||
}
|
||||
delete entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first EntityLumpEntry with a matching hammerid.
|
||||
*/
|
||||
EntityLumpEntry FindEntityLumpEntryByHammerID(int hammerid) {
|
||||
for (int i, n = EntityLump.Length(); i < n; i++) {
|
||||
EntityLumpEntry entry = EntityLump.Get(i);
|
||||
|
||||
char value[32];
|
||||
if (entry.GetNextKey("hammerid", value, sizeof(value)) != -1
|
||||
&& StringToInt(value) == hammerid) {
|
||||
return entry;
|
||||
}
|
||||
delete entry;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses an entity's output value (as formatted in the entity string).
|
||||
* Refer to https://developer.valvesoftware.com/wiki/AddOutput for the format.
|
||||
*
|
||||
* @return True if the output string was successfully parsed, false if not.
|
||||
*/
|
||||
stock bool ParseEntityOutputString(const char[] output, char[] targetName, int targetNameLength,
|
||||
char[] inputName, int inputNameLength, char[] variantValue, int variantValueLength,
|
||||
float &delay, int &nFireCount) {
|
||||
int delimiter;
|
||||
char buffer[32];
|
||||
|
||||
{
|
||||
// validate that we have something resembling an output string (four commas)
|
||||
int i, c, nDelim;
|
||||
while ((c = FindCharInString(output[i], ',')) != -1) {
|
||||
nDelim++;
|
||||
i += c + 1;
|
||||
}
|
||||
if (nDelim < 4) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
delimiter = SplitString(output, ",", targetName, targetNameLength);
|
||||
delimiter += SplitString(output[delimiter], ",", inputName, inputNameLength);
|
||||
delimiter += SplitString(output[delimiter], ",", variantValue, variantValueLength);
|
||||
|
||||
delimiter += SplitString(output[delimiter], ",", buffer, sizeof(buffer));
|
||||
delay = StringToFloat(buffer);
|
||||
|
||||
nFireCount = StringToInt(output[delimiter]);
|
||||
|
||||
return true;
|
||||
}
|
161
scripting/testsuite/entpropelements.sp
Normal file
161
scripting/testsuite/entpropelements.sp
Normal file
@@ -0,0 +1,161 @@
|
||||
#include <sourcemod>
|
||||
#include <sdktools>
|
||||
|
||||
// Coverage:
|
||||
// GetEntPropArraySize - PropSend/PropData
|
||||
|
||||
// GetEntPropString - PropData
|
||||
|
||||
// GetEntProp - PropSend/PropData
|
||||
// GetEntPropEnt - PropSend/PropData
|
||||
|
||||
// SetEntProp - PropSend/PropData
|
||||
|
||||
public OnPluginStart()
|
||||
{
|
||||
RegConsoleCmd("sm_listammo", sm_listammo, "sm_listammo <send|data> [target] - Lists current ammo for self or specified player");
|
||||
RegConsoleCmd("sm_listweapons", sm_listweapons, "sm_listweapons <send|data> [target] - Lists current weapons for self or specified player");
|
||||
RegConsoleCmd("sm_setammo", sm_setammo, "sm_setammo <ammotype> <amount> <send|data> [target]");
|
||||
RegConsoleCmd("sm_teststrings", sm_teststrings);
|
||||
}
|
||||
|
||||
public Action:sm_listammo(client, argc)
|
||||
{
|
||||
decl String:buffer[64];
|
||||
new target = client;
|
||||
if (argc >= 2)
|
||||
{
|
||||
GetCmdArg(2, buffer, sizeof(buffer));
|
||||
target = FindTarget(client, buffer, false, false);
|
||||
if (target <= 0)
|
||||
{
|
||||
ReplyToCommand(client, "Bad client");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
}
|
||||
else if (client == 0)
|
||||
{
|
||||
ReplyToCommand(client, "Dillweed");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
new PropType:proptype = PropType:-1;
|
||||
GetCmdArg(1, buffer, sizeof(buffer));
|
||||
if (!strcmp(buffer, "send"))
|
||||
proptype = Prop_Send;
|
||||
else if (!strcmp(buffer, "data"))
|
||||
proptype = Prop_Data;
|
||||
|
||||
new ammo;
|
||||
new max = GetEntPropArraySize(target, proptype, "m_iAmmo");
|
||||
for (new i = 0; i < max; i++)
|
||||
{
|
||||
if ((ammo = GetEntProp(target, proptype, "m_iAmmo", _, i)) > 0)
|
||||
ReplyToCommand(client, "Slot %d, Ammo %d", i, ammo);
|
||||
}
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:sm_listweapons(client, argc)
|
||||
{
|
||||
decl String:buffer[64];
|
||||
new target = client;
|
||||
if (argc >= 2)
|
||||
{
|
||||
GetCmdArg(2, buffer, sizeof(buffer));
|
||||
target = FindTarget(client, buffer, false, false);
|
||||
if (target <= 0)
|
||||
{
|
||||
ReplyToCommand(client, "Bad client");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
}
|
||||
else if (client == 0)
|
||||
{
|
||||
ReplyToCommand(client, "Dillweed");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
new PropType:proptype = PropType:-1;
|
||||
GetCmdArg(1, buffer, sizeof(buffer));
|
||||
if (!strcmp(buffer, "send"))
|
||||
proptype = Prop_Send;
|
||||
else if (!strcmp(buffer, "data"))
|
||||
proptype = Prop_Data;
|
||||
|
||||
new weapon, String:classname[64];
|
||||
new max = GetEntPropArraySize(target, proptype, "m_hMyWeapons");
|
||||
for (new i = 0; i < max; i++)
|
||||
{
|
||||
if ((weapon = GetEntPropEnt(target, proptype, "m_hMyWeapons", i)) == -1)
|
||||
continue;
|
||||
|
||||
GetEdictClassname(weapon, classname, sizeof(classname));
|
||||
ReplyToCommand(client, "Slot %d - \"%s\"", i, classname);
|
||||
}
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:sm_setammo(client, argc)
|
||||
{
|
||||
decl String:buffer[64];
|
||||
new target = client;
|
||||
if (argc >= 4)
|
||||
{
|
||||
GetCmdArg(4, buffer, sizeof(buffer));
|
||||
target = FindTarget(client, buffer, false, false);
|
||||
if (target <= 0)
|
||||
{
|
||||
ReplyToCommand(client, "Bad client");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
}
|
||||
else if (client == 0)
|
||||
{
|
||||
ReplyToCommand(client, "Dillweed");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
new PropType:proptype = PropType:-1;
|
||||
GetCmdArg(3, buffer, sizeof(buffer));
|
||||
if (!strcmp(buffer, "send"))
|
||||
proptype = Prop_Send;
|
||||
else if (!strcmp(buffer, "data"))
|
||||
proptype = Prop_Data;
|
||||
|
||||
new max = GetEntPropArraySize(target, proptype, "m_iAmmo");
|
||||
|
||||
new ammotype = GetCmdArgInt(1);
|
||||
|
||||
if (ammotype >= max)
|
||||
{
|
||||
ReplyToCommand(client, "Ammotype out of bounds");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
new amount = GetCmdArgInt(2);
|
||||
|
||||
SetEntProp(target, proptype, "m_iAmmo", amount, _, ammotype);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:sm_teststrings(client, argc)
|
||||
{
|
||||
new gpe = CreateEntityByName("game_player_equip");
|
||||
DispatchKeyValue(gpe, "tf_weapon_rocketlauncher", "2");
|
||||
DispatchKeyValue(gpe, "tf_weapon_pistol", "1");
|
||||
|
||||
decl String:value[64];
|
||||
for (new i = 0; i < 2; i++)
|
||||
{
|
||||
GetEntPropString(gpe, Prop_Data, "m_weaponNames", value, sizeof(value), i);
|
||||
ReplyToCommand(client, "At %d, I see a \"%s\"", i, value);
|
||||
}
|
||||
|
||||
AcceptEntityInput(gpe, "Kill");
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
85
scripting/testsuite/fakenative1.sp
Normal file
85
scripting/testsuite/fakenative1.sp
Normal file
@@ -0,0 +1,85 @@
|
||||
#include <sourcemod>
|
||||
|
||||
public Plugin:myinfo =
|
||||
{
|
||||
name = "FakeNative Testing Lab #1",
|
||||
author = "AlliedModders LLC",
|
||||
description = "Test suite #1 for dynamic natives",
|
||||
version = "1.0.0.0",
|
||||
url = "http://www.sourcemod.net/"
|
||||
};
|
||||
|
||||
public bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max)
|
||||
{
|
||||
CreateNative("TestNative1", __TestNative1);
|
||||
CreateNative("TestNative2", __TestNative2);
|
||||
CreateNative("TestNative3", __TestNative3);
|
||||
CreateNative("TestNative4", __TestNative4);
|
||||
CreateNative("TestNative5", __TestNative5);
|
||||
return true;
|
||||
}
|
||||
|
||||
public __TestNative1(Handle:plugin, numParams)
|
||||
{
|
||||
PrintToServer("TestNative1: Plugin: %x params: %d", plugin, numParams);
|
||||
if (numParams == 4)
|
||||
{
|
||||
ThrowNativeError(SP_ERROR_NATIVE, "Four parameters ARE NOT ALLOWED lol");
|
||||
}
|
||||
return 5;
|
||||
}
|
||||
|
||||
public __TestNative2(Handle:plugin, numParams)
|
||||
{
|
||||
new String:buffer[512];
|
||||
new bytes;
|
||||
|
||||
GetNativeString(1, buffer, sizeof(buffer), bytes);
|
||||
|
||||
for (new i=0; i<bytes; i++)
|
||||
{
|
||||
buffer[i] = buffer[i] + 1;
|
||||
}
|
||||
|
||||
SetNativeString(1, buffer, bytes+1);
|
||||
}
|
||||
|
||||
public __TestNative3(Handle:plugin, numParams)
|
||||
{
|
||||
new val1 = GetNativeCell(1);
|
||||
new val2 = GetNativeCellRef(2);
|
||||
|
||||
SetNativeCellRef(2, val1+val2);
|
||||
}
|
||||
|
||||
public __TestNative4(Handle:plugin, numParams)
|
||||
{
|
||||
new size = GetNativeCell(3);
|
||||
new local[size];
|
||||
|
||||
GetNativeArray(1, local, size);
|
||||
SetNativeArray(2, local, size);
|
||||
}
|
||||
|
||||
public __TestNative5(Handle:plugin, numParams)
|
||||
{
|
||||
new local = GetNativeCell(1);
|
||||
|
||||
if (local)
|
||||
{
|
||||
FormatNativeString(2, 4, 5, GetNativeCell(3));
|
||||
} else {
|
||||
new len = GetNativeCell(3);
|
||||
new fmt_len;
|
||||
new String:buffer[len];
|
||||
|
||||
GetNativeStringLength(4, fmt_len);
|
||||
|
||||
new String:format[fmt_len];
|
||||
|
||||
GetNativeString(2, buffer, len);
|
||||
GetNativeString(4, format, fmt_len);
|
||||
|
||||
FormatNativeString(0, 0, 5, len, _, buffer, format);
|
||||
}
|
||||
}
|
87
scripting/testsuite/fakenative2.sp
Normal file
87
scripting/testsuite/fakenative2.sp
Normal file
@@ -0,0 +1,87 @@
|
||||
#include <sourcemod>
|
||||
|
||||
native TestNative1(gaben, ...);
|
||||
native TestNative2(String:buffer[]);
|
||||
native TestNative3(value1, &value2);
|
||||
native TestNative4(const input[], output[], size);
|
||||
native TestNative5(bool:local, String:buffer[], maxlength, const String:fmt[], {Handle,Float,String,_}:...);
|
||||
|
||||
public Plugin:myinfo =
|
||||
{
|
||||
name = "FakeNative Testing Lab #2",
|
||||
author = "AlliedModders LLC",
|
||||
description = "Test suite #2 for dynamic natives",
|
||||
version = "1.0.0.0",
|
||||
url = "http://www.sourcemod.net/"
|
||||
};
|
||||
|
||||
public OnPluginStart()
|
||||
{
|
||||
RegServerCmd("test_native1", Test_Native1);
|
||||
RegServerCmd("test_native2", Test_Native2);
|
||||
RegServerCmd("test_native3", Test_Native3);
|
||||
RegServerCmd("test_native4", Test_Native4);
|
||||
RegServerCmd("test_native5", Test_Native5);
|
||||
}
|
||||
|
||||
public Action:Test_Native1(args)
|
||||
{
|
||||
PrintToServer("Returned: %d", TestNative1(1));
|
||||
PrintToServer("Returned: %d", TestNative1(1,2));
|
||||
PrintToServer("Returned: %d", TestNative1(1,2,3,4));
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:Test_Native2(args)
|
||||
{
|
||||
new String:buffer[] = "IBM";
|
||||
|
||||
PrintToServer("Before: %s", buffer);
|
||||
|
||||
TestNative2(buffer);
|
||||
|
||||
PrintToServer("AfteR: %s", buffer);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:Test_Native3(args)
|
||||
{
|
||||
new value1 = 5, value2 = 6
|
||||
|
||||
PrintToServer("Before: %d, %d", value1, value2);
|
||||
|
||||
TestNative3(value1, value2);
|
||||
|
||||
PrintToServer("After: %d, %d", value1, value2);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:Test_Native4(args)
|
||||
{
|
||||
new input[5] = {0, 1, 2, 3, 4};
|
||||
new output[5];
|
||||
|
||||
TestNative4(input, output, 5);
|
||||
|
||||
PrintToServer("[0=%d] [1=%d] [2=%d] [3=%d] [4=%d]", input[0], input[1], input[2], input[3], input[4]);
|
||||
PrintToServer("[0=%d] [1=%d] [2=%d] [3=%d] [4=%d]", output[0], output[1], output[2], output[3], output[4]);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:Test_Native5(args)
|
||||
{
|
||||
new String:buffer1[512];
|
||||
new String:buffer2[512];
|
||||
|
||||
TestNative5(true, buffer1, sizeof(buffer1), "%d gabens in the %s", 50, "gabpark");
|
||||
TestNative5(true, buffer2, sizeof(buffer2), "%d gabens in the %s", 50, "gabpark");
|
||||
|
||||
PrintToServer("Test 1: %s", buffer1);
|
||||
PrintToServer("Test 2: %s", buffer2);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
73
scripting/testsuite/filetest.sp
Normal file
73
scripting/testsuite/filetest.sp
Normal file
@@ -0,0 +1,73 @@
|
||||
#include <sourcemod>
|
||||
|
||||
public Plugin:myinfo =
|
||||
{
|
||||
name = "File test",
|
||||
author = "AlliedModders LLC",
|
||||
description = "Tests file functions",
|
||||
version = "1.0.0.0",
|
||||
url = "http://www.sourcemod.net/"
|
||||
};
|
||||
|
||||
public void OnPluginStart()
|
||||
{
|
||||
RegServerCmd("test_fread1", Test_ReadBinStr);
|
||||
}
|
||||
|
||||
File OpenFile2(const String:path[], const String:mode[])
|
||||
{
|
||||
File file = OpenFile(path, mode);
|
||||
if (!file)
|
||||
PrintToServer("Failed to open file %s for %s", path, mode);
|
||||
else
|
||||
PrintToServer("Opened file handle %x: %s", file, path);
|
||||
return file;
|
||||
}
|
||||
|
||||
public Action Test_ReadBinStr(args)
|
||||
{
|
||||
int items[] = {1, 3, 5, 7, 0, 92, 193, 26, 0, 84, 248, 2};
|
||||
File of = OpenFile2("smbintest", "wb");
|
||||
if (!of)
|
||||
return Plugin_Handled;
|
||||
of.Write(items, sizeof(items), 1);
|
||||
of.Close();
|
||||
|
||||
File inf = OpenFile2("smbintest", "rb");
|
||||
char buffer[sizeof(items)];
|
||||
inf.ReadString(buffer, sizeof(items), sizeof(items));
|
||||
inf.Seek(0, SEEK_SET);
|
||||
int items2[sizeof(items)];
|
||||
inf.Read(items2, sizeof(items), 1);
|
||||
inf.Close();
|
||||
|
||||
for (new i = 0; i < sizeof(items); i++)
|
||||
{
|
||||
if (buffer[i] != items[i])
|
||||
{
|
||||
PrintToServer("FAILED ON INDEX %d: %d != %d", i, buffer[i], items[i]);
|
||||
return Plugin_Handled;
|
||||
}
|
||||
else if (items2[i] != items[i])
|
||||
{
|
||||
PrintToServer("FAILED ON INDEX %d: %d != %d", i, items2[i], items[i]);
|
||||
return Plugin_Handled;
|
||||
}
|
||||
}
|
||||
|
||||
inf = OpenFile2("smbintest", "rb");
|
||||
for (new i = 0; i < sizeof(items); i++)
|
||||
{
|
||||
new item;
|
||||
if (!inf.ReadInt8(item) || item != items[i])
|
||||
{
|
||||
PrintToServer("FAILED ON INDEX %d: %d != %d", i, item, items[i]);
|
||||
return Plugin_Handled;
|
||||
}
|
||||
}
|
||||
|
||||
PrintToServer("Test passed!");
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
31
scripting/testsuite/findmap.sp
Normal file
31
scripting/testsuite/findmap.sp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <sourcemod>
|
||||
|
||||
public void OnPluginStart()
|
||||
{
|
||||
RegServerCmd("test_findmap", test_findmap);
|
||||
}
|
||||
|
||||
public Action test_findmap( int argc )
|
||||
{
|
||||
char mapName[PLATFORM_MAX_PATH];
|
||||
GetCmdArg(1, mapName, sizeof(mapName));
|
||||
|
||||
char resultName[18];
|
||||
switch (FindMap(mapName, mapName, sizeof(mapName)))
|
||||
{
|
||||
case FindMap_Found:
|
||||
strcopy(resultName, sizeof(resultName), "Found");
|
||||
case FindMap_NotFound:
|
||||
strcopy(resultName, sizeof(resultName), "NotFound");
|
||||
case FindMap_FuzzyMatch:
|
||||
strcopy(resultName, sizeof(resultName), "FuzzyMatch");
|
||||
case FindMap_NonCanonical:
|
||||
strcopy(resultName, sizeof(resultName), "NonCanonical");
|
||||
case FindMap_PossiblyAvailable:
|
||||
strcopy(resultName, sizeof(resultName), "PossiblyAvailable");
|
||||
}
|
||||
|
||||
PrintToServer("FindMap says %s - \"%s\"", resultName, mapName);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
81
scripting/testsuite/floats.sp
Normal file
81
scripting/testsuite/floats.sp
Normal file
@@ -0,0 +1,81 @@
|
||||
public OnPluginStart()
|
||||
{
|
||||
RegServerCmd("test_floats", TestFloats)
|
||||
}
|
||||
|
||||
check(bool:got, bool:expect, const String:message[]="")
|
||||
{
|
||||
if (got != expect) {
|
||||
ThrowError("Check failed", message)
|
||||
}
|
||||
}
|
||||
|
||||
public Action:TestFloats(args)
|
||||
{
|
||||
new Float:x = 5.3
|
||||
new Float:y = 10.2
|
||||
|
||||
check(x < y, true)
|
||||
check(x <= y, true)
|
||||
check(x > y, false)
|
||||
check(x >= y, false)
|
||||
check(x == y, false)
|
||||
check(x != y, true)
|
||||
|
||||
x = 10.5
|
||||
y = 2.3
|
||||
|
||||
check(x < y, false)
|
||||
check(x <= y, false)
|
||||
check(x > y, true)
|
||||
check(x >= y, true)
|
||||
check(x == y, false)
|
||||
check(x != y, true)
|
||||
|
||||
x = 10.5
|
||||
y = x
|
||||
|
||||
check(x < y, false)
|
||||
check(x <= y, true)
|
||||
check(x > y, false)
|
||||
check(x >= y, true)
|
||||
check(x == y, true)
|
||||
check(x != y, false)
|
||||
|
||||
x = 0.0
|
||||
y = 0.0
|
||||
new Float:nan = x / y
|
||||
|
||||
check(x < nan, false)
|
||||
check(x <= nan, false)
|
||||
check(x > nan, false)
|
||||
check(x >= nan, false)
|
||||
check(x == nan, false)
|
||||
check(x != nan, true)
|
||||
check(nan < y, false)
|
||||
check(nan <= y, false)
|
||||
check(nan > y, false)
|
||||
check(nan >= y, false)
|
||||
check(nan == y, false)
|
||||
check(nan != y, true)
|
||||
check(nan == nan, false)
|
||||
check(nan != nan, true)
|
||||
|
||||
x = 10.5
|
||||
y = 0.0
|
||||
check(!x, false)
|
||||
check(!y, true)
|
||||
check(!nan, true)
|
||||
|
||||
y = -2.7
|
||||
check(-x == -10.5, true)
|
||||
check(-y == 2.7, true)
|
||||
|
||||
new String:buffer[32]
|
||||
Format(buffer, sizeof(buffer), "%f", nan)
|
||||
check(StrEqual(buffer, "NaN"), true)
|
||||
|
||||
PrintToServer("Tests finished.")
|
||||
|
||||
return Plugin_Stop
|
||||
}
|
167
scripting/testsuite/fwdtest1.sp
Normal file
167
scripting/testsuite/fwdtest1.sp
Normal file
@@ -0,0 +1,167 @@
|
||||
#include <sourcemod>
|
||||
|
||||
public Plugin:myinfo =
|
||||
{
|
||||
name = "Forward Testing Lab #1",
|
||||
author = "AlliedModders LLC",
|
||||
description = "Tests suite #1 for forwards created by plugins",
|
||||
version = "1.0.0.0",
|
||||
url = "http://www.sourcemod.net/"
|
||||
};
|
||||
|
||||
new Handle:g_GlobalFwd = null;
|
||||
new Handle:g_PrivateFwd = null;
|
||||
|
||||
public OnPluginStart()
|
||||
{
|
||||
RegServerCmd("test_create_gforward", Command_CreateGlobalForward);
|
||||
RegServerCmd("test_create_pforward", Command_CreatePrivateForward);
|
||||
RegServerCmd("test_exec_gforward", Command_ExecGlobalForward);
|
||||
RegServerCmd("test_exec_pforward", Command_ExecPrivateForward);
|
||||
}
|
||||
|
||||
public OnPluginEnd()
|
||||
{
|
||||
delete g_GlobalFwd;
|
||||
delete g_PrivateFwd;
|
||||
}
|
||||
|
||||
public Action:Command_CreateGlobalForward(args)
|
||||
{
|
||||
if (g_GlobalFwd != null)
|
||||
{
|
||||
delete g_GlobalFwd;
|
||||
}
|
||||
|
||||
g_GlobalFwd = CreateGlobalForward("OnGlobalForward", ET_Ignore, Param_Any, Param_Cell, Param_Float, Param_String, Param_Array, Param_CellByRef, Param_FloatByRef);
|
||||
|
||||
if (g_GlobalFwd == null)
|
||||
{
|
||||
PrintToServer("Failed to create global forward!");
|
||||
}
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:Command_CreatePrivateForward(args)
|
||||
{
|
||||
new Handle:pl;
|
||||
new Function:func;
|
||||
|
||||
if (g_PrivateFwd != null)
|
||||
{
|
||||
delete g_PrivateFwd;
|
||||
}
|
||||
|
||||
g_PrivateFwd = CreateForward(ET_Hook, Param_Cell, Param_String, Param_VarArgs);
|
||||
|
||||
if (g_PrivateFwd == null)
|
||||
{
|
||||
PrintToServer("Failed to create private forward!")
|
||||
}
|
||||
|
||||
pl = FindPluginByFile("fwdtest2.smx");
|
||||
|
||||
if (!pl)
|
||||
{
|
||||
PrintToServer("Could not find fwdtest2.smx!");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
func = GetFunctionByName(pl, "OnPrivateForward");
|
||||
|
||||
/* This shouldn't happen, but oh well */
|
||||
if (func == INVALID_FUNCTION)
|
||||
{
|
||||
PrintToServer("Could not find \"OnPrivateForward\" in fwdtest2.smx!");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
if (!AddToForward(g_PrivateFwd, pl, func) || !AddToForward(g_PrivateFwd, GetMyHandle(), ZohMyGod))
|
||||
{
|
||||
PrintToServer("Failed to add functions to private forward!");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:Command_ExecGlobalForward(args)
|
||||
{
|
||||
new a = 99;
|
||||
new Float:b = 4.215;
|
||||
new err, ret;
|
||||
|
||||
if (g_GlobalFwd == null)
|
||||
{
|
||||
PrintToServer("Failed to execute global forward. Create it first.");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
PrintToServer("Beginning call to %d functions in global forward \"OnGlobalForward\"", GetForwardFunctionCount(g_GlobalFwd));
|
||||
|
||||
Call_StartForward(g_GlobalFwd);
|
||||
Call_PushCell(OnPluginStart);
|
||||
Call_PushCell(7);
|
||||
Call_PushFloat(-8.5);
|
||||
Call_PushString("Anata wa doko desu ka?");
|
||||
Call_PushArray({0.0, 1.1, 2.2}, 3);
|
||||
Call_PushCellRef(a);
|
||||
Call_PushFloatRef(b);
|
||||
err = Call_Finish(ret);
|
||||
|
||||
PrintToServer("Call to global forward \"OnGlobalForward\" completed");
|
||||
PrintToServer("Error code = %d (expected: %d)", err, 0);
|
||||
PrintToServer("Return value = %d (expected: %d)", ret, Plugin_Continue);
|
||||
|
||||
PrintToServer("a = %d (expected: %d)", a, 777);
|
||||
PrintToServer("b = %f (expected: %f)", b, -0.782);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:Command_ExecPrivateForward(args)
|
||||
{
|
||||
new err, ret;
|
||||
|
||||
if (g_PrivateFwd == null)
|
||||
{
|
||||
PrintToServer("Failed to execute private forward. Create it first.");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
PrintToServer("Beginning call to %d functions in private forward", GetForwardFunctionCount(g_PrivateFwd));
|
||||
|
||||
Call_StartForward(g_PrivateFwd);
|
||||
Call_PushCell(24);
|
||||
Call_PushString("I am a format string: %d %d %d %d %d %d");
|
||||
Call_PushCell(0);
|
||||
Call_PushCell(1);
|
||||
Call_PushCell(2);
|
||||
Call_PushCell(3);
|
||||
Call_PushCell(4);
|
||||
Call_PushCell(5);
|
||||
err = Call_Finish(ret);
|
||||
|
||||
PrintToServer("Call to private forward completed");
|
||||
PrintToServer("Error code = %d (expected: %d)", err, 0);
|
||||
PrintToServer("Return value = %d (expected: %d)", ret, Plugin_Handled);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:ZohMyGod(num, const String:format[], ...)
|
||||
{
|
||||
decl String:buffer[128];
|
||||
|
||||
PrintToServer("Inside private forward #1");
|
||||
|
||||
PrintToServer("num = %d (expected: %d)", num, 24);
|
||||
|
||||
VFormat(buffer, sizeof(buffer), format, 3);
|
||||
PrintToServer("buffer = \"%s\" (expected: \"%s\")", buffer, "I am a format string: 0 1 2 3 4 5");
|
||||
|
||||
PrintToServer("End private forward #1");
|
||||
|
||||
return Plugin_Continue;
|
||||
}
|
43
scripting/testsuite/fwdtest2.sp
Normal file
43
scripting/testsuite/fwdtest2.sp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include <sourcemod>
|
||||
|
||||
public Plugin:myinfo =
|
||||
{
|
||||
name = "Forward Testing Lab #2",
|
||||
author = "AlliedModders LLC",
|
||||
description = "Tests suite #2 for forwards created by plugins",
|
||||
version = "1.0.0.0",
|
||||
url = "http://www.sourcemod.net/"
|
||||
};
|
||||
|
||||
public Action:OnPrivateForward(num, const String:format[], ...)
|
||||
{
|
||||
decl String:buffer[128];
|
||||
|
||||
PrintToServer("Inside private forward #2");
|
||||
|
||||
PrintToServer("num = %d (expected: %d)", num, 24);
|
||||
|
||||
VFormat(buffer, sizeof(buffer), format, 3);
|
||||
PrintToServer("buffer = \"%s\" (expected: \"%s\")", buffer, "I am a format string: 0 1 2 3 4 5");
|
||||
|
||||
PrintToServer("End private forward #2");
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public OnGlobalForward(Function:a, b, Float:c, const String:d[], Float:e[3], &f, &Float:g)
|
||||
{
|
||||
PrintToServer("Inside global forward \"OnGlobalForward\"");
|
||||
|
||||
PrintToServer("a = %d (expected: %d)", a, 11);
|
||||
PrintToServer("b = %d (expected: %d)", b, 7);
|
||||
PrintToServer("c = %f (expected: %f)", c, -8.5);
|
||||
PrintToServer("d = \"%s\" (expected: \"%s\")", d, "Anata wa doko desu ka?");
|
||||
PrintToServer("e = %f %f %f (expected: %f %f %f)", e[0], e[1], e[2], 0.0, 1.1, 2.2);
|
||||
|
||||
PrintToServer("f = %d (expected %d, setting to %d)", f, 99, 777);
|
||||
f = 777;
|
||||
|
||||
PrintToServer("g = %f (expected %f, setting to %f)", g, 4.215, -0.782);
|
||||
g = -0.782;
|
||||
}
|
129
scripting/testsuite/gamerules-props.sp
Normal file
129
scripting/testsuite/gamerules-props.sp
Normal file
@@ -0,0 +1,129 @@
|
||||
#include <sourcemod>
|
||||
#include <sdktools>
|
||||
|
||||
enum Game { Game_TF, Game_SWARM }
|
||||
new Game:g_Game;
|
||||
|
||||
public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
|
||||
{
|
||||
decl String:gamedir[64];
|
||||
GetGameFolderName(gamedir, sizeof(gamedir));
|
||||
if (!strcmp(gamedir, "tf"))
|
||||
{
|
||||
g_Game = Game_TF;
|
||||
return APLRes_Success;
|
||||
}
|
||||
|
||||
if (!strcmp(gamedir, "swarm"))
|
||||
{
|
||||
g_Game = Game_SWARM;
|
||||
return APLRes_Success;
|
||||
}
|
||||
|
||||
strcopy(error, err_max, "These tests are only supported on TF2 and Alien Swarm");
|
||||
return APLRes_Failure;
|
||||
}
|
||||
|
||||
public OnPluginStart()
|
||||
{
|
||||
if (g_Game == Game_TF)
|
||||
{
|
||||
RegConsoleCmd("gr_getstate", gr_getstate);
|
||||
RegConsoleCmd("gr_ttr", gr_ttr);
|
||||
RegConsoleCmd("gr_tbs", gr_tbs);
|
||||
RegConsoleCmd("gr_nextspawn", gr_nextspawn);
|
||||
RegConsoleCmd("gr_settime", gr_settime);
|
||||
RegConsoleCmd("gr_getgoal", gr_getgoal);
|
||||
RegConsoleCmd("gr_setgoal", gr_setgoal);
|
||||
}
|
||||
else if (g_Game == Game_SWARM)
|
||||
{
|
||||
HookEvent("entity_killed", entity_killed);
|
||||
RegConsoleCmd("gr_getstimmer", gr_getstimmer);
|
||||
}
|
||||
}
|
||||
|
||||
public Action:gr_getstate(client, argc)
|
||||
{
|
||||
ReplyToCommand(client, "Round state is %d", GameRules_GetRoundState());
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
stock Float:GameRules_GetTimeUntilRndReset()
|
||||
{
|
||||
new Float:flRestartTime = GameRules_GetPropFloat("m_flRestartRoundTime");
|
||||
if (flRestartTime == -1.0)
|
||||
return flRestartTime;
|
||||
|
||||
return flRestartTime - GetGameTime();
|
||||
}
|
||||
|
||||
public Action:gr_ttr(client, argc)
|
||||
{
|
||||
ReplyToCommand(client, "Time til restart is %.2f", GameRules_GetTimeUntilRndReset());
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:gr_tbs(client, argc)
|
||||
{
|
||||
ReplyToCommand(client, "Time between spawns for team2 is %.2f", GameRules_GetPropFloat("m_TeamRespawnWaveTimes", 2));
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:gr_nextspawn(client, argc)
|
||||
{
|
||||
ReplyToCommand(client, "Next spawn for team2 is %.2f", GameRules_GetPropFloat("m_flNextRespawnWave", 2));
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:gr_settime(client, argc)
|
||||
{
|
||||
GameRules_SetPropFloat("m_TeamRespawnWaveTimes", 2.0, 2, true);
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:gr_getgoal(client, argc)
|
||||
{
|
||||
decl String:goal[64];
|
||||
GameRules_GetPropString("m_pszTeamGoalStringRed", goal, sizeof(goal));
|
||||
ReplyToCommand(client, "Red goal string is \"%s\"", goal);
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:gr_setgoal(client, argc)
|
||||
{
|
||||
GameRules_SetPropString("m_pszTeamGoalStringRed", "urururur", true);
|
||||
|
||||
decl String:goal[64];
|
||||
GameRules_GetPropString("m_pszTeamGoalStringRed", goal, sizeof(goal));
|
||||
ReplyToCommand(client, "Red goal string is \"%s\"", goal);
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
//.. DIE
|
||||
public entity_killed(Handle:event, const String:name[], bool:dontBroadcast)
|
||||
{
|
||||
new ent = GetEventInt(event, "entindex_killed");
|
||||
if (!IsValidEdict(ent))
|
||||
return;
|
||||
|
||||
decl String:classname[64];
|
||||
GetEdictClassname(ent, classname, sizeof(classname));
|
||||
|
||||
if (!!strcmp(classname, "asw_marine"))
|
||||
return;
|
||||
|
||||
decl Float:deathvec[3];
|
||||
GameRules_GetPropVector("m_vMarineDeathPos", deathvec);
|
||||
PrintToChatAll("Death vec is %.3f %.3f %.3f", deathvec[0], deathvec[1], deathvec[2]);
|
||||
}
|
||||
|
||||
// you can manually induce this with asw_PermaStim (needs sv_cheats)
|
||||
public Action:gr_getstimmer(client, argc)
|
||||
{
|
||||
ReplyToCommand(client, "%N (%.2f/%.2f)",
|
||||
GameRules_GetPropEnt("m_hStartStimPlayer"),
|
||||
GameRules_GetPropFloat("m_flStimStartTime"),
|
||||
GameRules_GetPropFloat("m_flStimEndTime"));
|
||||
return Plugin_Handled;
|
||||
}
|
28
scripting/testsuite/goto_test.sp
Normal file
28
scripting/testsuite/goto_test.sp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include <sourcemod>
|
||||
|
||||
public OnPluginStart()
|
||||
{
|
||||
RegServerCmd("test_goto", Test_Goto);
|
||||
}
|
||||
|
||||
public Action:Test_Goto(args)
|
||||
{
|
||||
new bool:hello = false;
|
||||
new String:crab[] = "space crab";
|
||||
|
||||
sample_label:
|
||||
|
||||
new String:yam[] = "yams";
|
||||
|
||||
PrintToServer("%s %s", crab, yam);
|
||||
|
||||
if (!hello)
|
||||
{
|
||||
new bool:what = true;
|
||||
hello = what
|
||||
goto sample_label;
|
||||
}
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
58
scripting/testsuite/keyvalues.sp
Normal file
58
scripting/testsuite/keyvalues.sp
Normal file
@@ -0,0 +1,58 @@
|
||||
|
||||
#include <sourcemod>
|
||||
|
||||
public Plugin:myinfo =
|
||||
{
|
||||
name = "KeyValues test",
|
||||
author = "AlliedModders LLC",
|
||||
description = "KeyValues test",
|
||||
version = SOURCEMOD_VERSION,
|
||||
url = "http://www.sourcemod.net/"
|
||||
};
|
||||
|
||||
|
||||
public OnPluginStart()
|
||||
{
|
||||
RegServerCmd("test_keyvalues", RunTests);
|
||||
}
|
||||
|
||||
public Action:RunTests(argc)
|
||||
{
|
||||
new String:validKv[] =
|
||||
"\"root\" \
|
||||
{ \
|
||||
\"child\" \"value\" \
|
||||
\"subkey\" { \
|
||||
subchild subvalue \
|
||||
subfloat 1.0 \
|
||||
} \
|
||||
}";
|
||||
|
||||
KeyValues kv = CreateKeyValues("");
|
||||
|
||||
if (!kv.ImportFromString(validKv))
|
||||
ThrowError("Valid kv not read correctly!");
|
||||
|
||||
char value[128];
|
||||
kv.GetString("child", value, sizeof(value));
|
||||
|
||||
if (!StrEqual(value, "value"))
|
||||
ThrowError("Child kv should have 'value' but has: '%s'", value);
|
||||
|
||||
if (!kv.JumpToKey("subkey"))
|
||||
ThrowError("No sub kv subkey exists!");
|
||||
|
||||
kv.GetString("subchild", value, sizeof(value));
|
||||
|
||||
if (!StrEqual(value, "subvalue"))
|
||||
ThrowError("Subkv subvalue should have 'subvalue' but has: '%s'", value);
|
||||
|
||||
float subfloat = kv.GetFloat("subfloat");
|
||||
|
||||
if (subfloat != 1.0)
|
||||
ThrowError( "Subkv subfloat should have 1.0 but has: %f", subfloat)
|
||||
|
||||
delete kv;
|
||||
|
||||
PrintToServer("KeyValue tests passed!");
|
||||
}
|
25
scripting/testsuite/mapdisplayname.sp
Normal file
25
scripting/testsuite/mapdisplayname.sp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <sourcemod>
|
||||
|
||||
public void OnPluginStart()
|
||||
{
|
||||
RegServerCmd("test_mapdisplayname", test_mapdisplayname);
|
||||
}
|
||||
|
||||
public Action test_mapdisplayname( int argc )
|
||||
{
|
||||
char mapName[PLATFORM_MAX_PATH];
|
||||
GetCmdArg(1, mapName, sizeof(mapName));
|
||||
|
||||
char displayName[PLATFORM_MAX_PATH];
|
||||
|
||||
if (GetMapDisplayName(mapName, displayName, sizeof(displayName)))
|
||||
{
|
||||
PrintToServer("GetMapDisplayName says \"%s\" for \"%s\"", displayName, mapName);
|
||||
}
|
||||
else
|
||||
{
|
||||
PrintToServer("GetMapDisplayName says \"%s\" was not found or not resolved", mapName);
|
||||
}
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
102
scripting/testsuite/outputtest.sp
Normal file
102
scripting/testsuite/outputtest.sp
Normal file
@@ -0,0 +1,102 @@
|
||||
#include <sourcemod>
|
||||
#include <sdktools>
|
||||
|
||||
public Plugin myinfo =
|
||||
{
|
||||
name = "Entity Output Hook Testing",
|
||||
author = "AlliedModders LLC",
|
||||
description = "Test suite for Entity Output Hooks",
|
||||
version = "1.0.0.0",
|
||||
url = "http://www.sourcemod.net/"
|
||||
};
|
||||
|
||||
public void OnPluginStart()
|
||||
{
|
||||
HookEntityOutput("point_spotlight", "OnLightOn", OutputHook);
|
||||
HookEntityOutput("point_spotlight", "OnLightOff", OutputHook);
|
||||
|
||||
HookEntityOutput("func_door", "OnOpen", OutputHook);
|
||||
HookEntityOutput("func_door_rotating", "OnOpen", OutputHook);
|
||||
HookEntityOutput("prop_door_rotating", "OnOpen", OutputHook);
|
||||
HookEntityOutput("func_door", "OnClose", OutputHook);
|
||||
HookEntityOutput("func_door_rotating", "OnClose", OutputHook);
|
||||
HookEntityOutput("prop_door_rotating", "OnClose", OutputHook);
|
||||
|
||||
if (GetEngineVersion() == Engine_CSGO) {
|
||||
// The server library calls with output names from Activator (from "plated_c4" activator entity in current example).
|
||||
HookEntityOutput("planted_c4", "OnBombBeginDefuse", OutputHook);
|
||||
HookEntityOutput("planted_c4", "OnBombDefuseAborted", OutputHook);
|
||||
|
||||
// Never fired for planted_c4, only planted_c4_training.
|
||||
HookEntityOutput("planted_c4", "OnBombDefused", OutputHook);
|
||||
}
|
||||
}
|
||||
|
||||
public void OutputHook(const char[] name, int caller, int activator, float delay)
|
||||
{
|
||||
char callerClassname[64];
|
||||
if (caller >= 0 && IsValidEntity(caller)) {
|
||||
GetEntityClassname(caller, callerClassname, sizeof(callerClassname));
|
||||
}
|
||||
|
||||
char activatorClassname[64];
|
||||
if (activator >= 0 && IsValidEntity(activator)) {
|
||||
GetEntityClassname(activator, activatorClassname, sizeof(activatorClassname));
|
||||
}
|
||||
|
||||
LogMessage("[ENTOUTPUT] %s (caller: %d/%s, activator: %d/%s)", name, caller, callerClassname, activator, activatorClassname);
|
||||
}
|
||||
|
||||
public void OnMapStart()
|
||||
{
|
||||
int ent = FindEntityByClassname(-1, "point_spotlight");
|
||||
|
||||
if (ent == -1)
|
||||
{
|
||||
LogMessage("[ENTOUTPUT] Could not find a point_spotlight");
|
||||
ent = CreateEntityByName("point_spotlight");
|
||||
DispatchSpawn(ent);
|
||||
}
|
||||
|
||||
LogMessage("[ENTOUTPUT] Begin basic");
|
||||
|
||||
AcceptEntityInput(ent, "LightOff");
|
||||
AcceptEntityInput(ent, "LightOn");
|
||||
|
||||
AcceptEntityInput(ent, "LightOff", .caller = ent);
|
||||
AcceptEntityInput(ent, "LightOn", .caller = ent);
|
||||
|
||||
AcceptEntityInput(ent, "LightOff", .activator = ent);
|
||||
AcceptEntityInput(ent, "LightOn", .activator = ent);
|
||||
|
||||
AcceptEntityInput(ent, "LightOff", ent, ent);
|
||||
AcceptEntityInput(ent, "LightOn", ent, ent);
|
||||
|
||||
LogMessage("[ENTOUTPUT] End basic, begin once");
|
||||
|
||||
HookSingleEntityOutput(ent, "OnLightOn", OutputHook, true);
|
||||
HookSingleEntityOutput(ent, "OnLightOff", OutputHook, true);
|
||||
|
||||
AcceptEntityInput(ent, "LightOff", ent, ent);
|
||||
AcceptEntityInput(ent, "LightOn", ent, ent);
|
||||
|
||||
AcceptEntityInput(ent, "LightOff", ent, ent);
|
||||
AcceptEntityInput(ent, "LightOn", ent, ent);
|
||||
|
||||
LogMessage("[ENTOUTPUT] End once, begin single");
|
||||
|
||||
HookSingleEntityOutput(ent, "OnLightOn", OutputHook, false);
|
||||
HookSingleEntityOutput(ent, "OnLightOff", OutputHook, false);
|
||||
|
||||
AcceptEntityInput(ent, "LightOff", ent, ent);
|
||||
AcceptEntityInput(ent, "LightOn", ent, ent);
|
||||
|
||||
AcceptEntityInput(ent, "LightOff", ent, ent);
|
||||
AcceptEntityInput(ent, "LightOn", ent, ent);
|
||||
|
||||
// Comment these out (and reload the plugin heaps) to test for leaks on plugin unload
|
||||
UnhookSingleEntityOutput(ent, "OnLightOn", OutputHook);
|
||||
UnhookSingleEntityOutput(ent, "OnLightOff", OutputHook);
|
||||
|
||||
LogMessage("[ENTOUTPUT] End single");
|
||||
}
|
26
scripting/testsuite/ptstest.sp
Normal file
26
scripting/testsuite/ptstest.sp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <sourcemod>
|
||||
|
||||
public Plugin:myinfo =
|
||||
{
|
||||
name = "Test target filters",
|
||||
author = "AlliedModders LLC",
|
||||
description = "Tests target filters",
|
||||
version = "1.0.0.0",
|
||||
url = "http://www.sourcemod.net/"
|
||||
};
|
||||
|
||||
public OnPluginStart()
|
||||
{
|
||||
AddMultiTargetFilter("@crab", filter, "all players", true)
|
||||
}
|
||||
|
||||
public bool:filter(const String:pattern[], Handle:clients)
|
||||
{
|
||||
for (new i = 1; i <= MaxClients; i++) {
|
||||
if (IsPlayerInGame(i))
|
||||
PushArrayCell(clients, i)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
331
scripting/testsuite/sorttest.sp
Normal file
331
scripting/testsuite/sorttest.sp
Normal file
@@ -0,0 +1,331 @@
|
||||
#include <sourcemod>
|
||||
|
||||
public Plugin:myinfo =
|
||||
{
|
||||
name = "Sorting Test",
|
||||
author = "AlliedModders LLC",
|
||||
description = "Tests sorting functions",
|
||||
version = "1.0.0.0",
|
||||
url = "http://www.sourcemod.net/"
|
||||
};
|
||||
|
||||
public OnPluginStart()
|
||||
{
|
||||
RegServerCmd("test_sort_ints", Command_TestSortInts)
|
||||
RegServerCmd("test_sort_floats", Command_TestSortFloats)
|
||||
RegServerCmd("test_sort_strings", Command_TestSortStrings)
|
||||
RegServerCmd("test_sort_1d", Command_TestSort1D)
|
||||
RegServerCmd("test_sort_2d", Command_TestSort2D)
|
||||
RegServerCmd("test_adtsort_ints", Command_TestSortADTInts)
|
||||
RegServerCmd("test_adtsort_floats", Command_TestSortADTFloats)
|
||||
RegServerCmd("test_adtsort_strings", Command_TestSortADTStrings)
|
||||
RegServerCmd("test_adtsort_custom", Command_TestSortADTCustom)
|
||||
}
|
||||
|
||||
/*****************
|
||||
* INTEGER TESTS *
|
||||
*****************/
|
||||
// Note that integer comparison is just int1-int2 (or a variation therein)
|
||||
|
||||
PrintIntegers(const array[], size)
|
||||
{
|
||||
for (new i=0; i<size; i++)
|
||||
{
|
||||
PrintToServer("array[%d] = %d", i, array[i])
|
||||
}
|
||||
}
|
||||
|
||||
public Action:Command_TestSortInts(args)
|
||||
{
|
||||
new array[10] = {6, 7, 3, 2, 8, 5, 0, 1, 4, 9}
|
||||
|
||||
PrintToServer("Testing ascending sort:")
|
||||
SortIntegers(array, 10, Sort_Ascending)
|
||||
PrintIntegers(array, 10)
|
||||
|
||||
PrintToServer("Testing descending sort:")
|
||||
SortIntegers(array, 10, Sort_Descending)
|
||||
PrintIntegers(array, 10)
|
||||
|
||||
PrintToServer("Testing random sort:")
|
||||
SortIntegers(array, 10, Sort_Random)
|
||||
PrintIntegers(array, 10)
|
||||
|
||||
return Plugin_Handled
|
||||
}
|
||||
|
||||
/**************************
|
||||
* Float comparison tests *
|
||||
**************************/
|
||||
|
||||
PrintFloats(const Float:array[], size)
|
||||
{
|
||||
for (new i=0; i<size; i++)
|
||||
{
|
||||
PrintToServer("array[%d] = %f", i, array[i])
|
||||
}
|
||||
}
|
||||
|
||||
public Action:Command_TestSortFloats(args)
|
||||
{
|
||||
new Float:array[10] = {6.3, 7.6, 3.2, 2.1, 8.5, 5.2, 0.4, 1.7, 4.8, 8.2}
|
||||
|
||||
PrintToServer("Testing ascending sort:")
|
||||
SortFloats(array, 10, Sort_Ascending)
|
||||
PrintFloats(array, 10)
|
||||
|
||||
PrintToServer("Testing descending sort:")
|
||||
SortFloats(array, 10, Sort_Descending)
|
||||
PrintFloats(array, 10)
|
||||
|
||||
PrintToServer("Testing random sort:")
|
||||
SortFloats(array, 10, Sort_Random)
|
||||
PrintFloats(array, 10)
|
||||
|
||||
return Plugin_Handled
|
||||
}
|
||||
|
||||
public Custom1DSort(elem1, elem2, const array[], Handle:hndl)
|
||||
{
|
||||
new Float:f1 = Float:elem1
|
||||
new Float:f2 = Float:elem2
|
||||
if (f1 > f2)
|
||||
{
|
||||
return -1;
|
||||
} else if (f1 < f2) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Action:Command_TestSort1D(args)
|
||||
{
|
||||
new Float:array[10] = {6.3, 7.6, 3.2, 2.1, 8.5, 5.2, 0.4, 1.7, 4.8, 8.2}
|
||||
|
||||
SortCustom1D(_:array, 10, Custom1DSort)
|
||||
PrintFloats(array, 10)
|
||||
|
||||
return Plugin_Handled
|
||||
}
|
||||
|
||||
/***************************
|
||||
* String comparison tests *
|
||||
***************************/
|
||||
|
||||
PrintStrings(const String:array[][], size)
|
||||
{
|
||||
for (new i=0; i<size; i++)
|
||||
{
|
||||
PrintToServer("array[%d] = %s", i, array[i])
|
||||
}
|
||||
}
|
||||
|
||||
public Action:Command_TestSortStrings(args)
|
||||
{
|
||||
new String:strarray[][] =
|
||||
{
|
||||
"faluco",
|
||||
"bailopan",
|
||||
"pm onoto",
|
||||
"damaged soul",
|
||||
"sniperbeamer",
|
||||
"sidluke",
|
||||
"johnny got his gun",
|
||||
"gabe newell",
|
||||
"pRED*'s awesome",
|
||||
"WHAT?!"
|
||||
}
|
||||
|
||||
PrintToServer("Testing ascending sort:")
|
||||
SortStrings(strarray, 10, Sort_Ascending)
|
||||
PrintStrings(strarray, 10)
|
||||
|
||||
PrintToServer("Testing descending sort:")
|
||||
SortStrings(strarray, 10, Sort_Descending)
|
||||
PrintStrings(strarray, 10)
|
||||
|
||||
PrintToServer("Testing random sort:")
|
||||
SortStrings(strarray, 10, Sort_Random)
|
||||
PrintStrings(strarray, 10)
|
||||
|
||||
return Plugin_Handled
|
||||
}
|
||||
|
||||
public Custom2DSort(String:elem1[], String:elem2[], String:array[][], Handle:hndl)
|
||||
{
|
||||
return strcmp(elem1, elem2)
|
||||
}
|
||||
|
||||
public Action:Command_TestSort2D(args)
|
||||
{
|
||||
new String:array[][] =
|
||||
{
|
||||
"faluco",
|
||||
"bailopan",
|
||||
"pm onoto",
|
||||
"damaged soul",
|
||||
"sniperbeamer",
|
||||
"sidluke",
|
||||
"johnny got his gun",
|
||||
"gabe newell",
|
||||
"pred is a crab",
|
||||
"WHAT?!"
|
||||
}
|
||||
|
||||
SortCustom2D(_:array, 10, Custom2DSort)
|
||||
PrintStrings(array, 10)
|
||||
|
||||
return Plugin_Handled
|
||||
}
|
||||
|
||||
/*******************
|
||||
* ADT ARRAY TESTS *
|
||||
*******************/
|
||||
// Int and floats work the same as normal comparisions. Strings are direct
|
||||
// comparisions with no hacky memory stuff like Pawn arrays.
|
||||
|
||||
PrintADTArrayIntegers(Handle:array)
|
||||
{
|
||||
new size = GetArraySize(array);
|
||||
for (new i=0; i<size;i++)
|
||||
{
|
||||
PrintToServer("array[%d] = %d", i, GetArrayCell(array, i));
|
||||
}
|
||||
}
|
||||
|
||||
public Action:Command_TestSortADTInts(args)
|
||||
{
|
||||
new Handle:array = CreateArray();
|
||||
PushArrayCell(array, 6);
|
||||
PushArrayCell(array, 7);
|
||||
PushArrayCell(array, 3);
|
||||
PushArrayCell(array, 2);
|
||||
PushArrayCell(array, 8);
|
||||
PushArrayCell(array, 5);
|
||||
PushArrayCell(array, 0);
|
||||
PushArrayCell(array, 1);
|
||||
PushArrayCell(array, 4);
|
||||
PushArrayCell(array, 9);
|
||||
|
||||
PrintToServer("Testing ascending sort:")
|
||||
SortADTArray(array, Sort_Ascending, Sort_Integer)
|
||||
PrintADTArrayIntegers(array)
|
||||
|
||||
PrintToServer("Testing descending sort:")
|
||||
SortADTArray(array, Sort_Descending, Sort_Integer)
|
||||
PrintADTArrayIntegers(array)
|
||||
|
||||
PrintToServer("Testing random sort:")
|
||||
SortADTArray(array, Sort_Random, Sort_Integer)
|
||||
PrintADTArrayIntegers(array)
|
||||
|
||||
return Plugin_Handled
|
||||
|
||||
}
|
||||
|
||||
PrintADTArrayFloats(Handle:array)
|
||||
{
|
||||
new size = GetArraySize(array);
|
||||
for (new i=0; i<size;i++)
|
||||
{
|
||||
PrintToServer("array[%d] = %f", i, float:GetArrayCell(array, i));
|
||||
}
|
||||
}
|
||||
|
||||
public Action:Command_TestSortADTFloats(args)
|
||||
{
|
||||
new Handle:array = CreateArray();
|
||||
PushArrayCell(array, 6.0);
|
||||
PushArrayCell(array, 7.0);
|
||||
PushArrayCell(array, 3.0);
|
||||
PushArrayCell(array, 2.0);
|
||||
PushArrayCell(array, 8.0);
|
||||
PushArrayCell(array, 5.0);
|
||||
PushArrayCell(array, 0.0);
|
||||
PushArrayCell(array, 1.0);
|
||||
PushArrayCell(array, 4.0);
|
||||
PushArrayCell(array, 9.0);
|
||||
|
||||
PrintToServer("Testing ascending sort:")
|
||||
SortADTArray(array, Sort_Ascending, Sort_Float)
|
||||
PrintADTArrayFloats(array)
|
||||
|
||||
PrintToServer("Testing descending sort:")
|
||||
SortADTArray(array, Sort_Descending, Sort_Float)
|
||||
PrintADTArrayFloats(array)
|
||||
|
||||
PrintToServer("Testing random sort:")
|
||||
SortADTArray(array, Sort_Random, Sort_Float)
|
||||
PrintADTArrayFloats(array)
|
||||
|
||||
return Plugin_Handled
|
||||
}
|
||||
|
||||
PrintADTArrayStrings(Handle:array)
|
||||
{
|
||||
new size = GetArraySize(array);
|
||||
decl String:buffer[64];
|
||||
for (new i=0; i<size;i++)
|
||||
{
|
||||
GetArrayString(array, i, buffer, sizeof(buffer));
|
||||
PrintToServer("array[%d] = %s", i, buffer);
|
||||
}
|
||||
}
|
||||
|
||||
public Action:Command_TestSortADTStrings(args)
|
||||
{
|
||||
new Handle:array = CreateArray(ByteCountToCells(64));
|
||||
PushArrayString(array, "faluco");
|
||||
PushArrayString(array, "bailopan");
|
||||
PushArrayString(array, "pm onoto");
|
||||
PushArrayString(array, "damaged soul");
|
||||
PushArrayString(array, "sniperbeamer");
|
||||
PushArrayString(array, "sidluke");
|
||||
PushArrayString(array, "johnny got his gun");
|
||||
PushArrayString(array, "gabe newell");
|
||||
PushArrayString(array, "Hello pRED*");
|
||||
PushArrayString(array, "WHAT?!");
|
||||
|
||||
PrintToServer("Testing ascending sort:")
|
||||
SortADTArray(array, Sort_Ascending, Sort_String)
|
||||
PrintADTArrayStrings(array)
|
||||
|
||||
PrintToServer("Testing descending sort:")
|
||||
SortADTArray(array, Sort_Descending, Sort_String)
|
||||
PrintADTArrayStrings(array)
|
||||
|
||||
PrintToServer("Testing random sort:")
|
||||
SortADTArray(array, Sort_Random, Sort_String)
|
||||
PrintADTArrayStrings(array)
|
||||
|
||||
return Plugin_Handled
|
||||
}
|
||||
|
||||
public ArrayADTCustomCallback(index1, index2, Handle:array, Handle:hndl)
|
||||
{
|
||||
decl String:buffer1[64], String:buffer2[64];
|
||||
GetArrayString(array, index1, buffer1, sizeof(buffer1));
|
||||
GetArrayString(array, index2, buffer2, sizeof(buffer2));
|
||||
|
||||
return strcmp(buffer1, buffer2);
|
||||
}
|
||||
|
||||
public Action:Command_TestSortADTCustom(args)
|
||||
{
|
||||
new Handle:array = CreateArray(ByteCountToCells(64));
|
||||
PushArrayString(array, "faluco");
|
||||
PushArrayString(array, "bailopan");
|
||||
PushArrayString(array, "pm onoto");
|
||||
PushArrayString(array, "damaged soul");
|
||||
PushArrayString(array, "sniperbeamer");
|
||||
PushArrayString(array, "sidluke");
|
||||
PushArrayString(array, "johnny got his gun");
|
||||
PushArrayString(array, "gabe newell");
|
||||
PushArrayString(array, "pRED*'s running out of ideas");
|
||||
PushArrayString(array, "WHAT?!");
|
||||
|
||||
PrintToServer("Testing custom sort:")
|
||||
SortADTArrayCustom(array, ArrayADTCustomCallback)
|
||||
PrintADTArrayStrings(array);
|
||||
}
|
318
scripting/testsuite/sqltest.sp
Normal file
318
scripting/testsuite/sqltest.sp
Normal file
@@ -0,0 +1,318 @@
|
||||
#include <sourcemod>
|
||||
#include <testing>
|
||||
|
||||
public Plugin:myinfo =
|
||||
{
|
||||
name = "SQL Testing Lab",
|
||||
author = "AlliedModders LLC",
|
||||
description = "Tests basic function calls",
|
||||
version = "1.0.0.0",
|
||||
url = "http://www.sourcemod.net/"
|
||||
};
|
||||
|
||||
public OnPluginStart()
|
||||
{
|
||||
RegServerCmd("sql_test_normal", Command_TestSql1)
|
||||
RegServerCmd("sql_test_stmt", Command_TestSql2)
|
||||
RegServerCmd("sql_test_thread1", Command_TestSql3)
|
||||
RegServerCmd("sql_test_thread2", Command_TestSql4)
|
||||
RegServerCmd("sql_test_thread3", Command_TestSql5)
|
||||
RegServerCmd("sql_test_txn", Command_TestTxn)
|
||||
|
||||
new Handle:hibernate = FindConVar("sv_hibernate_when_empty");
|
||||
if (hibernate != null) {
|
||||
ServerCommand("sv_hibernate_when_empty 0");
|
||||
}
|
||||
}
|
||||
|
||||
PrintQueryData(Handle:query)
|
||||
{
|
||||
if (!SQL_HasResultSet(query))
|
||||
{
|
||||
PrintToServer("Query Handle %x has no results", query)
|
||||
return
|
||||
}
|
||||
|
||||
new rows = SQL_GetRowCount(query)
|
||||
new fields = SQL_GetFieldCount(query)
|
||||
|
||||
decl String:fieldNames[fields][32]
|
||||
PrintToServer("Fields: %d", fields)
|
||||
for (new i=0; i<fields; i++)
|
||||
{
|
||||
SQL_FieldNumToName(query, i, fieldNames[i], 32)
|
||||
PrintToServer("-> Field %d: \"%s\"", i, fieldNames[i])
|
||||
}
|
||||
|
||||
PrintToServer("Rows: %d", rows)
|
||||
decl String:result[255]
|
||||
new row
|
||||
while (SQL_FetchRow(query))
|
||||
{
|
||||
row++
|
||||
PrintToServer("Row %d:", row)
|
||||
for (new i=0; i<fields; i++)
|
||||
{
|
||||
SQL_FetchString(query, i, result, sizeof(result))
|
||||
PrintToServer(" [%s] %s", fieldNames[i], result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Action:Command_TestSql1(args)
|
||||
{
|
||||
new String:error[255]
|
||||
new Handle:db = SQL_DefConnect(error, sizeof(error))
|
||||
if (db == null)
|
||||
{
|
||||
PrintToServer("Failed to connect: %s", error)
|
||||
return Plugin_Handled
|
||||
}
|
||||
|
||||
new Handle:query = SQL_Query(db, "SELECT * FROM gab")
|
||||
if (query == null)
|
||||
{
|
||||
SQL_GetError(db, error, sizeof(error))
|
||||
PrintToServer("Failed to query: %s", error)
|
||||
} else {
|
||||
PrintQueryData(query)
|
||||
delete query
|
||||
}
|
||||
|
||||
delete db
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:Command_TestSql2(args)
|
||||
{
|
||||
new String:error[255]
|
||||
new Handle:db = SQL_DefConnect(error, sizeof(error))
|
||||
if (db == null)
|
||||
{
|
||||
PrintToServer("Failed to connect: %s", error)
|
||||
return Plugin_Handled
|
||||
}
|
||||
|
||||
new Handle:stmt = SQL_PrepareQuery(db, "SELECT * FROM gab WHERE gaben > ?", error, sizeof(error))
|
||||
if (stmt == null)
|
||||
{
|
||||
PrintToServer("Failed to prepare query: %s", error)
|
||||
} else {
|
||||
SQL_BindParamInt(stmt, 0, 1)
|
||||
if (!SQL_Execute(stmt))
|
||||
{
|
||||
SQL_GetError(stmt, error, sizeof(error))
|
||||
PrintToServer("Failed to execute query: %s", error)
|
||||
} else {
|
||||
PrintQueryData(stmt)
|
||||
}
|
||||
delete stmt
|
||||
}
|
||||
|
||||
delete db
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
new Handle:g_ThreadedHandle = null;
|
||||
|
||||
public CallbackTest3(Handle:owner, Handle:hndl, const String:error[], any:data)
|
||||
{
|
||||
PrintToServer("CallbackTest1() (owner %x) (hndl %x) (error \"%s\") (data %d)", owner, hndl, error, data);
|
||||
if (g_ThreadedHandle != null && hndl != null)
|
||||
{
|
||||
delete hndl;
|
||||
} else {
|
||||
g_ThreadedHandle = hndl;
|
||||
}
|
||||
}
|
||||
|
||||
public Action:Command_TestSql3(args)
|
||||
{
|
||||
if (g_ThreadedHandle != null)
|
||||
{
|
||||
PrintToServer("A threaded connection already exists, run the next test");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
new String:name[32];
|
||||
GetCmdArg(1, name, sizeof(name));
|
||||
|
||||
SQL_TConnect(CallbackTest3, name);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
|
||||
public Action:Command_TestSql4(args)
|
||||
{
|
||||
SQL_LockDatabase(g_ThreadedHandle);
|
||||
new Handle:query = SQL_Query(g_ThreadedHandle, "SELECT * FROM gab")
|
||||
if (query == null)
|
||||
{
|
||||
new String:error[255];
|
||||
SQL_GetError(g_ThreadedHandle, error, sizeof(error))
|
||||
PrintToServer("Failed to query: %s", error)
|
||||
} else {
|
||||
PrintQueryData(query)
|
||||
delete query
|
||||
}
|
||||
SQL_UnlockDatabase(g_ThreadedHandle);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public CallbackTest5(Handle:owner, Handle:hndl, const String:error[], any:data)
|
||||
{
|
||||
if (hndl == null)
|
||||
{
|
||||
PrintToServer("Failed to query: %s", error)
|
||||
} else {
|
||||
PrintQueryData(hndl)
|
||||
SQL_TQuery(g_ThreadedHandle, CallbackTest6, "UPDATE gab SET `gaben` = `gaben` + 1 WHERE `gaben` >= 4", 52)
|
||||
}
|
||||
}
|
||||
|
||||
public CallbackTest6(Handle:owner, Handle:hndl, const String:error[], any:data)
|
||||
{
|
||||
if (hndl == null)
|
||||
{
|
||||
PrintToServer("Failed to query: %s", error)
|
||||
} else {
|
||||
PrintToServer("Queried!");
|
||||
SQL_TQuery(g_ThreadedHandle, CallbackTest7, "UPDATE gab SET `gaben` = `gaben` + 1 WHERE `gaben` >= 4", 52)
|
||||
}
|
||||
}
|
||||
|
||||
public CallbackTest7(Handle:owner, Handle:hndl, const String:error[], any:data)
|
||||
{
|
||||
if (hndl == null)
|
||||
{
|
||||
PrintToServer("Failed to query: %s", error)
|
||||
} else {
|
||||
PrintToServer("Queried!");
|
||||
}
|
||||
}
|
||||
|
||||
public Action:Command_TestSql5(args)
|
||||
{
|
||||
SQL_TQuery(g_ThreadedHandle, CallbackTest5, "SELECT * FROM gab", 52)
|
||||
SQL_TQuery(g_ThreadedHandle, CallbackTest5, "SELECT * FROM gab", 52)
|
||||
SQL_TQuery(g_ThreadedHandle, CallbackTest5, "SELECT * FROM gab", 52)
|
||||
SQL_TQuery(g_ThreadedHandle, CallbackTest5, "SELECT * FROM gab", 52)
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
FastQuery(Handle:db, const String:query[])
|
||||
{
|
||||
new String:error[256];
|
||||
if (!SQL_FastQuery(db, query)) {
|
||||
SQL_GetError(db, error, sizeof(error));
|
||||
ThrowError("ERROR: %s", error);
|
||||
}
|
||||
}
|
||||
|
||||
public Txn_Test1_OnSuccess(Handle:db, any:data, numQueries, Handle:results[], any:queryData[])
|
||||
{
|
||||
SetTestContext("Transaction Test 1");
|
||||
AssertEq("data", data, 1000);
|
||||
AssertEq("numQueries", numQueries, 3);
|
||||
AssertEq("queryData[0]", queryData[0], 50);
|
||||
AssertEq("queryData[1]", queryData[1], 60);
|
||||
AssertEq("queryData[2]", queryData[2], 70);
|
||||
AssertFalse("HasResultSet(0)", SQL_HasResultSet(results[0]));
|
||||
AssertFalse("HasResultSet(1)", SQL_HasResultSet(results[1]));
|
||||
AssertTrue("HasResultSet(2)", SQL_HasResultSet(results[2]));
|
||||
AssertTrue("FetchRow(2)", SQL_FetchRow(results[2]));
|
||||
AssertEq("FetchInt(2, 0)", SQL_FetchInt(results[2], 0), 5);
|
||||
AssertFalse("FetchRow(2)", SQL_FetchRow(results[2]));
|
||||
}
|
||||
|
||||
public Txn_Test1_OnFailure(Handle:db, any:data, numQueries, const String:error[], failIndex, any:queryData[])
|
||||
{
|
||||
ThrowError("Transaction test 1 failed: %s (failIndex=%d)", error, failIndex);
|
||||
}
|
||||
|
||||
public Txn_Test2_OnSuccess(Handle:db, any:data, numQueries, Handle:results[], any:queryData[])
|
||||
{
|
||||
ThrowError("Transaction test 2 failed: should have failed");
|
||||
}
|
||||
|
||||
public Txn_Test2_OnFailure(Handle:db, any:data, numQueries, const String:error[], failIndex, any:queryData[])
|
||||
{
|
||||
SetTestContext("Transaction Test 2");
|
||||
AssertEq("data", data, 1000);
|
||||
AssertEq("numQueries", numQueries, 3);
|
||||
AssertEq("queryData[0]", queryData[0], 50);
|
||||
AssertEq("queryData[1]", queryData[1], 60);
|
||||
AssertEq("queryData[2]", queryData[2], 70);
|
||||
AssertEq("failIndex", failIndex, 1);
|
||||
}
|
||||
|
||||
public Txn_Test3_OnSuccess(Handle:db, any:data, numQueries, Handle:results[], any:queryData[])
|
||||
{
|
||||
SetTestContext("Transaction Test 3");
|
||||
AssertEq("data", data, 0);
|
||||
AssertEq("numQueries", numQueries, 1);
|
||||
AssertEq("queryData[0]", queryData[0], 0);
|
||||
AssertTrue("HasResultSet(0)", SQL_HasResultSet(results[0]));
|
||||
AssertTrue("FetchRow(0)", SQL_FetchRow(results[0]));
|
||||
AssertEq("FetchInt(0, 0)", SQL_FetchInt(results[0], 0), 5);
|
||||
}
|
||||
|
||||
public Action:Command_TestTxn(args)
|
||||
{
|
||||
new String:error[256];
|
||||
new Handle:db = SQL_Connect("storage-local", false, error, sizeof(error));
|
||||
if (db == null) {
|
||||
ThrowError("ERROR: %s", error);
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
FastQuery(db, "DROP TABLE IF EXISTS egg");
|
||||
FastQuery(db, "CREATE TABLE egg(id int primary key)");
|
||||
FastQuery(db, "INSERT INTO egg (id) VALUES (1)");
|
||||
FastQuery(db, "INSERT INTO egg (id) VALUES (2)");
|
||||
FastQuery(db, "INSERT INTO egg (id) VALUES (3)");
|
||||
|
||||
SetTestContext("CreateTransaction");
|
||||
|
||||
new Transaction:txn = SQL_CreateTransaction();
|
||||
AssertEq("AddQuery", txn.AddQuery("INSERT INTO egg (id) VALUES (4)", 50), 0);
|
||||
AssertEq("AddQuery", txn.AddQuery("INSERT INTO egg (id) VALUES (5)", 60), 1);
|
||||
AssertEq("AddQuery", txn.AddQuery("SELECT COUNT(id) FROM egg", 70), 2);
|
||||
SQL_ExecuteTransaction(
|
||||
db,
|
||||
txn,
|
||||
Txn_Test1_OnSuccess,
|
||||
Txn_Test1_OnFailure,
|
||||
1000
|
||||
);
|
||||
|
||||
txn = SQL_CreateTransaction();
|
||||
AssertEq("AddQuery", txn.AddQuery("INSERT INTO egg (id) VALUES (6)", 50), 0);
|
||||
AssertEq("AddQuery", txn.AddQuery("INSERT INTO egg (id) VALUES (6)", 60), 1);
|
||||
AssertEq("AddQuery", txn.AddQuery("SELECT COUNT(id) FROM egg", 70), 2);
|
||||
SQL_ExecuteTransaction(
|
||||
db,
|
||||
txn,
|
||||
Txn_Test2_OnSuccess,
|
||||
Txn_Test2_OnFailure,
|
||||
1000
|
||||
);
|
||||
|
||||
// Make sure the transaction was rolled back - COUNT should be 5.
|
||||
txn = SQL_CreateTransaction();
|
||||
AssertEq("CloneHandle", _:CloneHandle(txn), _:null);
|
||||
txn.AddQuery("SELECT COUNT(id) FROM egg");
|
||||
SQL_ExecuteTransaction(
|
||||
db,
|
||||
txn,
|
||||
Txn_Test3_OnSuccess
|
||||
);
|
||||
|
||||
db.Close();
|
||||
return Plugin_Handled;
|
||||
}
|
7
scripting/testsuite/sqltest.sql
Normal file
7
scripting/testsuite/sqltest.sql
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
CREATE TABLE gaben (gaben int primary key, fat varchar(32));
|
||||
|
||||
INSERT INTO gaben VALUES(1, 'what the');
|
||||
INSERT INTO gaben VALUES(2, 'Bee''s Knees!');
|
||||
INSERT INTO gaben VALUES(3, 'newell');
|
||||
INSERT INTO gaben VALUES(4, 'CRAB CAKE.');
|
51
scripting/testsuite/stacktest.sp
Normal file
51
scripting/testsuite/stacktest.sp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include <sourcemod>
|
||||
|
||||
public Plugin:myinfo =
|
||||
{
|
||||
name = "Stack Tests",
|
||||
author = "AlliedModders LLC",
|
||||
description = "Tests stack functions",
|
||||
version = "1.0.0.0",
|
||||
url = "http://www.sourcemod.net/"
|
||||
};
|
||||
|
||||
public OnPluginStart()
|
||||
{
|
||||
RegServerCmd("test_stack", Test_Stack);
|
||||
}
|
||||
|
||||
public Action:Test_Stack(args)
|
||||
{
|
||||
int test[20];
|
||||
char buffer[42];
|
||||
|
||||
test[0] = 5
|
||||
test[1] = 7
|
||||
|
||||
ArrayStack stack = ArrayStack(30);
|
||||
stack.Push(50);
|
||||
stack.PushArray(test, 2);
|
||||
stack.PushArray(test, 2);
|
||||
stack.PushString("space craaab");
|
||||
stack.Push(12);
|
||||
|
||||
PrintToServer("empty? %d", stack.Empty);
|
||||
|
||||
stack.Pop();
|
||||
stack.PopString(buffer, sizeof(buffer));
|
||||
PrintToServer("popped: \"%s\"", buffer);
|
||||
test[0] = 0
|
||||
test[1] = 0
|
||||
PrintToServer("values: %d, %d", test[0], test[1]);
|
||||
stack.PopArray(test, 2);
|
||||
PrintToServer("popped: %d, %d", test[0], test[1]);
|
||||
test[0] = stack.Pop(1);
|
||||
PrintToServer("popped: x, %d", test[0]);
|
||||
test[0] = stack.Pop();
|
||||
PrintToServer("popped: %d", test[0]);
|
||||
|
||||
PrintToServer("empty? %d", stack.Empty);
|
||||
|
||||
delete stack;
|
||||
return Plugin_Handled;
|
||||
}
|
156
scripting/testsuite/structtest.sp
Normal file
156
scripting/testsuite/structtest.sp
Normal file
@@ -0,0 +1,156 @@
|
||||
#include <sourcemod>
|
||||
#include <structs>
|
||||
|
||||
public Plugin:myinfo =
|
||||
{
|
||||
name = "Struct Abstraction Test",
|
||||
author = "pRED*",
|
||||
description = "",
|
||||
version = "1.0",
|
||||
url = "http://www.sourcemod.net/"
|
||||
};
|
||||
|
||||
public OnPluginStart()
|
||||
{
|
||||
RegServerCmd("sm_getstructstring", Command_GetString);
|
||||
RegServerCmd("sm_setstructstring", Command_SetString);
|
||||
|
||||
RegServerCmd("sm_getstructint", Command_GetInt);
|
||||
RegServerCmd("sm_setstructint", Command_SetInt);
|
||||
|
||||
RegServerCmd("sm_getstructfloat", Command_GetFloat);
|
||||
RegServerCmd("sm_setstructfloat", Command_SetFloat);
|
||||
|
||||
}
|
||||
|
||||
public Action:Command_GetString(args)
|
||||
{
|
||||
if (args != 2)
|
||||
{
|
||||
ReplyToCommand(0, "[SM] Usage: sm_getstructstring <struct> <string>");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
decl String:arg1[32], String:arg2[32], String:value[32];
|
||||
GetCmdArg(1, arg1, sizeof(arg1));
|
||||
GetCmdArg(2, arg2, sizeof(arg2));
|
||||
|
||||
new Handle:strct = GetWeaponStruct(arg1);
|
||||
GetStructString(strct, arg2, value, sizeof(value));
|
||||
|
||||
LogMessage("Value of %s: %s", arg2, value);
|
||||
|
||||
delete strct;
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:Command_SetString(args)
|
||||
{
|
||||
if (args != 3)
|
||||
{
|
||||
ReplyToCommand(0, "[SM] Usage: sm_setstructstring <struct> <string> <value>");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
decl String:arg1[32], String:arg2[32], String:value[32];
|
||||
GetCmdArg(1, arg1, sizeof(arg1));
|
||||
GetCmdArg(2, arg2, sizeof(arg2));
|
||||
GetCmdArg(3, value, sizeof(value));
|
||||
|
||||
new Handle:strct = GetWeaponStruct(arg1);
|
||||
SetStructString(strct, arg2, value);
|
||||
|
||||
delete strct;
|
||||
|
||||
return Plugin_Handled;
|
||||
|
||||
}
|
||||
|
||||
public Action:Command_GetInt(args)
|
||||
{
|
||||
if (args != 2)
|
||||
{
|
||||
ReplyToCommand(0, "[SM] Usage: sm_getstructint <struct> <string>");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
decl String:arg1[32], String:arg2[32];
|
||||
GetCmdArg(1, arg1, sizeof(arg1));
|
||||
GetCmdArg(2, arg2, sizeof(arg2));
|
||||
|
||||
new Handle:strct = GetWeaponStruct(arg1);
|
||||
new value = GetStructInt(strct, arg2);
|
||||
|
||||
LogMessage("Value of %s: %i", arg2, value);
|
||||
|
||||
delete strct;
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:Command_SetInt(args)
|
||||
{
|
||||
if (args != 3)
|
||||
{
|
||||
ReplyToCommand(0, "[SM] Usage: sm_setstructint <struct> <string> <value>");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
decl String:arg1[32], String:arg2[32], String:value[32];
|
||||
GetCmdArg(1, arg1, sizeof(arg1));
|
||||
GetCmdArg(2, arg2, sizeof(arg2));
|
||||
GetCmdArg(3, value, sizeof(value));
|
||||
|
||||
new Handle:strct = GetWeaponStruct(arg1);
|
||||
SetStructInt(strct, arg2, StringToInt(value));
|
||||
|
||||
|
||||
delete strct;
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:Command_GetFloat(args)
|
||||
{
|
||||
if (args != 2)
|
||||
{
|
||||
ReplyToCommand(0, "[SM] Usage: sm_getstructint <struct> <string>");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
decl String:arg1[32], String:arg2[32];
|
||||
GetCmdArg(1, arg1, sizeof(arg1));
|
||||
GetCmdArg(2, arg2, sizeof(arg2));
|
||||
|
||||
new Handle:strct = GetWeaponStruct(arg1);
|
||||
new Float:value = GetStructFloat(strct, arg2);
|
||||
|
||||
LogMessage("Value of %s: %f", arg2, value);
|
||||
|
||||
delete strct;
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:Command_SetFloat(args)
|
||||
{
|
||||
if (args != 3)
|
||||
{
|
||||
ReplyToCommand(0, "[SM] Usage: sm_setstructint <struct> <string> <value>");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
decl String:arg1[32], String:arg2[32], String:value[32];
|
||||
GetCmdArg(1, arg1, sizeof(arg1));
|
||||
GetCmdArg(2, arg2, sizeof(arg2));
|
||||
GetCmdArg(3, value, sizeof(value));
|
||||
|
||||
new Handle:strct = GetWeaponStruct(arg1);
|
||||
SetStructFloat(strct, arg2, StringToFloat(value));
|
||||
|
||||
|
||||
delete strct;
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
234
scripting/testsuite/tf2-test.sp
Normal file
234
scripting/testsuite/tf2-test.sp
Normal file
@@ -0,0 +1,234 @@
|
||||
#include <sourcemod>
|
||||
#include <sdktools>
|
||||
#include <tf2>
|
||||
#include <tf2_stocks>
|
||||
|
||||
public Plugin:myinfo =
|
||||
{
|
||||
name = "TF2 Test",
|
||||
author = "pRED*",
|
||||
description = "Test of Tf2 functions",
|
||||
version = "1.0",
|
||||
url = "www.sourcemod.net"
|
||||
}
|
||||
|
||||
public OnPluginStart()
|
||||
{
|
||||
RegConsoleCmd("sm_burnme", Command_Burn);
|
||||
RegConsoleCmd("sm_respawn", Command_Respawn);
|
||||
RegConsoleCmd("sm_disguise", Command_Disguise);
|
||||
RegConsoleCmd("sm_remdisguise", Command_RemDisguise);
|
||||
RegConsoleCmd("sm_class", Command_Class);
|
||||
RegConsoleCmd("sm_remove", Command_Remove);
|
||||
RegConsoleCmd("sm_changeclass", Command_ChangeClass);
|
||||
RegConsoleCmd("sm_regenerate", Command_Regenerate);
|
||||
RegConsoleCmd("sm_uberme", Command_UberMe);
|
||||
RegConsoleCmd("sm_unuberme", Command_UnUberMe);
|
||||
RegConsoleCmd("sm_setpowerplay", Command_SetPowerPlay);
|
||||
RegConsoleCmd("sm_panic", Command_Panic);
|
||||
RegConsoleCmd("sm_bighit", Command_BigHit);
|
||||
RegConsoleCmd("sm_frighten", Command_Frighten);
|
||||
}
|
||||
|
||||
public Action:Command_Class(client, args)
|
||||
{
|
||||
TF2_RemoveAllWeapons(client);
|
||||
|
||||
PrintToChat(client, "Test: sniper's classnum is %i (should be %i)", TF2_GetClass("sniper"), TFClass_Sniper);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:Command_Remove(client, args)
|
||||
{
|
||||
new one = GetCmdArgInt(1);
|
||||
|
||||
TF2_RemoveWeaponSlot(client, one);
|
||||
|
||||
PrintToChat(client, "Test: heavy's classnum is %i (should be %i)", TF2_GetClass("heavy"), TFClass_Heavy);
|
||||
|
||||
new doms = TF2_GetPlayerResourceData(client, TFResource_Dominations);
|
||||
PrintToChat(client, "Dominations read test: %i", doms);
|
||||
|
||||
TF2_SetPlayerResourceData(client, TFResource_Dominations, doms + 10);
|
||||
doms = TF2_GetPlayerResourceData(client, TFResource_Dominations);
|
||||
PrintToChat(client, "Dominations write test: %i", doms);
|
||||
|
||||
/* Note: This didn't appear to change my dominations value when I pressed tab. */
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:Command_ChangeClass(client, args)
|
||||
{
|
||||
new one = GetCmdArgInt(1);
|
||||
|
||||
PrintToChat(client, "Current class is :%i", TF2_GetPlayerClass(client));
|
||||
|
||||
TF2_SetPlayerClass(client, TFClassType:one);
|
||||
|
||||
PrintToChat(client, "New class is :%i", TF2_GetPlayerClass(client));
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Action:Command_Burn(client, args)
|
||||
{
|
||||
if (client == 0)
|
||||
{
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
TF2_IgnitePlayer(client, client);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:Command_Disguise(client, args)
|
||||
{
|
||||
if (client == 0)
|
||||
{
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
if (args < 2)
|
||||
{
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
new one = GetCmdArgInt(1);
|
||||
new two = GetCmdArgInt(2);
|
||||
|
||||
TF2_DisguisePlayer(client, TFTeam:one, TFClassType:two);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:Command_RemDisguise(client, args)
|
||||
{
|
||||
if (client == 0)
|
||||
{
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
TF2_RemovePlayerDisguise(client);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
|
||||
public Action:Command_Respawn(client, args)
|
||||
{
|
||||
if (client == 0)
|
||||
{
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
|
||||
TF2_RespawnPlayer(client);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:Command_Regenerate(client, args)
|
||||
{
|
||||
if (client == 0)
|
||||
{
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
TF2_RegeneratePlayer(client);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:Command_UberMe(client, args)
|
||||
{
|
||||
if (client == 0)
|
||||
{
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
if (args < 1)
|
||||
{
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
decl String:text[10];
|
||||
GetCmdArg(1, text, sizeof(text));
|
||||
|
||||
new Float:one = StringToFloat(text);
|
||||
|
||||
TF2_AddCondition(client, TFCond_Ubercharged, one);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:Command_UnUberMe(client, args)
|
||||
{
|
||||
if (client == 0)
|
||||
{
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
TF2_RemoveCondition(client, TFCond_Ubercharged);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:Command_SetPowerPlay(client, args)
|
||||
{
|
||||
if (client == 0)
|
||||
{
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
if (args < 1)
|
||||
{
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
new bool:one = GetCmdArgInt(1) != 0;
|
||||
|
||||
TF2_SetPlayerPowerPlay(client, one);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:Command_Panic(client, args)
|
||||
{
|
||||
if (client == 0)
|
||||
{
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
TF2_StunPlayer(client, 15.0, 0.25, TF_STUNFLAGS_LOSERSTATE);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:Command_BigHit(client, args)
|
||||
{
|
||||
if (client == 0)
|
||||
{
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
TF2_StunPlayer(client, 5.0, _, TF_STUNFLAGS_BIGBONK, client);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:Command_Frighten(client, args)
|
||||
{
|
||||
if (client == 0)
|
||||
{
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
TF2_StunPlayer(client, 5.0, _, TF_STUNFLAGS_GHOSTSCARE);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
163
scripting/testsuite/tries.sp
Normal file
163
scripting/testsuite/tries.sp
Normal file
@@ -0,0 +1,163 @@
|
||||
// vim: set sts=2 ts=8 sw=2 tw=99 et ft=c :
|
||||
#include <sourcemod>
|
||||
|
||||
public Plugin:myinfo =
|
||||
{
|
||||
name = "Trie test",
|
||||
author = "AlliedModders LLC",
|
||||
description = "Trie tests",
|
||||
version = "1.0.0.0",
|
||||
url = "http://www.sourcemod.net/"
|
||||
};
|
||||
|
||||
public OnPluginStart()
|
||||
{
|
||||
RegServerCmd("test_maps", RunTests);
|
||||
}
|
||||
|
||||
public Action:RunTests(argc)
|
||||
{
|
||||
StringMap map = new StringMap();
|
||||
|
||||
for (new i = 0; i < 64; i++) {
|
||||
char buffer[24];
|
||||
Format(buffer, sizeof(buffer), "%d", i);
|
||||
|
||||
if (!map.SetValue(buffer, i))
|
||||
ThrowError("set map to %d failed", i);
|
||||
|
||||
new value;
|
||||
if (!map.GetValue(buffer, value))
|
||||
ThrowError("get map %d", i);
|
||||
if (value != i)
|
||||
ThrowError("get map %d == %d", i, i);
|
||||
}
|
||||
|
||||
// Setting 17 without replace should fail.
|
||||
new value;
|
||||
if (map.SetValue("17", 999, false))
|
||||
ThrowError("set map 17 should fail");
|
||||
if (!map.GetValue("17", value) || value != 17)
|
||||
ThrowError("value at 17 not correct");
|
||||
if (!map.SetValue("17", 999))
|
||||
ThrowError("set map 17 = 999 should succeed");
|
||||
if (!map.GetValue("17", value) || value != 999)
|
||||
ThrowError("value at 17 not correct");
|
||||
|
||||
// Check size is 64.
|
||||
if (map.Size != 64)
|
||||
ThrowError("map size not 64");
|
||||
|
||||
// Check "cat" is not found.
|
||||
int array[64];
|
||||
char string[64];
|
||||
if (map.GetValue("cat", value) ||
|
||||
map.GetArray("cat", array, sizeof(array)) ||
|
||||
map.GetString("cat", string, sizeof(string)))
|
||||
{
|
||||
ThrowError("map should not have a cat");
|
||||
}
|
||||
|
||||
// Check that "17" is not a string or array.
|
||||
if (map.GetArray("17", array, sizeof(array)) ||
|
||||
map.GetString("17", string, sizeof(string)))
|
||||
{
|
||||
ThrowError("entry 17 should not be an array or string");
|
||||
}
|
||||
|
||||
// Strings.
|
||||
if (!map.SetString("17", "hellokitty"))
|
||||
ThrowError("17 should be string");
|
||||
if (!map.GetString("17", string, sizeof(string)) ||
|
||||
strcmp(string, "hellokitty") != 0)
|
||||
{
|
||||
ThrowError("17 should be hellokitty");
|
||||
}
|
||||
if (map.GetValue("17", value) ||
|
||||
map.GetArray("17", array, sizeof(array)))
|
||||
{
|
||||
ThrowError("entry 17 should not be an array or string");
|
||||
}
|
||||
|
||||
// Arrays.
|
||||
new data[5] = { 93, 1, 2, 3, 4 };
|
||||
if (!map.SetArray("17", data, 5))
|
||||
ThrowError("17 should be string");
|
||||
if (!map.GetArray("17", array, sizeof(array)))
|
||||
ThrowError("17 should be hellokitty");
|
||||
for (new i = 0; i < 5; i++) {
|
||||
if (data[i] != array[i])
|
||||
ThrowError("17 slot %d should be %d, got %d", i, data[i], array[i]);
|
||||
}
|
||||
if (map.GetValue("17", value) ||
|
||||
map.GetString("17", string, sizeof(string)))
|
||||
{
|
||||
ThrowError("entry 17 should not be an array or string");
|
||||
}
|
||||
|
||||
if (!map.SetArray("17", data, 1))
|
||||
ThrowError("couldn't set 17 to 1-entry array");
|
||||
// Check that we fixed an old bug where 1-entry arrays where cells
|
||||
if (!map.GetArray("17", array, sizeof(array), value))
|
||||
ThrowError("couldn't fetch 1-entry array");
|
||||
if (value != 1)
|
||||
ThrowError("array size mismatch (%d, expected %d)", value, 1);
|
||||
// Check that we maintained backward compatibility.
|
||||
if (!map.GetValue("17", value))
|
||||
ThrowError("backwards compatibility failed");
|
||||
if (value != data[0])
|
||||
ThrowError("wrong value (%d, expected %d)", value, data[0]);
|
||||
|
||||
// Remove "17".
|
||||
if (!map.Remove("17"))
|
||||
ThrowError("17 should have been removed");
|
||||
if (map.Remove("17"))
|
||||
ThrowError("17 should not exist");
|
||||
if (map.GetValue("17", value) ||
|
||||
map.GetArray("17", array, sizeof(array)) ||
|
||||
map.GetString("17", string, sizeof(string)))
|
||||
{
|
||||
ThrowError("map should not have a 17");
|
||||
}
|
||||
|
||||
map.Clear();
|
||||
|
||||
if (map.Size)
|
||||
ThrowError("size should be 0");
|
||||
|
||||
map.SetString("adventure", "time!");
|
||||
map.SetString("butterflies", "bees");
|
||||
map.SetString("egg", "egg");
|
||||
|
||||
StringMapSnapshot keys = map.Snapshot();
|
||||
{
|
||||
if (keys.Length != 3)
|
||||
ThrowError("map snapshot length should be 3");
|
||||
|
||||
bool found[3];
|
||||
for (new i = 0; i < keys.Length; i++) {
|
||||
new size = keys.KeyBufferSize(i);
|
||||
char[] buffer = new char[size];
|
||||
keys.GetKey(i, buffer, size);
|
||||
|
||||
if (strcmp(buffer, "adventure") == 0)
|
||||
found[0] = true;
|
||||
else if (strcmp(buffer, "butterflies") == 0)
|
||||
found[1] = true;
|
||||
else if (strcmp(buffer, "egg") == 0)
|
||||
found[2] = true;
|
||||
else
|
||||
ThrowError("unexpected key: %s", buffer);
|
||||
}
|
||||
|
||||
if (!found[0] || !found[1] || !found[2])
|
||||
ThrowError("did not find all keys");
|
||||
}
|
||||
delete keys;
|
||||
|
||||
PrintToServer("All tests passed!");
|
||||
|
||||
delete map;
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
Reference in New Issue
Block a user