Mirage Source
MS4 + Byte Arrays - Printable Version

+- Mirage Source (https://mirage-engine.uk/forums)
+-- Forum: Mirage Source (Nostalgia) (https://mirage-engine.uk/forums/forumdisplay.php?fid=61)
+--- Forum: Archive (2006-2011) (https://mirage-engine.uk/forums/forumdisplay.php?fid=18)
+---- Forum: Source Code Development (https://mirage-engine.uk/forums/forumdisplay.php?fid=51)
+----- Forum: Mirage Source 4 (Visual Basic 6) (https://mirage-engine.uk/forums/forumdisplay.php?fid=44)
+----- Thread: MS4 + Byte Arrays (/showthread.php?tid=2618)

Pages: 1 2


MS4 + Byte Arrays - William - 14-03-2009

I have obviously not done enough work around here so I spent this day programming in byte arrays into MS4 - but 1 way only. Sending from the client to the server. Everything seems to work just fine, the only problem I've seen is that the map isn't saving (there could be more problems because I havn't tested everything in the game). I will fix that later but I'm currently getting blind by looking at it for this long. So if someone else would like to take a look at it go ahead.

http://www.key2heaven.net/ms/downloads/ ... Arrays.rar

When the final small glitches are fixed, I'd hope DFA will use this source to continue his work on. If his now still working on it.


Re: MS4 + Byte Arrays - Matt - 14-03-2009

He works on it here and there but he doesn't have internet access at home.

Btw, is this your method or the method Verrigan posted? Dugor was talkin' about how Verrigan's method has a huge flaw in it when there's more than one person online at a time.

Just a heads up if you're using Verrigan's method.


Re: MS4 + Byte Arrays - William - 14-03-2009

Matt Wrote:He works on it here and there but he doesn't have internet access at home.

Btw, is this your method or the method Verrigan posted? Dugor was talkin' about how Verrigan's method has a huge flaw in it when there's more than one person online at a time.

Just a heads up if you're using Verrigan's method.
This is verrigans method but it doesn't have all the same procedures in the code. This is the system I use in k2h and it works great with no flaws. And Grim helped me adding this to k2h long ago and I trust his judgement.

IOCP has flaws, are you sure he wasn't talking about that?


Re: MS4 + Byte Arrays - Matt - 14-03-2009

William Wrote:
Matt Wrote:He works on it here and there but he doesn't have internet access at home.

Btw, is this your method or the method Verrigan posted? Dugor was talkin' about how Verrigan's method has a huge flaw in it when there's more than one person online at a time.

Just a heads up if you're using Verrigan's method.
This is verrigans method but it doesn't have all the same procedures in the code. This is the system I use in k2h and it works great with no flaws. And Grim helped me adding this to k2h long ago and I trust his judgement.

IOCP has flaws, are you sure he wasn't talking about that?

Ah, okay then.

No, not the IOCP. Verrigan's method had a huge flaw. Dugor was talkin' about it when he started helping me convert FPO to byte array packets. He was explaining why he quit using Verrigan's method and came up with his own. I was just making sure you weren't wasting your time with Verrigan's base method. But I see you already have an altered version to work with.

Good job.


Re: MS4 + Byte Arrays - Coke - 14-03-2009

Woot. Go William :3


Re: MS4 + Byte Arrays - William - 14-03-2009

Matt Wrote:
William Wrote:
Matt Wrote:He works on it here and there but he doesn't have internet access at home.

Btw, is this your method or the method Verrigan posted? Dugor was talkin' about how Verrigan's method has a huge flaw in it when there's more than one person online at a time.

Just a heads up if you're using Verrigan's method.
This is verrigans method but it doesn't have all the same procedures in the code. This is the system I use in k2h and it works great with no flaws. And Grim helped me adding this to k2h long ago and I trust his judgement.

IOCP has flaws, are you sure he wasn't talking about that?

Ah, okay then.

No, not the IOCP. Verrigan's method had a huge flaw. Dugor was talkin' about it when he started helping me convert FPO to byte array packets. He was explaining why he quit using Verrigan's method and came up with his own. I was just making sure you weren't wasting your time with Verrigan's base method. But I see you already have an altered version to work with.

Good job.
It's hard for me to know if there is a flaw since I don't know what flaw dugor was talking about. But I've had multiple connections without any problems. And for some reason I consider my server to be more stable now when it has byte arrays compared to before. But that could be because of several other reasons.


Re: MS4 + Byte Arrays - Matt - 14-03-2009

If you can have multiple connections, you don't have the flaw.

If I recall correctly, he was talking about how the packets would get really messed up with more than one person connected.


Re: MS4 + Byte Arrays - William - 14-03-2009

Matt Wrote:If you can have multiple connections, you don't have the flaw.

If I recall correctly, he was talking about how the packets would get really messed up with more than one person connected.
That doesn't sound like theres something wrong with verrs core system, but rather the convertion of subs handeling the packets and such. This system works fine, but I just didn't fix a few bugs in this version. I might do it later today though after I get some food.


Re: MS4 + Byte Arrays - Matt - 14-03-2009

William Wrote:
Matt Wrote:If you can have multiple connections, you don't have the flaw.

If I recall correctly, he was talking about how the packets would get really messed up with more than one person connected.
That doesn't sound like theres something wrong with verrs core system, but rather the convertion of subs handeling the packets and such. This system works fine, but I just didn't fix a few bugs in this version. I might do it later today though after I get some food.

I'm not saying there's a problem with the system you're adding. I was just making sure you were aware of the flaw in Verrigan's system if you were using that as the base.


Re: MS4 + Byte Arrays - Jacob - 14-03-2009

The issue was with the IncomingData sub. What Verrigan was doing was pulling out an Integer every time data arrived. If a full packet wasn't there, it would still take out an integer causing packet errors. If you don't know, you don't always get a full packet at once.


Re: MS4 + Byte Arrays - Matt - 14-03-2009

Yeah, I couldn't remember the issue, just that there was one. Lol.


Re: MS4 + Byte Arrays - Dragoons Master - 14-03-2009

I fixed that when I was developing the MSCPP VB6 Client:
The IncomingData sub should look like this:
Code:
Sub IncomingData(ByVal DataLength As Long)
  Dim dBytes() As Byte
  Dim pl As Integer

  frmMirage.Socket.GetData dBytes, vbByte, DataLength
  PlayerBuffer = AddToBuffer(PlayerBuffer, dBytes)

  'Check to make sure we have at least 2 bytes (Integer), so we can
  'check the packet length.
  pl = 0
  If aLen(PlayerBuffer) >= 2 Then
    pl = GetIntegerFromBuffer(PlayerBuffer)
  End If

  'While we have our entire packet in the buffer, handle it. :)
  While pl >= 2 And aLen(PlayerBuffer) >= pl + 2
    PlayerBuffer = RemoveFromBuffer(PlayerBuffer, 2)

    'Setting dbytes = "" causes the UBound to be -1.
    dBytes = ""

    'Put the remaining bytes of the packet from the player's
    'buffer into the dbytes array.
    dBytes = AddToBuffer(dBytes, PlayerBuffer, pl)

    'Remove the packet we just copied to dbytes.
    PlayerBuffer = RemoveFromBuffer(PlayerBuffer, aLen(dBytes))

    'If we have a packet with data in it, handle it.
    If aLen(dBytes) >= 2 Then
      Call HandleData(dBytes)
    End If

    'Check if we have a packet length again. (2 bytes for an integer..)
    If aLen(PlayerBuffer) >= 2 Then
      pl = GetIntegerFromBuffer(PlayerBuffer)
    Else
      pl = 0
    End If
  Wend
End Sub
I also found a bug wih the modBuffer, but I think that was already fixed at some version I couldn't find. Anyway, I'll post it here:
Code:
'****************************************************************
'* WHEN        WHO        WHAT
'* ----        ---        ----
'* 09/13/2005  Verrigan   Created module to handle adding and
'*                        reading data to/from a 'buffer'.
'****************************************************************
Option Explicit
'One thing to note, always initialize your byte array to "".
'i.e. dBytes = ""
'This sets the UBound of the byte array to -1, allowing us
'to have a size of 0. If the array is not initialized, or
'you have emptied the array, aLen will cause a RT error.
Public Function aLen(ByRef dBytes() As Byte) As Integer
  aLen = (UBound(dBytes) - LBound(dBytes)) + 1
End Function
'****************************************************************
'* WHEN        WHO        WHAT
'* ----        ---        ----
'* 09/13/2005  Verrigan   PrefixBuffer() function created so you
'*                        can add data to the beginning of a
'*                        buffer.
'****************************************************************
Public Function PrefixBuffer(ByRef Buffer() As Byte, ByVal StartAddr As Long, ByVal ByteLen As Long) As Byte()
  Dim tBytes() As Byte
  
  ReDim tBytes(UBound(Buffer) + ByteLen)
  
  Call CopyMemory(tBytes(0), ByVal StartAddr, ByteLen)
  If aLen(Buffer) > 0 Then
    Call CopyMemory(tBytes(ByteLen), Buffer(0), aLen(Buffer))
  End If
  
  PrefixBuffer = tBytes
End Function
'****************************************************************
'* WHEN        WHO        WHAT
'* ----        ---        ----
'* 09/13/2005  Verrigan   AddToBuffer() function created so you
'*                        can concatenate byte arrays. Data is
'*                        added to the end of the buffer.
'****************************************************************
Public Function AddToBuffer(ByRef Buffer() As Byte, ByRef Additional() As Byte, Optional ByVal ByteLen As Long) As Byte()
  Dim tBytes() As Byte
  Dim tLen As Long
  
  If ByteLen = 0 Then
    ByteLen = aLen(Additional)
  End If
  tLen = aLen(Buffer) + ByteLen
  
  ReDim tBytes(tLen - 1)
  
  If Not UBound(Buffer) < 0 Then
    Call CopyMemory(tBytes(0), Buffer(0), aLen(Buffer))
  End If
  
  Call CopyMemory(tBytes(aLen(Buffer)), Additional(0), ByteLen)
  
  AddToBuffer = tBytes
End Function
'****************************************************************
'* WHEN        WHO        WHAT
'* ----        ---        ----
'* 09/13/2005  Verrigan   AddByteToBuffer() function created to
'*                        add a byte to the end of a buffer.
'****************************************************************
Public Function AddByteToBuffer(ByRef Buffer() As Byte, ByVal vData As Byte) As Byte()
  Dim tBytes() As Byte

  ReDim tBytes(UBound(Buffer) + 1)
  
  If aLen(Buffer) > 0 Then
    Call CopyMemory(tBytes(0), Buffer(0), aLen(Buffer))
  End If
  
  Call CopyMemory(tBytes(aLen(Buffer)), vData, 1)
  
  AddByteToBuffer = tBytes
End Function
'****************************************************************
'* WHEN        WHO        WHAT
'* ----        ---        ----
'* 09/13/2005  Verrigan   AddIntegerToBuffer() function created
'*                        to add an integer to the end of a
'*                        buffer.
'****************************************************************
Public Function AddIntegerToBuffer(ByRef Buffer() As Byte, vData As Integer) As Byte()
  Dim tBytes() As Byte

  ReDim tBytes(UBound(Buffer) + 2)
  
  If aLen(Buffer) > 0 Then
    Call CopyMemory(tBytes(0), Buffer(0), aLen(Buffer))
  End If
  
  Call CopyMemory(tBytes(aLen(Buffer)), vData, 2)
  
  AddIntegerToBuffer = tBytes
End Function
'****************************************************************
'* WHEN        WHO        WHAT
'* ----        ---        ----
'* 09/13/2005  Verrigan   AddLongToBuffer() function created to
'*                        add a long to the end of a buffer.
'****************************************************************
Public Function AddLongToBuffer(ByRef Buffer() As Byte, vData As Long) As Byte()
  Dim tBytes() As Byte

  ReDim tBytes(UBound(Buffer) + 4)
  
  If aLen(Buffer) > 0 Then
    Call CopyMemory(tBytes(0), Buffer(0), aLen(Buffer))
  End If
  
  Call CopyMemory(tBytes(aLen(Buffer)), vData, 4)
  
  AddLongToBuffer = tBytes
End Function
'****************************************************************
'* WHEN        WHO        WHAT
'* ----        ---        ----
'* 09/13/2005  Verrigan   AddStringToBuffer() function created to
'*                        add a string to the end of a buffer.
'*                        It adds the string length (as an
'*                        integer) and then the string.
'****************************************************************
Public Function AddStringToBuffer(ByRef Buffer() As Byte, vData As String) As Byte()
  Dim sLen As Integer
  Dim sBytes() As Byte
  Dim tBytes() As Byte
  
  ReDim tBytes(UBound(Buffer) + 2 + Len(vData))
  
  sLen = CInt(Len(vData))
  sBytes = StrConv(vData, vbFromUnicode)
  If aLen(Buffer) > 0 Then
    Call CopyMemory(tBytes(0), Buffer(0), aLen(Buffer))
  End If
  
  Call CopyMemory(tBytes(aLen(Buffer)), sLen, 2)
  
  If vData  vbNullString Then
    Call CopyMemory(tBytes(aLen(Buffer) + 2), sBytes(0), aLen(sBytes))
  End If
  
  AddStringToBuffer = tBytes
End Function
'****************************************************************
'* WHEN        WHO        WHAT
'* ----        ---        ----
'* 09/13/2005  Verrigan   GetFromBuffer() function created to
'*                        grab a specified number of bytes from
'*                        the beginning of the buffer. All of the
'*                        Get*FromBuffer() functions have the
'*                        option to remove those bytes before it
'*                        returns the value to the caller.
'****************************************************************
Public Function GetFromBuffer(ByRef Buffer() As Byte, ByVal ByteLen As Long, Optional ClearBytes As Boolean) As Byte()
  Dim tBytes() As Byte

  ReDim tBytes(ByteLen - 1)
  
  Call CopyMemory(tBytes(0), Buffer(0), ByteLen)
  
  GetFromBuffer = tBytes
  
  If ClearBytes Then
    Buffer = RemoveFromBuffer(Buffer, ByteLen)
  End If
End Function
'****************************************************************
'* WHEN        WHO        WHAT
'* ----        ---        ----
'* 09/13/2005  Verrigan   GetByteFromBuffer() function created to
'*                        grab 1 byte from the beginning of the
'*                        buffer.
'****************************************************************
Public Function GetByteFromBuffer(ByRef Buffer() As Byte, Optional ClearBytes As Boolean) As Byte
  Dim RetVal As Byte
  
  Call CopyMemory(RetVal, Buffer(0), 1)
  
  GetByteFromBuffer = RetVal
  
  If ClearBytes Then
    Buffer = RemoveFromBuffer(Buffer, 1)
  End If
End Function
'****************************************************************
'* WHEN        WHO        WHAT
'* ----        ---        ----
'* 09/13/2005  Verrigan   GetIntegerFromBuffer() function created
'*                        to grab 1 integer from the beginning of
'*                        the buffer.
'****************************************************************
Public Function GetIntegerFromBuffer(ByRef Buffer() As Byte, Optional ClearBytes As Boolean) As Integer
  Dim RetVal As Integer
  
  Call CopyMemory(RetVal, Buffer(0), 2)
  
  GetIntegerFromBuffer = RetVal
  
  If ClearBytes Then
    Buffer = RemoveFromBuffer(Buffer, 2)
  End If
End Function
'****************************************************************
'* WHEN        WHO        WHAT
'* ----        ---        ----
'* 09/13/2005  Verrigan   GetLongFromBuffer() function created to
'*                        grab 1 long from the beginning of the
'*                        buffer.
'****************************************************************
Public Function GetLongFromBuffer(ByRef Buffer() As Byte, Optional ClearBytes As Boolean) As Long
  Dim RetVal As Long
  
  Call CopyMemory(RetVal, Buffer(0), 4)
  
  GetLongFromBuffer = RetVal
  
  If ClearBytes Then
    Buffer = RemoveFromBuffer(Buffer, 4)
  End If
End Function
'****************************************************************
'* WHEN        WHO        WHAT
'* ----        ---        ----
'* 09/13/2005  Verrigan   GetStringFromBuffer() function created
'*                        to grab a string from the beginning of
'*                        the buffer. It grabs the first 2 bytes
'*                        to determine the size of the string,
'*                        and then the string.
'****************************************************************
Public Function GetStringFromBuffer(ByRef Buffer() As Byte, Optional ClearBytes As Boolean) As String
  Dim sLen As Integer
  Dim tBytes() As Byte
  
  sLen = GetIntegerFromBuffer(Buffer, ClearBytes)
  
  If sLen > 0 Then
    ReDim tBytes(sLen - 1)
    
    Call CopyMemory(tBytes(0), Buffer(0), sLen)
    
    GetStringFromBuffer = StrConv(tBytes, vbUnicode)
    
    If ClearBytes Then
      Buffer = RemoveFromBuffer(Buffer, sLen)
    End If
  End If
End Function
'****************************************************************
'* WHEN        WHO        WHAT
'* ----        ---        ----
'* 09/13/2005  Verrigan   RemoveFromBuffer() function created to
'*                        delete a specified number of bytes from
'*                        the beginning of the buffer.
'****************************************************************
Public Function RemoveFromBuffer(ByRef Buffer() As Byte, ByVal ByteLen As Long) As Byte()
  Dim tBytes() As Byte
  
  If ByteLen > UBound(Buffer) Then
    RemoveFromBuffer = ""
    Exit Function
  End If
  
  ReDim tBytes(UBound(Buffer) - ByteLen)
  
  Call CopyMemory(tBytes(0), Buffer(LBound(Buffer) + ByteLen), aLen(Buffer) - ByteLen)
  
  RemoveFromBuffer = tBytes
End Function
'****************************************************************
'* WHEN        WHO        WHAT
'* ----        ---        ----
'* 09/13/2005  Verrigan   FillBuffer() function created to copy
'*                        a specified number of bytes from a
'*                        specified memory location to a buffer.
'****************************************************************
Public Function FillBuffer(ByVal StartAddr As Long, ByVal ByteLen As Long) As Byte()
  Dim tBytes() As Byte
  
  ReDim tBytes(ByteLen - 1)
  
  Call CopyMemory(tBytes(0), ByVal StartAddr, ByteLen)
  
  FillBuffer = tBytes
End Function



Re: MS4 + Byte Arrays - William - 14-03-2009

Well as I said I didn't do byte arrays for server sending to client. But client sending to server - but I bet your code is correct DM Tongue

However, I am interested in what you did with modBuffer.


Re: MS4 + Byte Arrays - Robin - 14-03-2009

Should just load the buffer commands into a class. Cleans it up.

Code:
Player(index).Buffer.AddInteger(levelVal)

Code:
levelVal = Player(index).Buffer.TakeInteger

;D


Re: MS4 + Byte Arrays - Jacob - 14-03-2009

Like my buffer class Wink


Re: MS4 + Byte Arrays - William - 14-03-2009

Feel free to finish the server to client part. Sounds like you guys want to do it :mrgreen: or check the current one so I don't need to go bug check again :p


Re: MS4 + Byte Arrays - GIAKEN - 14-03-2009

Finish what you started, William Tongue


Re: MS4 + Byte Arrays - William - 14-03-2009

GIAKEN Wrote:Finish what you started, William Tongue
I always do.


Re: MS4 + Byte Arrays - William - 16-03-2009

Lea Wrote:hah
Says the person who hasn't done any noticealbe programming as far as I can remember ^^ lol


Re: MS4 + Byte Arrays - Anthony - 17-03-2009

I assume you use binary saving/loading William? XD.


Re: MS4 + Byte Arrays - William - 17-03-2009

... Was Dave the first one to introduce binary saving/loading to ms forum?


Re: MS4 + Byte Arrays - Matt - 17-03-2009

William Wrote:... Was Dave the first one to introduce binary saving/loading to ms forum?

Technically, Consty did. With the maps. Dave was the first one to show anyone how to do it with items and stuff though.


Re: MS4 + Byte Arrays - William - 17-03-2009

Give me a copy of MS where the maps aren't binary please Tongue


Re: MS4 + Byte Arrays - Matt - 17-03-2009

William Wrote:Give me a copy of MS where the maps aren't binary please Tongue

Nobody has one.. Lol. You would have to rewrite the whole system to use INI.


Re: MS4 + Byte Arrays - William - 17-03-2009

Hehe, lol Im not gonna do it :p