Adam's Lair Forum
https://forum.adamslair.net:80/

DualityNet - Networking Base for your awesome game
https://forum.adamslair.net:80/viewtopic.php?f=18&t=851
Page 1 of 2

Author:  Elfocrash [ 2016/07/09, 23:11 ]
Post subject:  DualityNet - Networking Base for your awesome game

Hello everyone,

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:
Image

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:
Image

All you have to do is run it.
The gameserver is fully asynchronous.
The client side is synchronous.

ClientPackets/ServerPacket

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:
Image

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:
Image

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:
Image

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.

Image

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:
Image

Receiving a client packet:
Image


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.

Github repo: https://github.com/Elfocrash/DualityNet

Space stuff Multiplayer Test


Thanks,
Elfocrash

Author:  hsnabn [ 2016/07/10, 11:40 ]
Post subject:  Re: DualityNet - Networking Base for your awesome game

Damn, that looks pretty good. Great work!

Author:  Elfocrash [ 2016/07/10, 12:32 ]
Post subject:  Re: DualityNet - Networking Base for your awesome game

Thanks a lot.

I might have to update some of the pictures because i completely separated the packet handling on client and on server.

I will probably make a small example too with a realistic scenario.

Author:  Adam [ 2016/07/10, 14:51 ]
Post subject:  Re: DualityNet - Networking Base for your awesome game

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?

Author:  Elfocrash [ 2016/07/10, 14:58 ]
Post subject:  Re: DualityNet - Networking Base for your awesome game

Mainly because people don't quite understand structs (from personal experience) so i thought i'd rather keep the things that users might wanna add themselves more familiar to what they know.

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 xD

Author:  indiemaatheus [ 2016/07/10, 15:06 ]
Post subject:  Re: DualityNet - Networking Base for your awesome game

That indeed looks solid, good job! Looking forward to see a demo so I can take a look on how it works.

Quote:
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 xD

I lol'd, c'mon. :mrgreen:

Author:  hsnabn [ 2016/07/10, 15:17 ]
Post subject:  Re: DualityNet - Networking Base for your awesome game

Elfocrash wrote:
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 xD
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.

Author:  Adam [ 2016/07/10, 15:50 ]
Post subject:  Re: DualityNet - Networking Base for your awesome game

By the way, I'm moving this topic to the Projects forum, I think it fits better over there.

Author:  Elfocrash [ 2016/07/10, 15:51 ]
Post subject:  Re: DualityNet - Networking Base for your awesome game

Adam wrote:
By the way, I'm moving this topic to the Projects forum, I think it fits better over there.


Yeah sure np :)

Author:  Elfocrash [ 2016/07/10, 19:18 ]
Post subject:  Re: DualityNet - Networking Base for your awesome game

Yeap, im onto something :)

Only some movement related stuff to figure out and it should be good to go.

Image

Page 1 of 2 All times are UTC + 1 hour [ DST ]
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/