Sign in to follow this  
Ceeser

[RELEASE] xmlData - Easy data handling

Recommended Posts

Hello guys,

A while ago I've been thinking "saving data is pretty annoying.. alot of lines, you are often doing it multiple times for different scripts."
So I decided to make a resource as a central handler of data storing/loading.

Now I want to share this resource to the community and hope that it will also help you save some time at scripting.

The resource (including its functions) are added to the MTA Wiki which can be found here.

 


What is xmlData?


xmlData is a resource that provides 3 shared (so server-  and client-side) exported functions for automated saving/loding/deleting of files:

xmlSaveData require the data it should store to be a table and xmlLoadData will return the data as a table.

These functions are exported function by the resource, so you need to call them.
Example:

local xml = exports.xmlData
local tbl = {posX = 500, posY = 300, sizeX = 300, sizeY = 200}

-- Saving
xml:xmlSaveData("myFileName", tbl, false, true) -- This will save the file non-serverProtected but encrypted
-- or you can do this
xml:xmlSaveData("myFileName", tbl, 7) -- This will save the file serverProtected, encrypted, resourceProtected

-- Loading
local myTable = xml:xmlLoadData("myFileName", 7) -- This will attempt to load the data saved in highest security level
-- Note: You need to load the data on the same security level as you saved it.



Data security


This resource also gives you ways to secure the data you want to store:

  • Server protection -- If a file is server protected, only the server that has created it is able to read/modify it
  • Encryption -- If a file is encrypted humans won't be able to read/modify it
  • Resource Protection -- If a file is resource protected only a resource with the same name is able to read/modify it

Combining these parameters will give you different levels of security for your file.
For simplification you can instead of passing booleans just pass the security level you want to have (see the functions syntax please)

  • 0 - No protection (any server, any resource or humans could read/modify)
  • 1 - Very low protection (creator resource on any server or humans could read/modify)
  • 2 - Very low protection (any resource on any server could read/modify, humans cant)
  • 3 - Low protection (only creator resource on any server could read/modify, humans cant)
  • 4 - Medium protection (any resource on the creator server or humans could read/modify) - Default setting if no 'security parameters' are given
  • 5 - Medium protection (only creator resource on the creator server or humans could read/modify)
  • 6 - High protection (any resource on the creator server could read/modify, humans cant)
  • 7 - Very high protection (only creator resource on creator server could read/modify, humans cant)

 

Other uses


You can ofc use this script for example to save protected login data, but you can also use it in these ways for example:

  • Cross-Resource communication: You could save a file called "settings" in resourceA and then load it in resourceB. Like this you have an easy way to make your server resources talk with each other without the need of events, exported functions and passing arguments. (if the file is not resourceProtected)
  • Cross-Server communication: One step further could be that for example mapping script settings could be synchronized between different mapping servers (if the file is not serverProtected)

 

Download


The download for this resource can be found on the MTA Community page.
Note: This resource does not require admin/any acl rank.

I hope you like it and it will save you some work ;)


Sincerely,
Ceeser

  • Like 2

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.