Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Binary Accounts... The Easy Way
#1
Alright as many of you (especially Sise Tongue ) know... Binary Accounts can get tricky at times, and they're a pain to have to constantly update all the time to make sure that everything lines up right. The solution? This tutorial.

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.
Reply
#2
How wonderful this is I think the main problem people have with binary is making an editor correctly.
Reply
#3
Yep, making an editor for these types of files is more tricky, since you have to be more specific when reading from it.
Reply
#4
Yeah personally ive been through hell and back trying to do this lol...
Reply
#5
sry for bumping this post up, but, did anyone find a way for a editor he wants to share? ^^
Reply
#6
Moved to Optimizations.
Reply
#7
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.
Reply
#8
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.
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)