| Mirage Source http://www.miragesource.net/forums/ |
|
| MS4 + Byte Arrays http://www.miragesource.net/forums/viewtopic.php?f=193&t=5258 |
Page 1 of 2 |
| Author: | William [ Sat Mar 14, 2009 2:59 pm ] |
| Post subject: | MS4 + Byte Arrays |
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. |
|
| Author: | Matt [ Sat Mar 14, 2009 3:16 pm ] |
| Post subject: | Re: MS4 + Byte Arrays |
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. |
|
| Author: | William [ Sat Mar 14, 2009 3:19 pm ] |
| Post subject: | Re: MS4 + Byte Arrays |
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? |
|
| Author: | Matt [ Sat Mar 14, 2009 3:49 pm ] |
| Post subject: | Re: MS4 + Byte Arrays |
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. |
|
| Author: | Coke [ Sat Mar 14, 2009 4:12 pm ] |
| Post subject: | Re: MS4 + Byte Arrays |
Woot. Go William :3 |
|
| Author: | William [ Sat Mar 14, 2009 4:24 pm ] |
| Post subject: | Re: MS4 + Byte Arrays |
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. |
|
| Author: | Matt [ Sat Mar 14, 2009 4:26 pm ] |
| Post subject: | Re: MS4 + Byte Arrays |
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. |
|
| Author: | William [ Sat Mar 14, 2009 4:29 pm ] |
| Post subject: | Re: MS4 + Byte Arrays |
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. |
|
| Author: | Matt [ Sat Mar 14, 2009 4:45 pm ] |
| Post subject: | Re: MS4 + Byte Arrays |
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. |
|
| Author: | Jacob [ Sat Mar 14, 2009 5:11 pm ] |
| Post subject: | Re: MS4 + Byte Arrays |
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. |
|
| Author: | Matt [ Sat Mar 14, 2009 5:12 pm ] |
| Post subject: | Re: MS4 + Byte Arrays |
Yeah, I couldn't remember the issue, just that there was one. Lol. |
|
| Author: | Dragoons Master [ Sat Mar 14, 2009 5:26 pm ] |
| Post subject: | Re: MS4 + Byte Arrays |
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 |
|
| Author: | William [ Sat Mar 14, 2009 5:32 pm ] |
| Post subject: | Re: MS4 + Byte Arrays |
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 However, I am interested in what you did with modBuffer. |
|
| Author: | Robin [ Sat Mar 14, 2009 5:44 pm ] |
| Post subject: | Re: MS4 + Byte Arrays |
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 |
|
| Author: | Jacob [ Sat Mar 14, 2009 5:48 pm ] |
| Post subject: | Re: MS4 + Byte Arrays |
Like my buffer class |
|
| Author: | William [ Sat Mar 14, 2009 6:04 pm ] |
| Post subject: | Re: MS4 + Byte Arrays |
Feel free to finish the server to client part. Sounds like you guys want to do it |
|
| Author: | GIAKEN [ Sat Mar 14, 2009 8:20 pm ] |
| Post subject: | Re: MS4 + Byte Arrays |
Finish what you started, William |
|
| Author: | William [ Sat Mar 14, 2009 8:47 pm ] |
| Post subject: | Re: MS4 + Byte Arrays |
GIAKEN wrote: Finish what you started, William I always do. |
|
| Author: | Lea [ Sun Mar 15, 2009 1:49 pm ] |
| Post subject: | Re: MS4 + Byte Arrays |
hah |
|
| Author: | William [ Mon Mar 16, 2009 6:54 pm ] |
| Post subject: | Re: MS4 + Byte Arrays |
Lea wrote: hah Says the person who hasn't done any noticealbe programming as far as I can remember ^^ lol |
|
| Author: | Anthony [ Tue Mar 17, 2009 4:54 am ] |
| Post subject: | Re: MS4 + Byte Arrays |
I assume you use binary saving/loading William? XD. |
|
| Author: | William [ Tue Mar 17, 2009 3:28 pm ] |
| Post subject: | Re: MS4 + Byte Arrays |
... Was Dave the first one to introduce binary saving/loading to ms forum? |
|
| Author: | Matt [ Tue Mar 17, 2009 3:32 pm ] |
| Post subject: | Re: MS4 + Byte Arrays |
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. |
|
| Author: | William [ Tue Mar 17, 2009 3:33 pm ] |
| Post subject: | Re: MS4 + Byte Arrays |
Give me a copy of MS where the maps aren't binary please |
|
| Author: | Matt [ Tue Mar 17, 2009 3:37 pm ] |
| Post subject: | Re: MS4 + Byte Arrays |
William wrote: Give me a copy of MS where the maps aren't binary please Nobody has one.. Lol. You would have to rewrite the whole system to use INI. |
|
| Page 1 of 2 | All times are UTC |
| Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |
|