Level ideal: Do you have access?


#1

Running a little bit out of math now and going for a subject that I find quite interesting: Permission System Binary-Based.

Level: The clock reached midnight and all the tasks performed by a certain group has come to an end. It’s time to retreat. The group lined up to get in the Human Headquarters Tower. But last week an ogre had gotten access to said building and it cost us one life: George Boolean. To honor his death, a boolean security system has been activated at the building. Now, every human has an access code that will give him/her permission to access certain rooms. The binary access required to get inside the Headquarters is 16. Anyone without access will be shot instantly. The ogres that disguised themselves as humans to follow this group is about to be aware of that.

Mission: Shoot everyone that doesn’t have binary access 16 added up to his/her code. This will teach the player how to setup a permission system not based on hierarchy.

Solution:

// Get the person that is trying to access the building
var person = getNearest();
if((person.access & 16) == 16){
    this.say("Welcome, " + person.name = ". You can enter the building with the access " + person.access);
}else{
    this.attack(person);
}

Guide/Extra information: This concept allows you to build a permission system action-oriented. For instance, a CRUD use-case can have:

  1. Read = 1
  2. Create = 2
  3. Update = 4
  4. Delete = 8
  5. Print = 16

And you can have a user that:

  1. Can create and delete, but can’t read or update(2 + 8 = 10).
  2. Update and Print, but can’t read or create (4 + 16 = 20)
  3. Can do anything (1 + 2 + 4 + 8 + 16 = 31)
  4. Can only Print (16)

Maybe it doesn’t make sense to you someone being able to create some data, but not being able to read it or etc; but there are permission cases that following hierarchy (if you can delete, you can do anything) simply can’t solve your problem.