gm_concmdhook - An omnipotent console command hook

Description: A simple module which allows a coder to see all console commands being run and choose to disable them from running.

**Example Code:
**[lua] require( “concmdhook” )

local function PlayerFromAddress(address)
for k, v in ipairs(player.GetAll()) do
if (v:IPAddress() == address) then
return v
end
end
end
if CLIENT then
hook.Add( “OnConCommand”, “TestHook”, function ( cmd )
Msg( "Command was run: " … cmd … "
" )
if ( string.find(cmd, “disconnect”) ) then
Msg(“Now you can never leave me!”)
return false;
end
end )
else
hook.Add( “OnConCommand”, “TestHook”, function ( cmd, addr )
local ply = PlayerFromAddress( addr )
if ply == nil then
Msg("Server command ran: " … cmd … "
")
return;
end
Msg("Player " … ply:Name() … " ran " … cmd … "
");
if ( string.find(cmd, “npc_thinknow”) ) then
ply:ChatPrint(“Please don’t crash us :)”)
return false
end
end )
end
[/lua]
Other Info: This module is statesafe, meaning the client, server, and menu can all use this module without interfering. The order by which the module asks for input is Menu, Server, Client.

More Info: The addr argument is the IP address of the player running the command. Bare with me on this, but please use the supplied function to find the player with the given IP address.

Download: v1.1

Source: SVN

Isn’t this fairly useless without that player argument? <_<

[editline]12:14AM[/editline]

Actually I can see the use for clients, but the player arg for servers would be more useful.

That’s a SourceNet thing, and I don’t want to copypasta code from Chrisaster’s gm_sourcenet.

[editline]06:23PM[/editline]

Actually I just talked to him, he gave me the OK to use that code. I’ll be testing a few things out and see what I come up with.

Excellent. What happens when you return false? Does it act like the concommand doesn’t exist, or just do nothing?

The command is not processed.

Nice one.

Waiting for the ply arg. I have already a use for this :wink:

There you guys go.

If you return false serverside does it stop the client executing it?

Returning false will always stop the command from processing.

Doesn’t slog do something like this?

Wait what:



> require("concmdhook")...
[gm_concmdhook] Loaded!
test
Server command ran: test
addons\ulib\lua\ulib\server\hook.lua:139: attempt to index local 'gm' (a nil val
ue)


O.o

ULX isn’t compatible with anything.

You can make it more compatible by reporting that bug.

I can’t because I am using a 1 1/2 year old version, because it’s fucking highly modified :stuck_out_tongue:

Just replace the hook module with the latest version.

Or just remove it, it doesnt seem to affect it, only fucks shit up

If the gm argument is nil, just set it to GAMEMODE.

[editline]12:39PM[/editline]

For your custom hook module.

[editline]12:40PM[/editline]

That’s serversided only.

Now if we just got a linux version of this or slog.

Crazy idea: A lua<->pawn “bridge” so we could hook stuff with sourcemod’s already built in features. They would keep hooks working and we would just reap the benefits.

How about we just look at Sourcemod’s sourcecode and reap the benefits? :v: