SHARE
TWEET

nameban

it300 Apr 28th, 2017 (edited) 153 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Name Banning 2.0 script by Devieth
  2. -- Revision 1.0
  3.  
  4. api_version = "1.10.0.0"
  5. filename = "bans.data"
  6.  
  7. function OnScriptLoad()
  8.     register_callback(cb['EVENT_PREJOIN'], "PreJoin")
  9.     register_callback(cb['EVENT_COMMAND'], "Command")
  10.     network_struct = read_dword(sig_scan("F3ABA1????????BA????????C740??????????E8????????668B0D") + 3)
  11.     if halo_type == "PC" then ce, client_info_size = 0x0,0x60 else ce, client_info_size = 0x40, 0xEC end
  12. end
  13.  
  14. function OnScriptUnload()
  15. end
  16.  
  17. function Command(PlayerIndex, Command, Enviroment, Password)
  18.     local respond = true
  19.     if isadmin(PlayerIndex) or Enviroment == 0 then
  20.         local Command = string.gsub(Command, '"', "")
  21.         local t = tokenizestring(Command, " ")
  22.         if t[1] == "ban" then
  23.             respond = false
  24.             if t[2] ~= nil then
  25.                 if tonumber(t[2]) ~= nil then
  26.                     if player_present(t[2]) then
  27.                         local name, ip = get_var(t[2], "$name"), get_ip(t[2])
  28.                         write_ban(name..":"..ip.."\n", "a")
  29.                         xprint(PlayerIndex, get_var(t[2], "$name").." has been banned!")
  30.                         if t[3] ~= nil then
  31.                             local reason = assemble(t, 2, " ")
  32.                             say_all(name .. " has been banned from the server! Reason: '"..reason.."' 1")
  33.                             execute_command("sv_ban "..tonumber(t[2]).." 1s")
  34.                         else
  35.                             execute_command("sv_ban "..tonumber(t[2]).." 1s")
  36.                         end
  37.                         update_ban_header()
  38.                     else
  39.                         xprint(PlayerIndex, "Error: Player is not in the server.")
  40.                     end
  41.                 end
  42.             else
  43.                 xprint(PlayerIndex, "Error: Please use the players number.")
  44.             end
  45.         elseif t[1] == "unban" then
  46.             respond = false
  47.             if tonumber(t[2]) ~= nil then
  48.                 read_bans()
  49.                 local removed = false
  50.                 for i = 1,#lines do
  51.                     if i == tonumber(t[2]) then
  52.                         xprint(PlayerIndex, lines[i] .. " has been unbanned!")
  53.                         table.remove(lines, i)
  54.                         removed = true
  55.                         break
  56.                     end
  57.                 end
  58.                 if removed then
  59.                     rebuild_bans()
  60.                 else
  61.                     xprint(PlayerIndex, "Error: Failed to unban player or the ban may not exist.")
  62.                 end
  63.             else
  64.                 xprint(PlayerIndex, "Error: Please use the ban id.")
  65.             end
  66.         elseif t[1] == "bans" then
  67.             respond = false
  68.             list_bans(PlayerIndex)
  69.         end
  70.     end
  71.     return respond
  72. end
  73.  
  74. function PreJoin(PlayerIndex)
  75.     local name = read_widestring((network_struct + 0x1AA + ce + to_real_index(PlayerIndex) * 0x20), 12)
  76.     local ip = get_ip(PlayerIndex)
  77.     read_bans(PlayerIndex, name, ip)
  78. end
  79.  
  80. function get_ip(PlayerIndex)
  81.     local m_connection = read_dword(read_dword(read_dword(get_client_machine_info(PlayerIndex))))
  82.     local m_1 = read_byte(m_connection)
  83.     local m_2 = read_byte(m_connection + 0x1)
  84.     local m_3 = read_byte(m_connection + 0x2)
  85.     local m_4 = read_byte(m_connection + 0x3)
  86.     return m_1.."."..m_2.."."..m_3.."."..m_4
  87. end
  88.  
  89. function isadmin(PlayerIndex)
  90.     if player_present(PlayerIndex) then
  91.         local lvl = get_var(PlayerIndex, "$lvl")
  92.         if lvl ~= "-1" then
  93.             return true
  94.         end
  95.     end
  96.     return false
  97. end
  98.  
  99. function read_bans(PlayerIndex, name, ip)
  100.     local file = io.open(filename, "rb")
  101.     if file then
  102.         lines = {}
  103.         for line in io.lines(filename) do
  104.             lines[#lines + 1] = line
  105.             if name ~= nil then
  106.                 local t = tokenizestring(line, ":")
  107.                 if t[1] == name or t[2] == get_ip(PlayerIndex) then
  108.                     execute_command("sv_ban "..PlayerIndex.." 1s")
  109.                     update_ban_header()
  110.                     break
  111.                 end
  112.             end
  113.         end
  114.         file:close()
  115.     end
  116. end
  117.  
  118. function list_bans(PlayerIndex)
  119.     read_bans()
  120.     if lines then
  121.         if #lines > 0 then
  122.             for k,v in pairs(lines) do
  123.                 if k == 1 then
  124.                     xprint(PlayerIndex, "Index|tName:Ip")
  125.                 end
  126.                 xprint(PlayerIndex,'[' .. k .. ']|t'.. v)
  127.             end
  128.         else
  129.             xprint(PlayerIndex, "Error: There are no bans.")
  130.         end
  131.     else
  132.         xprint(PlayerIndex, "Error: There are no bans.")
  133.     end
  134. end
  135.  
  136. function rebuild_bans()
  137.     if #lines > 0 then
  138.         for i = 1,#lines do
  139.             if i == 1 then
  140.                 write_ban(lines[i].."\n", "w+")
  141.             else
  142.                 write_ban(lines[i].."\n", "a")
  143.             end
  144.         end
  145.     else
  146.         write_ban("", "w+")
  147.     end
  148.     read_bans()
  149. end
  150.  
  151. function update_ban_header()
  152.     if halo_type == "CE" then
  153.         local banlist_size = read_dword(0x5C5280)
  154.         execute_command("sv_unban ".. banlist_size - 1)
  155.     end
  156. end
  157.  
  158. function write_ban(value, mode)
  159.     local file = io.open(filename, mode)
  160.     if file then
  161.         file:write(value)
  162.         file:close()
  163.     end
  164. end
  165.  
  166. function xprint(PlayerIndex, Message)
  167.     if tonumber(PlayerIndex) ~= 0 then
  168.         rprint(PlayerIndex, Message)
  169.     else
  170.         local Message = string.gsub(Message, "|t", "    ")
  171.         cprint(Message, 10)
  172.     end
  173. end
  174.  
  175. function tokenizestring(inputstr, sep)
  176.     if sep == nil then
  177.         sep = "%s"
  178.     end
  179.     local t={} ; i=1
  180.     for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  181.         t[i] = str
  182.         i = i + 1
  183.     end
  184.     return t
  185. end
  186.  
  187. function assemble(t, start, spacer)
  188.     local words = {}
  189.     for i = 1,#t do
  190.         if i > start then
  191.             if i == #t then
  192.                 words[i-start] = t[i]
  193.             else
  194.                 words[i-start] = t[i] .. spacer
  195.             end
  196.         end
  197.     end
  198.     return table.concat(words)
  199. end
  200.  
  201. function read_widestring(address, length)
  202.     local count = 0
  203.     local byte_table = {}
  204.     for i = 1,length do -- Reads the string.
  205.         if read_byte(address + count) ~= 0 then
  206.             byte_table[i] = string.char(read_byte(address + count))
  207.         end
  208.         count = count + 2
  209.     end
  210.     return table.concat(byte_table)
  211. end
  212.  
  213. function get_client_machine_info(PlayerIndex)
  214.     if player_present(PlayerIndex) then
  215.         return network_struct + 0x3B8 + ce + to_real_index(PlayerIndex) * client_info_size
  216.     else
  217.         return network_struct + 0x3B8 + ce + (tonumber(PlayerIndex) - 1) * client_info_size
  218.     end
  219. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top