added request to server

update
rubin 2 years ago
parent 63f0a2a10b
commit 32782e0168
  1. 64
      mafia-tools.lua

@ -21,8 +21,62 @@ function main()
thisScript():unload()
end
config.init()
lua_thread.create(timer_2min.loop)
lua_thread.create(ammo_timer.loop)
lua_thread.create(request.loop)
while true do
wait(0)
end
end
-->> REQUEST
request = {}
request.loop = function()
request.wait = 0
while true do
wait(0)
if os.time() - request.wait >= 5 then
request.wait = os.time()
local ip, port = sampGetCurrentServerAddress()
local _, myid = sampGetPlayerIdByCharHandle(PLAYER_PED)
local myname = sampGetPlayerNickname(myid)
local request_table = {
sender = myname,
server = string.format("%s:%s", ip, port),
room = "test",
send = {}
}
local url = string.format("http://mafia.deadpoo.net/%s", encodeJson(request_table))
local result, text = pcall(openURL, url, os.tmpname(), true)
if result then
sampfuncsLog(text)
local result = pcall(request.handler, text)
if not result then
addChatMessage("Сервер 'mafia-tools' не отвечает!")
break
end
end
end
end
end
request.handler = function(text)
local info = decodeJson(text)
if info["result"] == "ok" then
sampfuncsLog("OK")
end
end
-->> AMMO TIMER
ammo_timer = {}
ammo_timer.onServerMessage = function(color, message)
if message:find("^ Следующее ограбление будет доступно в (%d+:%d+:%d+)") then
end
end
ammo_timer.loop = function()
while true do
wait(0)
@ -119,7 +173,7 @@ function sampev.onServerMessage(color, message)
end
-->> UPDATE MODULE
function openURL(url, fpath)
function openURL(url, fpath, message_off)
local text = ""
local file_download = false
local download_final = false
@ -154,8 +208,10 @@ function openURL(url, fpath)
if (text:find("Not found") and not text:find('"Not found"')) or text == "" then
text = ""
addChatMessage("Не удалось скачать обновление по ссылке:")
addChatMessage(url)
if not message_off then
addChatMessage("Не удалось скачать обновление по ссылке:")
addChatMessage(url)
end
end
return text

Loading…
Cancel
Save