Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Zlip mixed with IOCP+PackerBuffer
#1
So, I can't seem to get ZLip working correctly serverside. Client side was easy. You see after installing IOCP and the packet buffer to it, I wanted to try Zlip. But the packetbuffer sub SendQueuedData had to be changed in order to work with IOCP (thanks Obsidian).

So here is my SendQueuedData sub with IOCP and the packet buffer added:
Code:
Sub SendQueuedData()
Dim i As Integer, n As Long
Dim TmpStr As String
Dim dbytes() As Byte
Dim Sploc As Integer
Dim ECloc As Integer
Dim lR As Long

    For i = 1 To MAX_PLAYERS
      TmpStr = ""
      With ConQueues(i)
        If Not .Lock Then
            On Error Resume Next
            If GameServer.Sockets(i).Socket Is Nothing Then
                .Lines = ""
            End If
            If Len(.Lines) = 0 And QueueDisconnect(i) = True Then
                Call CloseSocket(i)
                QueueDisconnect(i) = False
            Else
            If Len(.Lines) > 0 Then
               If Len(.Lines) < MAX_PACKETLEN Then
                 TmpStr = .Lines
               Else
                 TmpStr = Left(.Lines, MAX_PACKETLEN)
               End If
               .Lines = Right(.Lines, Len(.Lines) - Len(TmpStr))
            End If
          End If
          If Len(TmpStr) > 0 Then
            dbytes = StrConv(TmpStr, vbFromUnicode)
            If IsConnected(i) Then
                'Call EnigmaEncrypt(dbytes, "travis")
                GameServer.Sockets(i).WriteBytes dbytes
                DoEvents
            End If
          End If
        End If
      End With
    Next
    DoEvents
End Sub
This is what Zlib want me to replace it with:
Code:
Sub SendQueuedData()
Dim ECloc As Integer
Dim lR As Long

  Dim i As Integer, N As Long
  Dim TmpStr As String

  For i = 1 To MAX_PLAYERS
    If frmServer.lblOnOff.Caption = "OFFLINE" Then Exit Sub
    TmpStr = ""
    With ConQueues(i)
      If Not .Lock Then
        If frmServer.Socket(i).State  7 Then
          .Lines = ""
        End If
        If Len(.Lines) = 0 And QueueDisconnect(i) = True Then
          Call CloseSocket(i)
          QueueDisconnect(i) = False
        Else
          If Len(.Lines) > 0 Then
             If Len(.Lines) < MAX_PACKETLEN Then
               TmpStr = .Lines
             Else
               TmpStr = Left(.Lines, MAX_PACKETLEN)
             End If
             ECloc = InStr(1, .Lines, END_CHAR)
             TmpStr = Left(.Lines, ECloc)
             .Lines = Right(.Lines, Len(.Lines) - Len(TmpStr))
          End If
        End If
        If Len(TmpStr) > 0 Then
             Debug.Print "Sending: " & TmpStr
             TmpStr = Compress(TmpStr, lR)
             TmpStr = lR & SEP_CHAR & TmpStr
             Call frmServer.Socket(i).SendData(TmpStr)
        End If
      End If
    End With
    DoEvents
  Next
End Sub
If you look close, you will se some differences between them. And I need to know how to make Zlib work with IOCP and the packetbuffer.So somehow they should be mixed together. THis is out of my knowledge so I need some help.

Related Topics
Zlib: http://ms.shannaracorp.com/backup-forum ... sp?TID=218
PacketBuffer: http://ms.shannaracorp.com/backup-forum ... sp?TID=224
IOCP: http://ms.shannaracorp.com/backup-forum ... sp?TID=120
Reply
#2
You keep saying Zlip, instead of Zlib.

Why don't you compare all of them, find the differences, and just add all the differences into one sub?
Reply
#3
I added ZLib into one of my sources. It worked fine, except when it was compiled. It only worked correctly when it was run in VB. Does anyone else have that problem?
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
#4
You don't understand what zlib does do you? Well here it is.

Just using strings with zlib:
Code:
If Len(TmpStr) > 0 Then
            TmpStr = Compress(TmpStr, lR)
            TmpStr = lR & SEP_CHAR & TmpStr
            dbytes = StrConv(TmpStr, vbFromUnicode)
            If IsConnected(i) Then
                GameServer.Sockets(i).WriteBytes dbytes
                DoEvents
            End If
          End If
does zlib need a string to enrypt? or can it encrypt byte arrays?
If it can decrypt byte arrays faster(which it should) theres probably a better way.
Reply
#5
@Advocate: Just noticed I wrote both Zlib and Zlip.. hehe anyway, just a spelling error..

@Misunderstood: If I understood Zlib correctly, I think it Compresses the data (encrypts it). And it doesn't make the packets bigger, that why Zlib is so good. And it also allows for decryption. WHich means that the encryption actually is a compression.. well anyway. The code you posted, is that only what should be changed?

@Kite: Dont know yet, cause I aint got it working yet. ALthough I will try with Miss code first.
Reply
#6
Well it is the only place data is sent to the client right?
If it is, then yes, otherwise, no.
Reply
#7
Most any compression you find will make packets bigger, or not compress them more then a byte or two, unless you have packets >150 bytes (in which case, for a 2D game, you're already ****ed).

ZLib compresses in byte arrays, as does like every other encryption / compression.

Quote:dbytes = StrConv(TmpStr, vbFromUnicode)

That is turning your string into a byte array right there.
Reply
#8
Zlib Home Site Wrote:the compression method currently used in zlib essentially never expands the data.
Reply
#9
I have done plenty of testing with tons of different compression algorithms on packets ranging from like 3 bytes to 300 bytes. "Essentially never" may not apply to insanely small data. :wink:
Reply
#10
Okay Im following your advice, and will not add Zlib. Thanks
Reply
#11
Glad I could be of help. :wink:
Reply
#12
I'd add it more of a conditional type of thing. You know, adding it for the biggest packets and such.
Reply
#13
pingu Wrote:I'd add it more of a conditional type of thing. You know, adding it for the biggest packets and such.

I don't see a reason for that, either you have it for all or none. That my opinion at least. And I don't think the biggest once will help you anything, but let Spodi respond Tongue
Reply
#14
Well you shouldn't have packets that large, especially not sent more then once every few minutes. If you do for some really wierd reason, though, you can add a check of the packet size first (>250 bytes) then compress it and check if the compression did much of anything (discard the compression if < 10 bytes saved). If it did compress, add a byte to the start of the packet that states it is compressed.
Reply
#15
How do you check the size of a packet?
Reply
#16
you can remove that enigmaencrypt... that was something else i was working on before i sent you that code... :roll:
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)