Official Soldat Forums
Server Talk => Scripting Releases => Topic started by: DeMo on May 11, 2007, 07:36:30 pm
-
Script Name: Edit soldat.ini via admin
Script Description: These functions enable you to read (/rconf) and write (/wconf) values to/from your server's soldat.ini via admin (adminlog, ARSSE, ESA etc). You can read current values and write new ones as well, this enables you to reconfigure certain aspects of your server on the fly, without the need to re-upload soldat.ini everytime.
Original Author(s): DeMo
Core Version: 1.0.0 (sv2.6.0)
Requeriments: KeYDoN's xsplit (http://forums.soldat.pl/index.php?topic=12742.0)
Procedure to read values:
procedure readConf(params : string);
var
section, key : string;
args : TStringArray;
begin
args := xsplit(params, ' ');
//check if params were passed
if (ArrayHigh(args) = 0) then begin
WriteLn('RCONF ERROR: No parameters passed.');
exit;
end;
//argument ok, check if is in form section\key
if (ContainsString(args[1], '\')) then begin
section := uppercase(GetPiece(args[1], '\', 0));
key := GetPiece(args[1], '\', 1);
end
else begin
WriteLn('RCONF ERROR: Invalid format, use Section\Key');
exit;
end;
//check if section is valid
if ((section = 'GAME') OR (section = 'NETWORK') OR (section = 'BOTS')) then begin
WriteLn('RCONF: '+ section + '\' + key + ' = ' + ReadINI('soldat.ini', section, key, 'Invalid Key!'));
end
else begin
WriteLn('RCONF ERROR: Invalid Section (' + section + '), use GAME, NETWORK or BOTS');
end;
end;
Usage: /rconf Section\Key (not case sensitive)
Example: /rconf game\max_grenades
Procedure to write values:
procedure writeConf(params : string);
var
section, key, newfile : string;
args, strlist : TStringArray;
i : integer;
begin
args := xsplit(params, ' ');
//check if params were passed
if (ArrayHigh(args) = 0) then begin
WriteLn('WCONF ERROR: No parameters passed.');
exit;
end;
//argument ok, check if is in form section\key
if (ContainsString(args[1], '\')) then begin
section := uppercase(GetPiece(args[1], '\', 0));
key := GetPiece(args[1], '\', 1);
end
else begin
WriteLn('WCONF ERROR: Invalid format, use Section\Key');
exit;
end;
//argument and format ok, check if new value was passed
if (ArrayHigh(args) = 1) then begin
WriteLn('WCONF ERROR: No value specified! (ie: /writeconf network\ase_register 1)');
exit;
end;
//all ok, check section and write value
if ((section = 'GAME') OR (section = 'NETWORK') OR (section = 'BOTS')) then begin
strlist := xsplit(ReadFile('soldat.ini'), chr(13)+chr(10));
for i := 0 to ArrayHigh(strlist) do begin
if (MaskCheck(uppercase(strlist[i]), uppercase(key + '=*')) = True) then begin
//change the key
strlist[i] := key + '=' + args[2];
WriteLn('WCONF: ' + key + ' changed to: ' + args[2]);
break;
end
else begin
if (i = ArrayHigh(strlist)) then begin
WriteLn('WCONF ERROR: Invalid key (' + key + ')!');
exit;
end;
end;
end;
//rewrite the file
newfile := strlist[0];
for i := 1 to ArrayHigh(strlist) do begin
newfile := newfile + chr(13)+chr(10) + strlist[i];
end;
WriteFile('soldat.ini', newfile);
WriteLn('WCONF: soldat.ini successfully rewritten!');
end
else begin
WriteLn('WCONF ERROR: Invalid Section (' + section + '), use GAME, NETWORK or BOTS');
end;
end;
Usage: /wconf Section\Key value (not case sensitive)
Example: /wconf game\max_grenades 4
Don't forget to add the calls to the OnCommand event in Core.pas
function OnCommand(ID: Byte; Text: string): boolean;
begin
if (StrPos('/rconf', Text) > 0) then begin
readConf(Text);
Result := false;
end;
if (StrPos('/wconf', Text) > 0) then begin
writeConf(Text);
Result := false;
end;
end;
**IMPORTANT**: After writing new values to your soldat.ini, don't forget to send the /loadcon command to make the server read the new config!!
If you have any questions, critics or suggestions feel free to post here or PM me.
Also, should you find any bugs.. please let me know!
Hope you like it.
-
I didn't test it, but i have to admit it's a very nice job. Can be usefull as well. I think I'm gonna use it to change what weapons are available, to enable dodge-ball mode on the fly. :D
-
I thought that the WriteFile procedure now only adds text to the beginning of the file, as it seems to be doing for the 2.6.1 prerelease... maybe not on the 2.6.0... or im going crazy.
I havn't tested it neither but it looks great though!
-
Dorkey, it should work fine in 2.6.0 and 2.6.1 using Keydon's xsplit function.
The way I programmed it, it first loads your soldat.ini into a string, then searches this string for the parameter you want to change, once it finds the parameter it replaces the value and rewrites everything back to soldat.ini. In theory there's no way it'll write something in the wrong section, but I'll do some testing.
-
Please post this script in .zip archive
-
In your procedure to write values you are missing some semi-colons on a couple end statements.
You should only leave out the semi-colon if the next line is an else statement.
Until you fix these errors this script will not be compatible with my script combiner. :(
-
Thank you mike, guess it's fixed now.
I'm not a pascal programmer, when I wrote the code I had some trouble trying to identify where to use and not to use the semicolon. ;)
@kusyi
Why do you need a .zip? Can't you just copy and paste the code?
-
i can't combine my scripts(
-
You can use my script combiner:
http://scriptcombiner.awardspace.com/