mirror of
https://github.com/SWG-Source/dsrc.git
synced 2026-07-13 22:01:04 -04:00
Handle auto-store username as objvar on login and add username methods
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user