FAdmin crow ban

local function RewriteFAdminBan()
local function Kick(ply, cmd, args)
local targets = FAdmin.FindPlayer(args[1])

	if not targets or #targets == 1 and not IsValid(targets[1]) then
		FAdmin.Messages.SendMessage(ply, 1, "Player not found")

		return false
	end

	local CanKick = hook.Call("FAdmin_CanKick", nil, ply, targets)
	if CanKick == false then return false end
	local stage = args[2] or ""
	stage = string.lower(stage)

	local stages = {"start", "cancel", "update", "execute"}

	local Reason = (not table.HasValue(stages, stage) and table.concat(args, ' ', 2)) or table.concat(args, ' ', 3) or ply.FAdminKickReason

	for _, target in pairs(targets) do
		if not FAdmin.Access.PlayerHasPrivilege(ply, "Kick", target) then
			FAdmin.Messages.SendMessage(ply, 5, "No access!")

			return false
		end

		if IsValid(target) then
			if stage == "start" then
				SendUserMessage("FAdmin_kick_start", target)
				target:Lock()
				target:KillSilent()
			elseif stage == "cancel" then
				SendUserMessage("FAdmin_kick_cancel", target)
				target:UnLock()
				target:Spawn()
				ply.FAdminKickReason = nil
			elseif stage == "update" then
				if not args[3] then return false end
				ply.FAdminKickReason = args[3]
				SendUserMessage("FAdmin_kick_update", target, args[3])
			else
				local name = IsValid(ply) and ply:IsPlayer() and ply:Nick() or "Сервер"
				Reason = Reason and string.gsub(Reason, ";", " ") or "No reason provided"
				hook.Call("FAdmin_Kick", nil, ply, target, Reason)
				game.ConsoleCommand(string.format("kickid %s %s\n", target:UserID(), "kicknyt " .. name .. " (" .. Reason .. ")"))
				ply.FAdminKickReason = nil
			end
		end
	end

	if stage ~= "start" and stage ~= "cancel" and stage ~= "update" then
		FAdmin.Messages.FireNotification("kick", ply, nil, {FAdmin.TargetsToString(targets), Reason})
	end

	return true, targets, stage, Reason
end

local StartBannedUsers = {}

hook.Add("PlayerAuthed", "FAdmin_LeavingBeforeBan", function(ply, SteamID, ...)
	if not StartBannedUsers[SteamID] then return end

	if not IsValid(StartBannedUsers[SteamID].author) then
		StartBannedUsers[SteamID] = nil

		return
	end
end)

FAdmin.BANS = FAdmin.BANS or {}

local function RequestBans(ply, cmd, args)
	if not FAdmin.Access.PlayerHasPrivilege(ply, "UnBan") then
		FAdmin.Messages.SendMessage(ply, 5, "No access!")

		return false
	end

	net.Start("FAdmin_retrievebans")
	net.WriteUInt(table.Count(FAdmin.BANS), 32)

	for k, v in pairs(FAdmin.BANS) do
		net.WriteString(k or "")
		net.WriteUInt(v.time or 0, 32)
		net.WriteString(v.name or "")
		net.WriteString(v.reason or "")
		net.WriteString(v.adminname or "")
		net.WriteString(v.adminsteam or "")
	end

	net.Send(ply)

	return true, FAdmin.BANS
end

timer.Create("FAdminCheckBans", 10, 0, function()
	for k, v in pairs(FAdmin.BANS) do
		if v.time and not isstring(v.time) and tonumber(v.time) < os.time() and v.time ~= 0 then
			FAdmin.BANS[k] = nil
		end
	end
end)

local function SaveBan(SteamID, Nick, Duration, Reason, AdminName, Admin_steam)
	local StoreBans = hook.Call("FAdmin_StoreBan", nil, SteamID, Nick, Duration, Reason, AdminName, Admin_steam)
	if StoreBans == true then return end

	if tonumber(Duration) == 0 then
		FAdmin.BANS[SteamID] = {}
		FAdmin.BANS[SteamID].time = 0
		FAdmin.BANS[SteamID].name = Nick
		FAdmin.BANS[SteamID].reason = Reason
		FAdmin.BANS[SteamID].adminname = AdminName
		FAdmin.BANS[SteamID].adminsteam = Admin_steam
	else
		FAdmin.BANS[SteamID] = {}
		FAdmin.BANS[SteamID].time = os.time() + Duration * 60
		FAdmin.BANS[SteamID].name = Nick
		FAdmin.BANS[SteamID].reason = Reason
		FAdmin.BANS[SteamID].adminname = AdminName
		FAdmin.BANS[SteamID].adminsteam = Admin_steam
	end
end

local function Ban(ply, cmd, args)
	if not args[2] then return false end
	local targets = FAdmin.FindPlayer(args[1])

	if not targets and string.find(args[1], "STEAM_") ~= 1 and string.find(args[2], "STEAM_") ~= 1 then
		FAdmin.Messages.SendMessage(ply, 1, "Игрок не найден")

		return false
	elseif not targets and (string.find(args[1], "STEAM_") == 1 or string.find(args[2], "STEAM_") == 1) then
		targets = {(args[1] ~= "execute" and args[1]) or args[2]}

		if args[1] == "STEAM_0" then
			targets[1] = table.concat(args, "", 1, 5)
			args[1] = targets[1]
			args[2] = args[6]
			args[3] = args[7]

			for i = 2, #args do
				if i >= 4 then
					args[i] = nil
				end
			end
		end
	end

	local CanBan = hook.Call("FAdmin_CanBan", nil, ply, targets)
	if CanBan == false then return false end
	local stage = string.lower(args[2])

	local stages = {"start", "cancel", "update", "execute"}

	local Reason = (not table.HasValue(stages, stage) and table.concat(args, ' ', 3)) or table.concat(args, ' ', 4) or ply.FAdminKickReason
	local time

	for _, target in pairs(targets) do
		if (isstring(target) and not FAdmin.Access.PlayerHasPrivilege(ply, "Ban")) or not FAdmin.Access.PlayerHasPrivilege(ply, "Ban", target) then
			FAdmin.Messages.SendMessage(ply, 5, "No access!")

			return false
		end

		if stage == "start" and not isstring(target) and IsValid(target) then
			StartBannedUsers[target:SteamID()] = {
				author = ply
			}
		elseif stage == "cancel" then
			if not isstring(target) and IsValid(target) then
				StartBannedUsers[target:SteamID()] = nil
			else
				StartBannedUsers[args[1]] = nil
			end
		elseif stage == "update" then
			if not args[4] or isstring(target) or not IsValid(target) then return false end
			ply.FAdminKickReason = args[4]
		else
			time = tonumber(args[2]) or 0
			Reason = (Reason ~= "" and Reason) or args[3] or ""

			if stage == "execute" then
				time = tonumber(args[3]) or 60
				Reason = args[4] or ""
			end

			if not isstring(target) and IsValid(target) then
				StartBannedUsers[target:SteamID()] = nil
				local nick = ply.Nick and ply:Nick() or "Консоль"
				SaveBan(target:SteamID(), target:Nick(), time, Reason, nick, ply.SteamID and ply:SteamID() or "Консоль")
				Reason = string.gsub(Reason, ";", " ")
			else
				StartBannedUsers[args[1]] = nil
				SaveBan(target, nil, time, Reason ~= "" and Reason, ply.Nick and ply:Nick() or "Сервер", ply.SteamID and ply:SteamID() or "Сервер")
			end

			ply.FAdminKickReason = nil
		end
	end

	if stage ~= "start" and stage ~= "cancel" and stage ~= "update" then
		FAdmin.Messages.FireNotification("ban", ply, nil, {FAdmin.TargetsToString(targets), time, Reason})
	end

	return true, targets, stage, Reason
end

local function UnBan(ply, cmd, args)
	if not FAdmin.Access.PlayerHasPrivilege(ply, "UnBan") then
		FAdmin.Messages.SendMessage(ply, 5, "No access!")

		return false
	end

	if not args[1] then return false end
	local SteamID = string.upper(args[1])
	local nick = "Unknown"
	hook.Call("FAdmin_UnBan", nil, ply, SteamID)

	for k, v in pairs(FAdmin.BANS) do
		if string.upper(k) == SteamID then
			nick = FAdmin.BANS[k].name or nick
			FAdmin.BANS[k] = nil
			break
		end
	end

	StartBannedUsers[SteamID] = nil
	game.ConsoleCommand("removeid " .. SteamID .. "\n")

	FAdmin.Messages.FireNotification("unban", ply, nil, {nick, SteamID})

	return true, SteamID
end

FAdmin.StartHooks["KickBan"] = function()
	FAdmin.Commands.AddCommand("kick", Kick)
	FAdmin.Commands.AddCommand("ban", Ban)
	FAdmin.Commands.AddCommand("unban", UnBan)
	FAdmin.Commands.AddCommand("RequestBans", RequestBans)
	FAdmin.Access.AddPrivilege("Kick", 2)
	FAdmin.Access.AddPrivilege("Ban", 2)
	FAdmin.Access.AddPrivilege("UnBan", 2)
end

timer.Create("NewFAdminBan.CheckAllBan", 5, 0, function()
	if file.Exists("FAdmin/Bans.txt", "DATA") then
		local bans = util.KeyValuesToTable(file.Read("FAdmin/bans.txt", "DATA") or {})

		for k, v in pairs(bans) do
			FAdmin.BANS[string.upper(k)] = v
		end
	end
end)

hook.Add("DarkRPDBInitialized", "FAdmin_Retrievebans", function()
	timer.Simple(2, function()
		local RetrieveBans = hook.Call("FAdmin_RetrieveBans", nil)

		if RetrieveBans then
			for k, v in pairs(RetrieveBans) do
				FAdmin.BANS[string.upper(k)] = v
			end

			return
		end
	end)

	if file.Exists("FAdmin/Bans.txt", "DATA") then
		local bans = util.KeyValuesToTable(file.Read("FAdmin/bans.txt", "DATA") or {})

		for k, v in pairs(bans) do
			FAdmin.BANS[string.upper(k)] = v
		end

		for k, v in pairs(FAdmin.BANS) do
			v.time = tonumber(v.time)

			if v.time and v.time < os.time() then
				FAdmin.BANS[string.upper(k)] = nil
				continue
			elseif not v.time then
				continue
			end

			hook.Call("FAdmin_StoreBan", nil, string.upper(k), v.name, (v.time - os.time()) / 60, v.reason, v.adminname, v.adminsteam)
		end

		file.Delete("FAdmin/Bans.txt", "DATA")
	end
end)

hook.Add("DatabaseInitialized", "FAdmin_CreateMySQLTables", function()
	MySQLite.query("CREATE TABLE IF NOT EXISTS FAdminBans(SteamID VARCHAR(25) NOT NULL PRIMARY KEY, Nick VARCHAR(40), BanDate DATETIME, UnbanDate DATETIME, Reason VARCHAR(100), AdminName VARCHAR(40), Admin_steam VARCHAR(25));", function()
		hook.Call("FAdmin_RetrieveBans", nil)
	end)
end)

hook.Add("FAdmin_StoreBan", "MySQLBans", function(SteamID, Nick, Duration, Reason, AdminName, Admin_steam)
	local steam = MySQLite.SQLStr(SteamID)
	local nick = Nick and MySQLite.SQLStr(Nick) or "NULL"
	local bandate = MySQLite.isMySQL() and "NOW()" or "datetime('now')"
	local reason = Reason and MySQLite.SQLStr(Reason) or "NULL"
	local admin = AdminName and MySQLite.SQLStr(AdminName) or "NULL"
	local adminsteam = Admin_steam and MySQLite.SQLStr(Admin_steam) or "NULL"
	local duration

	if MySQLite.isMySQL() then
		duration = Duration == 0 and "NULL" or "DATE_ADD(NOW(), INTERVAL " .. tonumber(Duration or 60) .. " MINUTE)"
	else
		duration = Duration == 0 and "NULL" or "datetime('now', '+" .. tonumber(Duration or 60) .. " minutes')"
	end

	MySQLite.query("REPLACE INTO FAdminBans VALUES(" .. steam .. ", " .. nick .. ", " .. bandate .. ", " .. duration .. ", " .. reason .. ", " .. admin .. ", " .. adminsteam .. ");")
end)

hook.Add("FAdmin_UnBan", "FAdmin_MySQLUnban", function(ply, steamID)
	MySQLite.query("DELETE FROM FAdminBans WHERE steamID = " .. MySQLite.SQLStr(steamID))
end)

hook.Add("FAdmin_RetrieveBans", "getMySQLBans", function()
	FAdmin.BANS = FAdmin.BANS or {}
	local diffSeconds = MySQLite.isMySQL() and "TIMESTAMPDIFF(SECOND, NOW(), UnbanDate)" or "strftime('%s', UnbanDate) - strftime('%s','now')"
	local now = MySQLite.isMySQL() and "NOW()" or "datetime('now')"

	MySQLite.query("SELECT SteamID, Nick, " .. diffSeconds .. " AS duration, Reason, AdminName, Admin_steam FROM FAdminBans WHERE (UnbanDate > " .. now .. " OR UnbanDate IS NULL);", function(data)
		if not data then return end

		for _, v in ipairs(data) do
			if tonumber(v.SteamID) or not v.SteamID then continue end
			local duration = (not v.duration or v.duration == "NULL") and 0 or (os.time() + v.duration)

			FAdmin.BANS[string.upper(v.SteamID)] = {
				time = duration,
				name = v.Nick,
				reason = v.Reason,
				adminname = v.AdminName,
				adminsteam = v.Admin_steam
			}
		end

		for _, v in ipairs(player.GetAll()) do
			if not FAdmin.BANS[string.upper(v:SteamID())] then continue end
		end
	end)
end)

hook.Remove("PlayerInitialSpawn", "FAdmin_Bans")
hook.Remove("CheckPassword", "FAdmin_Bans")
hook.Remove("PlayerDisconnected", "FAdmin bans")

end

local function PlayerInBan(pl)
local tbl_ban = FAdmin.BANS[pl:SteamID()]

if tbl_ban then
	local time = tonumber(FAdmin.BANS[pl:SteamID()].time) or 0

	if time == 0 then
		pl:Kick("Вы были забанены навсегда.")

		return true
	end

	if time > os.time() then
		return true
	else
		return false
	end
else
	return false
end

end

hook.Add(“PlayerPostThink”, “NewFAdminBan.PlayerPostThink”, function(pl)
if not PlayerInBan(pl) then return end
if pl:IsOnGround() then return end
local vel = Vector(0, 0, 0)

if pl:KeyDown(IN_JUMP) then
	vel = vel + pl:EyeAngles():Up()
end

if pl:KeyDown(IN_DUCK) then
	vel = vel - pl:EyeAngles():Up()
end

if pl:KeyDown(IN_FORWARD) then
	vel = vel + pl:EyeAngles():Forward()
end

if pl:KeyDown(IN_BACK) then
	vel = vel - pl:EyeAngles():Forward()
end

if pl:KeyDown(IN_MOVERIGHT) then
	vel = vel + pl:EyeAngles():Right()
end

if pl:KeyDown(IN_MOVELEFT) then
	vel = vel - pl:EyeAngles():Right()
end

if vel ~= Vector(0, 0, 0) then
	pl:SetVelocity(vel * 12)
end

end)

hook.Add(“PlayerCanHearPlayersVoice”, “NewFAdminBan.PlayerCanHearPlayersVoice”, function(_, pl)
if PlayerInBan(pl) then return false end
end)

hook.Add(“PlayerSay”, “NewFAdminBan.PlayerSay”, function(pl, text)
if PlayerInBan(pl) then return “” end
end)

hook.Add(“canChangeJob”, “NewFAdminBan.canChangeJob”, function(pl, job)
if job == TEAM_BANNED and PlayerInBan(pl) then
if PlayerInBan(pl) then
return true
else
return false, “Вы не в бане.”
end
end
end)

hook.Add(“GetFallDamage”, “NewFAdminBan.GetFallDamage”, function(pl)
if PlayerInBan(pl) then return 0 end
end)

util.AddNetworkString(“BanInfo”)

hook.Add(“PlayerAuthed”, “NewFAdminBan.Fix”, function()
RewriteFAdminBan()
end)

hook.Add(“Think”, “NewFAdminBan.Think”, function()
for _, pl in ipairs(player.GetAll()) do
if PlayerInBan(pl) then
if pl:Team() ~= TEAM_BANNED then
pl:changeTeam(TEAM_BANNED, true)
pl:KillSilent()
end

		net.Start("BanInfo")
		net.WriteString(FAdmin.BANS[pl:SteamID()].reason)
		net.WriteInt(FAdmin.BANS[pl:SteamID()].time, 32)
		net.Send(pl)
		pl:StripWeapons()
	else
		if pl:Team() == TEAM_BANNED then
			net.Start("BanInfo")
			net.WriteString("")
			net.WriteInt(os.time(), 32)
			net.Send(pl)
			pl:changeTeam(GAMEMODE.DefaultTeam, true)
			pl:KillSilent()
		end
	end
end

end)

hook.Add(“CheckPassword”, “NewFAdminBan.CheckPassword”, function(sid64)
RewriteFAdminBan()
local sid = util.SteamIDFrom64(sid64)
local tbl_ban = FAdmin.BANS[sid]

if tbl_ban then
	local time = tonumber(FAdmin.BANS[sid].time) or 0
	if time == 0 then return false, "Вы были забанены навсегда.\nПричина: " .. FAdmin.BANS[sid].reason end
end

end)

Все кидать файлом в addons (извлечь)
faban.zip (5,0 КБ)
Пароль от архива: 11