Checking Console Commands?

Yeah, I want to know how to check the console commands clients enter on my server by having them printed to the server console (specifically ULX console commands)

I know that each ulx console command uses “ulx” at the start but how would I check every time a player enters a console command beginning with “ulx”?

Thanks.

I would look here: http://www.facepunch.com/showthread.php?t=791247&highlight=engineConsoleCommand

Idea is you use this thing called the “engineConsoleCommand”, which is a function called whenever someone tries to use a console command. You can check if the concommand has ulx in the name or whatnot.

Could I just, oh I don’t know, make a function and then have that function called with the same concommand ULX uses? (Like ulx ban?) or would that fuck stuff up?

Probably and certainly. Like, if you tried to use ulx ban it made confetti or something?

Like for instance

[lua]
function UlxBanShit( args args args )
– Lol Shit
– Regular ULX function
end
hook.Add(“ulx ban bla bla bla”, UlxBanShit)

function SappinYourSpy( ply, cmd, args )
print(ply… " just used the concmd " … cmd)
end
hook.Add(“ulx ban bla bla bla”, SappinYourSpy)
[/lua]

Something like that? And both functions still worked?

[lua]newEngineConCommand = engineConsoleCommand

function engineConsoleCommand(ply , cmd , args)
if cmd == “ulx” and args[1] == “ban” then

	local GETTING_BANNED = nil
	for _,v in ipairs(player.GetAll()) do 
		if string.match(v:Name(),args[2]) then GETTING_BANNED = v end
	end
	
	if GETTING_BANNED then GETTING_BANNED:ChatPrint("OH SHIT YOU'RE GETTING BANNED") end

	newEngineConCommand(ply , cmd , args)
	
end

end[/lua]

It would look more like that.

Hm Ok… I think I’m getting this… so if I wanted it to print in console then it would be

[lua]
newEngineConCommand = engineConsoleCommand

function engineConsoleCommand(ply , cmd , args)
if cmd == “ulx” then
newEngineConCommand(ply , cmd , args)
print( ply … " used the command " … cmd … " with args " … args )
end
end
[/lua]

Yeah, like that. However, I’ve never really experimented this before, so there could be two things wrong there:

  1. Calling the newEngineConCommand function might act as a “return” and stop the whole engineConsoleCommand, so it would never get to the print. In any case, it’s safest to put it last in the if statement.

  2. I think args is a table rather than a string, but who knows.

This?

[lua]
newEngineConCommand = engineConsoleCommand

function engineConsoleCommand(ply , cmd , args)
if cmd == “ulx” then
print( ply … " used the command " … cmd … " with these args:" )
PrintTable( args )
newEngineConCommand(ply , cmd , args)
end
end
[/lua]

Yeah, like that. You can tell me if it works or not.

Nope, it didn’t work :confused:

engineConsoleCommand returns a Boolean

[lua]
newEngineConCommand = engineConsoleCommand

function engineConsoleCommand(ply , cmd , args)
if cmd == “ulx” then
print( ply … " used the command " … cmd … " with these args:" )
PrintTable( args )
newEngineConCommand(ply , cmd , args)
return true
end
return false
end
[/lua]

Cheers for boxes :wink:

Also if you want you can concatenate the args instead of using PrintTable
[lua]print( ply … " used the command " … cmd … " with these args: "…table.concat( args, “:” ) ) [/lua]

replacing “:” with your seperator

For example using “,” when the persons args are hello and world would return the string
hello,world
or if you used the seperator " " then it would return
hello world
and so on

What the fuck are you doing octogon? Returning false will give the “unknown command” error, even if the command exists. Also, will infinite loop the client.

[lua]
octogon used the command ulx with these args:
1 = hp
2 = octogon
3 = 20
[/lua]

It works Just need a bit more improvement it spams the console like 50 times.

Found out it was the engineconsolecommand causing infinute loop intill breaking point.

here is the Code OP

[lua]
if( SERVER ) then
AddCSLuaFile(“ulxcmds.lua”)
else
include(“ulxcmds.lua”)

newEngineConCommand = engineConsoleCommand

function engineConsoleCommand(ply , cmd , args)
if cmd == “ulx” then
print(" " … LocalPlayer():Nick() … " used the command " … cmd … " with these args:" )
PrintTable( args )
–newEngineConCommand(ply , cmd , args)
end
end
end[/lua]

] ulx hp octogon 20
octogon used the command ulx with these args:
1 = hp
2 = octogon
3 = 20
] ulx tsay hi
octogon used the command ulx with these args:
1 = tsay
2 = hi
] ulx addgroup testing
octogon used the command ulx with these args:
1 = addgroup
2 = testing

K, testing now.

[editline]03:50PM[/editline]

It works, but you made it clientside only. Plus it breaks the actual ULX commands.

e.g. I type ulx slap cheif and it says that I used the command, but it doesn’t actually slap me.

Anyway to make this print in SERVER console and not fuck the original commands?

[editline]04:04PM[/editline]

Hmm… Ok well I fixed it to where it works clientside. Here’s the code:

[lua]
newEngineConCommand = engineConsoleCommand

function engineConsoleCommand(ply , cmd , args)
if cmd == “ulx” then
print( ply:Nick() … " used the command " … cmd … " with the args " … table.concat( args, " " ) )
newEngineConCommand(ply , cmd , args)
end
end
[/lua]

I tried it on server, and it didn’t recognize “ulx” as a command. :v:

Help?

[editline]04:20PM[/editline]

Ok, another note, although the code above DOES work with ulx commands, it breaks the spawn menu for some reason :confused:

Other commands work fine, such as “kill” and “cl_playermodel.”

Get SLog from azuisleets google code page. It logs all the console commands that people run, and you can choose to block whichever ones you want from being logged, or choose to have people banned for running certain commands.

It works fine for me i use a timer though.

I’ve edited the code to working on client-side

[lua]
newEngineConCommand = concommand.Run

function concommand.Run(ply , cmd , args)
if cmd == “ulx” then
print( ply:Nick() … " used the command " … cmd … " with the args " … table.concat( args, " " ) )
newEngineConCommand( ply, cmd, args )
return true
end
newEngineConCommand( ply, cmd, args )
end
[/lua]

That works fine on client, now how do I go about getting it on the server?

Look, i have this code



newEngineConCommand = engineConsoleCommand

function engineConsoleCommand(ply , cmd , args)
	newEngineConCommand(ply , cmd , args)
	print(ply,cmd,args)
end


It only reacts on binded commands(not all, only on spawnmenu and contextmenu) or on command like LocalPlayer():ConCommand(“blablabla”)
If i enter something like “hax” in console - this function doesn’t work…