ATTENTION! The process of updating WiKi to version Eco 10.x has begun. Those wishing to participate can find out more Information on our ECO Contribution Wiki Discord.
From April 26 to May 12, errors may occur in the Wiki, as we will be carrying out a major update to the information processing modules.

Generic Authorization

From Eco - English Wiki
Revision as of 18:52, 4 July 2021 by Redwyre (talk | contribs) (Created page with "{{ModdingOutdated}} == Modding Tutorial: Generic Authorization == === Intro === Want to authorize certain players to do certain actions with your world objects or items? W...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Warning: This content is outdated.

Modding Tutorial: Generic Authorization[edit | edit source]

Intro[edit | edit source]

Want to authorize certain players to do certain actions with your world objects or items? We added the AuthorizationController just for that! It's the same one we use for all the current content and is easy to use in your own mods.

Steps[edit | edit source]

Include:

    using Eco.Gameplay.Buildings

Create an *AuthorizationController* in your world object or item class:

    [DataMember]
    public AuthorizationController Authorization { get; private set; }

Initialize it in the constructor:

    this.Authorization = new AuthorizationController();
    this.Authorization.AddAuthorizedPlayer(playerCreator);
    this.Authorization.Name = "Some Default Name";

Open the Authorization UI[edit | edit source]

Whenever you want to toggle the visibility of the authorization manager UI (for example, on left click), call:

    this.Authorization.OpenAuthorizationMenuOn(player);

Check If a Player Is Authorized:[edit | edit source]

    if (this.Authorization.IsAuthorized(player))
        // do something

That's it![edit | edit source]

Feel free to have multiple AuthorizationControllers for a single object if you wish to have different auth for various actions.

Full API for AuthorizationController[edit | edit source]

    public List<string> AuthorizedUsers { get; set; } = new List<string>();
    public string Name { get; set;}
    
    public bool IsAuthorized(Player player)
    public bool AddAuthorizedPlayer(Player player)
    public bool AddAuthorizedUser(ServerUser user)
    public bool RemoveAuthorizedUser(ServerUser user)
    public bool RemoveAuthorizedPlayer(Player player)
    public void OpenAuthorizationMenuOn(Player player)