My name is Elfocrash and ever since i discovered Duality i really liked the job Adam has done. I saw this demand from the users of a solid networking system. Adam said himself that it is not one of his priorities so I think I can help.
The only solutions i saw around is some synchronous symbol separated solutions :'( fully single threaded and synchronous, so really there is not a solid solution out there.
So i preset your *drum roll* DualityNet! (What an original and creative name)
DualityNet is here to solve all your multiplayer problems and offer a solid packet based solution for networking.
General games networking.
As you may or may not know in almost every game the server and the client communicate with each other using packets.
A packet is basically a byte array of data constructed in a specific structure. A packet with structure cSdd is a packet that consists of those datatypes in this very specific order: byte,String,Int,Int.
If the client sends a packet like this to the server then the server will read the first byte, called the OpCode, which is a unique identifier for this specific packet and then the server knows exactly with which sequence it needs to read this packet and do stuff. Same for the server to client packet.
How does DualityNet work?
Exactly like the example i showed you above. DualityNet consists of a gameserver and the client hook. The gameserver is your backend that will receive the client packets and send the info to the client and the hook is how the user will read and set packets.
Here is all you have to do to enable DualityNet on your CorePlugin:
And that's literally all you have to do to hook your functionality to the client.
The other side of things is also pretty minimal. You have a never ending console application which has the role of the gameserver.
It looks like this:
All you have to do is run it. The gameserver is fully asynchronous. The client side is synchronous.
Client packets are the packets that the client will send to the server. Server packets are the packets that the server will send to the client.
Here is what they look like:
Client packet to the right and the response to this packet to the left.
The packet handler will check the opcode and decide which client packet is which and run it:
How do I write my own packets?
Client packets Client packets are usually ones that request something from the server or inform it for something. That get the data from the client and they send it over to the server. A packet is constructed by many different datatypes converted in a byte array. Here is how you read a movement validation clientpacket:
Server packets Server packets are the ones the server sends to the client. I will use the same example as above and i will show how we would create this movement validation packet as the server this time. The reason for this packet could be to validate the users initial position after a restart setting him again in his previous location.
See the structure? Always the opcode to identity the packet and then whatever you want.
Sending and receiving the packets I won't bore you with networking stuff so i will just give you the answer.
Sending a client packet:
Receiving a client packet:
Famous last words It is not quite finished yet but i will post the public github repo so you can fork and contribute if you want or just track the progress.
Please leave a comment with your feedback and suggestions.
Joined: 2013/05/11, 22:30 Posts: 1933 Location: Germany
That does look interesting. I like the rather low-level approach you're taking here. Looking forward to a sample game for this! Maybe network Pong? Or, for something more complex, multiplayer Asteroids?
Is there a specific reason for user-defined packets being classes although your internal, raw Packet is (which I suspect is a good decision) a struct?
I might create a MMO Rpg demo but my main problem is i don't know how i can have a textbox for login credentials
You can get the character input that was typed since the last update by using Duality.DualityApp.Keyboard.CharInput. I think that might be what you're looking for. Though I imagine you'd need to make your own textbox, make the password look like asterisks etc. on your own.