Raised This Month: $476 Target: $400
 119% 

[INCLUDE] AutoExecConfig: Read and append to auto configs


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Impact123
AlliedModders Donor
Join Date: Oct 2011
Location: Germany
Old 12-28-2012 , 22:28   [INCLUDE] AutoExecConfig: Read and append to auto configs
Reply With Quote #1

What is this?
We all know how cool the autoexecconfig function is, but also that it doesn't support appending if you add a new convar.
There are several threads and also a few bug reports mentioning this, but somehow nobody wrote an complete working solution till now.
Currently i work on a bigger project where convars sometimes are added every second release.
In times of plugins like the updater, people expect to not have to add new convars by hand at release.
Enough reasons for me to try to write an solution for this "mess".
The most important things i had in mind were security, performance, easy implementation and consistent files (white spaces, newlines)

I've came up with a working but relatively slow solution with some limitations.


How does it work?
If you add a convar with the appropriate function it will be searched in the auto-config-file you have set before.
If it can't be found within the file, it will add it with the information you created the convar with.
After that, the file should be cleaned from unnecessary white spaces created by the user or autoexecconfig itself. This is done purely for the viewers pleasure and to conserve some bytes.


Isn't that expensive?
It is, unfortunately file operations are expensive, there's nothing i can do about it.
You can run the example file and see for yourself how fast it is.


The source
You can view the source and some more information on Github.
I'd love to receive pull request over Github and/or hear some ideas, criticism or enhancements.


Limitations
Although all functions return something, some also multiple defined values/codes, you currently can't get the return of the parser/appender while adding a convar.
This could be fixed with a by ref value, but i feel that, in some cases, it would make the command longer than it needs to be.
As a workaround this can be retrieved directly after you created a convar with one of the AutoExecConfig_Get*Result functions.
If you clean the configfile from white spaces or other unnecessary chars, also those made by users are removed.


Notes
This include requires the sourcemod 1.7 compiler, see here for more information.
The prototype or name of some functions may be changed or even removed in later versions, but this will not cause compatibility issues with plugins.
Convars with a FCVAR_DONTRECORD flag will be skipped by the appender.
The parser will ignore spaces between convars and values, inside values or behind values for security.
The search, by default, is case sensitive.
The cleaner will format your file the way autoexecconfig does, 2 spaces after information, 1 after convars.
The value of a convar must be quoted, otherwise the parser will not find it.
Please let me know if you use this in your plugin. I'm interested in how it's used.


Implementing
Here is a basic example of the usage. Please also take a look at the include file and the test plugin for more functions.
PHP Code:
public OnPluginStart()
{
    
// Set the file for the include, the extnesion can be omitted
    
AutoExecConfig_SetFile("plugin.myplugin");

    
AutoExecConfig_CreateConVar("sm_myplugin_enabled""1""Whether or not this plugin is enabled");
    
AutoExecConfig_CreateConVar("sm_myplugin_chattrigger""myplugin""Chattrigger to open the menu of this plugin");
    
AutoExecConfig_CreateConVar("sm_myplugin_adminflag""b""Adminflag needed to use the chattrigger");

    
// This makes an internal call to AutoExecConfig with the given configfile
    
AutoExecConfig_ExecuteFile();

    
// Cleaning is an relatively expensive operation and should be done at the end
    
AutoExecConfig_CleanFile();

__________________

Last edited by Impact123; 04-07-2015 at 23:22. Reason: Spelling and grammar
Impact123 is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 12-29-2012 , 00:06   Re: [INCLUDE] Autoexecconfig read and append beta
Reply With Quote #2

This is a really cool contribution, but it really should be a part of Core alongside AutoExecConfig.
__________________
asherkin is online now
Impact123
AlliedModders Donor
Join Date: Oct 2011
Location: Germany
Old 12-29-2012 , 01:58   Re: [INCLUDE] Autoexecconfig read and append beta
Reply With Quote #3

Thanks.
One of the bugs i referred to is this five year old one, maybe sometime it will be supported natively.

Yours sincerely
Impact
__________________

Last edited by Impact123; 12-29-2012 at 03:21.
Impact123 is offline
Impact123
AlliedModders Donor
Join Date: Oct 2011
Location: Germany
Old 12-30-2012 , 18:36   Re: [INCLUDE] Autoexecconfig read and append beta
Reply With Quote #4

Just an little statusupdate here.

Cleaner now must be called by the developer, it was just too expensive to call it everytime a cvar was added, performance should be a lot better now.
In addition to that change i added some defined return values to the function.
Because you can't see the parser or appenderresults while adding a cvar i've added two functions to grab the results as an workaround for that.
All functions which you can input an buffer to now safely terminate it even if the function fails.
There now is a function with which you can get the formatted autoconfigfilepath if you need to.
Also i've came to test it on linux, as i thought it works fine there too.

Yours sincerely
Impact
__________________

Last edited by Impact123; 12-31-2012 at 12:36.
Impact123 is offline
Root_
Veteran Member
Join Date: Jan 2012
Location: ryssland
Old 01-06-2013 , 04:15   Re: [INCLUDE] Autoexecconfig read and append beta
Reply With Quote #5

Interesting and useful idea! I would like to see that in future sourcemod releases.
It looks nice (especially because I need only <include> file for working!) I'll give it a try to my future plugins! Thanks
__________________


dodsplugins.com - Plugins and Resources for Day of Defeat
http://twitch.tv/zadroot
Root_ is offline
Popoklopsi
Veteran Member
Join Date: Apr 2010
Old 01-20-2013 , 08:36   Re: [INCLUDE] Autoexecconfig read and append beta
Reply With Quote #6

SetFile looks only in cfg/sourcemod, but config files can also be only in the cfg folder!

When appending a new cvar, a long description get cut, don't know why.
__________________

Last edited by Popoklopsi; 01-20-2013 at 08:36.
Popoklopsi is offline
Impact123
AlliedModders Donor
Join Date: Oct 2011
Location: Germany
Old 01-20-2013 , 12:48   Re: [INCLUDE] Autoexecconfig read and append beta
Reply With Quote #7

Nice find, i'll look into it and report back.
This must come from cleanfile, it's copybuffer is 128 in size, how long is your description?

Yours sincerely
Impact
__________________
Impact123 is offline
Popoklopsi
Veteran Member
Join Date: Apr 2010
Old 01-20-2013 , 12:51   Re: [INCLUDE] Autoexecconfig read and append beta
Reply With Quote #8

Yes that could be^^ it have 154 symbols, but it breaks at 60^^
__________________
Popoklopsi is offline
Impact123
AlliedModders Donor
Join Date: Oct 2011
Location: Germany
Old 01-20-2013 , 13:53   Re: [INCLUDE] Autoexecconfig read and append beta
Reply With Quote #9

I've made some changes to the file, tell me if this works out for you.

Raw changelog


Yours sincerely
Impact
__________________
Impact123 is offline
TnTSCS
AlliedModders Donor
Join Date: Oct 2010
Location: Undisclosed...
Old 07-29-2013 , 11:22   Re: [INCLUDE] Autoexecconfig read and append beta
Reply With Quote #10

Updated my iBots plugin to use this - I missed this when you first posted it, but I'm glad I found it... thank you.
__________________
View my Plugins | Donate
TnTSCS is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:25.


Powered by vBulletin®
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Theme made by Freecode