Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Packetbuffer for IOCP
#1
Difficulty: 1/5

Introduction
You should only make this change if you have IOCP.

Step 1, complete this tutorial:
http://www.key2heaven.net/ms/forums/viewtopic.php?t=894

Step 2, replace the whole sub:
Code:
Sub SendQueuedData()
  Dim i As Integer, n As Long
  Dim TmpStr As String

  For i = 1 To MAX_PLAYERS

    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
             .Lines = Right(.Lines, Len(.Lines) - Len(TmpStr))
          End If
        End If
        If Len(TmpStr) > 0 Then
          Call frmServer.Socket(i).SendData(TmpStr)
        End If
      End If
    End With
  Next
  DoEvents
End Sub
With this:
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 = vbNullString
      With ConQueues(i)
        If Not .Lock Then
            On Error Resume Next
            If GameServer.Sockets(i).Socket Is Nothing Then
                .Lines = vbNullString
            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
                GameServer.Sockets(i).WriteBytes dbytes
                DoEvents
            End If
          End If
        End If
      End With
    Next
    DoEvents
End Sub

That should make the packet buffer work for IOCP as well.
Reply
#2
thanks
Reply
#3
Uhh to add this tut - http://www.key2heaven.net/ms/forums/viewtopic.php?t=894 you dont need to have ICOP...

I recommend you make that clear to everyone because your post was very unclear about that.
Reply
#4
Damien, don't get me doubting my knowledge when Im correct. You see this was added with IOCP:
Code:
Public Sub WriteBytes(dbytes() As Byte, Optional thenShutdown As Boolean)
  Call mvarSocket.Write(dbytes, thenShutdown)
End Sub

And for example, the packet buffer had this in the original tutorial:
Code:
If Len(TmpStr) > 0 Then
  Call frmServer.Socket(i).SendData(TmpStr)
End If
And the new has to look like this:
Code:
If Len(TmpStr) > 0 Then
            dbytes = StrConv(TmpStr, vbFromUnicode)
            If IsConnected(i) Then
                GameServer.Sockets(i).WriteBytes dbytes
                DoEvents
            End If
          End If
You see how it uses the '.WriteBytes'. I believe a few other things had to be changed as well.

And also, I helped another person with that code for this IOCP with the packet buffer, and that worked fine for me too.

My former Topic concerning this: http://www.key2heaven.net/ms/forums/vie ... 401aa29e01
Reply
#5
Please read before posting any comments that may be taken as 'flame-bait', and please, if you have the urge to flame someone, PM them and try to keep the forum clean... it really doesn't make anyone look good, or better than the person they decide to flame. It is pointless and annoying for everyone. That is all.
Reply
#6
Works great, thanks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)