- 63
- 4
как сделать активацию по ключу, чтоб был ключ, которые можно вводить один раз, и через определенное количество времени он сбрасывался, и нужно было вводить новый
я делаю, но то у меня ключи бесконечно раз активировать можно, то основное окно скрипта не открывается, то ещё какая-то хуйня
вот полностью рабочий и вроде идеальный код
но когда закидываю в свой скрипт происходит хуйня какая-то
я делаю, но то у меня ключи бесконечно раз активировать можно, то основное окно скрипта не открывается, то ещё какая-то хуйня
вот полностью рабочий и вроде идеальный код
Lua:
require 'lib.moonloader'
local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local ACTIVATION_DAYS = 3
local LOG_FILE = "timekey_logs.txt"
local activated = false
local days_remaining = 0
local show_window = true
local entered_key = imgui.ImBuffer(64)
local valid_keys = {
["ABC123"] = true,
["TESTKEY"] = true
}
local SECRET_KEY = "s3cr3t_k3y"
local function xorEncrypt(text, key)
local result = ""
for i = 1, #text do
local k = i % #key + 1
result = result .. string.char(bit.bxor(text:byte(i), key:byte(k)))
end
return result
end
local function getConfigPath()
local path = getWorkingDirectory() .. "\\lib"
if not doesDirectoryExist(path) then
createDirectory(path)
end
return path
end
local function getActivationFilePath()
return getConfigPath() .. "\\timekey_activation.enc"
end
local function getUsedKeysFilePath()
return getConfigPath() .. "\\timekey_used_keys.enc"
end
local function getLogFilePath()
return getConfigPath() .. "\\" .. LOG_FILE
end
local function logEvent(message)
local file = io.open(getLogFilePath(), "a")
if file then
file:write(os.date("[%Y-%m-%d %H:%M:%S] ") .. message .. "\n")
file:close()
end
end
local function isKeyUsed(key)
local file = io.open(getUsedKeysFilePath(), "r")
if file then
local content = xorEncrypt(file:read("*a"), SECRET_KEY)
file:close()
return content:find(key) ~= nil
end
return false
end
local function isValidKey(key)
return valid_keys[key] and not isKeyUsed(key)
end
local function checkActivationTime()
local file = io.open(getActivationFilePath(), "r")
if file then
local data = file:read("*a")
file:close()
data = xorEncrypt(data, SECRET_KEY)
local activation_date = data:match("DATE:(%d+)")
local key = data:match("KEY:(%w+)")
if activation_date and key then
local days_passed = os.difftime(os.time(), tonumber(activation_date)) / (24 * 60 * 60)
days_remaining = math.max(0, ACTIVATION_DAYS - days_passed)
return days_remaining > 0, key
end
end
return false, nil
end
local function activate(key)
local encrypted_data = xorEncrypt("KEY:" .. key .. "DATE:" .. os.time(), SECRET_KEY)
local file = io.open(getActivationFilePath(), "w")
if file then
file:write(encrypted_data)
file:close()
local used_file = io.open(getUsedKeysFilePath(), "a")
if used_file then
used_file:write(xorEncrypt(key .. "\n", SECRET_KEY))
used_file:close()
end
logEvent("Активация успешна. Ключ: " .. key)
return true
end
logEvent("Ошибка активации. Ключ: " .. key)
return false
end
function imgui.OnDrawFrame()
if show_window then
imgui.Begin(u8:decode("Активация (3 дня)"), nil, imgui.WindowFlags.AlwaysAutoResize)
if activated then
imgui.Text((string.format("✅ Активировано | Осталось дней: %.1f", tonumber(days_remaining) or 0)))
imgui.Text(("Ключ: " .. tostring(entered_key.v)))
else
imgui.Text(("Введите ключ:"))
imgui.InputText("##key_input", entered_key)
if imgui.Button(("Активировать")) then
local key = tostring(entered_key.v)
if isValidKey(key) then
if activate(key) then
activated, days_remaining = true, ACTIVATION_DAYS
sampAddChatMessage(u8:decode("[KEY] Активация на 3 дня!"), 0x00FF00)
else
sampAddChatMessage(u8:decode("[KEY] Ошибка активации!"), 0xFF0000)
end
else
sampAddChatMessage(u8:decode("[KEY] Неверный/использованный ключ!"), 0xFF9900)
logEvent("Попытка ввода неверного ключа: " .. key)
end
end
end
imgui.End()
end
end
function main()
repeat wait(0) until isSampAvailable()
getConfigPath()
local status, key = checkActivationTime()
activated = status
if activated then
local file = io.open(getActivationFilePath(), "r")
if file then
local data = xorEncrypt(file:read("*a"), SECRET_KEY)
entered_key.v = data:match("KEY:(%w+)") or ""
file:close()
end
sampAddChatMessage(u8:decode(string.format("[KEY] Активно! Осталось дней: %.1f", tonumber(days_remaining) or 0)), 0x00AAFF)
end
while true do
wait(0)
imgui.Process = true
if activated and os.time() % 86400 < 100 then
local new_status = checkActivationTime()
if not new_status then
activated = false
sampAddChatMessage(u8:decode("[KEY] Срок активации истек!"), 0xFF9900)
os.remove(getActivationFilePath())
end
end
end
end
но когда закидываю в свой скрипт происходит хуйня какая-то
Последнее редактирование: