Generic Authorization
From Eco - English Wiki
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)