Raised This Month: $7 Target: $400
 1% 

[INCLUDE] AutoExecConfig: Read and append to auto configs


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Impact123
Veteran Member
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?
In short, this provides the missing functionality to update your autoconfig if you add new convars to your plugins.
When i wrote this I've worked on a bigger project where convars were added very often and telling people to rewrite their configs made me hesitant to add them.
In times of plugins like the updater people expect to not have to add new convars by hand.
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 can be cleaned from unnecessary white spaces created by the user or autoexecconfig itself. This is done purely for the viewer's pleasure and to conserve some bytes.


The source / Download
You can view the source and some more information on Github.
Feel free to send pull requests, ideas, criticism or enhancements.


Limitations
Although most 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.



Notes
This include requires a sourcemod compiler with version 1.7+, 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 find a bug or have suggestions.


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 void OnPluginStart()
{
    
// Set the file for the include, the extension 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 should be done at the end
    
AutoExecConfig_CleanFile();

__________________

Last edited by Impact123; 04-09-2021 at 13:42.
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 offline
Impact123
Veteran Member
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
Veteran Member
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
dordnung
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 dordnung; 01-20-2013 at 08:36.
dordnung is offline
Impact123
Veteran Member
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
dordnung
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^^
__________________
dordnung is offline
Impact123
Veteran Member
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 02:08.


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