Крашит игру с библиотекой "requests"

main4ik

Участник
Автор темы
32
5
При заходе в игру сразу игра зависает намертво и не подает признаков жизни если удалить из lib папку mime то игра работает без каких либо отказов. Что делать?
Если нужен лог прикрепляю
 

Вложения

  • moonloader.log
    5.6 KB · Просмотры: 4
Последнее редактирование:

Strone

Участник
66
13
В main() стоит
Lua:
if not isSampLoaded() or not isSampfuncsLoaded() then return end
 while not isSampAvailable() do wait(100) end

Возможно дело помимо либы в остальном коде, названии переменной, цикле, который написал выше и require\import без локальной переменной.
 

Я Санёк

Потрачен
206
68
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.

main4ik

Участник
Автор темы
32
5

-- Lua Requests library for http ease

local http_socket = require('socket.http')
local https_socket = require('ssl.https')
local url_parser = require('socket.url')
local ltn12 = require('ltn12')
local json = require('cjson.safe')
local xml = require('xml')
local md5sum = require('md5') -- TODO: Make modular?
local base64 = require('base64')

local requests = {
_DESCRIPTION = 'Http requests made simpler',
http_socket = http_socket,
https_socket = https_socket
}

local _requests = {}

--User facing function the make a request use Digest Authentication
--TODO: Determine what else should live in authentication
function requests.HTTPDigestAuth(user, password)
return { _type = 'digest', user = user, password = password}
end

--User facing function the make a request use Basic Authentication
--TODO: Determine what else should live in authentication
function requests.HTTPBasicAuth(user, password)
return { _type = 'basic', user = user, password = password}
end

function requests.post(url, args)
return requests.request("POST", url, args)
end

function requests.get(url, args)
return requests.request("GET", url, args)
end

function requests.delete(url, args)
return requests.request("DELETE", url, args)
end

function requests.patch(url, args)
return requests.request("PATCH", url, args)
end

function requests.put(url, args)
return requests.request("PUT", url, args)
end

function requests.options(url, args)
return requests.request("OPTIONS", url, args)
end

function requests.head(url, args)
return requests.request("HEAD", url, args)
end

function requests.trace(url, args)
return requests.request("TRACE", url, args)
end

--Sets up all the data for a request and makes the request
function requests.request(method, url, args)
local request

if type(url) == "table" then
request = url
else
request = args or {}
request.url = url
end

request.method = method
_requests.parse_args(request)

-- TODO: Find a better way to do this
if request.auth and request.auth._type == 'digest' then
local response = _requests.make_request(request)
return _requests.use_digest(response, request)
else
return _requests.make_request(request)
end
end

--Makes a request
function _requests.make_request(request)
local response_body = {}
local full_request = {
method = request.method,
url = request.url,
headers = request.headers,
source = ltn12.source.string(request.data),
sink = ltn12.sink.table(response_body),
redirect = request.allow_redirects,
proxy = request.proxy
}

local response = {}
local ok
local socket = string.find(full_request.url, '^https:') and not request.proxy and https_socket or http_socket

ok, response.status_code, response.headers, response.status = socket.request(full_request)

assert(ok, 'error in '..request.method..' request: '..response.status_code)
response.text = table.concat(response_body)
response.json = function () return json.decode(response.text) end
response.xml = function () return xml.load(response.text) end

return response
end

--Parses through all the possible arguments for a request
function _requests.parse_args(request)
_requests.check_url(request)
_requests.check_data(request)
_requests.create_header(request)
_requests.check_timeout(request.timeout)
_requests.check_redirect(request.allow_redirects)
end

--Format the the url based on the params argument
function _requests.format_params(url, params) -- TODO: Clean
if not params or next(params) == nil then return url end

url = url..'?'
for key, value in pairs(params) do
if tostring(value) then
url = url..tostring(key)..'='

if type(value) == 'table' then
local val_string = ''

for _, val in ipairs(value) do
val_string = val_string..tostring(val)..','
end

url = url..val_string:sub(0, -2)
else
url = url..tostring(value)
end

url = url..'&'
end
end

return url:sub(0, -2)
end

--Check that there is a URL given and append to it if params are passed in.
function _requests.check_url(request)
assert(request.url, 'No url specified for request')
request.url = _requests.format_params(request.url, request.params)
end

-- Add to the HTTP header
function _requests.create_header(request)
request.headers = request.headers or {}
request.headers['Content-Length'] = request.data:len()

if request.cookies then
if request.headers.cookie then
request.headers.cookie = request.headers.cookie..'; '..request.cookies
else
request.headers.cookie = request.cookies
end
end

if request.auth then
_requests.add_auth_headers(request)
end
end

--Makes sure that the data is in a format that can be sent
function _requests.check_data(request)
request.data = request.data or ''

if type(request.data) == "table" then
request.data = json.encode(request.data)
end
end

--Set the timeout
function _requests.check_timeout(timeout)
http_socket.TIMEOUT = timeout or 5
https_socket.TIMEOUT = timeout or 5
end

--Checks is allow_redirects parameter is set correctly
function _requests.check_redirect(allow_redirects)
if allow_redirects and type(allow_redirects) ~= "boolean" then
error("allow_redirects expects a boolean value. received type = "..type(allow_redirects))
end
end

--Create the Authorization header for Basic Auth
function _requests.basic_auth_header(request)
local encoded = base64.encode(request.auth.user..':'..request.auth.password)
request.headers.Authorization = 'Basic '..encoded
end

-- Create digest authorization string for request header TODO: Could be better, but it should work
function _requests.digest_create_header_string(auth)
local authorization = ''
authorization = 'Digest username="'..auth.user..'", realm="'..auth.realm..'", nonce="'..auth.nonce
authorization = authorization..'", uri="'..auth.uri..'", qop='..auth.qop..', nc='..auth.nc
authorization = authorization..', cnonce="'..auth.cnonce..'", response="'..auth.response..'"'

if auth.opaque then
authorization = authorization..', opaque="'..auth.opaque..'"'
end

return authorization
end

--MD5 hash all parameters
local function md5_hash(...)
return md5sum.sumhexa(table.concat({...}, ":"))
end

-- Creates response hash TODO: Add functionality
function _requests.digest_hash_response(auth_table)
return md5_hash(
md5_hash(auth_table.user, auth_table.realm, auth_table.password),
auth_table.nonce,
auth_table.nc,
auth_table.cnonce,
auth_table.qop,
md5_hash(auth_table.method, auth_table.uri)
)
end

-- Add digest authentication to the request header
function _requests.digest_auth_header(request)
if not request.auth.nonce then return end

request.auth.cnonce = request.auth.cnonce or string.format("%08x", os.time())

request.auth.nc_count = request.auth.nc_count or 0
request.auth.nc_count = request.auth.nc_count + 1

request.auth.nc = string.format("%08x", request.auth.nc_count)

local url = url_parser.parse(request.url)
request.auth.uri = url_parser.build{path = url.path, query = url.query}
request.auth.method = request.method
request.auth.qop = 'auth'

request.auth.response = _requests.digest_hash_response(request.auth)

request.headers.Authorization = _requests.digest_create_header_string(request.auth)
end

--Checks the resonse code and adds additional headers for Digest Auth
-- TODO: Rename this
function _requests.use_digest(response, request)
if response.status_code == 401 then
_requests.parse_digest_response_header(response,request)
_requests.create_header(request)
response = _requests.make_request(request)
response.auth = request.auth
response.cookies = request.headers.cookie
return response
else
response.auth = request.auth
response.cookies = request.headers.cookie
return response
end
end

--Parse the first response from the host to make the Authorization header
function _requests.parse_digest_response_header(response, request)
for key, value in response.headers['www-authenticate']:gmatch('(%w+)="(%S+)"') do
request.auth[key] = value
end

if request.headers.cookie then
request.headers.cookie = request.headers.cookie..'; '..response.headers['set-cookie']
else
request.headers.cookie = response.headers['set-cookie']
end

request.auth.nc_count = 0
end

-- Call the correct authentication header function
function _requests.add_auth_headers(request)
local auth_func = {
basic = _requests.basic_auth_header,
digest = _requests.digest_auth_header
}

auth_func[request.auth._type](request)
end

--Return public functions
requests._private = _requests
return requests

 

Sidney31

Известный
1,124
385

-- Lua Requests library for http ease

local http_socket = require('socket.http')
local https_socket = require('ssl.https')
local url_parser = require('socket.url')
local ltn12 = require('ltn12')
local json = require('cjson.safe')
local xml = require('xml')
local md5sum = require('md5') -- TODO: Make modular?
local base64 = require('base64')

local requests = {
_DESCRIPTION = 'Http requests made simpler',
http_socket = http_socket,
https_socket = https_socket
}

local _requests = {}

--User facing function the make a request use Digest Authentication
--TODO: Determine what else should live in authentication
function requests.HTTPDigestAuth(user, password)
return { _type = 'digest', user = user, password = password}
end

--User facing function the make a request use Basic Authentication
--TODO: Determine what else should live in authentication
function requests.HTTPBasicAuth(user, password)
return { _type = 'basic', user = user, password = password}
end

function requests.post(url, args)
return requests.request("POST", url, args)
end

function requests.get(url, args)
return requests.request("GET", url, args)
end

function requests.delete(url, args)
return requests.request("DELETE", url, args)
end

function requests.patch(url, args)
return requests.request("PATCH", url, args)
end

function requests.put(url, args)
return requests.request("PUT", url, args)
end

function requests.options(url, args)
return requests.request("OPTIONS", url, args)
end

function requests.head(url, args)
return requests.request("HEAD", url, args)
end

function requests.trace(url, args)
return requests.request("TRACE", url, args)
end

--Sets up all the data for a request and makes the request
function requests.request(method, url, args)
local request

if type(url) == "table" then
request = url
else
request = args or {}
request.url = url
end

request.method = method
_requests.parse_args(request)

-- TODO: Find a better way to do this
if request.auth and request.auth._type == 'digest' then
local response = _requests.make_request(request)
return _requests.use_digest(response, request)
else
return _requests.make_request(request)
end
end

--Makes a request
function _requests.make_request(request)
local response_body = {}
local full_request = {
method = request.method,
url = request.url,
headers = request.headers,
source = ltn12.source.string(request.data),
sink = ltn12.sink.table(response_body),
redirect = request.allow_redirects,
proxy = request.proxy
}

local response = {}
local ok
local socket = string.find(full_request.url, '^https:') and not request.proxy and https_socket or http_socket

ok, response.status_code, response.headers, response.status = socket.request(full_request)

assert(ok, 'error in '..request.method..' request: '..response.status_code)
response.text = table.concat(response_body)
response.json = function () return json.decode(response.text) end
response.xml = function () return xml.load(response.text) end

return response
end

--Parses through all the possible arguments for a request
function _requests.parse_args(request)
_requests.check_url(request)
_requests.check_data(request)
_requests.create_header(request)
_requests.check_timeout(request.timeout)
_requests.check_redirect(request.allow_redirects)
end

--Format the the url based on the params argument
function _requests.format_params(url, params) -- TODO: Clean
if not params or next(params) == nil then return url end

url = url..'?'
for key, value in pairs(params) do
if tostring(value) then
url = url..tostring(key)..'='

if type(value) == 'table' then
local val_string = ''

for _, val in ipairs(value) do
val_string = val_string..tostring(val)..','
end

url = url..val_string:sub(0, -2)
else
url = url..tostring(value)
end

url = url..'&'
end
end

return url:sub(0, -2)
end

--Check that there is a URL given and append to it if params are passed in.
function _requests.check_url(request)
assert(request.url, 'No url specified for request')
request.url = _requests.format_params(request.url, request.params)
end

-- Add to the HTTP header
function _requests.create_header(request)
request.headers = request.headers or {}
request.headers['Content-Length'] = request.data:len()

if request.cookies then
if request.headers.cookie then
request.headers.cookie = request.headers.cookie..'; '..request.cookies
else
request.headers.cookie = request.cookies
end
end

if request.auth then
_requests.add_auth_headers(request)
end
end

--Makes sure that the data is in a format that can be sent
function _requests.check_data(request)
request.data = request.data or ''

if type(request.data) == "table" then
request.data = json.encode(request.data)
end
end

--Set the timeout
function _requests.check_timeout(timeout)
http_socket.TIMEOUT = timeout or 5
https_socket.TIMEOUT = timeout or 5
end

--Checks is allow_redirects parameter is set correctly
function _requests.check_redirect(allow_redirects)
if allow_redirects and type(allow_redirects) ~= "boolean" then
error("allow_redirects expects a boolean value. received type = "..type(allow_redirects))
end
end

--Create the Authorization header for Basic Auth
function _requests.basic_auth_header(request)
local encoded = base64.encode(request.auth.user..':'..request.auth.password)
request.headers.Authorization = 'Basic '..encoded
end

-- Create digest authorization string for request header TODO: Could be better, but it should work
function _requests.digest_create_header_string(auth)
local authorization = ''
authorization = 'Digest username="'..auth.user..'", realm="'..auth.realm..'", nonce="'..auth.nonce
authorization = authorization..'", uri="'..auth.uri..'", qop='..auth.qop..', nc='..auth.nc
authorization = authorization..', cnonce="'..auth.cnonce..'", response="'..auth.response..'"'

if auth.opaque then
authorization = authorization..', opaque="'..auth.opaque..'"'
end

return authorization
end

--MD5 hash all parameters
local function md5_hash(...)
return md5sum.sumhexa(table.concat({...}, ":"))
end

-- Creates response hash TODO: Add functionality
function _requests.digest_hash_response(auth_table)
return md5_hash(
md5_hash(auth_table.user, auth_table.realm, auth_table.password),
auth_table.nonce,
auth_table.nc,
auth_table.cnonce,
auth_table.qop,
md5_hash(auth_table.method, auth_table.uri)
)
end

-- Add digest authentication to the request header
function _requests.digest_auth_header(request)
if not request.auth.nonce then return end

request.auth.cnonce = request.auth.cnonce or string.format("%08x", os.time())

request.auth.nc_count = request.auth.nc_count or 0
request.auth.nc_count = request.auth.nc_count + 1

request.auth.nc = string.format("%08x", request.auth.nc_count)

local url = url_parser.parse(request.url)
request.auth.uri = url_parser.build{path = url.path, query = url.query}
request.auth.method = request.method
request.auth.qop = 'auth'

request.auth.response = _requests.digest_hash_response(request.auth)

request.headers.Authorization = _requests.digest_create_header_string(request.auth)
end

--Checks the resonse code and adds additional headers for Digest Auth
-- TODO: Rename this
function _requests.use_digest(response, request)
if response.status_code == 401 then
_requests.parse_digest_response_header(response,request)
_requests.create_header(request)
response = _requests.make_request(request)
response.auth = request.auth
response.cookies = request.headers.cookie
return response
else
response.auth = request.auth
response.cookies = request.headers.cookie
return response
end
end

--Parse the first response from the host to make the Authorization header
function _requests.parse_digest_response_header(response, request)
for key, value in response.headers['www-authenticate']:gmatch('(%w+)="(%S+)"') do
request.auth[key] = value
end

if request.headers.cookie then
request.headers.cookie = request.headers.cookie..'; '..response.headers['set-cookie']
else
request.headers.cookie = response.headers['set-cookie']
end

request.auth.nc_count = 0
end

-- Call the correct authentication header function
function _requests.add_auth_headers(request)
local auth_func = {
basic = _requests.basic_auth_header,
digest = _requests.digest_auth_header
}

auth_func[request.auth._type](request)
end

--Return public functions
requests._private = _requests
return requests

это код самой либы, а просят кинуть скрипт, в котором эта либа используется
 

main4ik

Участник
Автор темы
32
5

script_name('TreasureMAP')
script_version('4.1340')
script_author('Cosmo')

ini = require 'inicfg'
cfg = ini.load({
main = {
radius = 500,
color_s = 1,
color_f = 2,
react = 10,
markers = true,
fullmap = true
}
}, 'TreasureMAP')

local state = false
local exact_count = 0
local coords = {}
local pool = {}
local finded = {}
local markers = {}
local reaction = {-1, 3, 5, 10, 15}
local colors = {
[1] = {0x00FF00FF, 'Зелёный'},
[2] = {0xFFFF00FF, 'Жёлтый'},
[3] = {0xFF0000FF, 'Красный'},
[4] = {0x6666FFFF, 'Синий'},
[5] = {0xFF5000FF, 'Рыжий'},
[6] = {0xFFFFFFFF, 'Белый'},
[7] = {0xFF00FFFF, 'Розовый'},
[8] = {0xAAAAAAFF, 'Серый'},
[9] = {0x00FFFFFF, 'Голубой'},
[10] = {0xFF6060FF, 'Малиновый'},
[11] = {0x111111FF, 'Чёрный'},
[12] = {0xFFFFFF00, 'Отключен'},
[13] = {0x000000FF, 'Прозрачный'}
}

function main()
while not isSampAvailable() do wait(100) end
local sitecoords = getSiteArzMap()
coords, exact_count = getCoordOnMap(sitecoords)
sampRegisterChatCommand('trmap', show_menu)
addEventHandler('onScriptTerminate', function(script, quit)
if script == thisScript() then
ini.save(cfg, 'TreasureMAP.ini')
remove_markers()
remove_all()
end
end)

while true do
remove_markers()
if state then
local A = { getCharCoordinates(PLAYER_PED) }

for i, B in ipairs(coords) do
local dist = getDistanceBetweenCoords3d(A[1], A[2], A[3], B[1], B[2], B[3])

if not cfg.main.fullmap and B[4] == 0 then
if pool ~= nil then
removeBlip(pool)
pool = nil
end
goto skip
end

if dist <= cfg.main.react + 10.0 and cfg.main.markers then
markers = createUser3dMarker(B[1], B[2], B[3] + 1.5, 4)
end
if dist <= cfg.main.radius and pool == nil then
pool = addBlipForCoord(B[1], B[2], B[3])
changeBlipColour(pool, finded and colors[cfg.main.color_f][1] or colors[cfg.main.color_s][1])
elseif dist <= cfg.main.react and finded == nil then
finded = true
changeBlipColour(pool, colors[cfg.main.color_f][1])
elseif dist > cfg.main.radius and pool ~= nil then
removeBlip(pool)
pool = nil
end
::skip::
end
end

local result, button, list, _ = sampHasDialogRespond(101)
if result and button == 1 then
if list == 0 then
state = not state
if not state then remove_all() end
show_menu()
elseif list == 2 then
cfg.main.fullmap = not cfg.main.fullmap
show_menu()
elseif list == 3 or list == 4 then
cur_color = (list == 3 and 1 or 2)
change_color()
elseif list == 5 then
for i = 1, #reaction do
if cfg.main.react == reaction then
cfg.main.react = reaction[i + 1] or reaction[1]
if cfg.main.react == -1 then finded = {}; remove_all(true) end
show_menu()
break
end
end
elseif list == 6 then
cfg.main.markers = not cfg.main.markers
show_menu()
elseif list == 7 then
remove_all()
coords, exact_count = getCoordOnMap(sitecoords)
if #coords == 0 then show_menu() end
elseif list == 1 then
local max = 1500
for i = 100, max, 100 do
if cfg.main.radius == i then
cfg.main.radius = (i == max and 100 or i + 100)
show_menu()
break
end
end
else
show_menu()
end
elseif result and button == 0 then
ini.save(cfg, 'TreasureMAP.ini')
end

local result, button, _, input = sampHasDialogRespond(102)
if result then
input = tonumber(input)
if input ~= nil and button == 1 then
if input < 1 or input > #colors then
change_color()
else
cfg.main[cur_color == 1 and 'color_s' or 'color_f'] = input
remove_all(true)
show_menu()
end
else
show_menu()
end
end

wait(0)
end
end

function show_menu()
sampShowDialog(101, '{FF6060}TreasureMAP {FFFFFF}| ' .. #coords .. plural(#coords, {' точка', ' точки', ' точек'}),
string.format([[
Карта %s
Радиус: {FF6060}%s{FFFFFF} м.
Отображать: %s
Цвет обычных: %s
Цвет проверенных: %s
Радиус проверки: {FF6060}%s{FFFFFF}
3D маркеры: %s
Обновить точки (с сайта)

Автор: {FF6060}Cosmo
]],
state and '{FF6060}работает' or '{777777}не работает',
cfg.main.radius,
cfg.main.fullmap and ('{FF6060}Все (%d)'):format(#coords) or ('{FF6060}Только точные (%d)'):format(exact_count),
('{%06X}%s'):format(rgba_to_rgb(colors[cfg.main.color_s][1]), colors[cfg.main.color_s][2]),
('{%06X}%s'):format(rgba_to_rgb(colors[cfg.main.color_f][1]), colors[cfg.main.color_f][2]),
cfg.main.react == -1 and 'Отключен' or cfg.main.react .. ' м.',
cfg.main.markers and '{FF6060}Включены' or '{777777}Отключены'
),
'Выбрать', 'Закрыть', 2)
end

function change_color()
local get_colors = function()
local result = ''
for i = 1, #colors do
result = ('%s{FFFFFF}%s = {%06X}%s'):format(result .. (i % 2 == 0 and '\t\t' or '\n'), i, rgba_to_rgb(colors[1]), colors[2])
end
return result
end
sampShowDialog(102, '{FF6060}TreasureMAP {FFFFFF}| Выбор цвета',
string.format('%s\n\n{AAAAAA}Введите номер цвета:', get_colors()),
'Выбрать', 'Назад', 1
)
end

function remove_all(bool_update)
for i = 1, #coords do
if pool ~= nil then
if bool_update then
changeBlipColour(pool, finded and colors[cfg.main.color_f][1] or colors[cfg.main.color_s][1])
else
removeBlip(pool)
pool = nil
end
end
end
end

function remove_markers()
for i, marker in pairs(markers) do
removeUser3dMarker(marker)
markers = nil
end
end