EasyRak (RakNet Wrapper)

BlitzMax Forums/BlitzMax Programming/EasyRak (RakNet Wrapper)

Retimer(Posted 2009) [#1]
It looks like brucey might be tidying up an updated RakNet module, so i'm going to share the wrapper of a wrapper I put together, that i've been using on my servers for a while now.

First, you need jimons Raknet module, found HERE. Get the cross platform one, and place RakNet.mod into mods/jimon/ folder.

Retime.EasyRak (place in mods/retime/easyrak.mod, as "easyrak.bmx")


I also threw together a 10 minute example of how you can use it. To use it, run the server, then run a client, and move the mouse around the screen. It should update for the server and the client (you'll see a ball moving around - very very skim example of the way unreliable movement packets are used in online fps and some mmorpgs)...along with a couple usages of reliable packets.

server.bmx (place anywhere)





Client.bmx



Note, I haven't really gone through the module to find useless fields, or functions that may not work (security, for example, probobly doesn't work)....but the main core functions of it work.

Time


Zeke(Posted 2009) [#2]
wow. thanks. i think this is very useful for my morpg.. (And YES, not MMORPG, only MORPG).


Retimer(Posted 2009) [#3]
I'm not sure just how well raknet would work with mmorpgs - i'm sure with optimism there's no reason it couldn't support 50-100 players on a powerful server.
I suppose I should clarify that, that is how movement is usually done (as mentioned, a very dumbed down version of 'how') in FPS games, however some mmorpgs are done using unreliable packets as well.

As for packets:

UNRELIABLE - usually for packets that are sent 'constantly' ex: 5-10 times per second. It's not a big deal if a few packets here and there are lost in these cases. Free-movement (halflife/halo look and movement for example) is a good time to use it.

Reliable - It's reliable, but it might not recieve in the order you sent it. If it doesn't matter what order the packet comes in, then this is the packet to use. A good use for this might be spawning entities in a 2d/3d world, assuming they can't be destroyed within the same second that they are spawned. Ex: if you spawn an entire orc camp, does it matter which orc spawns first within the same second? not really...as long as the client can see that it has spawned.

RELIABLE_ORDERED - Same as tcp packets. It will arrive, and it will arrive in exactly the order you sent it. Good for sending stat updates, important messages all together.

Unlike basic tcp though, what's so great with raknet is that you won't have to seperate clumped together packets, amongst several other 'betters' about (r)udp. One thing you'll also notice is that I only supplied the bitstream method of sending data. I'm pretty sure this takes up more processing, for the value of less bandwidth used.


Zeke(Posted 2009) [#4]
well let me check..,, im currently using bnetex... and everythin is going well.. but.. i also want to check raknet... because there is packet encryption etc...


DreamLoader(Posted 2009) [#5]
nice work!!!


Blitzbat(Posted 2009) [#6]
It seems there is an error with reading and writing floats.

For example:
My server calculates the positions that are floats.
The servers float is 0.300000012
The client received -0.200000003

I've tried to turn off compression on server and client but it doesn't work , too.


Brucey(Posted 2009) [#7]
Looking at the bits...
00111110100110011001100110011010   <-  0.300000012
10111110010011001100110011001101   <- -0.200000003

it looks like the bits are out by 1. The negative bit is probably coming from the next/previous number.

HTH :-)


Brucey(Posted 2009) [#8]
Oh... and here's the code to see it for yourself :
Local f:Float = 0.300000012:Float
Local f2:Float = -0.200000003:Float
Print Bin(Int Ptr(Float Ptr(Varptr f))[0])
Print Bin(Int Ptr(Float Ptr(Varptr f2))[0])



Blitzbat(Posted 2009) [#9]
so maybe there is an error in my packet code?!


Blitzbat(Posted 2009) [#10]
addition:

i've tried it with integers. It works great.... mhh very strange

are there any suggestions to fix this problem?


Retimer(Posted 2009) [#11]
I will release a framework remake based on bruceys version of the raknet module soon. The above easyrak module was a rushed together prototype for creating servers/clients for my apps. There are some issues with jimons version of raknet, and with my old EasyRak module, so I wouldn't rely on it much.

It's more of a reference in the meantime.