PDA

View Full Version : Forms - Export/Import users



mixster
02-23-2008, 10:21 PM
After starting my script a while back, I dived into the uses of creating INI files to store data, thus the ExportUsers and ImportUsers was forged. It's very simple and should be easy to see how it works. You may need to tweak a couple of things depending on how your form works, but otherwise it *should* work straight oput the box. Also, you can change the filename it saves it as (I would recommend making it a const, but I just had it in like this because I was too lazy to scroll up when scripting it). To use it, just plop it in then make an export and import button, then direct them to the appropriate procedure.

Procedure ExportUsers(Sender: TObject);
Var
i: Integer;

Begin
For i:= 0 To GetArrayLength(Players) - 1 Do
Begin
WriteINI('Player' + IntToStr(i), 'Username', Players[i].Name, ScriptPath + 'sUsers.ini');
WriteINI('Player' + IntToStr(i), 'Password', Players[i].Pass, ScriptPath + 'sUsers.ini');
WriteINI('Player' + IntToStr(i), 'Nickname', Players[i].Nick, ScriptPath + 'sUsers.ini');
WriteINI('Player' + IntToStr(i), 'Active', BoolToStr(Players[i].Active), ScriptPath + 'sUsers.ini');
End;
End;

Procedure ImportUsers(Sender: TObject);
Var
i,ii: Integer;

Begin
While(Not(ReadINI('Player' + IntToStr(i), 'Username', ScriptPath + 'sUsers.ini') = '') and (i < 50)) Do
Inc(i);
Dec(i);
SetArrayLength(Players,i+1);
For ii:= 0 to i do
Begin
Players[ii].Name:= ReadINI('Player' + IntToStr(ii), 'Username', ScriptPath + 'sUsers.ini');
Players[ii].Pass:= ReadINI('Player' + IntToStr(ii), 'Password', ScriptPath + 'sUsers.ini');
Players[ii].Nick:= ReadINI('Player' + IntToStr(ii), 'Nickname' ,ScriptPath + 'sUsers.ini');
Players[ii].Active:= StrToBool(ReadINI('Player' + IntToStr(ii), 'Active', ScriptPath + 'sUsers.ini'));
End;
FCurPla:= 0;
edName.Text:= Players[FCurPla].Name;
edPass.Text:= Players[FCurPla].Pass;
edNick.Text:= Players[FCurPla].Nick;
cbActive.Text:= BoolToStr(Players[FCurPla].Active);
End;


Note: This was before the end of my over-capitalizing phase, so lots of capitals, yay!

Dan Cardin
02-24-2008, 11:24 PM
does that mean that you're going to have 4 .ini files per player? :( thats kinda...ehh. You could use something else...like make it write it all in one ini then write like
Password:'blaj';and use the between function and do like Password' and '; :)

Negaal
02-25-2008, 06:14 AM
Oh, smart, simple and effective:)

@Dan, there is no point is using between in reading ini's? You can read specific line with 1 command...don't remember exactly. I think im right.

mixster
02-25-2008, 07:17 AM
@Dan Cardin - It sets up 1 file for all the players (the end string in readINI and WriteINI). Player0, Player1 etc. are all sections, that then have Username, Password, Nickname and Active as sections in each player section, which are then assigned the players details.

@Negaal - Thanks, I used them after getting pissed off at my StrToArray function when I kept assigning things to the wrong array (ended up having all the usernames for the 1st person, all the password for the 2nd etc.) so I checked out INI's after seeing them in the Scar manual when seeing other things. I played with them for a bit and got the general hang of it and added it to my form template (it's got infinite players and everything!).

Also, as a note, it can't take more than 50 players atm as I doubted anyone would have more than that, but that just stops it reading an infinitely long file if the file gets messed up somehow. If you need more than 50, you just change the number in the repeat loop (for the file reading).

Sumilion
02-25-2008, 10:24 AM
There is something very similar to this in the SRLPlayerForm you know :).

It exports your players info into a DeclarePlayers; procedure and saves this as a scar file in your desired location. Check it out, it's pretty neat.

Dan Cardin
02-25-2008, 12:01 PM
oops i didnt see the commas and thought that the whole thing was the name of the file :p

mixster
02-25-2008, 03:54 PM
I knew I could never make anything original. Ahwell, atleast I made it much simpler and it saves it to a place you can change easily :) Took me a while to find SRLPlayerForm though, I looked for the filename most matching play in the misc section and I checked atleast 5 others before finding users.scar >< I'm just glad I finally found the form though, it looks kickass and it will only be a matter of time until I steal, err I mean, make something similar for my default script file :p

Sumilion
02-25-2008, 04:20 PM
I knew I could never make anything original. Ahwell, atleast I made it much simpler and it saves it to a place you can change easily :) Took me a while to find SRLPlayerForm though, I looked for the filename most matching play in the misc section and I checked atleast 5 others before finding users.scar >< I'm just glad I finally found the form though, it looks kickass and it will only be a matter of time until I steal, err I mean, make something similar for my default script file :p

Haha go ahead :) It is for use and learning purposes only I suppose :D