Command Protection script
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Command Protection script

Started by blackwings, 26 April, 2005, 14:39:54

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

blackwings

A simple command protection script made by me, suggestion are welcomed :D
-- Command Protection & Customizing 2.5 by blackwings - relesed 26/04-05
--- 28/04-05 - Tested on Ptokax 17.03
-- ADDED: !deluser command added
-- ADDED: a table for Ops that should be allowed to use the commansd on Ops
-- CHANGED/ADDED:message to a user that gets kicked + changed the TempBan().
-- CHANGED: changed the action from !drop to the ptokax default.
--- 29/04-05 - Tested on Ptokax 17.03
-- ADDED: valid prefix of the command check = !kick, +kick, /kick is allowed
-- ADDED: !nickban & !banip command
-- ADDED: table for protected profiles
-- ADDED: a counter for kicks & drops, which by default bans after 4 kicks/drops.
--- 01/05-05 - Tested on Ptokax 17.03
-- CHANGED: Name of the script to = Command Protection & Customizing
-- CHANGED: Optimized the code a little.
-- ADDED: on/off switch for each command for allowed Op username to use command
-- CHANGED: All the messages.

sBot = "CMDprot" 

tPrefix = frmHub:GetPrefixes()

-- How many times a user is allowed to be kicked/dropped, 0 = disabled.
theBan = 4

-- Put those operatos username that should be allowed to use these commands
-- 1 is to allow a certain commands for a Ops username, and the order is =
-- kick,ban,nickban,banip,delreguser,drop
theAllowed = {
["OpName01"] = {1,1,1,1,1,1},
["OpName02"] = {1,1,1,1,1,1},
}

-- Profiles that should be protected
tProfiles = {
	[0] = 1,
	[1] = 1,
	[2] = 1,
}

function ChatArrival(user, data)
	return CmdProte(user,data)
end
function ToArrival(user,data)
	return CmdProte(user,data)
end

function CmdProte(user, data)
	local s,e,Cmd, victim, Reason = string.find(data, "%b<>%s+(%S+)%s*(%S*)%s*(%S*).*|")
	local sCounter = 0
	if user.bOperator then
		if IfValidCMD(Cmd, "kick") then
			local sVictim = GetItemByName(victim)
			if Reason == "" then
				user:SendData(sBot, "You need to type a reason for the kick")
			else      
				if not tProfiles[sVictim.iProfile] then	 
					sCounter = sCounter + 1
					tempBanLeft = theBan - sCounter
					if sCounter < theBan then
						sVictim:SendPM(sBot, "You have been kicked! Reason: "..Reason)
						sVictim:SendPM(sBot, "Number of kicks left before permban: <"..tempBanLeft..">")
						sVictim:TempBan()
					elseif sCounter == theBan and theBan ~= 0 then
						sVictim:SendPM(sBot, "You are Permbanned! Reason: "..Reason)
						sVictim:Ban()
					end
				else
					if not theAllowed[user.sName] then
						user:SendPM(sBot, "You can't kick users of this profile")
						return 1
					else
						if theAllowed[user.sName][1]==1 then
							sVictim:SendPM(sBot, "You have been kicked! Reason: "..Reason)
							sVictim:TempBan()
						else
							user:SendPM(sBot, "You can't kick users of this profile")
							return 1
						end
					end
				end
			end
			return 1
		elseif IfValidCMD(Cmd, "ban") then
			local sVictim = GetItemByName(victim)
				if not tProfiles[sVictim.iProfile] then
					sVictim:SendPM(sBot, "You were killed")
					Ban(sVictim.sIP)
					NickBan(sVictim.sName)
				else
					if not theAllowed[user.sName] then
						user:SendPM(sBot, "You can't permban users of this profile")
						return 1
					else
						if theAllowed[user.sName][2]==1 then
							sVictim:SendPM(sBot, "You were killed")
							Ban(sVictim.sIP)
							NickBan(sVictim.sName)
						else
							user:SendPM(sBot, "You can't permban users of this profile")
							return 1
						end
					end
				end
			return 1
		elseif IfValidCMD(Cmd, "nickban") then
			local sVictim = GetItemByName(victim)
				if not tProfiles[sVictim.iProfile] then
					return nil
				else
					if not theAllowed[user.sName] then
						user:SendPM(sBot, "You can't nickban users of this profile")
						return 1
					else
						if theAllowed[user.sName][3]==1 then
							return nil
						else
							user:SendPM(sBot, "You can't nickban users of this profile")
							return 1
						end
					end
				end
			return 1
		elseif IfValidCMD(Cmd, "banip") then
			local sVictim = GetItemByName(victim)
				if not tProfiles[sVictim.iProfile] then
					return nil
				else
					if not theAllowed[user.sName] then
						user:SendPM(sBot, "You can't ban users IPs of this profile")
						return 1
					else
						if theAllowed[user.sName][4]==1 then
							return nil
						else
							user:SendPM(sBot, "You can't ban users IPs of this profile")
							return 1
						end
					end
				end
			return 1
		elseif IfValidCMD(Cmd, "delreguser") then
			local sVictim = GetItemByName(victim)
				if not tProfiles[sVictim.iProfile] then
					return nil
				else
					if not theAllowed[user.sName] then
						user:SendPM(sBot, "You can't delete users accounts of this profile")
						return 1
					else
						if theAllowed[user.sName][5]==1 then
							return nil
						else
							user:SendPM(sBot, "You can't delete users accounts of this profile")
							return 1
						end
					end
				end
			return 1
		elseif IfValidCMD(Cmd, "drop") then
			local sVictim = GetItemByName(victim)
				if not tProfiles[sVictim.iProfile] then
					sCounter = sCounter + 1
					if sCounter < theBan then
						return nil
					elseif sCounter == theBan and theBan ~= 0 then
						sVictim:Ban()
					end
				else
					if not theAllowed[user.sName] then
						user:SendPM(sBot, "You can't kick/drop users of this profile")
						return 1
					else
						if theAllowed[user.sName][6]==1 then
							return nil
						else
							user:SendPM(sBot, "You can't kick/drop users of this profile")
							return 1
						end
					end
				end
			return 1
		end
	else
		user:SendData(sBot, "You aren't allowed to use this command")
        end
end

function IfValidCMD(sIsCMD, sWhatCMD)
	for sIndex in tPrefix do
		if sIsCMD == (tPrefix[sIndex]..sWhatCMD) then
			return 1
		end
	end
end


Fangs404

awesome, thanks a ton.  i definitely plan on using this one.

blackwings

#2
thanx Fangs404, your welcome :D

CommandProtection 1.5 RELEASED!!

-- ADDED: !deluser command added
-- ADDED: a table for Ops that should be allowed to use the commansd on Ops
-- CHANGED/ADDED:message to a user that gets kicked + changed the TempBan().
-- CHANGED: changed the action from !drop to the ptokax default.

Any suggestions are welcommed :)

(The first post with the script  is edited)


Fangs404

i created my own version based off of your idea.

-- Command Protection v1.0
-- by Fangs404
-- last modified 4/28/05
-- tested with PtokaX 0.3.3.0 build 17.03

sBot = frmHub:GetHubBotName()
tPrefixes = frmHub:GetPrefixes()

function ChatArrival(user, sData)
	local s,e,sCmd,sVictim = string.find(sData, "^%b<>%s*(%S*)%s*(%S*)%s*(.*)|")
	sVictim = GetItemByName(sVictim)
	if user.bOperator and sVictim and sVictim.bOperator then
		if isValidCmd(sCmd, "gag") then
			user:SendData(sBot, "You can't mute "..sVictim.sName..".")
			return 1
		elseif isValidCmd(sCmd, "drop") then
			user:SendData(sBot, "You can't drop "..sVictim.sName..".")
			return 1
		elseif isValidCmd(sCmd, "nickban") then
			user:SendData(sBot, "You can't ban "..sVictim.sName..".")
			return 1
		elseif isValidCmd(sCmd, "tempban") then
			user:SendData(sBot, "You can't ban "..sVictim.sName..".")
			return 1
		elseif isValidCmd(sCmd, "ban") then
			user:SendData(sBot, "You can't ban "..sVictim.sName..".")
			return 1
		elseif isValidCmd(sCmd, "delreguser") then
			user:SendData(sBot, "You can't delete "..sVictim.sName..".")
			return 1
		end
        end
end

function isValidCmd(sCurCmd, sNeedCmd)
	for index in tPrefixes do
		if sCurCmd == (tPrefixes[index]..sNeedCmd) then
			return 1
		end
	end
end

blackwings

just a curious question Fangs404, why use function isValidCmd(sCurCmd, sNeedCmd)??


Fangs404

#5
QuoteOriginally posted by blackwings
just a curious question Fangs404, why use function isValidCmd(sCurCmd, sNeedCmd)??

it's a function i made that'll go through the list of all possible prefixes.  ! isn't the only prefix (by default).  !title, +title, /title, for example, all do the same thing.  go to the options tab and look at the hub commands prefix setting.  my function tests to see if the command is valid based on any of those prefixes.  i could've easily hardcoded in my commands, but i mainly did it so my code will work with anyone's hub without having to touch my actual code.  all the server admin has to do is copy my script into a lua file.

Fangs404

even more compact code:

-- OP Command Protection v1.1
-- by Fangs404
-- last modified 4/29/05
-- tested with PtokaX 0.3.3.0 build 17.03

sBot = frmHub:GetHubBotName()
tPrefixes = frmHub:GetPrefixes()

function ChatArrival(user, sData)
	local s,e,sCmd,sVictim = string.find(sData, "^%b<>%s*(%S*)%s*(%S*)%s*(.*)|")
	sVictim = GetItemByName(sVictim)
	if user.bOperator and sVictim and sVictim.bOperator then
		if isValidCmd(sCmd, "gag") then
			user:SendData(sBot, "You can't mute "..sVictim.sName..".")
			return 1
		elseif isValidCmd(sCmd, "drop") then
			user:SendData(sBot, "You can't drop "..sVictim.sName..".")
			return 1
		elseif isValidCmd(sCmd, "nickban") or isValidCmd(sCmd, "tempban") or isValidCmd(sCmd, "ban") then
			user:SendData(sBot, "You can't ban "..sVictim.sName..".")
			return 1
		elseif isValidCmd(sCmd, "delreguser") then
			user:SendData(sBot, "You can't delete "..sVictim.sName..".")
			return 1
		end
        end
end

function isValidCmd(sCurCmd, sNeedCmd)
	for index in tPrefixes do
		if sCurCmd == (tPrefixes[index]..sNeedCmd) then
			return 1
		end
	end
end

blackwings

CommandProtection 2.0 RELEASED!!

-- ADDED: valid prefix of the command check = !kick, +kick, /kick is allowed
-- ADDED: !nickban & !banip command
-- ADDED: table for protected profiles
-- ADDED: a counter for kicks & drops, which by default bans after 4 kicks/drops.

Any suggestions are welcommed :)

(The first post with the script is edited)


blackwings

#8
CommandProtection / Command Protection & Customizing - 2.5 RELEASED!!

-- CHANGED: Name of the script to = Command Protection & Customizing
-- CHANGED: Optimized the code a little.
-- ADDED: on/off switch for each command for allowed Op username to use command
-- CHANGED: All the messages.

Any suggestions are welcommed :)

(The first post with the script is edited)


SMF spam blocked by CleanTalk