23-08-2006, 11:53 AM
Introduction
I will explain the following:
- Sending packets from the client to server, and how to recieve them.
- Sending packets from server to client, and how to recieve them.
This is for http://www.miragesource.com use. Since Elysium Source uses Select Case for their packet system which is faster. But the packet is still the same.
Client to Server
This is how the code will look like finished (so to use it, just create a command button, and place this code in it):
Now in the server, open modHandleData or search for Sub HandleData.
And just below:
Add:
So now I will explain how that actually works. In the client we had:
Dim Packet As String ' This defines the variable Packet as a "word".
Packet = "GiveMeMyName" & SEP_CHAR & END_CHAR ' Here it gives the variable the correct memory, you always need to have a name of the packet, here that is: "GiveMeMyName". I will go through SEP and END later.
Call SendData(Packet) ' Here we sends it to the server.
So now, we made a easy packet. But what if you want to send variables in the packet, then it's time to learn about SEP_CHAR and END_CHAR.
SEP_CHAR: This is the thing that divides the packet up in pieces. It let's you have different variables between them. Like this:
If you study that, you can see how it works, you always have a SEP_CHAR after the packet name, and always between variables, and always before END_CHAR.
END_CHAR: This is the place that tells the code were the end of the packet is. You always use it in the end of the packet, as shown above.
But how do you recieve the variables that you send to the server?
You simply do this:
That wasn't hard if you go through the code above. Just remember this, in the above example I sent two numbers in the packet (2, and the players level). If you send for example "Bob". Then you will do this to:
Name = Parse(1) ' If it now was the first variable sent in the packet.
Server to Client
Under construction...
I will explain the following:
- Sending packets from the client to server, and how to recieve them.
- Sending packets from server to client, and how to recieve them.
This is for http://www.miragesource.com use. Since Elysium Source uses Select Case for their packet system which is faster. But the packet is still the same.
Client to Server
This is how the code will look like finished (so to use it, just create a command button, and place this code in it):
Code:
Dim Packet As String
Packet = "GiveMeMyName" & SEP_CHAR & END_CHAR
Call SendData(Packet)
Now in the server, open modHandleData or search for Sub HandleData.
And just below:
Code:
' Handle Data
Parse = Split(Data, SEP_CHAR)
Code:
' ::::::::::::::::::::::::::::::::::
' :: Give the player his name ::
' ::::::::::::::::::::::::::::::::::
If LCase(Parse(0)) = "GiveMeMyName" Then
Call PlayerMsg(Index, "Your name is: " & GetPlayerName(index), 1)
Exit Sub
End If
So now I will explain how that actually works. In the client we had:
Dim Packet As String ' This defines the variable Packet as a "word".
Packet = "GiveMeMyName" & SEP_CHAR & END_CHAR ' Here it gives the variable the correct memory, you always need to have a name of the packet, here that is: "GiveMeMyName". I will go through SEP and END later.
Call SendData(Packet) ' Here we sends it to the server.
So now, we made a easy packet. But what if you want to send variables in the packet, then it's time to learn about SEP_CHAR and END_CHAR.
SEP_CHAR: This is the thing that divides the packet up in pieces. It let's you have different variables between them. Like this:
Code:
Packet = "GiveMeMyName" & SEP_CHAR & "2" & SEP_CHAR & GetPlayerLevel(MyIndex) & SEP_CHAR & END_CHAR
END_CHAR: This is the place that tells the code were the end of the packet is. You always use it in the end of the packet, as shown above.
But how do you recieve the variables that you send to the server?
You simply do this:
Code:
' ::::::::::::::::::::::::::::::::::
' :: Give the player his name ::
' ::::::::::::::::::::::::::::::::::
If LCase(Parse(0)) = "GiveMeMyName" Then
i = Val(Parse(1)) ' This will make i = 2
n = Val(Parse(2)) ' This will make n the players Level
Call PlayerMsg(Index, "You are level: " & n & ", your special number is: " & i & ".", 1)
Exit Sub
End If
Name = Parse(1) ' If it now was the first variable sent in the packet.
Server to Client
Under construction...