| Mirage Source http://miragesource.net/forums/ |
|
| Binary Accounts... The Easy Way http://miragesource.net/forums/viewtopic.php?f=210&t=920 |
Page 1 of 1 |
| Author: | Obsidian [ Fri Dec 22, 2006 7:24 am ] |
| Post subject: | Binary Accounts... The Easy Way |
Alright as many of you (especially Sise Tutorial Difficulty 2/5 - Easy Okay so in Dave's tutorial (who i'm not downplaying.. dave is my hero), you would store every value individually into the binary file after you opened it, which is not a bad way of doing it. My way however, there is one simple line to both load and save, after the binary file is open. The only current drawback, however, is that it also stores your AccountVariables (the temoraries), into your account along with all of your account stuff. Not that it's a huge deal... you store like an extra 20 Bytes or something per account... but if you want... (since i know that Dave will kill me if i don't mention it), is create another UDT that's something like Type TempPlayerRec, store the info there, and pull it from that rather than the Account or PlayerRecs. But, without further adieu... onto the easy tutorial. First would be the... Save Player Sub. Now since this is all incredibly easy i'm not going to explain line by line, but simply post the code. Code: Sub SavePlayer(ByVal index As Long) Dim FileName As String Dim f As Long FileName = App.Path & "\accounts\" & Trim$(Player(index).Login) & ".bin" f = FreeFile Open FileName For Binary As #f Put #f, , Player(index) Close #f End Sub However, the Line, "Put #f, , Player(index)" should be of particular interest... that's the line that saves EVERYTHING. It basically goes through the UDT line at a time and stores it all into the binary file. After it has completed storing it... it closes the file. See how easy that was!!!!!!!! Okay same thing, but using get, rather than put... yep, you guessed it! LoadPLayer!!!!! Code: Sub LoadPlayer(ByVal index As Long, ByVal name As String) Dim FileName As String Dim f As Long Call ClearPlayer(index) FileName = App.Path & "\accounts\" & Trim(name) & ".bin" f = FreeFile Open FileName For Binary As #f Get #f, , Player(index) Close #f End Sub Okay now, these are only minor adjustments that need to be made to these other files, just so it verifies your account data and a few other things, and whalla... you're done! Replace the entire Function AccountExist, with this code: Code: Function AccountExist(ByVal name As String) As Boolean Dim FileName As String FileName = "accounts\" & Trim(name) & ".bin" If FileExist(FileName) Then AccountExist = True Else AccountExist = False End If End Function Replace the entire PasswordOK Function, with this code: Code: Function PasswordOK(ByVal name As String, ByVal Password As String) As Boolean
Dim FileName As String Dim RightPassword As String * NAME_LENGTH Dim temp As String Dim nLen As Integer Dim nFileNum As Integer PasswordOK = False If AccountExist(name) Then FileName = App.Path & "\Accounts\" & Trim$(name) & ".bin" nFileNum = FreeFile Open FileName For Binary As #nFileNum Get #nFileNum, NAME_LENGTH, RightPassword Close #nFileNum If UCase$(Trim$(Password)) = UCase$(Trim$(RightPassword)) Then PasswordOK = True End If End If End Function Alright, that's all for this lesson. I hope this helps you out. I'd like to give all credit for this to Dave. Had he not written the original tutorial, i probably wouldn't have made an attempt to understand any of this stuff. Post any questions/comments you might have. |
|
| Author: | TheRealDamien [ Fri Dec 22, 2006 9:13 am ] |
| Post subject: | |
How wonderful this is I think the main problem people have with binary is making an editor correctly. |
|
| Author: | Xlithan [ Fri Dec 22, 2006 10:37 am ] |
| Post subject: | |
Yep, making an editor for these types of files is more tricky, since you have to be more specific when reading from it. |
|
| Author: | TheRealDamien [ Fri Dec 22, 2006 11:32 am ] |
| Post subject: | |
Yeah personally ive been through hell and back trying to do this lol... |
|
| Author: | Gilgamesch [ Wed Jan 03, 2007 10:56 pm ] |
| Post subject: | |
sry for bumping this post up, but, did anyone find a way for a editor he wants to share? ^^ |
|
| Author: | Lea [ Thu Jan 04, 2007 12:14 am ] |
| Post subject: | |
I actually do it this way in my Valkoria source I have always been saying it's time to update that tutorial, I'm glad you did it for me Quote: The only current drawback, however, is that it also stores your AccountVariables (the temoraries), into your account along with all of your account stuff. Not that it's a huge deal... you store like an extra 20 Bytes or something per account... but if you want... (since i know that Dave will kill me if i don't mention it), is create another UDT that's something like Type TempPlayerRec, store the info there, and pull it from that rather than the Account or PlayerRecs. But, without further adieu... onto the easy tutorial.
First would be the... Save Player Sub. Now since this is all incredibly easy i'm not going to explain line by line, but simply post the code. Code: Sub SavePlayer(ByVal index As Long) Dim FileName As String Dim f As Long FileName = App.Path & "\accounts\" & Trim$(Player(index).Login) & ".bin" f = FreeFile Open FileName For Binary As #f Put #f, , Player(index) Close #f End Sub Instead of doing all that, You can Put the name and password seperately, then put each character in a For loop. That way you don't waste time juggling UDTs, and just put the data... |
|
| Author: | William [ Tue Jan 30, 2007 12:39 pm ] |
| Post subject: | |
Moved to Optimizations. |
|
| Author: | Obsidian [ Sat Feb 10, 2007 1:09 am ] |
| Post subject: | |
Yeah, for those of you wondering what dave was talking about... you can (in the Save/Load subs) simply just add this to it on the save player add this... Code: dim i as byte ' assuming you don't allow them to have more than 255 characters then change the Put #f, , Player(index) to this... Code: Put #f, , Trim$(Player(Index).Name)
Put #f, , Trim$(Player(Index).Password) For i = 1 to max_chars Put #f, , Player(index).Char(i) next i Do the same thing for the Load Sub, but use the Get Function, not put. Fairly simple, and it'll save you an extra like... 10-30 bytes per account... not a huge deal... but if you know dave.... every byte counts. |
|
| Author: | Robin [ Thu Mar 15, 2007 9:06 pm ] |
| Post subject: | |
It's an old, old, terribly old topic, but if you are lazy, simply add a quick button server side and make it pop-up an input box, make it so any name typed in gets admin access. This will save you having a crappy editor, and can also be commented when compiling, so only you can do it. |
|
| Author: | Lea [ Fri Jul 25, 2008 7:58 am ] |
| Post subject: | Re: Binary Accounts... The Easy Way |
uber bump. Was just looking at this quick after adding binary accounts to a source and getting errors I noticed a problem with this stuff Obsi had: Code: Put #f, , Trim$(Player(Index).Name) Put #f, , Trim$(Player(Index).Password) For i = 1 to max_chars Put #f, , Player(index).Char(i) next i BUT YOU CAN NOT TRIM$ THOSE STRINGS! Those extra bytes are wasted, however the code gets much more complex without them. kkthx. (PS. I didn't miss anything... time to debug!) |
|
| Page 1 of 1 | All times are UTC |
| Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |
|