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

Packet Name
http://miragesource.net/forums/viewtopic.php?f=201&t=644
Page 1 of 2

Author:  William [ Mon Oct 16, 2006 10:12 am ]
Post subject:  Packet Name

Would there be a big difference changing all the packet names ex:
Code:
 "playerlogin"


to something like this:

Code:
 "3"


So instead of having names, you can use numbers for them. and for easy use, you can make a .txt file numbered from 1 to max packets. Like

1. addPlayer
2. playerlogin
etc..

So you keep track of which packets are which number. Cause i believe 5 characters in the packet name, equals to 5 bytes? and if you use numbers, you would probably not get over than 100. so that would improve the speed some, correct?

Author:  Van [ Mon Oct 16, 2006 10:47 am ]
Post subject: 

Sounds logically, I think it will, but wouldn't it be even better if you send is a byte then, instead of a string?

Author:  Dragoons Master [ Mon Oct 16, 2006 1:08 pm ]
Post subject: 

It does work, I use it.
All my packets look like this:
Code:
Packet = Chr(15) & SEP_CHAR & Msg & END_CHAR

This is the global msg packet and I use Chr function which makes easier becouse I can have like 253 packets w/ only one byte(its not 255 becouse we have SEP_CHAR and END_CHAR)

Author:  Dark Echo [ Mon Oct 16, 2006 1:33 pm ]
Post subject: 

Thats an awesome idea.. Also it would 'help' provide a bit of protection against people who try and read your packets.. It might not stop them, but it would help a little.. Great idea dude.. :wink:

Author:  Spodi [ Mon Oct 16, 2006 2:18 pm ]
Post subject: 

I did this to vbGORE before I used binary packets and to the Kronia game. Though I created a UDT to define each of the packets so I could keep them in order instead of always having to look them up.

Code:
Public Type DCmd
  User_Move As String * 1
  User_Attack As String * 1
  Server_SetUserPos As String * 1
End Type
Public Dcmd As Dcmd


Code:
User_Move = Chr(1)
User_Attack = Chr(2)
...


Code:
Packet = Dcmd.User_Move & ...


Using just numbers limits you a ton. And yes this is an improvement on speed, an improvement where MS and ES both need badly. :wink:

Author:  William [ Mon Oct 16, 2006 2:50 pm ]
Post subject: 

@Spodi, your way is pretty much time consuming to 1000% :P hehe. You will need to put all the packet names into that Type..

@Dragoons Master, so your using from Char(1) to Char(253) ?

Author:  Gilgamesch [ Mon Oct 16, 2006 3:19 pm ]
Post subject: 

William wrote:
@Dragoons Master, so your using from Char(1) to Char(253) ?


i am using the same system, sepchar is chr(0) and endchar is chr(255) (not sure, i used the last one there is)

Author:  Spodi [ Mon Oct 16, 2006 3:27 pm ]
Post subject: 

How is it time consuming? You'll spend less time in the long run since you dont have to keep a lookup table of what every Chr(x) value is. Is it easier to see Server_UpdateUserPosition or Chr(213) and know what it is? Also, you're not calculating the char on the fly and rather storing it in memory (I think you can sacrafice one byte of memory) in a fixed-length string... doesn't get much faster then that. :wink:

Anyways, if you are assigning the characters anyways, why not just do it in an easy-to-use lookup table instead of some crappy lookup table you have to write in a seperate document? I just fail to see how it'd be more time consuming.

Author:  William [ Mon Oct 16, 2006 3:36 pm ]
Post subject: 

Hmm..

Well if your using my example, you wont need to write:

Code:
Public Type DCmd


Okay, I give in ;) But still you dont need to write a document if you have good memory :oops: hehe

Author:  Spodi [ Mon Oct 16, 2006 3:43 pm ]
Post subject: 

Ohhh trust me, you do. :wink: Theres 100's of features in vbGORE that I have completely forgot about that I find every now and then just because the project has become so large I even loose my way around it sometimes. :wink:

Also, if you ever want to have other programmers or distribute your code, it is a must to have. If you are going to use this method, it is a pretty safe thing to say that you will need a lookup table of "some sort". I suggested the above since I like to be able to type in a command where all my packet IDs are gathered up and nothing more, and have a list of the packets be shown. Since I use binary packets, too, misformatting one part of a packet can ruin the whole entire packet for the one recieving it (whether it is the server or client).

A seperate document with the packet information may be nice, but I can see it causing a bit of updating problems. For example, it'd be extra work if you want to change numbers or move things around since you have to edit it in multiple places. With this, I just have a sub that sets all the packet values, copy it from the server to client (or vise versa) and then the packet values will always match up, period. Doesn't matter then what numbers I use, as long as the names are correct. :D

You will also be kicking yourself if you ever take a break for a week or two and end up forgetting a bunch of the packet numbers if you dont chart them. :lol:

Another way you could do it is to format them like:

Code:
Public Const DCmd_Server_UpdateUserPos As String * 1 = C


...then type DCmd_ and press I believe Alt + Space to bring up the pop-up box, but that'd prevent you from using a lot of characters unfortunately.

Author:  William [ Mon Oct 16, 2006 3:55 pm ]
Post subject: 

Yeah I understand. Why do you want it to be called DCmd?

Author:  Spodi [ Mon Oct 16, 2006 4:06 pm ]
Post subject: 

DCmd is just what I use (Data Command). You can call it anything you want, though you will most likely want to use something pretty short. I have DCmd (packet identifiers), SID (stat identifiers), SkID (skill identifiers), and EID (emoticon identifiers) I believe. Now if I had to write those all out every time (would is a LOT of times), I'd just go crazy. :lol:

Though you can also, if you want to use something longer, use a short unique combination (like wjz), then just use a VB IDE plugin to find your temp name and change it to a different name. :wink:

Author:  William [ Mon Oct 16, 2006 4:22 pm ]
Post subject: 

I will probably make different types. Named like:

Code:
Type Account

Type Player

Type NPC

Type ITEM

etc.. Pretty easy to navigate that way.

Author:  Verrigan [ Mon Oct 16, 2006 4:24 pm ]
Post subject: 

I use an array to store the addresses of the functions.. Then, when I receive a packet, it parses out the first byte and calls the function by the address stored in the array based on the packet number. (Very fast)

Author:  William [ Mon Oct 16, 2006 4:25 pm ]
Post subject: 

Those are the things you should make small tuts for ;)

Author:  Spodi [ Mon Oct 16, 2006 4:27 pm ]
Post subject: 

Verrigan wrote:
I use an array to store the addresses of the functions.. Then, when I receive a packet, it parses out the first byte and calls the function by the address stored in the array based on the packet number. (Very fast)


Mind elaborating on what you mean / how you did this? :wink:

Author:  Verrigan [ Mon Oct 16, 2006 4:28 pm ]
Post subject: 

I did... and Spodi wrote one too. :)

Author:  William [ Mon Oct 16, 2006 4:28 pm ]
Post subject: 

Spodi wrote:
Verrigan wrote:
I use an array to store the addresses of the functions.. Then, when I receive a packet, it parses out the first byte and calls the function by the address stored in the array based on the packet number. (Very fast)


Mind elaborating on what you mean / how you did this? :wink:

Make a tut, make a tut ;) hehe

Author:  Verrigan [ Mon Oct 16, 2006 4:34 pm ]
Post subject: 

I made a tutorial... See 'Optimizing your packets'.. or whatever the name is..

Basically, I created a separate function for each packet.

I stored the function addresses in an array... And created an Enumeration of each of the packets.. Then... bleh... This will take a long time to explain...

My HandleData sub is about 10 lines.. It checks the packet type, calls the function by its address using CallWndProc (I think).. and so on and so forth..

I have a download somewhere, but it is not complete, and still a bit buggy.. (First edition...)

I've helped Dave get it working (almost 100%) in Valkoria.. but he has quit working on it for the time being.. :(

The download for the source is in the 'Optimize your packets' tutorial.. I am trying to eat, so I can't look for it atm. :P

Author:  William [ Mon Oct 16, 2006 4:38 pm ]
Post subject: 

Okay, thanks :)

Author:  Verrigan [ Mon Oct 16, 2006 4:40 pm ]
Post subject: 

Here's the link: http://www.verrigan.net/downloads/MSE-Verrigan.zip

Be warned... I mentioned before... It is old and buggy code.. But you'll get the idea. :)

Author:  William [ Mon Oct 16, 2006 4:41 pm ]
Post subject: 

Thanks, Ill check it out.

Author:  Spodi [ Mon Oct 16, 2006 4:43 pm ]
Post subject: 

Hmm, never really thought of using the memory address for a sub instead of just calling it by name - I'll check that out. Though, sounds like it might not be worth the hassle. :wink:

Author:  Verrigan [ Mon Oct 16, 2006 5:17 pm ]
Post subject: 

Spodi wrote:
Hmm, never really thought of using the memory address for a sub instead of just calling it by name - I'll check that out. Though, sounds like it might not be worth the hassle. :wink:


It's really not worth the hassle for a game with less than 50 players on it. ;)

Author:  Dragoons Master [ Tue Oct 17, 2006 2:27 am ]
Post subject: 

Spodi wrote:
Ohhh trust me, you do. :wink: Theres 100's of features in vbGORE that I have completely forgot about that I find every now and then just because the project has become so large I even loose my way around it sometimes. :wink:

Also, if you ever want to have other programmers or distribute your code, it is a must to have. If you are going to use this method, it is a pretty safe thing to say that you will need a lookup table of "some sort". I suggested the above since I like to be able to type in a command where all my packet IDs are gathered up and nothing more, and have a list of the packets be shown. Since I use binary packets, too, misformatting one part of a packet can ruin the whole entire packet for the one recieving it (whether it is the server or client).

A seperate document with the packet information may be nice, but I can see it causing a bit of updating problems. For example, it'd be extra work if you want to change numbers or move things around since you have to edit it in multiple places. With this, I just have a sub that sets all the packet values, copy it from the server to client (or vise versa) and then the packet values will always match up, period. Doesn't matter then what numbers I use, as long as the names are correct. :D

You will also be kicking yourself if you ever take a break for a week or two and end up forgetting a bunch of the packet numbers if you dont chart them. :lol:

Another way you could do it is to format them like:

Code:
Public Const DCmd_Server_UpdateUserPos As String * 1 = C


...then type DCmd_ and press I believe Alt + Space to bring up the pop-up box, but that'd prevent you from using a lot of characters unfortunately.

@Spodi, you are totaly right, it's much easier to use it this way.

@William, No. Like Gilgamesch said, I use from 1 to 236 and 238 - 255. 0 and 237 are the Sep and End chars.

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