Jump to content

[REL][UTIL]All server resources updater


darhal

Recommended Posts

Introduction :

Hello All today I will represent a usefull script that update all you resources to a version in condition that you forget to upgrade all your server scripts to 1.5 or 1.4 or whatever and giving in console use /upgradeall to upgrade to 1.x on each server restart and bla bla so this resource will add this line or update it

client="1.x" server="1.x">

it to all meta file in your server :

How to use ? :

Copy the code below and paste it in a resource ...

AFTER ADDING TO META AND THOSE STUFF:

You can choose the version to upgrade to by changing this first line in the code

versionToUpdate = "1.x" -- THE VERSION THAT WE WILL UPDATE TO EG: 1.4 

Go in-game and add admin rights to the resource (FOR LOADING ALL META FILES)

after just do /updateall (INGAME OR VIA SERVER CONSOLE)

wait some time to update all ..

after updating all running resources will be restarted and well done .

Source Code :

  
versionToUpdate = "1.5.0" -- THE VERSION THAT WE WILL UPDATE TO 
-- Server side 
  
Resources = {} 
  
  
outputDebugString("LOADING resources:...",  0,55,167,220) 
local resourceTable = getResources() -- get a table of resources 
for resourceKey, resourceValue in ipairs(resourceTable) do 
    -- iterate through the table and output each resource's name 
    local name = getResourceName(resourceValue) 
    table.insert(Resources, name) 
    outputDebugString("Resource :"..name.." has been loaded successfully ...",  0,55,167,220) 
end 
outputDebugString(""..#resourceTable.." resources has been loaded successfully ...",  0,55,167,220) 
  
Working = false 
Current = 1 
loading = false 
function forceLoad() 
    if Resources[Current]  then 
    outputDebugString("[uPDATER] "..Resources[Current], 0,55,167,220) 
            local xmlPatch = ":"..Resources[Current].."/meta.xml" 
            local xmlFile = xmlLoadFile(xmlPatch) 
            if xmlFile then                         
                            --Map Scripts 
                            local index = 0 
                            local scriptNode = xmlFindChild(xmlFile,'min_mta_version',index) 
                            if scriptNode then 
                                repeat 
                                    local sver = xmlNodeGetAttribute(scriptNode,'client') or false 
                                    local cver = xmlNodeGetAttribute(scriptNode,'client') or false 
                                   if cver and tostring(cver) and tostring(cver) ~= versionToUpdate then 
                                        xmlNodeSetAttribute(scriptNode,'client',versionToUpdate) 
                                        outputDebugString("UPDATE SYSTEM: ".. Resources[Current].." UPDATED CLIENT SIDE TO 1.5.0 and Saved successfully",3,0,255,0) 
                                    end 
                                    if sver and tostring(sver) and tostring(sver) ~= versionToUpdate then 
                                        xmlNodeSetAttribute(scriptNode,'server',versionToUpdate) 
                                        outputDebugString("UPDATE SYSTEM: ".. Resources[Current].." UPDATED SERVER SIDE TO 1.5.0 and Saved successfully",3,0,255,0) 
                                    end 
                                    index = index + 1 
                                    scriptNode = xmlFindChild(xmlFile,'min_mta_version',index) 
                                until not scriptNode 
                            else 
                                scriptNode = xmlCreateChild ( xmlFile,  "min_mta_version") 
                                xmlNodeSetAttribute(scriptNode, "client", versionToUpdate) 
                                 xmlNodeSetAttribute(scriptNode, "server", versionToUpdate) 
                                 outputDebugString("UPDATE SYSTEM: ".. Resources[Current].." UPDATED CLIENT & SERVER SIDE TO 1.5.0 and Saved successfully",3,0,255,0) 
                            end 
                            xmlSaveFile(xmlFile) 
                            xmlUnloadFile(xmlFile) 
            else 
                outputDebugString("UPDATE SYSTEM: Cant read xmlFile: meta.xml",3,220,20,20) 
                return false 
            end 
    end 
    
    Current = Current + 1 
    setTimer(forceLoad, 1000,1) 
     
    if Current == #Resources then 
        outputDebugString("UPDATE SYSTEM: ALL RESOURCES HAS BEEN UPDATED RESTARTING ALL. THIS ACTION MAY TAKE SERVAL MINUTES..") 
        restartAllResources() 
    end 
end 
addCommandHandler ( "updateall", forceLoad ) 
  
function restartAllResources() 
    -- we store a table of resources 
    local allResources = getResources() 
    -- for each one of them, 
    for index, res in ipairs(allResources) do 
        -- if it's running, 
        if getResourceState(res) == "running" then 
            -- then restart it 
            restartResource(res) 
        end 
    end 
end 
  
function fileLoad(path) 
    local File = fileOpen(path, true) 
    if File then 
        local data = fileRead(File, 500000000) 
        fileClose(File) 
        return data 
    end 
end 
  
function fileSave(path, data) 
    local File = fileCreate(path) 
    if File then 
        fileWrite(File, data) 
        fileClose(File) 
    end 
end 
  
  

Credits :

Credits go to :

- King12 (https://forum.multitheftauto.com/viewtopic.php?f ... 361#p79361) For making the code

- Darhal For editing it to be updater not compiler and some other stuff :D

Enjoy !

Link to comment
sorry to be rude but the we can uppdate all resource with any prob by typing upgrade all

Upgrade all command just upgrades deprecated functions. It is totally different.

+1

This resource is helpful these days, MTA "hacked" versions are spreading over the internet ..

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...