From 20cf52a3f1534585ff12c35f9596a3cf1d4f7366 Mon Sep 17 00:00:00 2001 From: AconiteGodOfSWG Date: Mon, 15 Feb 2021 04:09:58 -0500 Subject: [PATCH] Handle auto-store username as objvar on login and add username methods --- .../compiled/game/script/base_class.java | 39 +++++++++++++++++++ .../game/script/player/live_conversions.java | 4 ++ 2 files changed, 43 insertions(+) diff --git a/sku.0/sys.server/compiled/game/script/base_class.java b/sku.0/sys.server/compiled/game/script/base_class.java index cfeed4e42..002be9e3a 100755 --- a/sku.0/sys.server/compiled/game/script/base_class.java +++ b/sku.0/sys.server/compiled/game/script/base_class.java @@ -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 adminUsernames = Arrays.asList(dataTableGetStringColumn(getConfigSetting("ConnectionServer", "adminAccountDataTable"), "AdminAccounts")); + return adminUsernames.contains(getPlayerAccountUsername(player)); + } + } + } // class base_class diff --git a/sku.0/sys.server/compiled/game/script/player/live_conversions.java b/sku.0/sys.server/compiled/game/script/player/live_conversions.java index d69890819..5983e3e10 100755 --- a/sku.0/sys.server/compiled/game/script/player/live_conversions.java +++ b/sku.0/sys.server/compiled/game/script/player/live_conversions.java @@ -60,6 +60,7 @@ public class live_conversions extends script.base_script } public void runOncePerSessionConversions(obj_id player) throws InterruptedException { + handleStoreUsername(player); grantFemaleMasterPilotMedals(player); clearDotEffectObjvars(player); fixConsentList(player); @@ -300,6 +301,9 @@ public class live_conversions extends script.base_script removeObjVar(player, pclib.VAR_CONSENT_FROM_NAME); } } + public void handleStoreUsername(obj_id player) throws InterruptedException { + setObjVar(player, "system.accountUsername", _getPlayerUsernameDoNotUse(getLongWithNull(player))); + } public void setUnarmedDamageRanges(obj_id player) throws InterruptedException { if (hasConversionFlag(player, UNARMED_DAMAGE_SET))