How to check if a player has run a certain console command with a certain string?

Okay, so basically to prevent some net messages I made from being abused via lua_run_cl, how would I check if a player has run a certain console command with a certain string?

Basically I want to do something like this(if a function HasRunCommandWithString existed)


--net message stuff
util.AddNetworkString( "givewepon" );
net.Receive( "givewepon", function( len, ply )
if ply:HasRunCommandWithString( "lua_run_cl", "givewepon" ) then
print("Cheater! You can't use that command.")
return
end
    ply:Give( "weapon_sg552test" );
end );


You don’t prevent them from abusing them with clientside lua, you add serverside checks or rework your system to prevent abuse.

[editline]23rd May 2015[/editline]

For example, when/who do you want to be able to give a weapon to? Say you wanted to give a weapon when an admin clicks a button. You’d use the ply argument of the net.Receive function to check if the player IsAdmin().

If players can do lua_run_cl, they can also do lua_openscript_cl, thus making that useless.

Hmm. It seems that there isn’t a way to prevent abuse of net messages. I guess I’ll just have to let them stay as is… unless someone has a way, because I’m NOT making an admin-only menu.

Can you explain who and when you would like to be able to use the net message?

The only solution I can come up with is to only make the net message usable if the derma menu I’m using is open. This would make it so that if you open the console and use lua_run_cl then you can’t use it because the derma menu isn’t open. But, you can keep the derma menu open while you have the game paused. Or wait, couldn’t that be solved with


function GM:PlayerBindPress( ply, bind, pressed )
MsgN(bind)
if LocalPlayer() then
if ( string.find( bind, "escape" ) ) then 
DermaPanel:Hide()
end
end
end


?

Also, how would I go about making the message only usable if the derma menu is open, clientside?

Client code:


DermaButton.DoClick = function()
    net.Start( "givewepon" );
    net.SendToServer();
end


So you want anyone to be able to use the message when the menu is open? When will the menu be able to be opened?

OP, you should give this a little read: http://mywiki.wooledge.org/XyProblem.

The menu can be opened whenever the context menu buttons are pressed. Okay, the only thing I need to know is how I can make the net message only be usable when the derma menu is open. Then, this will all be done.

So. Someone can open their context menu any time to open a panel, then from that panel they can choose to give themselves a weapon.
So they can give themselves a weapon at any time?

They don’t open the context menu. The weapon menu replaces the context menu.

[editline]23rd May 2015[/editline]

But yeah, basically.

But, ALL I need to know is how to make the net message only be able to get called if the derma panel is open. That’s ALL I need to know. Then my problem is solved.

But they can open this menu at any time?

Yes.

[editline]23rd May 2015[/editline]

Okay, listen, I only need a simple if statement in the net function. I just have no idea how to do it. All I know is that it involves “if DermaPanel:Show() then”. The if statement is ALL I need. ALL I need…

Anything your client can do, a cheating client can pretend to have done.

But that’s a cheating client. Besides… just… augh. Noone is going to help me write the simple if statement I need in


DermaButton.DoClick = function()
    net.Start( "givewepon" );
    net.SendToServer();
end


, are they…

The “simple if statement” doesn’t exist.

what do you mean? I need to write it.

Please for sake of anything that is good tell WHAT you are trying to do instead of HOW you want to do it.

Also, if they can open the derma frame at any time, why do you need this check?

Here you go!

[lua]
net.Receive( “givewepon”, function( _len, _ply )
local _menuOpen = net.ReadBool();

if not _menuOpen then
    print("Cheater! You can't use that command.");
    return;
end

_ply:Give( "weapon_sg552test" );

end );
[/lua]
[lua]
DermaButton.DoClick = function()
net.Start( “givewepon” );
net.WriteBool( DermaButton:GetParent():IsVisible() );
net.SendToServer();
end;
[/lua]