XmlLoadData: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "<pageclass class="#228B22" subcaption="Useful Function - Shared"></pageclass> <lowercasetitle></lowercasetitle> <includeonly> Category:Useful Functions </includeonly> {{I...")
 
No edit summary
Line 12: Line 12:


This function provides an automated way of loading your data from an [[XML]] file created by [[xmlSaveData]] <br>
This function provides an automated way of loading your data from an [[XML]] file created by [[xmlSaveData]] <br>
To call this function, see the [[call]] function or the tip in this resources page: [[XmlData#Simplifying_the_export]]
To call this function, see the [[call]] function or the tip in this resources page: [[XmlData#Simplifying_the_export Simplifying the export]]




Line 18: Line 18:
<section name="Client" class="client" show="true">
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool xmlSaveData ( string fileName, table data [, bool serverProtected = true, bool encryptData = false, bool resourceProtected = false ] )
bool xmlLoadData ( fileName [, serverProtected, resourceProtected ] )
bool xmlLoadData ( fileName [, int securityLevel] )
</syntaxhighlight>
</syntaxhighlight>


Line 27: Line 28:
====Required Arguments====
====Required Arguments====
*'''fileName:''' The name of the file you want to create
*'''fileName:''' The name of the file you want to create
*'''data:''' The data you want to save (must be a table!)


====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'' it can only read the file created by the same server, otherwise it doesn't care which server created 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'' it can only read the file created by the caller-resource
*'''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. (See security levels here: [[XmlData#Security_Levels]]
*'''securityLevel:''' The level of security on which you want to store your data at. (See security levels here: [[XmlData#Security_Levels Security Levels]]
 
'''See [[https://wiki.multitheftauto.com/wiki/XmlData#Variables_and_Specified_Names Variables and Specified names]] for more detail.'''


===Returns===
===Returns===
Returns ''true'' if successful, ''false'' otherwise.
Returns ''true'' if successful, ''false'' otherwise.
'''Note: There is no encryption parameter in this function, because xmlLoadData will load and use a files key if it is encrypted.'''
</section>
</section>


Line 51: Line 54:
====Required Arguments====
====Required Arguments====
*'''fileName:''' The name of the file you want to create
*'''fileName:''' The name of the file you want to create
*'''data:''' The data you want to save (must be a table!)


====Optional Arguments====
====Optional Arguments====
Line 61: Line 63:
===Returns===
===Returns===
Returns ''true'' if successful, ''false'' otherwise.
Returns ''true'' if successful, ''false'' otherwise.
'''Note: There is no encryption parameter in this function, because xmlLoadData will load and use a files key if it is encrypted.'''
</section>
</section>



Revision as of 17:46, 12 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 this function, see the call function or the tip in this resources page: XmlData#Simplifying_the_export Simplifying the export


Syntax

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

Required Arguments

  • fileName: The name of the file you want to create

Optional Arguments

  • serverProtected: If set to true it can only read the file created by the same server, otherwise it doesn't care which server created it.
  • resourceProtected: If set to true it can only read the file created by the caller-resource

or

See [Variables and Specified names] for more detail.

Returns

Returns true if successful, false otherwise.

Note: There is no encryption parameter in this function, because xmlLoadData will load and use a files key if it is encrypted.

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

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. (See security levels here: XmlData#Security_Levels

Returns

Returns true if successful, false otherwise.

Note: There is no encryption parameter in this function, because xmlLoadData will load and use a files key if it is encrypted.


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>