Skip to content

Commit 0cab36a

Browse files
Fix username changing (#726)
* Fix username changing We were accidentally overriding the functions even when you didn't have arguments passed in. Now only add them if set, and don't make extra unneeded globals. * Restore ID protection
1 parent 8a0586d commit 0cab36a

1 file changed

Lines changed: 28 additions & 14 deletions

File tree

client/src/developer.lua

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
local system = require("client.src.system")
22
local DebugSettings = require("client.src.debug.DebugSettings")
3+
local logger = require("common.lib.logger")
34
---@diagnostic disable: duplicate-set-field
45

56
-- Put any local development changes you need in here that you don't want commited.
@@ -38,58 +39,71 @@ function developerTools.processArgs(args)
3839
GAME_UPDATER = require("updater.gameUpdater")
3940
else
4041
for match in string.gmatch(value, "user%-id=(.*)") do
41-
CUSTOM_USER_ID = match
42+
developerTools.customUserID = match
4243
end
4344
for match in string.gmatch(value, "username=(.*)") do
44-
CUSTOM_USERNAME = match
45+
developerTools.customUsername = match
4546
end
4647
end
4748
end
4849
end
4950

50-
local realId
51-
local realName
51+
local realId = nil
52+
local realName = nil
53+
54+
function developerTools.wrapUsernameConfig(customUsername)
55+
assert(customUsername)
5256

53-
function developerTools.wrapConfig()
5457
local read = readConfigFile
5558
local write = write_conf_file
5659

5760
readConfigFile = function(c)
5861
---@type UserConfig
5962
c = read(c)
6063
realName = c.name
61-
c.name = CUSTOM_USERNAME or realName
64+
logger.debug("Original username was " .. realName)
65+
c.name = customUsername
66+
logger.debug("Overwriting name to custom username: " .. c.name)
6267
end
6368

6469
write_conf_file = function()
65-
if config.name == CUSTOM_USERNAME then
70+
if config.name == customUsername then
71+
assert(realName)
6672
config.name = realName
6773
end
6874
write()
69-
config.name = CUSTOM_USERNAME or realName
75+
config.name = customUsername
7076
end
7177
end
7278

73-
function developerTools.wrapPersistence()
74-
local save = require("client.src.save")
79+
function developerTools.wrapUserIDRead(customUserID)
80+
assert(customUserID)
81+
82+
logger.debug("Overwriting userID with command line argument")
7583

84+
local save = require("client.src.save")
7685
local readId = save.read_user_id_file
7786
save.read_user_id_file = function(serverIP)
7887
realId = readId(serverIP)
79-
return CUSTOM_USER_ID or realId
88+
return customUserID
8089
end
8190

8291
local writeId = save.write_user_id_file
8392
save.write_user_id_file = function(userID, serverIP)
84-
if userID == CUSTOM_USER_ID then
93+
if userID == customUserID then
8594
userID = realId
8695
end
96+
assert(userID ~= nil)
8797
writeId(userID, serverIP)
8898
end
8999
end
90100

91101
developerTools.processArgs(arg)
92-
developerTools.wrapConfig()
93-
developerTools.wrapPersistence()
102+
if developerTools.customUsername then
103+
developerTools.wrapUsernameConfig(developerTools.customUsername)
104+
end
105+
if developerTools.customUserID then
106+
developerTools.wrapUserIDRead(developerTools.customUserID)
107+
end
94108

95109
return developerTools

0 commit comments

Comments
 (0)