mirror of
https://github.com/kasuganosoras/YumV
synced 2024-11-22 20:42:51 +08:00
Update main_server.lua
This commit is contained in:
parent
c5b0868f3b
commit
ebcaa3d516
@ -7,8 +7,8 @@ local yum = {}
|
|||||||
|
|
||||||
-- FiveM YumV config
|
-- FiveM YumV config
|
||||||
yum.mirror = "https://yumv.net/"
|
yum.mirror = "https://yumv.net/"
|
||||||
yum.version = "1.0.1"
|
yum.version = "1.0.2"
|
||||||
yum.versionnum = 11
|
yum.versionnum = 102
|
||||||
-- End
|
-- End
|
||||||
|
|
||||||
local downloading = 0
|
local downloading = 0
|
||||||
@ -172,7 +172,7 @@ function listAllPlugin(tb)
|
|||||||
padding3 = string.rep(" ", 51 - length3 - 19)
|
padding3 = string.rep(" ", 51 - length3 - 19)
|
||||||
print("+----------------------------------+------------------+")
|
print("+----------------------------------+------------------+")
|
||||||
print("| Total: " .. tostring(i) .. " resource(s)" .. padding3 .. " |")
|
print("| Total: " .. tostring(i) .. " resource(s)" .. padding3 .. " |")
|
||||||
print("+-----------------------------------------------------+")
|
print("+----------------------------------+------------------+")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 加载所有插件
|
-- 加载所有插件
|
||||||
@ -291,13 +291,60 @@ function addNewPlugin(name, version)
|
|||||||
file_put_contents(current_dir .. "/list.json", json.encode(data))
|
file_put_contents(current_dir .. "/list.json", json.encode(data))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- 检查 YumV 更新
|
||||||
|
function checkUpdate()
|
||||||
|
print("[YumV] Checking for YumV new version...")
|
||||||
|
Citizen.CreateThread(function()
|
||||||
|
local url = yum.mirror .. "?s=check_update&yum_version=" .. urlencode(yum.versionnum)
|
||||||
|
local rs = curl(url, 'GET')
|
||||||
|
if rs.status == 200 then
|
||||||
|
print(rs.body)
|
||||||
|
else
|
||||||
|
print("[YumV] Failed check plugin update, please check your network.")
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
function updateSelf()
|
||||||
|
print("[YumV] Updating YumV to new version...")
|
||||||
|
Citizen.CreateThread(function()
|
||||||
|
local url = yum.mirror .. "?s=get_update&yum_version=" .. urlencode(yum.versionnum)
|
||||||
|
local rs = curl(url, 'GET')
|
||||||
|
if rs.status == 200 then
|
||||||
|
local new_version = tonumber(rs.body)
|
||||||
|
if yum.versionnum == new_version then
|
||||||
|
print("[YumV] Your YumV is newest version, not need to update.")
|
||||||
|
else
|
||||||
|
url = yum.mirror .. "?s=get_update_download&yum_version=" .. urlencode(rs.body)
|
||||||
|
rs = curl(url, 'GET')
|
||||||
|
if rs.status == 200 then
|
||||||
|
print("[YumV] Downloading files, please don't stop the server.")
|
||||||
|
local cmd = "wget -q -4 \"" .. rs.body .. "\" -O \"" .. current_dir .. "/update.zip\""
|
||||||
|
-- print(cmd)
|
||||||
|
file_put_contents(current_dir .. "/update.zip", "")
|
||||||
|
-- 开始下载
|
||||||
|
os.execute(cmd)
|
||||||
|
print("[YumV] Download finished, decompressing... ")
|
||||||
|
unzip(current_dir .. "/update.zip", current_dir .. "/")
|
||||||
|
os.remove(current_dir .. "/update.zip");
|
||||||
|
print("[YumV] Update finished, please execute command: \"restart yum\".")
|
||||||
|
else
|
||||||
|
print("[YumV] Failed check plugin update, server return: " .. tostring(rs.status))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
print("[YumV] Failed check plugin update, server return: " .. tostring(rs.status))
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
-- 安装插件
|
-- 安装插件
|
||||||
function installPlugin(name, version)
|
function installPlugin(name, version)
|
||||||
local url = ""
|
local url = ""
|
||||||
if version == nil then
|
if version == nil then
|
||||||
url = yum.mirror .. "?s=download&name=" .. urlencode(name)
|
url = yum.mirror .. "?s=download&name=" .. urlencode(name) .. "&yum_version=" .. urlencode(yum.versionnum)
|
||||||
else
|
else
|
||||||
url = yum.mirror .. "?s=download&name=" .. urlencode(name) .. "&version=" .. urlencode(version)
|
url = yum.mirror .. "?s=download&name=" .. urlencode(name) .. "&version=" .. urlencode(version) .. "&yum_version=" .. urlencode(yum.versionnum)
|
||||||
end
|
end
|
||||||
local rs = curl(url, 'GET')
|
local rs = curl(url, 'GET')
|
||||||
if rs.status == 200 then
|
if rs.status == 200 then
|
||||||
@ -395,6 +442,8 @@ function printHelp()
|
|||||||
print(" search <name> Search a plugin in mirror database")
|
print(" search <name> Search a plugin in mirror database")
|
||||||
print(" list List all installed plugin")
|
print(" list List all installed plugin")
|
||||||
print(" version Show the yum plugin version")
|
print(" version Show the yum plugin version")
|
||||||
|
print(" checkyumv Check if YumV has new version")
|
||||||
|
print(" updateself Update YumV to newest version")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 注册命令
|
-- 注册命令
|
||||||
@ -404,10 +453,7 @@ RegisterCommand("yum", function(source, args, rawCommand)
|
|||||||
printHelp()
|
printHelp()
|
||||||
else
|
else
|
||||||
if args[1] == "test" then
|
if args[1] == "test" then
|
||||||
local f = assert(io.open("/tmp/fivem-yum-temp.zip", "rb"))
|
ExecuteCommand("restart yum")
|
||||||
local size = f:seek("end")
|
|
||||||
f:close()
|
|
||||||
print(size)
|
|
||||||
|
|
||||||
-- 删除一个插件
|
-- 删除一个插件
|
||||||
elseif args[1] == "remove" then
|
elseif args[1] == "remove" then
|
||||||
@ -570,6 +616,14 @@ RegisterCommand("yum", function(source, args, rawCommand)
|
|||||||
print("FiveM YumV plugin by Akkariin")
|
print("FiveM YumV plugin by Akkariin")
|
||||||
print("Version: " .. yum.version)
|
print("Version: " .. yum.version)
|
||||||
|
|
||||||
|
-- 检查 YumV 新版本
|
||||||
|
elseif args[1] == "checkyumv" then
|
||||||
|
checkUpdate()
|
||||||
|
|
||||||
|
-- 自动更新到新版本
|
||||||
|
elseif args[1] == "updateself" then
|
||||||
|
updateSelf()
|
||||||
|
|
||||||
-- 默认输出
|
-- 默认输出
|
||||||
else
|
else
|
||||||
print("Command not found: " .. args[1] .. ", use \"yum help\" to get help.")
|
print("Command not found: " .. args[1] .. ", use \"yum help\" to get help.")
|
||||||
@ -579,3 +633,4 @@ end, true)
|
|||||||
|
|
||||||
-- Load all installed plugins
|
-- Load all installed plugins
|
||||||
loadPluginList()
|
loadPluginList()
|
||||||
|
checkUpdate()
|
||||||
|
Loading…
Reference in New Issue
Block a user