forked from Devieth/Halo-Lua
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnameban.lua
220 lines (202 loc) · 5.46 KB
/
nameban.lua
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
-- Name Banning by Devieth
-- Script for SAPP
api_version = "1.10.0.0"
filename = "bans.data"
function OnScriptLoad()
register_callback(cb['EVENT_PREJOIN'], "PreJoin")
register_callback(cb['EVENT_COMMAND'], "Command")
network_struct = read_dword(sig_scan("F3ABA1????????BA????????C740??????????E8????????668B0D") + 3)
if halo_type == "PC" then ce, client_info_size = 0x0,0x60 else ce, client_info_size = 0x40, 0xEC end
end
function OnScriptUnload()
end
function Command(PlayerIndex, Command, Enviroment, Password)
local respond = true
if isadmin(PlayerIndex) or Enviroment == 0 then
local Command = string.gsub(Command, [["]], "")
local t = tokenizestring(Command, " ")
if t[1] == "ban" then
respond = false
if t[2] ~= nil then
if tonumber(t[2]) ~= nil then
if player_present(t[2]) then
local name, ip = get_var(t[2], "$name"), get_ip(t[2])
write_ban(name..":"..ip.."\n", "a")
xprint(PlayerIndex, get_var(t[2], "$name").." has been banned!")
if t[3] ~= nil then
local reason = assemble(t, 2, " ")
say_all(name .. " has been banned from the server! Reason: '"..reason.."' 1")
execute_command("sv_ban "..tonumber(t[2]).." 1s")
else
execute_command("sv_ban "..tonumber(t[2]).." 1s")
end
update_ban_header()
else
xprint(PlayerIndex, "Error: Player is not in the server.")
end
end
else
xprint(PlayerIndex, "Error: Please use the players number.")
end
elseif t[1] == "unban" then
respond = false
if tonumber(t[2]) ~= nil then
read_bans()
local removed = false
for i = 1,#lines do
if i == tonumber(t[2]) then
xprint(PlayerIndex, lines[i] .. " has been unbanned!")
table.remove(lines, i)
removed = true
break
end
end
if removed then
rebuild_bans()
else
xprint(PlayerIndex, "Error: Failed to unban player or the ban may not exist.")
end
else
xprint(PlayerIndex, "Error: Please use the ban id.")
end
elseif t[1] == "bans" then
respond = false
list_bans(PlayerIndex)
end
end
return respond
end
function PreJoin(PlayerIndex)
local name = read_widestring((network_struct + 0x1AA + ce + to_real_index(PlayerIndex) * 0x20), 12)
local ip = get_ip(PlayerIndex)
read_bans(PlayerIndex, name, ip)
end
function get_ip(PlayerIndex)
local m_connection = read_dword(read_dword(read_dword(get_client_machine_info(PlayerIndex))))
local m_1 = read_byte(m_connection)
local m_2 = read_byte(m_connection + 0x1)
local m_3 = read_byte(m_connection + 0x2)
local m_4 = read_byte(m_connection + 0x3)
return m_1.."."..m_2.."."..m_3.."."..m_4
end
function isadmin(PlayerIndex)
if player_present(PlayerIndex) then
local lvl = get_var(PlayerIndex, "$lvl")
if lvl ~= "-1" then
return true
end
end
return false
end
function read_bans(PlayerIndex, name, ip)
local file = io.open(filename, "rb")
if file then
lines = {}
for line in io.lines(filename) do
lines[#lines + 1] = line
if name ~= nil then
local t = tokenizestring(line, ":")
if t[1] == name or t[2] == get_ip(PlayerIndex) then
execute_command("sv_ban "..PlayerIndex.." 1s")
update_ban_header()
break
end
end
end
file:close()
end
end
function list_bans(PlayerIndex)
read_bans()
if lines then
if #lines > 0 then
for k,v in pairs(lines) do
if k == 1 then
xprint(PlayerIndex, "Index|tName:Ip")
end
xprint(PlayerIndex,'[' .. k .. ']|t'.. v)
end
else
xprint(PlayerIndex, "Error: There are no bans.")
end
else
xprint(PlayerIndex, "Error: There are no bans.")
end
end
function rebuild_bans()
if #lines > 0 then
for i = 1,#lines do
if i == 1 then
write_ban(lines[i].."\n", "w+")
else
write_ban(lines[i].."\n", "a")
end
end
else
write_ban("", "w+")
end
read_bans()
end
function update_ban_header()
if halo_type == "CE" then
local banlist_size = read_dword(0x5C5280)
execute_command("sv_unban ".. banlist_size - 1)
end
end
function write_ban(value, mode)
local file = io.open(filename, mode)
if file then
file:write(value)
file:close()
end
end
function xprint(PlayerIndex, Message)
if tonumber(PlayerIndex) ~= 0 then
rprint(PlayerIndex, Message)
else
local Message = string.gsub(Message, "|t", " ")
cprint(Message, 10)
end
end
function tokenizestring(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t={} ; i=1
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
t[i] = str
i = i + 1
end
return t
end
function assemble(t, start, spacer)
local words = {}
for i = 1,#t do
if i > start then
if i == #t then
words[i-start] = t[i]
else
words[i-start] = t[i] .. spacer
end
end
end
return table.concat(words)
end
function read_widestring(address, length)
local count = 0
local byte_table = {}
for i = 1,length do -- Reads the string.
if read_byte(address + count) ~= 0 then
byte_table[i] = string.char(read_byte(address + count))
end
count = count + 2
end
return table.concat(byte_table)
end
function get_client_machine_info(PlayerIndex)
if player_present(PlayerIndex) then
return network_struct + 0x3B8 + ce + to_real_index(PlayerIndex) * client_info_size
else
return network_struct + 0x3B8 + ce + (tonumber(PlayerIndex) - 1) * client_info_size
end
end