From c869464d812ad09709fa39fe508239f11ad0d390 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sun, 3 Dec 2017 12:56:34 -0700 Subject: [PATCH 1/3] Add DumpPermissionMatrix() which dumps a markdown permission matrix Note that -dump apparently isn't working lately. You probably want to call Utils.Dump() manually and invoke it in a custom build. --- TShockAPI/Utils.cs | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index 5081f8e4..2e0b8f82 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -1204,6 +1204,7 @@ namespace TShockAPI Permissions.DumpDescriptions(); ServerSideCharacters.ServerSideConfig.DumpDescriptions(); RestManager.DumpDescriptions(); + DumpPermissionMatrix("PermissionMatrix.txt"); DumpBuffs("BuffList.txt"); DumpItems("Items-1_0.txt", -48, 235); DumpItems("Items-1_1.txt", 235, 604); @@ -1212,6 +1213,7 @@ namespace TShockAPI DumpNPCs("NPCs.txt"); DumpProjectiles("Projectiles.txt"); DumpPrefixes("Prefixes.txt"); + if (exit) { Environment.Exit(1); @@ -1223,6 +1225,52 @@ namespace TShockAPI for(int i = 0; i < Main.recipe.Length; i++) Main.recipe[i] = new Recipe(); } + + // Dumps a matrix of all permissions and all groups in markdown format + // Hard coded to default groups because apparently we have poor querying tools + public void DumpPermissionMatrix(string path) + { + StringBuilder output = new StringBuilder(); + output.Append("|Permission|"); + + // Traverse to build group name list + foreach (Group g in TShock.Groups.groups) + { + output.Append(g.Name); + output.Append("|"); + } + + output.AppendLine(); + output.Append("|-------|"); + + foreach (Group g in TShock.Groups.groups) + { + output.Append("-------|"); + } + output.AppendLine(); + + foreach (var field in typeof(Permissions).GetFields().OrderBy(f => f.Name)) + { + output.Append("|"); + output.Append((string) field.GetValue(null)); + output.Append("|"); + + foreach (Group g in TShock.Groups.groups) + { + if (g.HasPermission((string) field.GetValue(null))) + { + output.Append("✔|"); + } + else + { + output.Append("|"); + } + } + output.AppendLine(); + } + + File.WriteAllText(path, output.ToString()); + } public void DumpBuffs(string path) { From 9aaf425330c040ee6161e798fd209f5bc3c9e475 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sun, 3 Dec 2017 15:04:50 -0700 Subject: [PATCH 2/3] Modify default permission sets to be more modern --- TShockAPI/DB/GroupManager.cs | 121 +++++++++++++++++++++++++++++++---- 1 file changed, 107 insertions(+), 14 deletions(-) diff --git a/TShockAPI/DB/GroupManager.cs b/TShockAPI/DB/GroupManager.cs index 9da13b9e..f952fee2 100644 --- a/TShockAPI/DB/GroupManager.cs +++ b/TShockAPI/DB/GroupManager.cs @@ -58,28 +58,121 @@ namespace TShockAPI.DB { // Add default groups if they don't exist AddDefaultGroup("guest", "", - string.Join(",", Permissions.canbuild, Permissions.canregister, Permissions.canlogin, Permissions.canpartychat, - Permissions.cantalkinthird, Permissions.canchat)); + string.Join(",", + Permissions.canbuild, + Permissions.canregister, + Permissions.canlogin, + Permissions.canpartychat, + Permissions.cantalkinthird, + Permissions.canchat)); AddDefaultGroup("default", "guest", - string.Join(",", Permissions.warp, Permissions.canchangepassword, Permissions.canlogout)); + string.Join(",", + Permissions.warp, + Permissions.canchangepassword, + Permissions.canlogout, + Permissions.summonboss, + Permissions.whisper, + Permissions.wormhole, + Permissions.canpaint)); - AddDefaultGroup("newadmin", "default", - string.Join(",", Permissions.kick, Permissions.editspawn, Permissions.reservedslot)); + AddDefaultGroup("vip", "default", + string.Join(",", + Permissions.reservedslot, + Permissions.renamenpc, + Permissions.startinvasion, + Permissions.summonboss, + Permissions.whisper, + Permissions.wormhole)); + + AddDefaultGroup("newadmin", "vip", + string.Join(",", + Permissions.kick, + Permissions.editspawn, + Permissions.reservedslot, + Permissions.annoy, + Permissions.checkaccountinfo, + Permissions.getpos, + Permissions.mute, + Permissions.rod, + Permissions.savessc, + Permissions.seeids, + "tshock.world.time.*")); AddDefaultGroup("admin", "newadmin", - string.Join(",", Permissions.ban, Permissions.whitelist, "tshock.world.time.*", Permissions.spawnboss, - Permissions.spawnmob, Permissions.managewarp, Permissions.time, Permissions.tp, Permissions.slap, - Permissions.kill, Permissions.logs, - Permissions.immunetokick, Permissions.tpothers)); + string.Join(",", + Permissions.ban, + Permissions.whitelist, + Permissions.spawnboss, + Permissions.spawnmob, + Permissions.managewarp, + Permissions.time, + Permissions.tp, + Permissions.slap, + Permissions.kill, + Permissions.logs, + Permissions.immunetokick, + Permissions.tpothers, + Permissions.advaccountinfo, + Permissions.broadcast, + Permissions.home, + Permissions.tpallothers, + Permissions.tpallow, + Permissions.tpnpc, + Permissions.tppos, + Permissions.tpsilent, + Permissions.userinfo)); AddDefaultGroup("trustedadmin", "admin", - string.Join(",", Permissions.maintenance, "tshock.cfg.*", "tshock.world.*", Permissions.butcher, Permissions.item, Permissions.give, - Permissions.heal, Permissions.immunetoban, Permissions.usebanneditem)); + string.Join(",", + Permissions.maintenance, + "tshock.cfg.*", + "tshock.world.*", + Permissions.butcher, + Permissions.item, + Permissions.give, + Permissions.heal, + Permissions.immunetoban, + Permissions.usebanneditem, + Permissions.allowclientsideworldedit, + Permissions.buff, + Permissions.buffplayer, + Permissions.clear, + Permissions.clearangler, + Permissions.godmode, + Permissions.godmodeother, + Permissions.ignoredamagecap, + Permissions.ignorehp, + Permissions.ignorekilltiledetection, + Permissions.ignoreliquidsetdetection, + Permissions.ignoremp, + Permissions.ignorenoclipdetection, + Permissions.ignorepaintdetection, + Permissions.ignoreplacetiledetection, + Permissions.ignoreprojectiledetection, + Permissions.ignorestackhackdetection, + Permissions.invade, + Permissions.startdd2, + Permissions.uploaddata, + Permissions.uploadothersdata)); - AddDefaultGroup("owner", "trustedadmin", string.Join(",", Permissions.su)); - - AddDefaultGroup("vip", "default", string.Join(",", Permissions.reservedslot)); + AddDefaultGroup("owner", "trustedadmin", + string.Join(",", + Permissions.su, + Permissions.allowdroppingbanneditems, + Permissions.antibuild, + Permissions.canusebannedprojectiles, + Permissions.canusebannedtiles, + Permissions.managegroup, + Permissions.manageitem, + Permissions.manageprojectile, + Permissions.manageregion, + Permissions.managetile, + Permissions.maxspawns, + Permissions.serverinfo, + Permissions.settempgroup, + Permissions.spawnrate, + Permissions.tpoverride)); } // Load Permissions from the DB From d1500d78410f04339905ca1ac7cea76a3cb7bba2 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sun, 3 Dec 2017 15:13:30 -0700 Subject: [PATCH 3/3] Update changelog w/ permissions --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 11c6aad5..ac93c9c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Added /region rename and OnRegionRenamed hook (@koneko-nyan, @deadsurgeon42) * Added /su, which temporarily elevates players with the tshock.su permission to super admin. In addition added, a new group, owner, that is suggested for new users to setup TShock with as opposed to superadmin. Finally, /su is implemented such that a 10 minute timeout will occur preventing people from just camping with it on. (@hakusaro) * Added /sudo, which runs a command as the superadmin group. If a user fails to execute a command but can sudo, they'll be told that they can override the permission check with sudo. Much better than just telling them to run /su and then re-run the command. (@hakusaro) +* Default permission sets for new databases are more modern. (@hakusaro) ## TShock 4.3.24