1.1 --- a/extensions/cstrike/extension.cpp Tue Dec 04 01:01:05 2007 +0000
1.2 +++ b/extensions/cstrike/extension.cpp Tue Dec 04 01:08:03 2007 +0000
1.3 @@ -32,6 +32,7 @@
1.4 #include "extension.h"
1.5 #include "RegNatives.h"
1.6 #include "timeleft.h"
1.7 +#include "iplayerinfo.h"
1.8
1.9 /**
1.10 * @file extension.cpp
1.11 @@ -73,6 +74,8 @@
1.12 sharesys->OverrideNatives(myself, g_CS_PrintHintText);
1.13 }
1.14
1.15 + playerhelpers->RegisterCommandTargetProcessor(this);
1.16 +
1.17 return true;
1.18 }
1.19
1.20 @@ -94,6 +97,7 @@
1.21 }
1.22 g_RegNatives.UnregisterAll();
1.23 gameconfs->CloseGameConfigFile(g_pGameConf);
1.24 + playerhelpers->UnregisterCommandTargetProcessor(this);
1.25 }
1.26
1.27 void CStrike::SDK_OnAllLoaded()
1.28 @@ -127,3 +131,112 @@
1.29 {
1.30 g_RegNatives.UnregisterAll();
1.31 }
1.32 +
1.33 +size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...)
1.34 +{
1.35 + va_list ap;
1.36 + va_start(ap, fmt);
1.37 + size_t len = vsnprintf(buffer, maxlength, fmt, ap);
1.38 + va_end(ap);
1.39 +
1.40 + if (len >= maxlength)
1.41 + {
1.42 + buffer[maxlength - 1] = '\0';
1.43 + return (maxlength - 1);
1.44 + }
1.45 + else
1.46 + {
1.47 + return len;
1.48 + }
1.49 +}
1.50 +
1.51 +bool CStrike::ProcessCommandTarget(cmd_target_info_t *info)
1.52 +{
1.53 + int max_clients;
1.54 + IPlayerInfo *pInfo;
1.55 + unsigned int team_index = 0;
1.56 + IGamePlayer *pPlayer, *pAdmin;
1.57 +
1.58 + if ((info->flags & COMMAND_FILTER_NO_MULTI) == COMMAND_FILTER_NO_MULTI)
1.59 + {
1.60 + return false;
1.61 + }
1.62 +
1.63 + if (info->admin)
1.64 + {
1.65 + if ((pAdmin = playerhelpers->GetGamePlayer(info->admin)) == NULL)
1.66 + {
1.67 + return false;
1.68 + }
1.69 + if (!pAdmin->IsInGame())
1.70 + {
1.71 + return false;
1.72 + }
1.73 + }
1.74 + else
1.75 + {
1.76 + pAdmin = NULL;
1.77 + }
1.78 +
1.79 + if (strcmp(info->pattern, "@ct") == 0 || strcmp(info->pattern, "@cts") == 0)
1.80 + {
1.81 + team_index = 3;
1.82 + }
1.83 + else if (strcmp(info->pattern, "@t") == 0 || strcmp(info->pattern, "@ts") == 0)
1.84 + {
1.85 + team_index = 2;
1.86 + }
1.87 +
1.88 + info->num_targets = 0;
1.89 +
1.90 + max_clients = playerhelpers->GetMaxClients();
1.91 + for (int i = 1;
1.92 + i <= max_clients && (cell_t)info->num_targets < info->max_targets;
1.93 + i++)
1.94 + {
1.95 + if ((pPlayer = playerhelpers->GetGamePlayer(i)) == NULL)
1.96 + {
1.97 + continue;
1.98 + }
1.99 + if (!pPlayer->IsInGame())
1.100 + {
1.101 + continue;
1.102 + }
1.103 + if ((pInfo = pPlayer->GetPlayerInfo()) == NULL)
1.104 + {
1.105 + continue;
1.106 + }
1.107 + if (pInfo->GetTeamIndex() != team_index)
1.108 + {
1.109 + continue;
1.110 + }
1.111 + if (playerhelpers->FilterCommandTarget(pAdmin, pPlayer, info->flags)
1.112 + != COMMAND_TARGET_VALID)
1.113 + {
1.114 + continue;
1.115 + }
1.116 + info->targets[info->num_targets] = i;
1.117 + info->num_targets++;
1.118 + }
1.119 +
1.120 + if (info->num_targets == 0)
1.121 + {
1.122 + info->reason = COMMAND_TARGET_EMPTY_FILTER;
1.123 + }
1.124 + else
1.125 + {
1.126 + info->reason = COMMAND_TARGET_VALID;
1.127 + }
1.128 +
1.129 + info->target_name_style = COMMAND_TARGETNAME_RAW;
1.130 + if (team_index == 2)
1.131 + {
1.132 + UTIL_Format(info->target_name, info->target_name_maxlength, "Terrorists");
1.133 + }
1.134 + else if (team_index == 3)
1.135 + {
1.136 + UTIL_Format(info->target_name, info->target_name_maxlength, "CTs");
1.137 + }
1.138 +
1.139 + return true;
1.140 +}
2.1 --- a/extensions/cstrike/extension.h Tue Dec 04 01:01:05 2007 +0000
2.2 +++ b/extensions/cstrike/extension.h Tue Dec 04 01:08:03 2007 +0000
2.3 @@ -44,7 +44,9 @@
2.4 * @brief Sample implementation of the SDK Extension.
2.5 * Note: Uncomment one of the pre-defined virtual functions in order to use it.
2.6 */
2.7 -class CStrike : public SDKExtension
2.8 +class CStrike :
2.9 + public SDKExtension,
2.10 + public ICommandTargetProcessor
2.11 {
2.12 public:
2.13 /**
2.14 @@ -85,6 +87,8 @@
2.15 void NotifyInterfaceDrop(SMInterface *pInterface);
2.16 bool QueryInterfaceDrop(SMInterface *pInterface);
2.17 public:
2.18 + bool ProcessCommandTarget(cmd_target_info_t *info);
2.19 +public:
2.20 #if defined SMEXT_CONF_METAMOD
2.21 /**
2.22 * @brief Called when Metamod is attached, before the extension version is called.