SRL Archive - OSR Help

How can I pull my login information from an external file?


jimthesoundman

2010-01-31 23:52:03

I'd like to have my scripts go to an external file and pull my username, password, and pin number. What is the most efficient way to do that?

I know I probably need to use ReadINI and WriteINI but I don't know how to do that.

Thanks in advance,

JIM

i luffs yeww

2010-01-31 23:54:22

Uhh.. shouldn't you know that info? :p

Frement

2010-02-01 00:04:45

I wrote a function, dont know if it works, you should try it.
function ReadTheFile( PathToFile: String; I: Integer ): String;
var S: String;
F: Integer;
TheArray: Array of String;
begin
F := OpenFile( PathToFile, False );
ReadFileString( F, S, FileSize( F ) );
CloseFile( F );
TheArray := Explode( ';', S );
Result := TheArray[ I ];
end;

Should read in the file like: username;password;pin

For username I is 0, and for password it is 1, etc.

Wanted

2010-02-01 00:06:59

Easiest way would to be Savesetting/load setting as it's pretty fail proof, WriteCharsfile string is a kinda tricky… I'd recommend INI files as they are easy to manage and manipulate.

jimmy_mac

2010-02-01 00:08:46

jimthesoundman: you could make a scar script and save it in the include folder which has this in it:
procedure DeclarePlayers;
begin
HowManyPlayers := 1; //Total Number of Players.
CurrentPlayer := 0; //Starting Player.
NumberOfPlayers(HowManyPlayers);

Players[0].Name :='username'; //Username.
Players[0].Pass :='password'; //Password.
Players[0].Nick :='ern'; //Nickname. (4 Letters of your username)
Players[0].Active := True; //Is the player active?
Players[0].Pin := '1234'; //Leave blank if you dont have one.
end;

then put this in your script:
{.include LoginDetails.scar}

Frement

2010-02-01 00:28:03

program TheFile;

function ReadTheFile( PathToFile: String; I: Integer ): String;
var S: String;
F: Integer;
TheArray: Array of String;
begin
F := OpenFile( PathToFile, False );
ReadFileString( F, S, FileSize( F ) );
CloseFile( F );
TheArray := Explode( ';', S );
Result := TheArray[ I ];
end;

function WriteTheFile( PathToFile, NewString: String; I: Integer ): Boolean;
var S, TheString: String;
F, O: Integer;
TheArray: Array of String;
begin
TheString := '';
F := OpenFile( PathToFile, False );
ReadFileString( F, S, FileSize( F ) );
CloseFile( F );
TheArray := Explode( ';', S );
TheArray[ I ] := NewString;
for O := 0 to GetArrayLength( TheArray ) - 1 do
begin
if not ( O = 0 ) then begin
TheArray[ O ] := ';' + TheArray[ O ];
end;
TheString := TheString + TheArray[ O ];
end;
F := RewriteFile( PathToFile, False );
WriteFileString( F, TheString );
CloseFile( F );
Result := True;
end;

begin
Writeln( ReadTheFile( ScriptPath + 'test.txt', 0 ) );
Writeln( ReadTheFile( ScriptPath + 'test.txt', 1 ) );
Writeln( ReadTheFile( ScriptPath + 'test.txt', 2 ) );
WriteTheFile( ScriptPath + 'test.txt', 'usernametest', 0 );
Writeln( ReadTheFile( ScriptPath + 'test.txt', 0 ) );
WriteTheFile( ScriptPath + 'test.txt', 'passwordtest', 1 );
Writeln( ReadTheFile( ScriptPath + 'test.txt', 1 ) );
WriteTheFile( ScriptPath + 'test.txt', 'pintest', 2 );
Writeln( ReadTheFile( ScriptPath + 'test.txt', 2 ) );
end.

{OUTPUT:
Successfully compiled (25 ms)
username
password
pin
usernametest
passwordtest
pintest
Successfully executed
FILE:
username;password;pin
}

The function worked good but i still recommend to use ini files.

E: Added a write function.

jimthesoundman

2010-02-01 02:07:35

Thank you all for your help. Very informative.

i luffs yeww

2010-02-01 02:22:12

I'm still confused on why you need this..?