Raised This Month: $51 Target: $400
 12% 

Solved Some issues with FindTarget / ProcessTargetString)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
pcmaster
AlliedModders Donor
Join Date: Sep 2009
Old 05-29-2017 , 15:25   Some issues with FindTarget / ProcessTargetString)
Reply With Quote #1

Currently trying to investigate some issues with FindTarget/ProcessTargetString in two plugins, one being the Timer !spec plugin, the other one selfMute (related issue https://forums.alliedmods.net/showpo...3&postcount=18).

In both cases, if a non-admin tries to self-mute/spectate another player, they will be presented the error message "[SM] You cannot target this player".
If any admin tries to use any of those commands, it works flawlessly.

This happens with both FindTarget and ProcessTargetString (seeing how FindTarget is only a wrapper).

Digging a bit into SM's source code, I came across this: https://github.com/alliedmodders/sou...ache.cpp#L1494 which is called from https://github.com/alliedmodders/sou...ager.cpp#L1503.
In both cases, the pAdmin object's Adminid is always -1 (as the caller isn't an admin), thus the check in AdminCache fails and the players get a "You cannot target" error.

Now, the fourth argument for FindTarget() allows disabling the immunity checks, which I tried - but with that enabled, the target filter doesn't properly work anymore.

Example:
Player - "Do you even Bitcoin"
sm_spec do - Multiple clients matched [..]
sm_spec "do you" - No matching targets found.
sm_spec "Do you even Bitcoin" - No matching targets found.
Each of the above commands work fine for admin commands (such as sm_who).
The command in general also work without the "" if the targeted player has a unique name.

Code used:
PHP Code:
// client = argument from RegConsoleCmd callback
new String:arg1[64];
GetCmdArgString(arg1sizeof(arg1));

new 
target FindTarget(clientarg1truefalse);
if (
target == -1
{
    return 
Plugin_Handled;
}

SetEntPropEnt(clientProp_Send"m_hObserverTarget"target); 
Am I (and the author of self-mute) using these functions wrong, or what could be the cause?
__________________
Stopped hosting servers as of November 2018, no longer active around here.

Last edited by pcmaster; 05-31-2017 at 13:55.
pcmaster is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 05-30-2017 , 08:20   Re: Some issues with FindTarget / ProcessTargetString)
Reply With Quote #2

Are you using the plugin from the first post or one of the alternates from later in the thread? The alternates will not ignore immunity which might explain the linked post. FindTarget will set the no-immunity flag which makes SM not do the CanAdminTarget check (your second SM code link shows this). I tested briefly and FindTarget worked as expected for me with non-admins.

If it tells you there's no matching target, then it's something else completely. Off the top of my head, the user you're trying to target might be using a character that looks the same but isn't the same as a normal ASCII character. With your example, if the user's name actually used an "o" from the Cyrillic alphabet, then it would look the same as a normal "o" but would never match targets if you typed a normal one.
Fyren is offline
pcmaster
AlliedModders Donor
Join Date: Sep 2009
Old 05-30-2017 , 15:10   Re: Some issues with FindTarget / ProcessTargetString)
Reply With Quote #3

First question - yes, I am using one of the version from later down the thread.
Once I figure out why the "No target" error occurs I will attach a fixed version to that thread.

Second question - already checked that, but the name of the player in question is pure ASCII, as in no special characters.
This also happens if you try to target ANY player with quotation marks around their name (even in console).

To take the example of the fixed sm_spec command (immunity check disabled).
sm_spec Player works, sm_spec "Player" does not (even if you write out the full name with correct caps and all).
Same in chat, /spec Player works, /spec "Player" does not.

During debugging, I also disabled the doublequotefix plugin suspecting that it might cause issues to no avail.
Also unloaded the spec plugin and checked if any other plugin may be overwriting the command - nothing...

Really confused why this is happening..

On another note: it would be nice if one could set a special flag in ProcessTargetString (and FindTarget), something like DISABLE_CALLER_IMMUNITY_CHECK (or something).
Setting this flag would disable the initial check if the caller (so any regular player) is an admin, but still leave the check of the target intact.
This would allow players to target eachother, but not admins (which have immunity set).
__________________
Stopped hosting servers as of November 2018, no longer active around here.

Last edited by pcmaster; 05-30-2017 at 15:10.
pcmaster is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 05-30-2017 , 16:22   Re: Some issues with FindTarget / ProcessTargetString)
Reply With Quote #4

With your sample code in your first post, quoting arguments for the command will break things. GetCmdArgString gets everything after the command, including quotes. If you don't want the quotes (because you're looking for a player name), use GetCmdArg() instead.
Fyren is offline
ambn
Veteran Member
Join Date: Feb 2015
Location: Fun servers
Old 05-30-2017 , 21:56   Re: Some issues with FindTarget / ProcessTargetString)
Reply With Quote #5

Quote:
Originally Posted by Fyren View Post
With your sample code in your first post, quoting arguments for the command will break things. GetCmdArgString gets everything after the command, including quotes. If you don't want the quotes (because you're looking for a player name), use GetCmdArg() instead.
He can use StripQuotes(StrArgument) as well .
__________________
ambn is offline
pcmaster
AlliedModders Donor
Join Date: Sep 2009
Old 05-31-2017 , 13:55   Re: Some issues with FindTarget / ProcessTargetString)
Reply With Quote #6

Yea, completly missed the part about GetCmdArgString, thanks!
Works now.
__________________
Stopped hosting servers as of November 2018, no longer active around here.
pcmaster is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:36.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode