Hi there! Congrats on your first plugin release.
Just looked at the plugin; you're definitely leaking
obj. What you'll want to do is not assign any
JSON_Object handles back to
obj, as you need to call
Cleanup() on the initial handle after you're done with the loop. Instead, you should assign them to separate
JSON_Object handles (which I think you don't need to clean up as they're nested objects). Haven't looked at the JSON library, but I think you can also chain the getters together like so:
Code:
JSON_Object collectionEntry = obj.GetObject("response").GetObject("collectiondetails").GetObjectIndexed(0);
collectionEntry.GetString("publishedfileid", id, sizeof(id));
JSON_Object collectionItems = collectionEntry.GetObject("children");
You're also leaking
item since you instantiate an initial
JSON_Object and then assign a new handle in the loop (the original gets lost entirely). Declare
JSON_Object item in the loop, the cleanup routines should be fine.
I think it's an odd choice to have
tf_workshop_map_collection as a command instead of a ConVar, but I suppose the command would work just fine.
All that said, I'm curious; what use case does this plugin serve? In my experience, Workshop maps are already synced from the file referenced in
mapcyclefile, and you can
sm_map workshop/any_valid_workshop_map_id or
changelevel and the server will change to it without performing any prior syncing (though of course it may need to download the map in that case).
(Disclaimer: I wrote
py-mapcyclefile and its successor
workshopmaps.py to automate syncing Workshop collections into my map cycles.)
__________________