Posts: 2,605
Threads: 412
Joined: Nov 2021
Reputation:
0
Introduction
Currently each packet has a name that takes up 1 byte per character. Thats not good, instead we want to keep the packet name, but only want it to take up 1-2 bytes per packet.
Backup your source!
Begin with adding this in a module in the client:
Code: Public Enum ClientPacketNames
End Enum
We will store the packet names inside it. And make them only take up 1-2 bytes, regarding what number thats assigned to them.
Now go into your handledata sub client side. The first packet on the top on a unedited mse1 is:
Code: If LCase(Parse(0)) = "alertmsg" Then
We will rename that line of code to this:
Code: If LCase(Parse(0)) = CPNAlertMsg Then
The CPN stands for ClientPacketNames, this is just how I'd like to organize it. Now, go into your:
Code: Public Enum ClientPacketNames
And at the top of that add:
So it looks like:
Code: Public Enum ClientPacketNames
CPNAlertMsg = 0 '"alertmsg"
End Enum
I suggest you add the packet name as a comment after the new name as I did in the example above, cause that method will be very usefull when your starting on the server.
Now all the names below that will have +1 on their number. So you dont need to write = 1, = 2 etc. It does that on its own.
Now basicly you do the same for all the packets in the client handledata sub. This is the time consuming part, but it's worth it. I will do one more example for you though. The next packet in a unedited mse1 is:
Code: If LCase(Parse(0)) = "allchars" Then
Now you should know how to write that, but if you don't, here it is:
Code: If LCase(Parse(0)) = CPNAllChars Then
And after that, you will need to add that to the Enum, so it looks like this:
Code: Public Enum ClientPacketNames
CPNAlertMsg = 0 ' "alertmsg"
CPNAllChars ' "allchars"
End Enum
That should give you enough information to carry this on through the whole client handledata sub.
When you have completed that! You will copy the whole Public Enum ClientPacketNames and paste it into the server in a module. When you've done that, you will start searching for the old packet names in the server. Now it's good that we saved those old names after the new onse in the enum type. So now, search for the first you have in your Enum type, in a unedited MSE1, It should be:
Now you will find this:
Code: Sub AlertMsg(ByVal Index As Long, ByVal Msg As String)
Dim Packet As String
Packet = "ALERTMSG" & SEP_CHAR & Msg & SEP_CHAR & END_CHAR
Call SendDataTo(Index, Packet)
Call CloseSocket(Index)
End Sub
But we are focusing on this part:
Code: Packet = "ALERTMSG" & SEP_CHAR & Msg & SEP_CHAR & END_CHAR
We will change that to the new packet name that only take 1 byte, instead of 8 bytes. So it looks like this:
Code: Packet = CPNAlertMsg & SEP_CHAR & Msg & SEP_CHAR & END_CHAR
And you will keep doing that for all the packets thats being sent from the server to client. When this is done, probably after 1-2 hours. You will do the same procedure, but from the other direction.
Now you start on the server, with adding a:
Code: Public Enum ServerPacketNames
End Enum
And do as you did in the client before, and also remember to paste the whole Public Enum ServerPacketNames into the client after your done with them.
If you need any further help, just post and I'd be glad to help you.
Posts: 2,605
Threads: 412
Joined: Nov 2021
Reputation:
0
I remember being confuzed about this when struggeling with ore 2 years back. And Verrigan never did a tutorial for this, I believe he made a source code floating around with it. But I don't think many people even have that source.
So I suggest you take a step back and let people add this since I've spoken with a lot of people who don't have this, and many dont know about it. So please give me another reason why I shouldn't post this ?
Dave, you made a binary account tut, and Obsi posted the newer version of it that was easier to follow. Verrigan's byte packet, binary packet, w/e tut was good, but didn't give many examples, so it's hard to follow, if you can even follow it at all.
Posts: 2,742
Threads: 115
Joined: Jun 2006
Reputation:
0
It's easy to follow >_>
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?
Robin Wrote:It's easy to follow >_>
Not for the average programmer.
Posts: 2,742
Threads: 115
Joined: Jun 2006
Reputation:
0
Well, if you're average you shouldn't try and add it then.
You'd just end up getting confused when adding new packets or following other tutorials which require you to edit packets.
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?
Posts: 2,605
Threads: 412
Joined: Nov 2021
Reputation:
0
Robin Wrote:Well, if you're average you shouldn't try and add it then.
You'd just end up getting confused when adding new packets or following other tutorials which require you to edit packets. A programmer should always push their limits, no matter what it is.
William Wrote:Robin Wrote:Well, if you're average you shouldn't try and add it then.
You'd just end up getting confused when adding new packets or following other tutorials which require you to edit packets. A programmer should always push their limits, no matter what it is.
Agreed. Most programmers, if they're smart, back up their project before attempting anything. Unless they know for a fact what they added will work and won't mess anything else up.
Dragoons Master
Unregistered
That is kind of correct, but if you try to add this thing to your game but never ever sow anything about packets and sockets, there will be no way you will ever understand this. I know you should push your limits but you can't try to understand complex numbers when you can only sum and multiply things... In all my tutorials I ask the user to read and read again and again, if you don't understand DON'T go ahead!
Posts: 2,742
Threads: 115
Joined: Jun 2006
Reputation:
0
Dragoons Master Wrote:That is kind of correct, but if you try to add this thing to your game but never ever sow anything about packets and sockets, there will be no way you will ever understand this. I know you should push your limits but you can't try to understand complex numbers when you can only sum and multiply things... In all my tutorials I ask the user to read and read again and again, if you don't understand DON'T go ahead!
-Hugs Dragoons Master-
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?
Why anyone can complain about a positive tutorial i dont know.
Posts: 2,605
Threads: 412
Joined: Nov 2021
Reputation:
0
Fox Wrote:Why anyone can complain about a positive tutorial i dont know. Same here.
Dragoons Master
Unregistered
That's not the point. What I'm talking about is that a user with no knowledge about packets should not try this for beggining. He should study on internet first and then do this. I never said that you should not post this tutorial, I just said that the tutorial does not have to be used by users that don't know anything about protocols, etc...
Dragoons Master Wrote:That's not the point. What I'm talking about is that a user with no knowledge about packets should not try this for beggining. He should study on internet first and then do this. I never said that you should not post this tutorial, I just said that the tutorial does not have to be used by users that don't know anything about protocols, etc...
I agree with you, but some people, myself included, don't learn anything from research. I learn more from trial and error and examples and such. I'm an average programmer, but I understand packets and such. All this does is instead of sending the string "packetname" it sends a number, to save space and shit.
Dragoons Master
Unregistered
Dragoons Master Wrote:Humm, ok then xD
What I'm saying is, a lot of people learn better from hands on experience than reading up on things. I have very little short term memory, so if I just read on something, I don't learn anything at all, cause I forget it really fast.
Anyways..
Will using this improve the speed any?
Posts: 2,605
Threads: 412
Joined: Nov 2021
Reputation:
0
I'd say it increases the speed some, the packets will be sent a little faster when the size is smaller. Instead of sending 10 bytes when a player move in the game, it now send 1 or 2 bytes depending on which number was assigned to the packet name in the type. If you've done optimizations such with $ etc. Then you should know that doing this tut is like 1000times better.
Guys what i dont understand is we obsess over bits, and bytes so much;
if you look at mainstream online games they spam the hell out of the server and client, they have 32897423987432 more packets sending constantly than MS does; yet we still get some little lags on MS.
Why is this? Simply because its vb6.0?
Posts: 2,605
Threads: 412
Joined: Nov 2021
Reputation:
0
Well, it's obviously cause vb aint so good. But never the less, the largest part is how it's programmed. I don't encounter any lag in my game now. And nor do the players. Of course it highly depends on how many players you got, but a MS game can for sure carry tons of players as long as you've spent a lot time fixing the source up.
Winsock plays a part in it too. These mainstream games have custom socket handlers and shit like that.
I'd just like to add a little note about this tutorial, if I may.
Any variable declared of a custom Enum type will be 4 bytes.
I even made a quick test program to confirm this.
I had one form, and one module.
In the module, I had this code:
Code: Public Enum PacketName
First = 1
Second
Third
Fourth
Fifth
Sixth
Seventh
Eighth
Ninth
Tenth
End Enum
In the form, I had this code:
Code: Private Sub Form_Load()
Dim myEnumVar As PacketName
myEnumVar = Fifth
MsgBox "myEnumVar: " & Str$(myEnumVar) & vbNewLine & "LenB: " & LenB(myEnumVar)
End
End Sub
When I ran the program, I got a message box containing this:
MessageBox Wrote:myEnumVar: 5
LenB: 4
I felt I needed to bring that to light since it was mentioned in the tutorial that it would make the packet ID be 1-2 bytes, but it will indeed be a full four bytes.
Of course, the way to make them 1 or 2 bytes is to have a bunch of constants set as bytes or integers. But by nature, all Enums are of data type Long.
P.S. I believe I may still have a copy of Verrigan's "binary packet" MSE where he tweaked all of the stuff. Granted, I can't check until I can get back to my computer at home.
Posts: 2,742
Threads: 115
Joined: Jun 2006
Reputation:
0
Convert it to byte.
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?
You mean a bunch of byte constants?
Or:
Code: Public Enum Packets As Byte
Blah = 1
MoreBlah
BlahBlah
FourthBlah
End Enum
Note: No clue if that'd even compile, I don't feel like pulling up VB6 right now. =x
I'm assuming you mean byte constants... which would be the best way to do it.
Posts: 2,742
Threads: 115
Joined: Jun 2006
Reputation:
0
cByte I think it's called.
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?
|