Added config reloading support.

Revision also includes:
* Added syntax checking on recoded/new console commands.
* Fixed sv_skyname handle being used when invalid.
* Fixed unhooking error on Weapon_Drop.
* Prefixed some API-style functions with 'stock' to stop compiler
warning.
* Separated downloads into its own file.
This commit is contained in:
Greyscale
2009-05-18 06:26:13 +02:00
parent 363be11591
commit 25b0caa68a
13 changed files with 675 additions and 216 deletions

View File

@ -35,7 +35,7 @@ enum WpnRestrictQuery
Successful_Group, /** Group (un)restrict query was successful. */
Failed_Weapon, /** Weapon (un)restrict was unsuccessful */
Failed_Group, /** Group (un)restrict was unsuccessful */
Invalid, /** Weapon/Group invalid */
WeaponInvalid, /** Weapon/Group invalid */
}
/**
@ -57,7 +57,7 @@ RestrictInit()
*/
RestrictOnCommandsCreate()
{
// Create admin commands.
// Create weapon admin commands.
RegAdminCmd("zr_restrict", RestrictRestrictCommand, ADMFLAG_GENERIC, "zr_restrict <weapon> - Restrict a weapon.");
RegAdminCmd("zr_unrestrict", RestrictUnrestrictCommand, ADMFLAG_GENERIC, "zr_unrestrict <weapon> - Unrestrict a weapon.");
}
@ -82,7 +82,7 @@ RestrictClearData()
/**
* Loads weapon data from file.
*/
RestrictOnMapStart()
RestrictLoad()
{
// Clear weapon restrict data.
RestrictClearData();
@ -99,7 +99,7 @@ RestrictOnMapStart()
// Get weapon groups config path.
decl String:pathweapongroups[PLATFORM_MAX_PATH];
new bool:exists = ConfigGetFilePath(CVAR_CONFIG_PATH_WEAPONGROUPS, pathweapongroups);
new bool:exists = ConfigGetCvarFilePath(CVAR_CONFIG_PATH_WEAPONGROUPS, pathweapongroups);
// If file doesn't exist, then log and stop.
if (!exists)
@ -221,7 +221,6 @@ RestrictClientInit(client)
RestrictOnClientDisconnect(client)
{
// Unhook "Weapon_CanUse" callback, and reset variable.
if (g_iCanUseHookID[client] != -1)
{
ZRTools_UnhookWeapon_CanUse(g_iCanUseHookID[client]);
@ -287,7 +286,7 @@ public Action:RestrictBuyCommand(client, argc)
* Successful_Group: The call successfully restricted a weapon group.
* Failed_Weapon: The call failed to restrict a weapon.
* Failed_Group: The call failed to restrict a weapon group.
* Invalid: The call was unsuccessful due to invalid weapon.
* WeaponInvalid: The call was unsuccessful due to invalid weapon.
*/
WpnRestrictQuery:RestrictRestrict(const String:weapon[], String:display[] = "")
{
@ -340,7 +339,7 @@ WpnRestrictQuery:RestrictRestrict(const String:weapon[], String:display[] = "")
strcopy(display, WEAPONS_MAX_LENGTH, weapon);
// Weapon name was invalid.
return Invalid;
return WeaponInvalid;
}
// Get display name of the weapon.
@ -368,7 +367,7 @@ WpnRestrictQuery:RestrictRestrict(const String:weapon[], String:display[] = "")
* Successful_Group: The call successfully restricted a weapon group.
* Failed_Weapon: The call failed to restrict a weapon.
* Failed_Group: The call failed to restrict a weapon group.
* Invalid: The call was unsuccessful due to invalid weapon.
* WeaponInvalid: The call was unsuccessful due to invalid weapon.
*/
WpnRestrictQuery:RestrictUnrestrict(const String:weapon[], String:display[] = "")
{
@ -425,7 +424,7 @@ WpnRestrictQuery:RestrictUnrestrict(const String:weapon[], String:display[] = ""
{
strcopy(display, WEAPONS_MAX_LENGTH, weapon);
return Invalid;
return WeaponInvalid;
}
// Get display name of the weapon.
@ -502,7 +501,7 @@ RestrictPrintRestrictOutput(client, WpnRestrictQuery:output, const String:weapon
}
}
// Weapon name was invalid.
case Invalid:
case WeaponInvalid:
{
if (reply)
{
@ -571,7 +570,7 @@ RestrictPrintUnrestrictOutput(client, WpnRestrictQuery:output, const String:weap
}
}
// Weapon name was invalid.
case Invalid:
case WeaponInvalid:
{
if (reply)
{
@ -886,6 +885,10 @@ public ZRTools_Action:RestrictCanUse(client, weapon)
return ZRTools_Continue;
}
/**
* Command callbacks.
*/
/**
* Command callback (zr_restrict)
* Restricts a weapon or group
@ -895,6 +898,13 @@ public ZRTools_Action:RestrictCanUse(client, weapon)
*/
public Action:RestrictRestrictCommand(client, argc)
{
// If not enough arguments given, then stop.
if (argc < 1)
{
TranslationReplyToCommand(client, "Weapons command restrict syntax");
return Plugin_Handled;
}
// If weapons module is disabled, then stop.
new bool:weapons = GetConVarBool(g_hCvarsList[CVAR_WEAPONS]);
if (!weapons)
@ -937,6 +947,13 @@ public Action:RestrictRestrictCommand(client, argc)
*/
public Action:RestrictUnrestrictCommand(client, argc)
{
// If not enough arguments given, then stop.
if (argc < 1)
{
TranslationReplyToCommand(client, "Weapons command unrestrict syntax");
return Plugin_Handled;
}
// If weapons module is disabled, then stop.
new bool:weapons = GetConVarBool(g_hCvarsList[CVAR_WEAPONS]);
if (!weapons)

View File

@ -18,7 +18,7 @@
/**
* Array that stores the "HookID" to be later unhooked on player disconnect.
*/
new g_iWeaponDropHookID[MAXPLAYERS + 1];
new g_iWeaponDropHookID[MAXPLAYERS + 1] = {-1, ...};
/**
* Client is joining the server.
@ -32,14 +32,18 @@ WeaponAlphaClientInit(client)
}
/**
* Unhook Weapon_CanUse function on a client.
* Client is leaving the server.
*
* @param client The client index.
*/
WeaponAlphaOnClientDisconnect(client)
{
// Unhook "Weapon_Drop" on client.
ZRTools_UnhookWeapon_Drop(g_iWeaponDropHookID[client]);
// Unhook "Weapon_Drop" callback, and reset variable.
if (g_iWeaponDropHookID[client] != -1)
{
ZRTools_UnhookWeapon_Drop(g_iWeaponDropHookID[client]);
g_iWeaponDropHookID[client] = -1;
}
}
/**

View File

@ -56,6 +56,15 @@ WeaponsInit()
RestrictInit();
}
/**
* Create commands related to weapons here.
*/
WeaponsOnCommandsCreate()
{
// Forward event to sub-modules.
RestrictOnCommandsCreate();
}
/**
* Clears weapon data.
*/
@ -78,6 +87,13 @@ WeaponsLoad()
// Clear weapon data.
WeaponsClearData();
// Get weapons config path.
decl String:pathweapons[PLATFORM_MAX_PATH];
new bool:exists = ConfigGetCvarFilePath(CVAR_CONFIG_PATH_WEAPONS, pathweapons);
// Register config info.
ConfigRegisterConfig(ConfigWeapons, false, GetFunctionByName(GetMyHandle(), "WeaponsOnConfigReload"), _, pathweapons, CONFIG_FILE_ALIAS_WEAPONS);
// If module is disabled, then stop.
new bool:weapons = GetConVarBool(g_hCvarsList[CVAR_WEAPONS]);
if (!weapons)
@ -85,10 +101,6 @@ WeaponsLoad()
return;
}
// Get weapons config path.
decl String:pathweapons[PLATFORM_MAX_PATH];
new bool:exists = ConfigGetFilePath(CVAR_CONFIG_PATH_WEAPONS, pathweapons);
// If file doesn't exist, then log and stop.
if (!exists)
{
@ -104,8 +116,26 @@ WeaponsLoad()
// Validate weapons config.
WeaponsValidateConfig();
// Set config data.
ConfigSetConfigLoaded(ConfigWeapons, true);
ConfigSetConfigHandle(ConfigWeapons, kvWeapons);
// Forward event to sub-module.
RestrictOnMapStart();
RestrictLoad();
}
/**
* Called when configs are being reloaded.
*
* @param config The config being reloaded. (only if 'all' is false)
*/
public WeaponsOnConfigReload(ConfigFile:config)
{
// Reload weapons config.
if (config == ConfigWeapons)
{
WeaponsLoad();
}
}
/**
@ -120,12 +150,6 @@ WeaponsValidateConfig()
}
}
WeaponsOnCommandsCreate()
{
// Forward event to sub-modules.
RestrictOnCommandsCreate();
}
/**
* Client is joining the server.
*
@ -156,7 +180,7 @@ WeaponsOnClientDisconnect(client)
* on it when finished!
* @return The size of the array.
*/
WeaponsCreateWeaponArray(&Handle:arrayWeapons, maxlen = WEAPONS_MAX_LENGTH)
stock WeaponsCreateWeaponArray(&Handle:arrayWeapons, maxlen = WEAPONS_MAX_LENGTH)
{
// Initialize array handle.
arrayWeapons = CreateArray(maxlen);
@ -189,7 +213,7 @@ WeaponsCreateWeaponArray(&Handle:arrayWeapons, maxlen = WEAPONS_MAX_LENGTH)
* @param weapon The weapon name.
* @return Returns true if valid, false it not.
*/
bool:WeaponsIsValidWeapon(const String:weapon[])
stock bool:WeaponsIsValidWeapon(const String:weapon[])
{
// Reset keyvalue's traversal stack.
KvRewind(kvWeapons);
@ -219,7 +243,7 @@ bool:WeaponsIsValidWeapon(const String:weapon[])
* @param weapon The weapon name.
* @param display Returns with the display name, is not changed if weapon is invalid.
*/
WeaponsGetDisplayName(const String:weapon[], String:display[])
stock WeaponsGetDisplayName(const String:weapon[], String:display[])
{
// Reset keyvalue's traversal stack.
KvRewind(kvWeapons);
@ -246,7 +270,7 @@ WeaponsGetDisplayName(const String:weapon[], String:display[])
* @param weapon The weapon name.
* @return Returns true if restricted, false it not.
*/
bool:WeaponsIsWeaponMenu(const String:weapon[])
stock bool:WeaponsIsWeaponMenu(const String:weapon[])
{
// Reset keyvalue's traversal stack.
KvRewind(kvWeapons);
@ -278,7 +302,7 @@ bool:WeaponsIsWeaponMenu(const String:weapon[])
* @param weapon The weapon name.
* @return The float value of the knockback multiplier, 1.0 if not found.
*/
Float:WeaponGetWeaponKnockback(const String:weapon[])
stock Float:WeaponGetWeaponKnockback(const String:weapon[])
{
// Reset keyvalue's traversal stack.
KvRewind(kvWeapons);
@ -312,7 +336,7 @@ Float:WeaponGetWeaponKnockback(const String:weapon[])
* @param weapons The weapon index array.
* -1 if no weapon in slot.
*/
WeaponsGetClientWeapons(client, weapons[WeaponsType])
stock WeaponsGetClientWeapons(client, weapons[WeaponsType])
{
// x = weapon slot.
for (new x = 0; x < WEAPONS_SLOTS_MAX; x++)
@ -328,7 +352,7 @@ WeaponsGetClientWeapons(client, weapons[WeaponsType])
* @return The weapon index of the deployed weapon.
* -1 if no weapon is deployed.
*/
WeaponsGetDeployedWeaponIndex(client)
stock WeaponsGetDeployedWeaponIndex(client)
{
// Return the client's active weapon.
return GetEntDataEnt2(client, offsActiveWeapon);
@ -340,7 +364,7 @@ WeaponsGetDeployedWeaponIndex(client)
* @param client The client index.
* @return The slot number of deployed weapon.
*/
WeaponsType:WeaponsGetDeployedWeaponSlot(client)
stock WeaponsType:WeaponsGetDeployedWeaponSlot(client)
{
// Get all client's weapon indexes.
new weapons[WeaponsType];
@ -373,7 +397,7 @@ WeaponsType:WeaponsGetDeployedWeaponSlot(client)
* @param client The client index.
* @param weapon The weapon index to force client to drop.
*/
WeaponsForceClientDrop(client, weapon)
stock WeaponsForceClientDrop(client, weapon)
{
// Force client to drop weapon.
SDKCall(g_hToolsCSWeaponDrop, client, weapon, true, false);