core/smn_player.cpp
changeset 1621 ac5d4c68a99a
parent 1576 f36378b2d71f
child 1624 709b1f973c05
     1.1 --- a/core/smn_player.cpp	Sun Oct 21 17:58:35 2007 +0000
     1.2 +++ b/core/smn_player.cpp	Sun Oct 21 20:06:30 2007 +0000
     1.3 @@ -881,7 +881,11 @@
     1.4  	return g_Players.GetClientOfUserId(params[1]);
     1.5  }
     1.6  
     1.7 -static cell_t _ShowActivity(IPluginContext *pContext, const cell_t *params, const char *tag, cell_t fmt_param)
     1.8 +static cell_t _ShowActivity(IPluginContext *pContext,
     1.9 +							const cell_t *params,
    1.10 +							const char *tag,
    1.11 +							cell_t fmt_param,
    1.12 +							unsigned int mode)
    1.13  {
    1.14  	char message[255];
    1.15  	char buffer[255];
    1.16 @@ -912,13 +916,31 @@
    1.17  		{
    1.18  			g_SourceMod.SetGlobalTarget(client);
    1.19  			g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
    1.20 +
    1.21 +			if (pContext->GetContext()->n_err != SP_ERROR_NONE)
    1.22 +			{
    1.23 +				return 0;
    1.24 +			}
    1.25 +
    1.26  			UTIL_Format(message, sizeof(message), "%s%s\n", tag, buffer);
    1.27  			engine->ClientPrintf(pPlayer->GetEdict(), message);
    1.28  			display_in_chat = true;
    1.29  		}
    1.30 -	} else {
    1.31 +		else if (mode == 2)
    1.32 +		{
    1.33 +			display_in_chat = true;
    1.34 +		}
    1.35 +	}
    1.36 +	else
    1.37 +	{
    1.38  		g_SourceMod.SetGlobalTarget(LANG_SERVER);
    1.39  		g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
    1.40 +
    1.41 +		if (pContext->GetContext()->n_err != SP_ERROR_NONE)
    1.42 +		{
    1.43 +			return 0;
    1.44 +		}
    1.45 +
    1.46  		UTIL_Format(message, sizeof(message), "%s%s\n", tag, buffer);
    1.47  		META_CONPRINT(message);
    1.48  	}
    1.49 @@ -947,15 +969,23 @@
    1.50  			if ((value & 1) || (value & 2))
    1.51  			{
    1.52  				const char *newsign = sign;
    1.53 -				if (value & 2)
    1.54 +				if ((value & 2) || (i == client))
    1.55  				{
    1.56  					newsign = name;
    1.57  				}
    1.58  				g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
    1.59 +
    1.60 +				if (pContext->GetContext()->n_err != SP_ERROR_NONE)
    1.61 +				{
    1.62 +					return 0;
    1.63 +				}
    1.64 +
    1.65  				UTIL_Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer);
    1.66  				g_HL2.TextMsg(i, HUD_PRINTTALK, message);
    1.67  			}
    1.68 -		} else {
    1.69 +		}
    1.70 +		else
    1.71 +		{
    1.72  			/* Treat this as an admin user */
    1.73  			bool is_root = g_Admins.GetAdminFlag(id, Admin_Root, Access_Effective);
    1.74  			if ((value & 4) 
    1.75 @@ -963,11 +993,17 @@
    1.76  				|| ((value & 16) && is_root))
    1.77  			{
    1.78  				const char *newsign = sign;
    1.79 -				if ((value & 8) || ((value & 16) && is_root))
    1.80 +				if ((value & 8) || ((value & 16) && is_root) || (i == client))
    1.81  				{
    1.82  					newsign = name;
    1.83  				}
    1.84  				g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
    1.85 +
    1.86 +				if (pContext->GetContext()->n_err != SP_ERROR_NONE)
    1.87 +				{
    1.88 +					return 0;
    1.89 +				}
    1.90 +
    1.91  				UTIL_Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer);
    1.92  				g_HL2.TextMsg(i, HUD_PRINTTALK, message);
    1.93  			}
    1.94 @@ -979,7 +1015,7 @@
    1.95  
    1.96  static cell_t ShowActivity(IPluginContext *pContext, const cell_t *params)
    1.97  {
    1.98 -	return _ShowActivity(pContext, params, "[SM] ", 2);
    1.99 +	return _ShowActivity(pContext, params, "[SM] ", 2, 1);
   1.100  }
   1.101  
   1.102  static cell_t ShowActivityEx(IPluginContext *pContext, const cell_t *params)
   1.103 @@ -987,7 +1023,15 @@
   1.104  	char *str;
   1.105  	pContext->LocalToString(params[2], &str);
   1.106  
   1.107 -	return _ShowActivity(pContext, params, str, 3);
   1.108 +	return _ShowActivity(pContext, params, str, 3, 1);
   1.109 +}
   1.110 +
   1.111 +static cell_t ShowActivity2(IPluginContext *pContext, const cell_t *params)
   1.112 +{
   1.113 +	char *str;
   1.114 +	pContext->LocalToString(params[2], &str);
   1.115 +
   1.116 +	return _ShowActivity(pContext, params, str, 3, 2);
   1.117  }
   1.118  
   1.119  static cell_t KickClient(IPluginContext *pContext, const cell_t *params)
   1.120 @@ -1036,7 +1080,9 @@
   1.121  	if (!pPlayer)
   1.122  	{
   1.123  		return pContext->ThrowNativeError("Client index %d is invalid", client);
   1.124 -	} else if (!pPlayer->IsInGame()) {
   1.125 +	}
   1.126 +	else if (!pPlayer->IsInGame())
   1.127 +	{
   1.128  		return pContext->ThrowNativeError("Client %d is not in game", client);
   1.129  	}
   1.130  
   1.131 @@ -1059,9 +1105,13 @@
   1.132  	if (!pPlayer)
   1.133  	{
   1.134  		return pContext->ThrowNativeError("Client index %d is invalid", client);
   1.135 -	} else if (!pPlayer->IsInGame()) {
   1.136 +	}
   1.137 +	else if (!pPlayer->IsInGame())
   1.138 +	{
   1.139  		return pContext->ThrowNativeError("Client %d is not in game", client);
   1.140 -	} else if (!pPlayer->IsAuthorized()) {
   1.141 +	}
   1.142 +	else if (!pPlayer->IsAuthorized())
   1.143 +	{
   1.144  		return pContext->ThrowNativeError("Client %d is not authorized", client);
   1.145  	}
   1.146  
   1.147 @@ -1079,9 +1129,12 @@
   1.148  	if (!pPlayer)
   1.149  	{
   1.150  		return pContext->ThrowNativeError("Client index %d is invalid", client);
   1.151 -	} else if (!pPlayer->IsInGame()) {
   1.152 +	}
   1.153 +	else if (!pPlayer->IsInGame()) {
   1.154  		return pContext->ThrowNativeError("Client %d is not in game", client);
   1.155 -	} else if (!pPlayer->IsAuthorized()) {
   1.156 +	}
   1.157 +	else if (!pPlayer->IsAuthorized())
   1.158 +	{
   1.159  		return pContext->ThrowNativeError("Client %d is not authorized", client);
   1.160  	}
   1.161  
   1.162 @@ -1108,6 +1161,42 @@
   1.163  	return pPlayer->IsInKickQueue() ? 1 : 0;
   1.164  }
   1.165  
   1.166 +static cell_t ProcessTargetString(IPluginContext *pContext, const cell_t *params)
   1.167 +{
   1.168 +	cmd_target_info_t info;
   1.169 +
   1.170 +	pContext->LocalToString(params[1], (char **)&info.pattern);
   1.171 +	info.admin = params[2];
   1.172 +	pContext->LocalToPhysAddr(params[3], &info.targets);
   1.173 +	info.max_targets = params[4];
   1.174 +	info.flags = params[5];
   1.175 +	pContext->LocalToString(params[6], &info.target_name);
   1.176 +	info.target_name_maxlength = params[7];
   1.177 +
   1.178 +	cell_t *tn_is_ml;
   1.179 +	pContext->LocalToPhysAddr(params[8], &tn_is_ml);
   1.180 +
   1.181 +	g_Players.ProcessCommandTarget(&info);
   1.182 +
   1.183 +	if (info.target_name_style == COMMAND_TARGETNAME_ML)
   1.184 +	{
   1.185 +		*tn_is_ml = 1;
   1.186 +	}
   1.187 +	else
   1.188 +	{
   1.189 +		*tn_is_ml = 0;
   1.190 +	}
   1.191 +
   1.192 +	if (info.num_targets == 0)
   1.193 +	{
   1.194 +		return info.reason;
   1.195 +	}
   1.196 +	else
   1.197 +	{
   1.198 +		return info.num_targets;
   1.199 +	}
   1.200 +}
   1.201 +
   1.202  REGISTER_NATIVES(playernatives)
   1.203  {
   1.204  	{"AddUserFlags",			AddUserFlags},
   1.205 @@ -1154,10 +1243,12 @@
   1.206  	{"GetClientOfUserId",		GetClientOfUserId},
   1.207  	{"ShowActivity",			ShowActivity},
   1.208  	{"ShowActivityEx",			ShowActivityEx},
   1.209 +	{"ShowActivity2",			ShowActivity2},
   1.210  	{"KickClient",				KickClient},
   1.211  	{"RunAdminCacheChecks",		RunAdminCacheChecks},
   1.212  	{"NotifyPostAdminCheck",	NotifyPostAdminCheck},
   1.213  	{"IsClientInKickQueue",		IsClientInKickQueue},
   1.214 +	{"ProcessTargetString",		ProcessTargetString},
   1.215  	{NULL,						NULL}
   1.216  };
   1.217