CubeCoders / AMP

Issue tracking and documentation for AMP
https://cubecoders.com/AMP
206 stars 39 forks source link

JPath for Generic Template not writing to json file. #925

Closed JonathanArendt closed 1 month ago

JonathanArendt commented 1 year ago

Bug Report

System Information

I confirm:

Symptoms

Reproduction

Add the following lines to the appropriate part of the openRCT2 template At Greelan/AMPTemplates:openRCT2

This is the neccessary addition to metaconfig.json

    ,{
        "ConfigFile":"user-data/users.json",
        "AutoMap":true,
        "ConfigType":"json"
    }

This is the user-data/users.json file, which is the file that the settings should be set to.

[
    {
        "groupId": 0,
        "hash": "",
        "name": "Server"
    },
    {
        "groupId": 0,
        "hash": "",
        "name": ""
    }
]

Additional lines to config.json, settings show up, but settings are not being writen to file, JPath may be incorrect / not functioning properly.

    ,{
        "DisplayName":"User Name",
        "Category":"OpenRCT2 Beta Features",
        "Description":"User Name for first admin, this should be set inorder to mannage games. Your user name based off of name set ingame.",
        "FieldName":"UserName",
        "InputType":"text",
        "ParamFieldName":"$.[1].name",
        "Placeholder":"Admin Player",
        "EnumValues":{}
    }
    ,{
        "DisplayName":"User Hash",
        "Category":"OpenRCT2 Beta Features",
        "Description":"User Name for first admin, this should be set inorder to mannage games. Your user name based off of name set ingame.",
        "FieldName":"UserHash",
        "InputType":"text",
        "ParamFieldName":"$.[1].hash",
        "Placeholder":"159FFE6F65C528C581E7CE710DC02E15AA1E44B1",
        "EnumValues":{}
    }

Error Message from console log when settings are being change.

[23:43:24] [API:admin Activity]   : Changing setting Meta.GenericModule.UserHash to 682c924e2e22b3f5d3a5e7b89d3f3dd6182dcfae
[23:43:25] [Generic:admin Info]   : Merging config file ./openrct2/server/user-data/config.ini (INI format) using Unicode (UTF-8) encoding.
[23:43:25] [Generic:admin Info]   : Merging config file ./openrct2/server/user-data/config.ini (INI format) using Unicode (UTF-8) encoding.
[23:43:25] [Core:admin Warning]   : Returned exception from API call Core/SetConfig
[23:43:25] [Core:admin Error]     : JsonReaderException
[23:43:25] [Core:admin Error]     : [0] (JsonReaderException) : Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path '', line 1, position 1.
[23:43:25] [Core:admin Error]     :    at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings)
   at Newtonsoft.Json.Linq.JObject.Parse(String json, JsonLoadSettings settings)
   at GenericModule.ModuleMain.MergeJSON(String finalPath, MetaConfigFile fileInfo)
   at GenericModule.ModuleMain.WriteMetaconfigs()
   at GenericModule.ModuleMain.SaveChanges(String key, String value)
   at GSMyAdmin.WebServer.WebMethods.UpdateSetting(String node, String value, SettingCacheEntry entry, SettingSpec cache)
   at GSMyAdmin.WebServer.WebMethods.SetConfig(String node, String value)
   at GSMyAdmin.WebServer.WebAttributes.<InvokeMethod>()
   at GSMyAdmin.WebServer.APIService.<InvokeAPI>()
PhonicUK commented 12 months ago

You don't need the . after the $ - so it should be $[1].name

JonathanArendt commented 12 months ago
[15:51:32] [API:admin Activity]   : Changing setting Meta.GenericModule.UserName to Jonathan1
[15:51:33] [Generic:admin Info]   : Merging config file ./openrct2/server/user-data/config.ini (INI format) using Unicode (UTF-8) encoding.
[15:51:33] [Core:admin Warning]   : Returned exception from API call Core/SetConfig
[15:51:33] [Core:admin Error]     : ArgumentNullException
[15:51:33] [Core:admin Error]     : [0] (ArgumentNullException) : Value cannot be null.
Parameter name: input
[15:51:33] [Core:admin Error]     :    at Text.RegularExpressions.Regex.Replace(String input, MatchEvaluator evaluator)
   at GenericModule.GenericModuleConfig.ApplicationConfig.SubstituteTemplates(String input, Dictionary`2 variables)
   at GenericModule.ModuleMain.MergeINI(String finalPath, MetaConfigFile fileInfo)
   at GenericModule.ModuleMain.WriteMetaconfigs()
   at GenericModule.ModuleMain.SaveChanges(String key, String value)
   at GSMyAdmin.WebServer.WebMethods.UpdateSetting(String node, String value, SettingCacheEntry entry, SettingSpec cache)
   at GSMyAdmin.WebServer.WebMethods.SetConfig(String node, String value)
   at GSMyAdmin.WebServer.WebAttributes.<InvokeMethod>()
   at GSMyAdmin.WebServer.APIService.<InvokeAPI>()

Same log error I got a different error this time.

IceOfWraith commented 1 month ago

Are you still working on this? If so I'll reopen. But the error you're getting seems to be because you are adjusting the existing generic template and broke the settings file connection.