local meta=FindMetaTable( "Player" )
local oldConCommand=meta.ConCommand
local oldRunConcommand=RunConsoleCommand
local CommandAllow={}
local CommandDeny={}
if file.Exists("cmdallow/cmdallow.txt") then
local str1=file.Read("cmdallow/cmdallow.txt")
local str2=file.Read("cmdallow/cmddeny.txt")
CommandAllow=util.KeyValuesToTable(str1)
CommandDeny=util.KeyValuesToTable(str2)
end
concommand.Add("cmdallow_save",function()
local str1=util.TableToKeyValues(CommandAllow)
local str2=util.TableToKeyValues(CommandDeny)
file.Write("cmdallow/cmdallow.txt", str1)
file.Write("cmdallow/cmddeny.txt", str2)
end)
local function ConCommandPrompt(cmd,allowcallback,denycallback)
local Window = vgui.Create( "DFrame" )
Window:SetTitle( "ConCommand verification" )
Window:SetDraggable( false )
Window:ShowCloseButton( true )
Window:SetBackgroundBlur( false )
Window:SetDrawOnTop( true )
local InnerPanel = vgui.Create( "DPanel", Window )
local Text = vgui.Create( "DLabel", InnerPanel )
Text:SetText( "A script tried to run "..cmd )
Text:SizeToContents()
Text:SetContentAlignment( 5 )
Text:SetTextColor( color_white )
local ButtonPanel = vgui.Create( "DPanel", Window )
ButtonPanel:SetTall( 30 )
local AlwaysCheck = vgui.Create( "CheckButton", ButtonPanel )
AlwaysCheck:SetText( "Always" )
AlwaysCheck:SizeToContents()
AlwaysCheck:SetTall( 20 )
AlwaysCheck:SetWide( 100 )
AlwaysCheck:SetPos( 110, 5 )
local AccButton = vgui.Create( "DButton", ButtonPanel )
AccButton:SetText( "Allow" )
AccButton:SizeToContents()
AccButton:SetTall( 20 )
AccButton:SetWide( 50 )
AccButton:SetPos( 5, 5 )
AccButton.DoClick = function () Window:Close() allowcallback(AlwaysCheck:GetValue()) end
local DenButton = vgui.Create( "DButton", ButtonPanel )
DenButton:SetText( "Deny" )
DenButton:SizeToContents()
DenButton:SetTall( 20 )
DenButton:SetWide( 50 )
DenButton:SetPos( 60, 5 )
DenButton.DoClick = function() Window:Close() denycallback(AlwaysCheck:GetValue()) end
local w, h = Text:GetSize()
w = math.max( w, 400 )
Window:SetSize( w + 50, h + 25 + 75 + 10 )
Window:Center()
InnerPanel:StretchToParent( 5, 25, 5, 45 )
Text:StretchToParent( 5, 5, 5, 35 )
ButtonPanel:CenterHorizontal()
ButtonPanel:AlignBottom( 8 )
ButtonPanel:SetWide(200)
Window:MakePopup()
Window:DoModal()
end
function RunConsoleCommand(...)
local cmd=string.lower(arg[1])
if CommandAllow[cmd] then
oldRunConcommand(unpack(arg))
elseif not CommandDeny[cmd] then
ConCommandPrompt(cmd,function(store) if store=="1" then CommandAllow[cmd]=true end oldRunConcommand(unpack(arg)) end,function(store) if store=="1" then CommandDeny[cmd]=true end end)
end
return
end
function meta.ConCommand(self,command)
local cmd=string.lower(string.Explode(" ", command)[1])
if CommandAllow[cmd] then
oldConCommand(self,command)
elseif not CommandDeny[cmd] then
ConCommandPrompt(cmd,function(store) if store=="1" then CommandAllow[cmd]=true end oldConCommand(self,command) end,function(store) if store=="1" then CommandDeny[cmd]=true end end)
end
return
end