From 5395d1018b61ec3917d73749990a192f61736193 Mon Sep 17 00:00:00 2001
From: thecraftianman <64441307+thecraftianman@users.noreply.github.com>
Date: Mon, 22 Jul 2024 18:40:24 -0400
Subject: [PATCH] Replace UniqueID with SteamID64 where applicable

---
 lua/ulx/log.lua                    |  2 +-
 lua/ulx/modules/cl/xgui_client.lua |  2 +-
 lua/ulx/modules/sh/user.lua        | 20 ++++++-------
 lua/ulx/modules/sh/util.lua        |  6 ++--
 lua/ulx/modules/slots.lua          |  2 +-
 lua/ulx/modules/xgui_server.lua    | 48 +++++++++++++++---------------
 lua/ulx/xgui/server/sv_groups.lua  |  2 +-
 7 files changed, 41 insertions(+), 41 deletions(-)

diff --git a/lua/ulx/log.lua b/lua/ulx/log.lua
index 145408dc..5db29abb 100644
--- a/lua/ulx/log.lua
+++ b/lua/ulx/log.lua
@@ -161,7 +161,7 @@ end
 local function echoToAdmins( txt )
 	local players = player.GetAll()
 	for _, ply in ipairs( players ) do
-		if ULib.ucl.authed[ ply:UniqueID() ] and ULib.ucl.query( ply, spawnechoAccess ) then
+		if ULib.ucl.authed[ ply:SteamID64() ] and ULib.ucl.query( ply, spawnechoAccess ) then
 			ULib.console( ply, txt )
 		end
 	end
diff --git a/lua/ulx/modules/cl/xgui_client.lua b/lua/ulx/modules/cl/xgui_client.lua
index edd476f3..4128e899 100644
--- a/lua/ulx/modules/cl/xgui_client.lua
+++ b/lua/ulx/modules/cl/xgui_client.lua
@@ -353,7 +353,7 @@ function xgui.show( tabname )
 		return
 	end
 
-	if not game.SinglePlayer() and not ULib.ucl.authed[LocalPlayer():UniqueID()] then
+	if not game.SinglePlayer() and not ULib.ucl.authed[LocalPlayer():SteamID64()] then
 		local unauthedWarning = xlib.makeframe{ label="XGUI Error!", w=250, h=90, showclose=true, skin=xgui.settings.skin }
 		xlib.makelabel{ label="Your ULX player has not been Authed!", x=10, y=30, parent=unauthedWarning }
 		xlib.makelabel{ label="Please wait a couple seconds and try again.", x=10, y=45, parent=unauthedWarning }
diff --git a/lua/ulx/modules/sh/user.lua b/lua/ulx/modules/sh/user.lua
index 36a5c132..c5252936 100644
--- a/lua/ulx/modules/sh/user.lua
+++ b/lua/ulx/modules/sh/user.lua
@@ -13,8 +13,8 @@ local function checkForValidId( calling_ply, id )
 			ULib.tsayError( calling_ply, "Invalid steamid.", true )
 			return false
 		end
-	elseif not tonumber( id ) then -- Assume uniqueid and check
-		ULib.tsayError( calling_ply, "Invalid Unique ID", true )
+	elseif not tonumber( id ) then -- Assume UniqueID/SteamID64 and check
+		ULib.tsayError( calling_ply, "Invalid UniqueID/SteamID64", true )
 		return false
 	end
 
@@ -49,7 +49,7 @@ usermanagementhelp:defaultAccess( ULib.ACCESS_ALL )
 usermanagementhelp:help( "See the user management help." )
 
 function ulx.adduser( calling_ply, target_ply, group_name )
-	local userInfo = ULib.ucl.authed[ target_ply:UniqueID() ]
+	local userInfo = ULib.ucl.authed[ target_ply:SteamID64() ]
 
 	local id = ULib.ucl.getUserRegisteredID( target_ply )
 	if not id then id = target_ply:SteamID() end
@@ -81,13 +81,13 @@ function ulx.adduserid( calling_ply, id, group_name )
 	end
 end
 local adduserid = ulx.command( CATEGORY_NAME, "ulx adduserid", ulx.adduserid, nil, false, false, true )
-adduserid:addParam{ type=ULib.cmds.StringArg, hint="SteamID, IP, or UniqueID" }
+adduserid:addParam{ type=ULib.cmds.StringArg, hint="SteamID, SteamID64, IP, or UniqueID" }
 adduserid:addParam{ type=ULib.cmds.StringArg, completes=ulx.group_names_no_user, hint="group", error="invalid group \"%s\" specified", ULib.cmds.restrictToCompletes }
 adduserid:defaultAccess( ULib.ACCESS_SUPERADMIN )
 adduserid:help( "Add a user by ID to specified group." )
 
 function ulx.removeuser( calling_ply, target_ply )
-	ULib.ucl.removeUser( target_ply:UniqueID() )
+	ULib.ucl.removeUser( target_ply:SteamID64() )
 
 	ulx.fancyLogAdmin( calling_ply, "#A removed all access rights from #T", target_ply )
 end
@@ -118,7 +118,7 @@ function ulx.removeuserid( calling_ply, id )
 	end
 end
 local removeuserid = ulx.command( CATEGORY_NAME, "ulx removeuserid", ulx.removeuserid, nil, false, false, true )
-removeuserid:addParam{ type=ULib.cmds.StringArg, hint="SteamID, IP, or UniqueID" }
+removeuserid:addParam{ type=ULib.cmds.StringArg, hint="SteamID, SteamID64, IP, or UniqueID" }
 removeuserid:defaultAccess( ULib.ACCESS_SUPERADMIN )
 removeuserid:help( "Permanently removes a user's access by ID." )
 
@@ -185,16 +185,16 @@ function ulx.userallowid( calling_ply, id, access_string, access_tag )
 	end
 end
 local userallowid = ulx.command( CATEGORY_NAME, "ulx userallowid", ulx.userallowid, nil, false, false, true )
-userallowid:addParam{ type=ULib.cmds.StringArg, hint="SteamID, IP, or UniqueID" }
+userallowid:addParam{ type=ULib.cmds.StringArg, hint="SteamID, SteamID64, IP, or UniqueID" }
 userallowid:addParam{ type=ULib.cmds.StringArg, hint="command" } -- TODO, add completes for this
 userallowid:addParam{ type=ULib.cmds.StringArg, hint="access tag", ULib.cmds.optional }
 userallowid:defaultAccess( ULib.ACCESS_SUPERADMIN )
 userallowid:help( "Add to a user's access." )
 
 function ulx.userdeny( calling_ply, target_ply, access_string, should_use_neutral )
-	local success = ULib.ucl.userAllow( target_ply:UniqueID(), access_string, should_use_neutral, true )
+	local success = ULib.ucl.userAllow( target_ply:SteamID64(), access_string, should_use_neutral, true )
 	if should_use_neutral then
-		success = success or ULib.ucl.userAllow( target_ply:UniqueID(), access_string, should_use_neutral, false ) -- Remove from both lists
+		success = success or ULib.ucl.userAllow( target_ply:SteamID64(), access_string, should_use_neutral, false ) -- Remove from both lists
 	end
 
 	if should_use_neutral then
@@ -250,7 +250,7 @@ function ulx.userdenyid( calling_ply, id, access_string, should_use_neutral )
 	end
 end
 local userdenyid = ulx.command( CATEGORY_NAME, "ulx userdenyid", ulx.userdenyid, nil, false, false, true )
-userdenyid:addParam{ type=ULib.cmds.StringArg, hint="SteamID, IP, or UniqueID" }
+userdenyid:addParam{ type=ULib.cmds.StringArg, hint="SteamID, SteamID64, IP, or UniqueID" }
 userdenyid:addParam{ type=ULib.cmds.StringArg, hint="command" } -- TODO, add completes for this
 userdenyid:addParam{ type=ULib.cmds.BoolArg, hint="remove explicit allow or deny instead of outright denying", ULib.cmds.optional }
 userdenyid:defaultAccess( ULib.ACCESS_SUPERADMIN )
diff --git a/lua/ulx/modules/sh/util.lua b/lua/ulx/modules/sh/util.lua
index 61c83af7..36ac4195 100644
--- a/lua/ulx/modules/sh/util.lua
+++ b/lua/ulx/modules/sh/util.lua
@@ -294,16 +294,16 @@ function ulx.debuginfo( calling_ply )
 	str = str .. "Dedicated server: " .. tostring( game.IsDedicated() ) .. "\n\n"
 
 	local players = player.GetAll()
-	str = str .. string.format( "Currently connected players:\nNick%s steamid%s uid%s id lsh\n", str.rep( " ", 27 ), str.rep( " ", 12 ), str.rep( " ", 7 ) )
+	str = str .. string.format( "Currently connected players:\nNick%s steamid%s steamid64%s id lsh\n", str.rep( " ", 27 ), str.rep( " ", 12 ), str.rep( " ", 7 ) )
 	for _, ply in ipairs( players ) do
 		local id = string.format( "%i", ply:EntIndex() )
 		local steamid = ply:SteamID()
-		local uid = tostring( ply:UniqueID() )
+		local steamid64 = tostring( ply:SteamID64() )
 		local name = utf8.force( ply:Nick() )
 
 		local plyline = name .. str.rep( " ", 32 - utf8.len( name ) ) -- Name
 		plyline = plyline .. steamid .. str.rep( " ", 20 - steamid:len() ) -- Steamid
-		plyline = plyline .. uid .. str.rep( " ", 11 - uid:len() ) -- Steamid
+		plyline = plyline .. steamid64 .. str.rep( " ", 11 - steamid64:len() ) -- Steamid
 		plyline = plyline .. id .. str.rep( " ", 3 - id:len() ) -- id
 		if ply:IsListenServerHost() then
 			plyline = plyline .. "y	  "
diff --git a/lua/ulx/modules/slots.lua b/lua/ulx/modules/slots.lua
index fd291477..49bb9fad 100644
--- a/lua/ulx/modules/slots.lua
+++ b/lua/ulx/modules/slots.lua
@@ -17,7 +17,7 @@ function calcSlots( disconnect )
 
 		local players = player.GetAll()
 		for _, player in ipairs( players ) do
-			if player:IsConnected() and ULib.ucl.authed[ player:UniqueID() ] and player:query( access ) then
+			if player:IsConnected() and ULib.ucl.authed[ player:SteamID64() ] and player:query( access ) then
 				admins = admins + 1
 			end
 		end
diff --git a/lua/ulx/modules/xgui_server.lua b/lua/ulx/modules/xgui_server.lua
index 0aee5aed..dbbcbe98 100644
--- a/lua/ulx/modules/xgui_server.lua
+++ b/lua/ulx/modules/xgui_server.lua
@@ -110,13 +110,13 @@ function xgui.init()
 	--Let the server know when players are/aren't ready to receive data.
 	function xgui.getInstalled( ply )
 		ULib.clientRPC( ply, "xgui.getInstalled" )
-		xgui.readyPlayers[ply:UniqueID()] = 1
+		xgui.readyPlayers[ply:SteamID64()] = 1
 	end
 	xgui.addCmd( "getInstalled", xgui.getInstalled )
 
 	function xgui.onDisconnect( ply )
-		xgui.activeUsers[ply:UniqueID()] = nil
-		xgui.readyPlayers[ply:UniqueID()] = nil
+		xgui.activeUsers[ply:SteamID64()] = nil
+		xgui.readyPlayers[ply:SteamID64()] = nil
 	end
 	hook.Add( "PlayerDisconnected", "xgui_ply_disconnect", xgui.onDisconnect )
 
@@ -159,25 +159,25 @@ function xgui.init()
 		plys = plyToTable( plys )
 
 		for k, ply in pairs( plys ) do
-			if not xgui.readyPlayers[ply:UniqueID()] then return end --Ignore requests to players who are not ready, they'll get the data as soon as they can.
+			if not xgui.readyPlayers[ply:SteamID64()] then return end --Ignore requests to players who are not ready, they'll get the data as soon as they can.
 
 			-- print("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv")
-			-- print("sendDataTable attempt. Will defer?", xgui.activeUsers[ply:UniqueID()] and not forceSend)
+			-- print("sendDataTable attempt. Will defer?", xgui.activeUsers[ply:SteamID64()] and not forceSend)
 			-- PrintTable(datatypes)
 			-- print(debug.traceback())
 			-- print("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^")
 
-			if xgui.activeUsers[ply:UniqueID()] and not forceSend then --If data is currently being sent to the client
+			if xgui.activeUsers[ply:SteamID64()] and not forceSend then --If data is currently being sent to the client
 				for _, dtype in ipairs( datatypes ) do
 					local exists = false
-					for _,existingArg in ipairs(xgui.activeUsers[ply:UniqueID()].tables) do
+					for _,existingArg in ipairs(xgui.activeUsers[ply:SteamID64()].tables) do
 						if dtype == existingArg then exists=true break end
 					end
-					if not exists then table.insert( xgui.activeUsers[ply:UniqueID()].tables, dtype ) end
+					if not exists then table.insert( xgui.activeUsers[ply:SteamID64()].tables, dtype ) end
 					--Clear any events relating to this data type, since those changes will be reflected whenever the new table is sent.
-					for i=#xgui.activeUsers[ply:UniqueID()].events,1,-1 do
-						if xgui.activeUsers[ply:UniqueID()].events[i][2] == dtype then
-							table.remove( xgui.activeUsers[ply:UniqueID()].events, i )
+					for i=#xgui.activeUsers[ply:SteamID64()].events,1,-1 do
+						if xgui.activeUsers[ply:SteamID64()].events[i][2] == dtype then
+							table.remove( xgui.activeUsers[ply:SteamID64()].events, i )
 						end
 					end
 				end
@@ -246,13 +246,13 @@ function xgui.init()
 		for k, ply in pairs( plys ) do
 
 			-- print("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv")
-			-- print("sendDataEvent attempt. Will defer?", xgui.activeUsers[ply:UniqueID()])
+			-- print("sendDataEvent attempt. Will defer?", xgui.activeUsers[ply:SteamID64()])
 			-- print(evtype, dtype, entry)
 			-- print(debug.traceback())
 			-- print("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^")
 
-			if xgui.activeUsers[ply:UniqueID()] then
-				table.insert( xgui.activeUsers[ply:UniqueID()].events, { evtype, dtype, entry } )
+			if xgui.activeUsers[ply:SteamID64()] then
+				table.insert( xgui.activeUsers[ply:SteamID64()].events, { evtype, dtype, entry } )
 				return
 			end
 
@@ -264,26 +264,26 @@ function xgui.init()
 
 	function xgui.sendChunks( ply, chunks )
 		ULib.clientRPC( ply, "xgui.expectChunks", #chunks )
-		if not xgui.activeUsers[ply:UniqueID()] then xgui.activeUsers[ply:UniqueID()] = { tables={}, events={} } end
+		if not xgui.activeUsers[ply:SteamID64()] then xgui.activeUsers[ply:SteamID64()] = { tables={}, events={} } end
 		for _, chunk in ipairs( chunks ) do
 			ULib.queueFunctionCall( ULib.clientRPC, ply, "xgui.getChunk", chunk[1], chunk[2], chunk[3] )
 		end
 	end
 
 	function xgui.chunksFinished( ply )
-		if xgui.activeUsers[ply:UniqueID()] then
-			if #xgui.activeUsers[ply:UniqueID()].tables > 0 then --Data tables have been requested while the player was transferring data
-				xgui.sendDataTable( ply, xgui.activeUsers[ply:UniqueID()].tables, true )
-				xgui.activeUsers[ply:UniqueID()].tables = {}
-			elseif #xgui.activeUsers[ply:UniqueID()].events > 0 then --No data tables are needed, and events have occurred while the player was transferring data
+		if xgui.activeUsers[ply:SteamID64()] then
+			if #xgui.activeUsers[ply:SteamID64()].tables > 0 then --Data tables have been requested while the player was transferring data
+				xgui.sendDataTable( ply, xgui.activeUsers[ply:SteamID64()].tables, true )
+				xgui.activeUsers[ply:SteamID64()].tables = {}
+			elseif #xgui.activeUsers[ply:SteamID64()].events > 0 then --No data tables are needed, and events have occurred while the player was transferring data
 				local chunks = {}
-				for _,v in ipairs( xgui.activeUsers[ply:UniqueID()].events ) do
+				for _,v in ipairs( xgui.activeUsers[ply:SteamID64()].events ) do
 					table.insert( chunks, v )
 				end
 				xgui.sendChunks( ply, chunks )
-				xgui.activeUsers[ply:UniqueID()].events = {}
+				xgui.activeUsers[ply:SteamID64()].events = {}
 			else --Client is up-to-date!
-				xgui.activeUsers[ply:UniqueID()] = nil
+				xgui.activeUsers[ply:SteamID64()] = nil
 			end
 		end
 	end
@@ -326,7 +326,7 @@ function xgui.postInit()
 	--Fix any users who requested data before the server was ready
 	for _, ply in pairs( player.GetAll() ) do
 		for UID, data in pairs( xgui.activeUsers ) do
-			if ply:UniqueID() == UID then
+			if ply:SteamID64() == UID then
 				ULib.clientRPC( ply, "xgui.getChunk", -1, "Initializing..." )
 			end
 		end
diff --git a/lua/ulx/xgui/server/sv_groups.lua b/lua/ulx/xgui/server/sv_groups.lua
index dcaa8bbc..a8fa0cad 100644
--- a/lua/ulx/xgui/server/sv_groups.lua
+++ b/lua/ulx/xgui/server/sv_groups.lua
@@ -32,7 +32,7 @@ function groups.init()
 
 	function xgui.playerExistsByID( id )
 		for k, v in ipairs( player.GetAll() ) do
-			if v:SteamID() == id or v:UniqueID() == id or ULib.splitPort( v:IPAddress() ) == id then
+			if v:SteamID() == id or v:SteamID64() == id or v:UniqueID() == id or ULib.splitPort( v:IPAddress() ) == id then
 				return v
 			end
 		end