Handle auto-store username as objvar on login and add username methods

This commit is contained in:
AconiteGodOfSWG
2021-02-15 04:09:58 -05:00
parent 788a36dc3b
commit 20cf52a3f1
2 changed files with 43 additions and 0 deletions
@@ -5,9 +5,12 @@
package script;
import script.library.utils;
import java.io.File;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.List;
import java.util.Vector;
@@ -26787,4 +26790,40 @@ public class base_class
_triggerServerWarning("[dsrc] "+message);
}
/**
* getPlayerAccountUsername
* Returns the username of a player (they must have logged in at least once for this to work)
*
* The helper method (_getPlayerUsernameDoNotUse) is called in player.live_conversions OnInitialize
* and grabs the account username to store it as an ObjVar on the player so it is accessible all the
* time. Otherwise, user names are only accessible when the player is online. Do not use the DoNotUse
* JNI method in any implementation where you're looking for the account username of a player. Instead,
* use the getPlayerAccountUsername method, provided they have logged in once, this will return their
* account username (and it will update automatically if a character-account transfer takes place)
*
* @param player the player's Network ID
* @return the username of the player
*/
public static String getPlayerAccountUsername(obj_id player) {
return getStringObjVar(player, "system.accountUsername");
}
public static native String _getPlayerUsernameDoNotUse(long player);
/**
* isInAdminTable
* Alternative to isGod check which validates if the player is connected from an account listed in the admin data table
* This validates the username regardless of whether /setGod is on or off so it is better for security and auditing of admin accounts
* or for announcements/messages to GM characters (in the case of SWG Source, for patch note/admin updates)
* @param player the player to validate
* @return if the player's account is in the admin table
*/
public static boolean isInAdminTable(obj_id player) throws InterruptedException {
if(utils.checkConfigFlag("GameServer", "adminGodToAll")) {
return true;
} else {
List<String> adminUsernames = Arrays.asList(dataTableGetStringColumn(getConfigSetting("ConnectionServer", "adminAccountDataTable"), "AdminAccounts"));
return adminUsernames.contains(getPlayerAccountUsername(player));
}
}
} // class base_class