Repository navigation
fix(access): apply 'as <name>' and save admins.json atomically - #197
Merged
Merged
Conversation
- AdminAccess: initialize reg_name and test it directly instead of the misspelled `"Regname" in locals()` check, so `!access <player> as <name> <level>` now sets the registered name. Level/permission checks unchanged. - AdminAccess: reject an empty target with a chat message (return 7) instead of raising IndexError on buffer[0]. - AccessManager.Save(): write to a temp file in the config directory, flush + fsync, keep the original file mode, then os.replace(); the temp file is removed on failure. JSON formatting and sorting are unchanged. - AccessManager.set_admin(): rename the loop variable that shadowed the `admin` parameter. Closes #191 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
16 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
!access <player> as <name> <level>now sets the nameAdminAccess._funccheckedif "Regname" in locals(), but the variable isreg_name, so the check was alwaysFalseand the registered name was never applied.reg_nameis now initialized toNoneand tested directly. When a name is given,targeted_player.admin.nameis set and the existing "level/name" chat message is used. All level and permission checks are unchanged.Empty target no longer raises
IndexErrorbuffer[0]raised when the target part parsed to an empty string. The command now repliesMissing target: use a player name or #useridin chat, like the other errors in this command, and returns7.Note:
CommandHandleralready stripsmessage[1], so most inputs never reach this path. This is a guard for unusual whitespace, for example a tab or an ideographic space.!access as foo 5still searches for a player whose name contains "as foo", as before.admins.jsonis saved atomicallyAccessManager.Save()used to truncate and rewriteadmins.jsonin place. If the process crashed, was killed or ran out of disk mid-write, the file was left truncated, and since #171 a malformedadmins.jsonaborts startup.Save()now:tempfile.mkstemp), then flushes and fsyncs it;mkstempcreates files as0600;os.replace;The JSON output (
indent="\t", level-descending sort, text-mode newlines) is byte-identical to before.Readability
In
set_admin, the loop variable shadowed theadminparameter. It is now namedexisting_admin.Test plan
I ran a throwaway script against a temp copy of
config/, drivingAdminAccess._funcwith stub torchlight and player-manager objects:!access Target as NewName 5returns 0, setsadmin.name = "NewName"and level 5, and the access manager stores the new name.!access #20 6returns 0 and keeps the name. Assigning a level at or above the caller's own still returns 4."\t as foo 5"," 5") returns 7 with the chat message.Save()output is byte-identical to the oldopen(..., "w")+json.dumpfor the same data.json.dump, and anos.replacefailure, both leave the originaladmins.jsonbyte-identical with no.tmpfile left behind.ruff check .,ruff format --check .andmypyshow no new errors. Only the 3 known baseline errors remain, and CI: Python Linting is red on master since the Python 3.12 bump (ruff UP041, mypy arg-type) #178 fixes them.No VERSION bump (batch policy, see #177).
Closes #191
Part of #177
🤖 Generated with Claude Code