Skip to content

Permission Groups#2587

Open
Wunka wants to merge 33 commits into
PixelGuys:masterfrom
Wunka:permisisonGroups
Open

Permission Groups#2587
Wunka wants to merge 33 commits into
PixelGuys:masterfrom
Wunka:permisisonGroups

Conversation

@Wunka

@Wunka Wunka commented Feb 23, 2026

Copy link
Copy Markdown
Contributor

Follow Up PR for #2530

This adds the rest from the permissionLayer PR which was split of. For Documentation see #2530

@Wunka Wunka marked this pull request as ready for review February 24, 2026 18:35
@BoySanic BoySanic moved this to High Priority in PRs to review Feb 26, 2026
Comment thread src/server/command/_list.zig Outdated
Comment thread src/server/command/permission/group.zig Outdated
Comment thread src/server/command/permission/perm.zig
Comment thread src/server/permission.zig
Comment thread src/server/server.zig Outdated
Comment thread src/server/permission.zig Outdated
}

pub fn getGroup(name: []const u8) error{GroupNotFound}!*PermissionGroup {
return groups.getPtr(name) orelse return error.GroupNotFound;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hashmaps don't have stable pointers

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the assert but thats probaly not enough right? I am sorry I am not that knowledgeable to know what would be the best course of action here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I finally brought myself back to this pr. I have changed the hashmap from StringHashMapUnmanaged(PermissionGroup) to StringHashMapUnmanaged(*PermissionGroup).
This should from my understanding fix the problem with the stable pointers

Comment thread src/server/world.zig Outdated
@IntegratedQuantum IntegratedQuantum moved this from High Priority to In review in PRs to review Mar 2, 2026
Comment thread src/server/command/permission/group.zig Outdated
Comment thread src/server/command/permission/group.zig Outdated
Comment thread src/server/command/permission/group.zig Outdated
Comment thread src/server/command/permission/group.zig Outdated
Comment thread src/server/permission.zig Outdated
Comment thread src/server/permission.zig
Comment thread src/server/server.zig Outdated
Comment thread src/server/world.zig Outdated
defer groupDir.close();
var iterator = groupDir.iterate();
while (try iterator.next()) |file| {
if (file.kind == .file and std.mem.endsWith(u8, file.name, ".zon")) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be better to make two guard clauses out of that condition.

@IntegratedQuantum IntegratedQuantum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to keep the line changes down, could you please split this into 3 PRs:

  • one only adds the core groups system and saving/loading in the world
  • one adds the changes to the User
  • one adds the group command

Comment thread src/server/world.zig Outdated
Comment thread src/server/world.zig Outdated
try files.cubyzDir().writeZon(path, worldData);
}

pub fn loadPermissionGroups(_: *ServerWorld, dir: main.files.Dir) !void {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function should also be in permission.zig.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it completly

Comment thread src/server/permission.zig

pub fn init(allocator: NeverFailingAllocator) *PermissionGroup {
sync.threadContext.assertCorrectContext(.server);
currentId += 1;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should immediately save the metadata file.

Comment thread src/server/permission.zig Outdated
Comment thread src/server/world.zig Outdated
@Wunka

Wunka commented May 1, 2026

Copy link
Copy Markdown
Contributor Author

Ok I did a few changes, here is a summary:

  • for each group and the metadata zon exists now a bool which says if we need to save it. That means on saving only changed things are overwritten (means also we can save not only on closing of the world but also in between, but currently not done)
  • I noticed with the change to one file per group I never addressed deleting the file, so I introduced a queue for saving these removed groups (inspired by the userdeinitList) to make this work.
  • added more tests for success cases as asked by quantum
  • after making the most changes, I removed in commit 6d272bb and e82e54a the command and changes to the user, so that will be done in follow up PRs

@IntegratedQuantum IntegratedQuantum moved this from In review to High Priority in PRs to review May 31, 2026

@IntegratedQuantum IntegratedQuantum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also there are some unaddressed comments from the last review

Comment thread src/server/world.zig Outdated
try self.saveWorldConfig();

try self.saveAllPlayers();
try self.savePermissionGroups();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is force save called frequently enough? I think it may not be.

Is there any reason against immediately saving on change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its just my thinking of not having these "different" logics mixed up. I have added to world update that the groups are saved. But if you really want it I can just save where I currently have updated = true

@IntegratedQuantum IntegratedQuantum moved this from High Priority to In review in PRs to review Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

4 participants