0 Members and 1 Guest are viewing this topic.
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;
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;
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;