Modding Help Getting a uuid of a player and kicking it if not in a whitelist

Discussion in 'Starbound Modding' started by Lucretia, Jun 15, 2022.

  1. Lucretia

    Lucretia Void-Bound Voyager

    Hi everyone!

    I found a mod that autokills a player after 5 seconds if they use the /admin command and their name is not on a whitelist of names
    I am not familiar with LUA programming but I have programming language notions (C++ and Java)
    From what I've seen reading the code it creates a status effect named unadmin when a player gains unauthorized Admin access, when the countdown reach 0 it kills the player.

    Now what I would like to achieve taking inspiration from this mod is having a whitelist of player name/uuids couples in an array that are authorized to gain admin access and kick players when they gain admin access illegally with no countdown, because I've seen people who seems to know some kind of exploit to gain admin access even if they don't have admin credentials of a server and frankly I'm sick of dealing with those trolls, this should limit the damages if no admins are connected at the moment.

    The mod is very simple is comprised of 3 files (I won't paste the whole code here only snippets):

    in player.config.patch it adds the basic lua script of the mod and that is self explanatory

    (will post snippets of the code here)
    Then there is the main LUA script that is mentioned in the player.config.patch
    That has a init function where it initialize the whitelist and the timer, Then it checks if the player name is in the whitelist and set the status effect timer to 1000000 plus a variable (adminEffectApplied) that is used in the update function:

    Code:
      self.whitelist = root.assetJson("/admins.whitelist")
      self.adminTimer = 5
      if self.whitelist[world.entityName(entity.id())] then self.adminTimer = 1000000 end
      self.adminEffectApplied = false
    
    there is an update function too (a snippet) that implement the timer and decreases it at each tick and enable/disable the custom "unadmin" status effect (that in my case would just be the kick event):
    Code:
       if self.adminTimer > 0 then self.adminTimer = self.adminTimer - dt return end
       self.adminTimer = 1
       local isAdmin = player.isAdmin()
       if player.isAdmin() and not self.adminEffectApplied and not self.whitelist[world.entityName(entity.id())] then
         status.addEphemeralEffects({{effect="unadmin",duration = 100000}})
         self.adminEffectApplied = true
       elseif not player.isAdmin() and self.adminEffectApplied then
         status.removeEphemeralEffect("unadmin")
         self.adminEffectApplied = false
       end
    
    That's the whitelist file;
    Code:
    {
       //Use "Player-name" : true, to allow a player to be admin without dying
       "Player1" : true
    }
    
    Then there are the files relative to the status effect (unadmin).

    Then what I would like to achieve is to get the player uuid and the player name and check if there is a coupled reference in the whitelist, if not it kicks the player, so I would modify the update function just to periodically check the admin status, also unsure of how to call the kick command inside a mod.

    I would modify the self.whitelist[world.entityName(entity.id())] but I am unsure how to do, also the whitelist format should be modified as of now it seems to be an array of a string and boolean coupled that is used to trigger the if-then-else(s) in the code but I am kind of unfamiliar with the LUA and this seems like a simple code to manipulate.

    Any advice is appreciated!

    Thanks!
     

Share This Page