diff --git a/lua/antihack/starcraft.lua b/lua/antihack/starcraft.lua new file mode 100644 index 0000000..fb7cdfe --- /dev/null +++ b/lua/antihack/starcraft.lua @@ -0,0 +1,83 @@ +--[[ + Simple Anti MapHack for Starcraft: BroodWar 1.16.1 + + + Copyright (C) 2014 HarpyWar (harpywar@gmail.com) + + This file is a part of the PvPGN Project http://pvpgn.pro + Licensed under the same terms as Lua itself. +]]-- + + +-- just unique request id for maphack +ah_mh_request_id = 99 +-- map visible offset +ah_mh_offset = 0x0047FD12 +-- map visible normal value (without maphack) +ah_mh_value = 139 + + +function ah_init() + timer_add("ah_timer", config.ah_interval, ah_timer_tick) + TRACE("Antihack activated") +end + +-- send memory check request to all players in games +function ah_timer_tick(options) + -- iterate all games + for i,game in pairs(api.server_get_games()) do + -- check only Starcraft: BroodWar + if game.clienttag and (game.clienttag == CLIENTTAG_BROODWARS) then + -- check only games where count of players > 1 + if game.players and (substr_count(game.players, ",") > -1) then + --DEBUG(game.players) + -- check every player in the game + for username in string.split(game.players,",") do + api.client_readmemory(username, ah_mh_request_id, ah_mh_offset, 2) + -- HINT: place here more readmemory requests + + end + end + end + end +end + +-- handle response from the client +function ah_handle_client(account, request_id, data) + local is_cheater = false + + -- maphack + if (request_id == ah_mh_request_id) then + -- read value from the memory + local value = bytes_to_int(data, 0, 2) + DEBUG(account.name .. " memory value: " .. value) + + if not (value == ah_mh_value) then + is_cheater = true + end + + -- process another hack check + --elseif (request_id == ...) then + + end + + + if (is_cheater) then + -- lock cheater account + account_set_auth_lock(account.name, true) + account_set_auth_lockreason(account.name, "we do not like cheaters") + + -- notify all players in the game about cheater + local game = api.game_get_by_id(account.game_id) + if game then + for username in string.split(game.players,",") do + api.message_send_text(username, message_type_error, nil, account.name .. " was banned by the antihack system.") + end + end + + -- kick cheater + api.client_kill(account.name) + + INFO(account.name .. " was banned by the antihack system.") + end +end diff --git a/lua/config.lua b/lua/config.lua index c74266d..c4dfcd5 100644 --- a/lua/config.lua +++ b/lua/config.lua @@ -19,5 +19,9 @@ config = { quiz_users_in_top = 15, -- how many users display in TOP list quiz_channel = nil, -- (do not modify!) channel when quiz has started (it assigned with start) + -- AntiHack (Starcraft) + ah = true, + ah_interval = 60, -- interval for send memory request to all players in games + } diff --git a/lua/extend/account_wrap.lua b/lua/extend/account_wrap.lua index 6fde66a..de1ce24 100644 --- a/lua/extend/account_wrap.lua +++ b/lua/extend/account_wrap.lua @@ -84,10 +84,10 @@ function account_set_auth_botlogin(username, value) end function account_get_auth_lock(username) - return api.account_get_attr(username, "BNET\\auth\\lockk", attr_type_bool) + return api.account_get_attr(username, "BNET\\auth\\lock", attr_type_bool) end function account_set_auth_lock(username, value) - return api.account_set_attr(username, "BNET\\auth\\lockk", attr_type_bool, value) + return api.account_set_attr(username, "BNET\\auth\\lock", attr_type_bool, value) end function account_get_auth_locktime(username) diff --git a/lua/handle_client.lua b/lua/handle_client.lua index 71de225..454bc0a 100644 --- a/lua/handle_client.lua +++ b/lua/handle_client.lua @@ -8,10 +8,13 @@ function handle_client_readmemory(account, request_id, data) - TRACE("Read memory request Id: " .. request_id) - + --TRACE("Read memory request Id: " .. request_id) + -- display memory bytes DEBUG(data) + + if (config.ah) then + ah_handle_client(account, request_id, data) + end end - diff --git a/lua/handle_game.lua b/lua/handle_game.lua index fb25cff..70a8f34 100644 --- a/lua/handle_game.lua +++ b/lua/handle_game.lua @@ -46,7 +46,7 @@ function handle_game_report(game) -- api.message_send_text(game.owner, message_type_info, game.owner, i.." = "..j) --end - --api.eventlog(eventlog_level_gui, __FUNCTION__, game.last_access) + --DEBUG(game.last_access) end diff --git a/lua/include/string.lua b/lua/include/string.lua index 0ad2bc7..d1d4714 100644 --- a/lua/include/string.lua +++ b/lua/include/string.lua @@ -56,4 +56,8 @@ function replace_char(pos, str, replacement) return str:sub(1, pos-1) .. replacement .. str:sub(pos+1) end - +-- return count of substr in str +function substr_count(str, substr) + local _, count = string.gsub(str, substr, "") + return count +end \ No newline at end of file diff --git a/lua/main.lua b/lua/main.lua index c6dd3cb..f184097 100644 --- a/lua/main.lua +++ b/lua/main.lua @@ -8,6 +8,10 @@ -- this function executes after preload all the lua scripts function main() - + + -- start antihack + if (config.ah) then + ah_init() + end end