Results 1 to 4 of 4

Thread: Winsock Buffer Problem

  1. #1

    Thread Starter
    Hyperactive Member wiccaan's Avatar
    Join Date
    Apr 2004
    Location
    127.0.0.1
    Posts
    475

    Winsock Buffer Problem

    Ok, with winsock, a friend and I are using encryption to send packets for our game. The problem we are having is when the game client recieves a packet with our home made encryption, the encryption key wont work unless its one byte in size.

    When the packet is recieved on the client its send to a buffer to decrypt the packet and check it. Then send it to the handler to decide what to do with the packet.

    This is the buffer we have right now:

    Code:
    Sub IncomingData(ByVal DataLength As Long)
    Dim Buffer As String
    Dim Packet As String
    Dim A As String
    Dim Start As Integer
    
        frmScourge.Socket.GetData Buffer, vbString, DataLength
    
        Buffer = Decrypt(Buffer, EncryptionKey)
        PlayerBuffer = PlayerBuffer & Buffer
            
        Start = InStr(PlayerBuffer, END_CHAR)
        Do While Start > 0
            Packet = Mid(PlayerBuffer, 1, Start - 1)
            PlayerBuffer = Mid(PlayerBuffer, Start + 1, Len(PlayerBuffer))
            Start = InStr(PlayerBuffer, END_CHAR)
            If Len(Packet) > 0 Then
    
                Call HandleData(Packet)
            End If
        Loop
    End Sub
    When the client gets data on the winsock control it calls that sub to buffer / decrypt the packet.

    Also, on the server it uses the same buffer to read the packets, so if this one must change the server buffer has to change as well.

    The exact problem we are having is the client can connect to the server, let you login and start playing, but the server is not buffering the sent packets from the client that allow you to do things such as drop items, equip items, and so on.

    We have checked the packets and found no problems with how they are recieved / sent and pin-pointed the problem to the buffer we have.

    (We have packet sniffed the game and decrypted the packets by hand and found no problems with them.)

    (Please note that I cant put our encryption on here for safty reasons toward the game.)

    If your able to help with what I can give, please do so.

    Thanks in advance.

    PS: To ensure that you under stand this, the packets are setup in sections using the encryption.

    When the packet is decrypted they read in sections like this:

    COMMAND¥WHATTODO¥HOWTODOIT¥í

    The ¥ is the spacer in the packet, and the í is our end of packet symble. The buffer looks for the end of packet symble to start buffering the packet.

    Hope someone can help us with our problem..
    If my post was helpful please rate it

  2. #2

  3. #3

    Thread Starter
    Hyperactive Member wiccaan's Avatar
    Join Date
    Apr 2004
    Location
    127.0.0.1
    Posts
    475

    Re: Winsock Buffer Problem

    Yes, it was tested without the encryption before hand and the same problems have been happening. We have been trying to rewrite the buffer for a few days now. Between the both of us we are stumpped. Ive probably rewriten it more then a thousand times with no luck.

    Tonight I rewrote it to a point where the packets get past the buffer and onto the handler but it gets a subscript out of range error when it trys to set the players hp and mp. Which I dont understand because the value of a new characters hp / mp are both 30/30.

    And when the error happens and I debug it highlights the line. I hover the mouse over values of things and it does the popup bubble saying what it equals and there is no problem with what it equals.

    So yea, Im totally stummped.

    I rewrote the buffer to this to get to the above:

    Code:
    Sub IncomingData(ByVal DataLength As Long)
     Dim Buffer As String
     Dim Packet As String
     Dim A As String
     Dim Start As Integer
      
         frmScourge.Socket.GetData Buffer
         Buffer = Decrypt(Buffer, EncryptionKey)
         PlayerBuffer = PlayerBuffer & Buffer
         Start = InStr(PlayerBuffer, END_CHAR)
         Do While Start > 0
          
          
         Start = InStr(PlayerBuffer, END_CHAR)
         Packet = Mid(PlayerBuffer, 1, Start - 1)
         PlayerBuffer = Mid(PlayerBuffer, Start + 1, Len(PlayerBuffer))
         Start = InStr(PlayerBuffer, END_CHAR)
          
     Loop
         If Len(Packet) > 0 Then
         Call HandleData(Packet)
         End If
      
     End Sub
    Ps: Sorry for posting this in the wrong section didnt notice there was a specific spot to post winsock problems now.

    Pss.. also just noticed you said in your post "WITHOUT decryption", did you mean without encryption completely or without decrypting the packets? Cause if the packets arnt decrypted nothing will happen.
    If my post was helpful please rate it

  4. #4

    Thread Starter
    Hyperactive Member wiccaan's Avatar
    Join Date
    Apr 2004
    Location
    127.0.0.1
    Posts
    475

    Re: Winsock Buffer Problem

    On a side note, with the above buffer, or I might have changed it a little, dont remember, but I get a subscript error. VB then highlights this line:

    Code:
    Player(MyIndex).MaxHP = Val(Section(1))
    Ok with this MyIndex is the index the player gets from the server (for the socket). MaxHP sets the players maxhp in the game.

    Then Val() is the value, the buffer sends the packet to the handle which then splits the packets into 4 sections:

    Command :: Value 1 :: Value 2 :: Value 3

    Section 0 is the command then 1-3 are the values.

    Section(1) in the above case equals 30 when the error happens. So I dont see why this is getting an error at that point in the code.

    Any idea's?
    If my post was helpful please rate it

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width