1
2
3
4
5
6
7
8
9
10
11
12
13
function banOnJoin(id)
	for _, usgn in pairs(bannedList) do
		if player(id,"usgn") == usgn then
			if player(id,"ip") ~= "0.0.0.0" then
				parse('banip '..player(id,"ip")..' 0 ')
			end
			if player(id,"steamid") ~= "0" then
				parse('bansteam '..player(id,"steamid")..' 0 ')
			end
			parse('banusgn '..usgn..' 0 ')
		end
	end
end
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
local BAN_REASON = 'pp'
local NO_IP = { ['0.0.0.0'] = true, ['127.0.0.1'] = true }
function banOnJoin(p)
	local usgnId = player(p, 'usgn')
	-- No need to use pairs or ipairs,
	-- they're slower.
	for i = 1, #bannedList do
		local entry = bannedList[i]
		-- Is this player banned?
		if entry == usgnId then
			local success
			-- Make sure to request all data
			-- before removing the player.
			local steamId = player(p, 'steamid')
			local ipAddress = player(p, 'ip')
			-- Remove the player.
			if usgnId > 0 then
				parse('banusgn "' .. usgnId .. '" "0" "' .. BAN_REASON .. '"')
				success = true
			end
			if steamId ~= '0' then
				parse('bansteam "' .. steamId .. '" "0" "' .. BAN_REASON .. '"')
				success = true
			end
			if not NO_IP[ipAddress] then
				parse('banip "' .. ipAddress .. '" "0" "' .. BAN_REASON .. '"')
				success = true
			end
			if not success then
				-- No need to pre-request the name,
				-- because the player wasn't removed.
				print('FATAL ERROR: Could not ban player "' .. player(p, 'name') .. '".')
			end
			break -- We're finished here.
		end
	end
end