BadgerCode / tttdamagelogs

Damagelogs and RDM Manager for Trouble in Terrorist Town (a Garry's Mod gamemode)
GNU General Public License v3.0
20 stars 23 forks source link

WIP: Move config and the MySql config into the data folder as json files. #79

Closed wgaylord closed 1 year ago

wgaylord commented 1 year ago

This pull request adds a new file in the config folder called config_loader.lua It has 4 functions two related to the config.lua and two related to mysqloo.lua

The config.lua related function load and save the values present in config.lua from and to a file stored in data/damagelog/config.json

The mysqloo.lua related functions do the same but for the settings in mysqloo.lua

Each entry is checked if it exists in the load function after the json is load as a table. This way if a new version of tttdamagelogs introduces a new config option everyone's configs are still valid. If any are missing it will then save the config which will save the defaults fron config.lua into the json file.

This is also a pathway for existing users to port their existing config.lua to the new json format. If the json files does not exist the load function will save the defaults, (values fron config.lua) and then return as if it had loaded properly.

This is an example of the json config file. (saved as a txt since I can't upload json to github on an PR) config.txt

Annoying you can't sort keys when using util.TableToJSON.

While the feature is complete this is a work in progress since I am not sure I am happy about how I have the json file setup. (Breaking things up into groups)

This is part of solving #60

BadgerCode commented 1 year ago

Wow this is awesome! ❤️ I've wanted this for a long time as it's crucial to the workshop version being usable by server owners.

I see you've also ensured it will first use the existing configuration lua file. Great job! This is important for anyone upgrading from a previous version of the damagelogs.

I will not be able to access my computer until next week, so unfortunately I will have to wait until sometime then to test this.

BadgerCode commented 1 year ago

Here's the example config.json you included in your PR description:

{
    "Reports": {
        "MoreReportsPerRound": false,
        "ReportsBeforePlaying": false,
        "NoStaffReports": false
    },
    "DiscordWebhookMode": 0.0,
    "PrivateMessagePrefix": "[RDM Manager]",
    "AbuseMessageMode": 0.0,
    "ForcedLanguage": "",
    "RDM_Manager_Enabled": true,
    "HideDonateButton": false,
    "Autoslay": {
        "Autoslay_CheckCustom": false,
        "DefaultReason11": "Trolling",
        "DefaultReason9": "Prop kill",
        "DefaultReason3": "2x RDM",
        "DefaultReason5": "Mass RDM",
        "DefaultReason6": "Super Mass",
        "ShowRemainingSlays": false,
        "DefaultReason10": "Consistent RDM",
        "DefaultReason8": "Hacking",
        "DefaultReason1": "Random Damage",
        "DefaultReason2": "RDM",
        "DefaultReason12": "Minge",
        "ULX_Autoslay_ForceRole": false,
        "DefaultReason": "Breaking Rules",
        "DefaultReason4": "Attempted Mass",
        "DefaultReason7": "Ghosting",
        "ULX_AutoslayMode": 1.0
    },
    "Use_MySQL": false,
    "LogDays": 61.0,
    "UseWorkshop": true,
    "Commands": {
        "RDM_Manager_Command": "!report",
        "Respond_Command": "!respond"
    },
    "Key": 99.0,
    "Permissions": {
        "owner": [
            4.0,
            true
        ],
        "founder": [
            4.0,
            true
        ],
        "admin": [
            4.0,
            true
        ],
        "superadmin": [
            4.0,
            true
        ],
        "operator": [
            3.0,
            false
        ],
        "user": [
            2.0,
            false
        ]
    },
    "Ban": {
        "DefaultReason6": "Super Mass",
        "DefaultReason7": "Ghosting",
        "DefaultReason8": "Hacking",
        "DefaultReason11": "Random Damage",
        "DefaultReason1": "Random Damage and leave",
        "AllowBanningThruManager": true,
        "DefaultReason2": "RDM and leave",
        "DefaultReason12": "Trolling",
        "DefaultReason3": "2x RDM and leave",
        "DefaultReason10": "Attempted RDM",
        "DefaultReason4": "Attempted Mass and leave",
        "DefaultReason9": "Consistent RDM",
        "DefaultReason5": "Mass RDM"
    }
}
BadgerCode commented 1 year ago

And here's the existing lua config: https://github.com/BadgerCode/tttdamagelogs/blob/master/lua/damagelogs/config/config.lua

Mysql: https://github.com/BadgerCode/tttdamagelogs/blob/master/lua/damagelogs/config/mysqloo.lua

As a part of testing, I will go over the JSON schema and compare it to the existing configuration files, to make sure nothing has been missed.

wgaylord commented 1 year ago

I will say that annoying KEY saves as a number, in this case KEY_F8 saves as 99 in the JSON. Which might be annoying for some people until we get a configuration GUI working.

BadgerCode commented 1 year ago

Does the GLUA JSON parser allow for comments in JSON? E.g.

{
  "someProperty": 1
  /* 1 = option a, 2 = option b, 3 = option c */
}
BadgerCode commented 1 year ago

Worth noting that there is a configuration section of the wiki. https://github.com/BadgerCode/tttdamagelogs/wiki/Configuring-the-damage-logs

I could add some more information to it, to explain the various properties

wgaylord commented 1 year ago

Does the GLUA JSON parser allow for comments in JSON? E.g.

{
  "someProperty": 1
  /* 1 = option a, 2 = option b, 3 = option c */
}

Just tested and it does not support having comments. And even if it did there would be no way to insert them from the lua side when we save a config. I do think that having the wiki with all the configuration information would be useful. (I wish you could make Pull Requests for wiki edits.)

BadgerCode commented 1 year ago

I shall try to take a look at this today/tomorrow now that I'm back home!

Regarding the wiki, I will look into some way to make it possible for people to submit PRs for wiki edits.

Right now, the configuration is documented on one page: https://github.com/BadgerCode/tttdamagelogs/wiki/Configuring-the-damage-logs

BadgerCode commented 1 year ago

Hey!

Sorry, it's been a busy few weeks. This will have to wait until about 2 weeks time (busy month for me).

BadgerCode commented 1 year ago

Heyo! Just to let you know I haven't forgotten about this. I'm hoping to have a look at it sometime this week.

BadgerCode commented 1 year ago

Overall approach

BadgerCode commented 1 year ago

Here are the tests I'm going to do

QA

wgaylord commented 1 year ago

Overall approach

  • ✅ Make sure the JSON looks good enough (since it's hard to change afterwards)

    • Overall, looks good

    • Autoslay

    • Could contain an array of default reasons

    • Ban

    • Could contain an array of default reasons

    • Permissions

    • Mapping: String role name -> Permissions array

      • Could be an object instead "user": { "access_level": 2, can_access_rdm_manager: false }
  • ✅ Make sure it loads config in the right order

    1. Default config (could be defined in Lua)
    2. Then Lua config
    3. Then JSON config
  • ✅ It should be easy to add new properties

    • The logic in lua\damagelogs\config\config_loader.lua could be simplified

    • Using https://wiki.facepunch.com/gmod/table.Merge

      • Overwrite the lua config with any properties that exist in the JSON
      • Always re-save the JSON, to add any new properties (remove the missing = 1 check)

I will look into working on some of this. As for the array for default ban and slay reasons I went the way I did since the rest of the damagelogs code uses that instead of an array. Also I agree with the permissions array stuff.

I forgot about table.Merge so I will working on re-doing that stuff to work with it and always resave the json as well.

wgaylord commented 1 year ago

I have just done some of the modifications, re did the config loading. Now uses merge. (It still does some a bit complicated when reading the perms, but thats explained in a comment.)

Currently it uses whats ever in the config.lua as the default / where to get the values if they are not in the JSON config.

Implemented the changes to the user rights area of the config.

wgaylord commented 1 year ago

Once you fine with the state of it I will squash the commits down to one.. (Or at least try my best to.)

BadgerCode commented 1 year ago

Heyo!

Sorry for the mega wait on this and the lack of updates. I will release a new version of the damage logs with these changes this weekend.

BadgerCode commented 1 year ago

Looks good! I'll give it a test now.

I might add a comment in the config.lua file, detailing what needs to be changed anytime a new configuration setting is added

We might also be able to simplify this process somehow

BadgerCode commented 1 year ago

QA

BadgerCode commented 1 year ago

I shall merge this in and update the wiki

BadgerCode commented 1 year ago

Wiki updated https://github.com/BadgerCode/tttdamagelogs/wiki/Configuring-the-damage-logs

BadgerCode commented 1 year ago

This has now been released https://github.com/BadgerCode/tttdamagelogs/releases/tag/v3.6.0