Mirage Source
http://www.miragesource.net/forums/

Packet Enum - Completed
http://www.miragesource.net/forums/viewtopic.php?f=210&t=2764
Page 1 of 2

Author:  William [ Wed Sep 26, 2007 3:48 pm ]
Post subject:  Packet Enum - Completed

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:
Code:
CPNAlertMsg = 0

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:
Code:
"alertmsg"

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.

Author:  Lea [ Wed Sep 26, 2007 3:54 pm ]
Post subject:  Re: Packet Enum

I am confused, William. Why are we writing tutorials to do what Verrigan's packet system already does? Anyone with the most limited skill could pull that out..

Author:  William [ Wed Sep 26, 2007 4:07 pm ]
Post subject:  Re: Packet Enum - Completed

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 ?

Author:  Matt [ Wed Sep 26, 2007 4:17 pm ]
Post subject:  Re: Packet Enum - Completed

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.

Author:  Robin [ Wed Sep 26, 2007 4:26 pm ]
Post subject:  Re: Packet Enum - Completed

It's easy to follow >_>

Author:  Matt [ Wed Sep 26, 2007 4:29 pm ]
Post subject:  Re: Packet Enum - Completed

Robin wrote:
It's easy to follow >_>


Not for the average programmer.

Author:  Robin [ Wed Sep 26, 2007 5:11 pm ]
Post subject:  Re: Packet Enum - Completed

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.

Author:  William [ Wed Sep 26, 2007 6:36 pm ]
Post subject:  Re: Packet Enum - Completed

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.

Author:  Matt [ Wed Sep 26, 2007 7:19 pm ]
Post subject:  Re: Packet Enum - Completed

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.

Author:  Dragoons Master [ Wed Sep 26, 2007 7:31 pm ]
Post subject:  Re: Packet Enum - Completed

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!

Author:  Robin [ Wed Sep 26, 2007 7:36 pm ]
Post subject:  Re: Packet Enum - Completed

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-

Author:  Coke [ Wed Sep 26, 2007 7:38 pm ]
Post subject:  Re: Packet Enum - Completed

Why anyone can complain about a positive tutorial i dont know.

Author:  William [ Wed Sep 26, 2007 7:41 pm ]
Post subject:  Re: Packet Enum - Completed

Fox wrote:
Why anyone can complain about a positive tutorial i dont know.

Same here.

Author:  Dragoons Master [ Wed Sep 26, 2007 7:46 pm ]
Post subject:  Re: Packet Enum - Completed

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...

Author:  Matt [ Wed Sep 26, 2007 7:53 pm ]
Post subject:  Re: Packet Enum - Completed

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.

Author:  Dragoons Master [ Wed Sep 26, 2007 8:08 pm ]
Post subject:  Re: Packet Enum - Completed

Humm, ok then xD

Author:  Matt [ Wed Sep 26, 2007 8:20 pm ]
Post subject:  Re: Packet Enum - Completed

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.

Author:  Lea [ Wed Sep 26, 2007 8:33 pm ]
Post subject:  Re: Packet Enum - Completed

Everyone forgets it fast. The trick is reading it over adn over as you need it. Eventually just memorize it.

Author:  Matt [ Wed Sep 26, 2007 8:46 pm ]
Post subject:  Re: Packet Enum - Completed

Anyways..

Will using this improve the speed any?

Author:  Lea [ Thu Sep 27, 2007 12:29 am ]
Post subject:  Re: Packet Enum - Completed

Speed? Probably not. It will reduce your bandwidth some.

Author:  William [ Thu Sep 27, 2007 9:05 am ]
Post subject:  Re: Packet Enum - Completed

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.

Author:  Coke [ Thu Sep 27, 2007 12:26 pm ]
Post subject:  Re: Packet Enum - Completed

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?

Author:  William [ Thu Sep 27, 2007 12:33 pm ]
Post subject:  Re: Packet Enum - Completed

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.

Author:  Matt [ Thu Sep 27, 2007 12:39 pm ]
Post subject:  Re: Packet Enum - Completed

Winsock plays a part in it too. These mainstream games have custom socket handlers and shit like that.

Author:  Lea [ Thu Sep 27, 2007 1:11 pm ]
Post subject:  Re: Packet Enum - Completed

These commercial game servers also run on 100 different computers with a fiber connection to the internet :)

Page 1 of 2 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/