XmlSaveData: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
 
(13 intermediate revisions by the same user not shown)
Line 1: Line 1:
<pageclass class="#228B22" subcaption="Useful Function - Shared"></pageclass>
<pageclass class="#228B22" subcaption="Useful Function - Shared"></pageclass>
<lowercasetitle></lowercasetitle>
<lowercasetitle></lowercasetitle>
<includeonly>
 
[[Category:Useful Functions]]
__NOTOC__
</includeonly>


{{Important Note|
{{Important Note|
This is an unofficial MTA function, so its not included into the game by default.<br>
This is an unofficial MTA function, so its not included into the game by default.<br>
Its an exported function of the [[xmlData]] resource.
Its an exported function of the [[xmlData]] resource.<br>
To access this function you need to have that resource on your server and it needs to be running}}
To access this function you need to have the resource running on your server.}}
 
 
This function provides an automated way of loading your data from an [[XML]] file created by [[xmlSaveData]] <br>
To call it, see the [[call]] function or the tip in this resources page: [https://wiki.multitheftauto.com/wiki/XmlData#Simplifying_the_export Simplifying the export]


This function provides an automated way of storing your data in an [[XML]] file.<br>


= Syntax =
= Syntax =
Line 28: Line 30:
====Optional Arguments====
====Optional Arguments====
*'''serverProtected:''' If set to ''true'' the script will protect the file so, that can only the creator server can access it.'''
*'''serverProtected:''' If set to ''true'' the script will protect the file so, that can only the creator server can access it.'''
*'''encryptData:''' If set to ''true'' the script will generate a random key and use it to encrypt your stored data. '''Note: If you want to store "sensitive data", always use encryption! (Account data should never be stored in serverside files - use a database instead!)'''
*'''encryptData:''' If set to ''true'' the script will generate a random key and use it to encrypt your stored data. '''Note: If you want to store "sensitive data", always use encryption!'''
*'''resourceProtected:''' If set to ''true'' the script will add the sourceResource name (so the name of the resource from which it got called) to the fileName, preventing it from getting read/overwritten/deleted by any other resource. If set to ''false'' you can use this script to call/send/modify tables from different resources without the use of events/other export functions.
*'''resourceProtected:''' If set to ''true'' the script will add the sourceResource name (so the name of the resource from which it got called) to the fileName, preventing it from getting read/overwritten/deleted by any other resource. If set to ''false'' you can use this script to call/send/modify tables from different resources without the use of events/other export functions.
or
or
*'''securityLevel:''' The level of security on which you want to store your data at (list at the bottom)
*'''securityLevel:''' The level of security on which you want to store your data at. (Details on the resource page: [https://wiki.multitheftauto.com/wiki/XmlData#Security_Levels Security Levels])
 
'''See [https://wiki.multitheftauto.com/wiki/XmlData#Variables_and_Specified_Names xmlData Variables and Specified names] for more detail.'''


===Returns===
===Returns===
Line 54: Line 58:
*'''resourceProtected:''' If set to ''true'' the script will add the sourceResource name (so the name of the resource from which it got called) to the fileName, preventing it from getting read/overwritten/deleted by any other resource. If set to ''false'' you can use this script to call/send/modify tables from different resources without the use of events/other export functions.
*'''resourceProtected:''' If set to ''true'' the script will add the sourceResource name (so the name of the resource from which it got called) to the fileName, preventing it from getting read/overwritten/deleted by any other resource. If set to ''false'' you can use this script to call/send/modify tables from different resources without the use of events/other export functions.
or
or
*'''securityLevel:''' The level of security on which you want to store your data at (list at the bottom)
*'''securityLevel:''' The level of security on which you want to store your data at. (Details on the resource page: [https://wiki.multitheftauto.com/wiki/XmlData#Security_Levels Security Levels])
 
'''See [https://wiki.multitheftauto.com/wiki/XmlData#Variables_and_Specified_Names xmlData Variables and Specified names] for more detail.'''


===Returns===
===Returns===
Line 61: Line 67:




= Security Levels =
== Example ==
Instead of manually adding bool parameters to the functions you can also just pass the security level you want to use for each function:
<section name="Client" class="client" show="true">
* '''0''' - No protection (any server, any resource or humans could read/modify)
This is the script where we specify the export shortcut and the data table which we want to store.
* '''1''' - Very low protection (creator resource on any server or humans could read/modify)
<syntaxhighlight lang="lua">
* '''2''' - Very low protection (any resource on any server could read/modify, humans cant)
local xml = exports.xmlData
* '''3''' - Low protection (only creator resource on any server could read/modify, humans cant)
local tblScriptSettings = {posX = 800, posY = 500, sizeX = 500, sizeY = 300, settings = {show = true, tab = 1}}
* '''4''' - Medium protection (any resource on the creator server or humans could read/modify) - DEFAULT
 
* '''5''' - Medium protection (only creator resource on the creator server or humans could read/modify)
xml:xmlSaveData("myFileName", tblScriptSettings , true, true) -- Save the data as "myFileName"
* '''6''' - High protection (any resource on the creator server could read/modify, humans cant)
</syntaxhighlight>
* '''7''' - Very high protection (only creator resource on creator server could read/modify, humans cant.
 
This will create a server-protected, encrypted file on the clients computer called "myFileName.xml". Also it will generate a random generated key and stores it.<br>
The created file will -(could, because encrypted with a random key)- like this:
 
<syntaxhighlight lang="xml">
<root posY="VgEN0+TERhg=" posX="mjX4Tj5u6oM=" sizeX="VgEN0+TERhg=" sizeY="htgOMaZurQQ=">
    <settings show="yeiNs/ne1Ks=" tab="OpijtdPvYqQ="></settings>
</root>
</syntaxhighlight>
</section>
 
 
==See Also==
{{Template:Shared_xml_functions}}
 
[[Category:Useful Functions]]

Latest revision as of 16:35, 13 September 2019



[[{{{image}}}|link=|]] Important Note:

This is an unofficial MTA function, so its not included into the game by default.
Its an exported function of the xmlData resource.
To access this function you need to have the resource running on your server.


This function provides an automated way of loading your data from an XML file created by xmlSaveData
To call it, see the call function or the tip in this resources page: Simplifying the export


Syntax

Click to collapse [-]
Client
bool xmlSaveData ( string fileName, table data [, bool serverProtected = true, bool encryptData = false, bool resourceProtected = false ] )
bool xmlSaveData ( string fileName, table data [, int securityLevel = 4] )

Required Arguments

  • fileName: The name of the file you want to create
  • data: The data you want to save (must be a table!)

Optional Arguments

  • serverProtected: If set to true the script will protect the file so, that can only the creator server can access it.
  • encryptData: If set to true the script will generate a random key and use it to encrypt your stored data. Note: If you want to store "sensitive data", always use encryption!
  • resourceProtected: If set to true the script will add the sourceResource name (so the name of the resource from which it got called) to the fileName, preventing it from getting read/overwritten/deleted by any other resource. If set to false you can use this script to call/send/modify tables from different resources without the use of events/other export functions.

or

  • securityLevel: The level of security on which you want to store your data at. (Details on the resource page: Security Levels)

See xmlData Variables and Specified names for more detail.

Returns

Returns true if successful, false otherwise.

Click to collapse [-]
Server
bool xmlSaveData ( string fileName, table data [, bool encryptData = false, bool resourceProtected = false ] )
bool xmlSaveData ( string fileName, table data [, int securityLevel = 4] )

Required Arguments

  • fileName: The name of the file you want to create
  • data: The data you want to save (must be a table!)

Optional Arguments

  • encryptData: If set to true the script will generate a random key and use it to encrypt your stored data. Note: If you want to store "sensitive data", always use encryption! (Account data should never be stored in serverside files - use a database instead!)
  • resourceProtected: If set to true the script will add the sourceResource name (so the name of the resource from which it got called) to the fileName, preventing it from getting read/overwritten/deleted by any other resource. If set to false you can use this script to call/send/modify tables from different resources without the use of events/other export functions.

or

  • securityLevel: The level of security on which you want to store your data at. (Details on the resource page: Security Levels)

See xmlData Variables and Specified names for more detail.

Returns

Returns true if successful, false otherwise.


Example

Click to collapse [-]
Client

This is the script where we specify the export shortcut and the data table which we want to store.

local xml = exports.xmlData
local tblScriptSettings = {posX = 800, posY = 500, sizeX = 500, sizeY = 300, settings = {show = true, tab = 1}}

xml:xmlSaveData("myFileName", tblScriptSettings , true, true) -- Save the data as "myFileName"

This will create a server-protected, encrypted file on the clients computer called "myFileName.xml". Also it will generate a random generated key and stores it.
The created file will -(could, because encrypted with a random key)- like this:

<root posY="VgEN0+TERhg=" posX="mjX4Tj5u6oM=" sizeX="VgEN0+TERhg=" sizeY="htgOMaZurQQ=">
    <settings show="yeiNs/ne1Ks=" tab="OpijtdPvYqQ="></settings>
</root>


See Also