Class TrainzGameObject

From TrainzOnline
(Difference between revisions)
Jump to: navigation, search
(IssueSecurityToken)
(IssueSecurityToken)
Line 45: Line 45:
 
;Returned Value
 
;Returned Value
 
*The issued SecurityToken.
 
*The issued SecurityToken.
;Syntax;
+
;Syntax
 
  KUID friendlyAsset = GetAsset().LookupKUIDTable("some-asset");
 
  KUID friendlyAsset = GetAsset().LookupKUIDTable("some-asset");
 
   
 
   

Revision as of 11:43, 26 February 2024


  • Base class for a GameObject that is an instance of a Trainz asset.


Contents

Init

public void Init(void)
public void Init(Asset asset)
Parameters
  • asset = Reference to the script's associated asset.
Returned Value
  • None
Syntax
  • None, method is automatically called by the game.
Notes
  • Initialisation method which is called by Trainz when the object is first created.
  • It is up to the script programmer to do any initialization tasks required here.
  • This may include starting monitor threads, adding message handlers, and so on.
  • Some derived classes have both an Init() and Init(Asset) method. It is recommended that you use the Init(Asset) version whenever you can.
  • Uses the 'mandatory' keyword, meaning you must call inherited() when overriding this function.
  • Since Init() is called from native Trainz code, you cannot use Sleep() or wait(). However, Init() can start threaded methods that are allowed to sleep and process messages.


GetAsset

public Asset GetAsset(void)
Parameters
  • None
Returned Value
  • A reference to the owning asset.
Syntax
Asset asset = GetAsset();
Notes
  • The returned Asset reference can be used to retrieve the KUID, StringTable or configuration data of the Asset.



IssueSecurityToken

native SecurityToken IssueSecurityToken(KUID asset, string[] rights)
Parameters
  • asset - The asset this token is intended to be used by.
  • rights - Array of string identifiers specifying the operations permitted by this token.
Returned Value
  • The issued SecurityToken.
Syntax
KUID friendlyAsset = GetAsset().LookupKUIDTable("some-asset");

string[] rights = new string[2];
rights[0] = "edit-settings";
rights[1] = "access-data";

SecurityToken token = IssueSecurityToken(friendlyAsset, rights);

Notes
  • Creates a SecurityToken object which can be issued to other assets to grant access to certain features.
  • The created SecurityToken can be given to trusted objects, and later passed to the Validate() function when checking permissions.
  • SecurityToken.IsIsOwnerLocallyModified() can be used to check the issued asset hasn't been modified in some form.


IssueSecurityToken

native SecurityToken IssueSecurityToken(SecurityToken source, KUID asset, string[] rights))


MergeSecurityTokens

native SecurityToken MergeSecurityTokens(SecurityToken[] tokens)


Validate

native bool Validate(SecurityToken token, TrainzGameObject owner, string operation)


Validate

native bool Validate(SecurityToken token, KUID owner, string operation)


Categories

Personal tools