PDA

View Full Version : RakNet Support (WIP)



SushiBox
11-27-2008, 01:18 AM
I am currently working on a 2D MMORPG in DarkGDK but me and my team have decided to switch over to NovaShell because of the very flexible license terms and it uses Box2D (which is what we were using anyway so no difference in the switch).

So I am kinda hoping Seth or a long time source user to give me some feedback on integrating RakNet in the source code (no LUA scripting support yet).

I already coded a basic server with user commands and etc, but do you think it is possible to convert NovaShell into a stand alone ORPG?

P.S. I will release a guide on implementing RakNet in the source once im successful.

harrio
11-27-2008, 11:41 PM
sweet sushi,

you will earn the respect and admiration of many here if you can move us closer to network support for novashell.

especially people like me who apparently are not sharp enough to figure it out.

thanks,

Seth
11-28-2008, 02:22 AM
Well, if I was doing a networked game here are some basic ideas...

Modify the Entity class so they can be tagged "net objects", remote net objects do not use the Box2d physics, the client will just received updates of position, rotation, map changes.

They could use prediction based on the displacements of the last two positions. Games like racing games work best for this, because you can't do a 180 degree instant turn.

A game server figures out what maps need to be sent updates on based on the player position, when things are out of range, they are automatically killed. (This server part heavily depends on the game type... the server could be a version of novashell that just doesn't draw what its doing to improve speed)

Some games, like Ultima Online use clicks and send desired tile to move to instead of sending rough movements, and verify the new position while displaying the walk animation so you don't notice the 200 MS delay while the server is actually checking each step you make. Otherwise, gameplay would be a drag.

A game like Quake/Torque engine doesn't verify movement the same way, it lets you move wherever you want and just tells the server where you are so it can distribute the data to the other players. So UDP packets are ok, and only some packets are "guaranteed", like shooting and such.

Where it gets tricky is you probably don't want Box2D doing much with netobjects.. so you want your server figuring out collision and game logic (best for security) using some other method like simple circle-circle checks.

SushiBox
11-28-2008, 12:08 PM
I am going to create it for a 2D MMORPG, keyboard controlled, and UDP. Although as you may know, RakNet can order and guarantee UDP packets so I will use a health mixture of both methods for streaming and messaging.

We only plan to use Box2D for movement and collision. No added physics like boxes and etc.

I am looking forward to more input like where to add the initial connection etc etc. Do you think any existing libraries will throw conflicts with RakNet? I haven't been able to test integration yet, I am modifying/learning the pre-exsistant source code.

Once I get the basic integration done I will release the source code so there will be a net enabled version. I am debating on wrapping the functions in LUA.

Thanks,
Dylan

harrio
11-28-2008, 10:42 PM
hey seth & sushi,

just a question, not a request. would the general workings of 2d type games like board games, cards, puzzles and stuff like that be easier to implement with networking or just as hard?

i know people here will chomp at the bit for orpg, but i'm sure some have other game types that they might want to try and implement online too.

i've been considering doing a bidwhist game or dominoes with an ethnic flavor to it. but i would not want it to be simply single player against ai. seth's engine is perfect for designing 2d casual games and such because the visual elements are almost like photoshop for games. so networking at some level of workable simplicity would be a pants soiling event for novashell.

also, as if i have not already asked too much, what are some good references or tutorial sites for getting my head around this 'networking' crap. i love it, and every game engine site i visit clamors for it. but like web design, only a few people actually do it, while the rest of ramble on 'wishing' we could do it too.

SushiBox
11-29-2008, 04:06 PM
Should be the same basic concept. The only thing, it is literally impossibly to integrate networking and keep this engine as flexible as it is. The user would HAVE to know a bit of C++, or else the scripting would be ridiculous to use or implement.

I plan to release COMPLETELY change the current engine to my needs, but I will post a guide on implementing a RakNet base into Novashell once im successful.

Go check out RakNet and mess around with it, if you watch all the incredibly long videos they have to offer, I guarantee you will learn a lot. You do not need to thread or worry about sockets cause RakNet already does this underneath. They take the working out of networking.

I'll keep you all updated, id also like to know if Seth would be too terribly upset if I released my modded version of the engine way down the road once my MMO is released.

You guys can visit my site here: www.SylereanOnline.com

SushiBox
11-29-2008, 10:23 PM
Update: I got the RakNet library implemented and some client sided code in there compiling with no errors. Problem is, i'm looking for a good insertion point to call the function.

I also added two new commands in the source:

LogNetwork - Saves a message to the log prepended with "Network: "

Usage: LogNetwork(const char *lpFormat, ...)

LogNetworkError - Saves a message to the log prepended with "Network Error: "

Usage: LogNetworkError(const char *lpFormat, ...)

I need to look more into how to create commands for LUA. I'm not sure how all the binding works yet.

Once again, ill keep all of you updated.

SushiBox
11-30-2008, 04:53 AM
Update: Clients can now successfully connect to the server! The server also has four user commands built in.

/help - displays a list of usable commands
/stat - displays in depth statistics on server communications
/ban - bans an IP for the session only (no database required)
/shutdown - shuts down the server and safely logs off clients

May not seem to incredibly in depth, but at least I got Novashell enabled with basic networking capabilities!!! Once I learn how to bind commands to LUA, I will create some basic commands such as setting the server IP and enabling networking.

Seth, mind enlightening me?

harrio
11-30-2008, 05:03 PM
sweet sushi,

i don't know what all of that means, but i know it sounds like steady progress towards basic networking in novashell...kudos.

i'm looking at the raknet site...it's painful. learning, or in my case, trying to learn, can be a violent, invasive ordeal at times.

wish i could contribute something as significant as what you are doing to the shellerz.

keep at it, i'm sure seth appreciates the help...

SushiBox
11-30-2008, 05:13 PM
Thanks harrio, right now I'm implementing MySQL into the server for some database support. Should be able to do some simple things such as logging in and etc. I just really need Seth to get on here and tutor me on the LUA bindings.

You can add me on MSN if you have, same with Seth.: Crank@Gomoku-MS.com

Seth
12-01-2008, 12:54 AM
Luabind isn't hard to use, but it's a nightmare to debug when something goes wrong... it's an insanely complicated template system to very quickly allow script to access classes.

Luabind docs (http://www.rasterbar.com/products/luabind/docs.html) is the best place to learn about it

So, let's say you have a NetworkManager.cpp global, and it has like 10 functions you want to give scripters access to.

Use the TextManager global (g_textManager) as an example.

First, you register it:

void luabindMisc(lua_State *pState)
{
module(pState)
[
,class_<TextManager>("TextManager")
.def("__tostring", &TextManagerToString)
.def("Add", &TextManager::Add)
.def("AddCustom", &TextManager::AddCustom)
.def("AddCustomScreen", &TextManager::AddCustomScreen)
];
}


Then you give the scripting system a way to access the global (if needed):

Luabind will automatically look at each of these functions and figure its parameters.

The "__tostring" is a special function that just tells the scripting system what to print if someone says LogMsg(GetTextManager); it isn't required.


luabind::globals(pLuaState)["GetTextManager"] = &g_textManager;

You can search to see where I do it in the source, but keep in mind, you probably want to put most of your stuff in separate files and just add 'hooks', so it's easier for you to add bugfixes ect that come from me.

Good luck!


I'll keep you all updated, id also like to know if Seth would be too terribly upset if I released my modded version of the engine way down the road once my MMO is released.


Certainly fine with me! Assuming you get that far... ;)

harrio
12-01-2008, 06:20 PM
great to see you and seth working together on this. of course it hurt my head just to read the 'advice' seth gave you.:confused:

now i'll finally be able to make that 'caveman checkers' online game i've always wanted to.

just joking...although;)

bobmanc
12-01-2008, 06:53 PM
Since Novashell is based on Clanlib wouldn't it make sense to try to use it's networking code?

SushiBox
12-01-2008, 07:55 PM
RakNet is an AMAZING UDP networking library, its commercially backed and very easy to use. I wouldn't ever want to use anything else.

I'm going to read Seth's response now, was way too tired last night haha.

nihilocrat
12-02-2008, 06:08 PM
One of the problems with using RakNet as NovaShell's networking lib of choice is that it has a closed-source license. If you wanted to sell your network-enabled NovaShell game, you'd have to buy a proper license from RakNet. If you wanted to sell your non-network-enabled game and not want to pay for a RakNet license, there would have to be some way of not including RakNet in your product.

Thankfully, it is licensed as CC non-commercial, so for non-commercial products you could use it however you wanted. Having it as a third-party plugin of some sort would be nice.

SushiBox
12-02-2008, 07:49 PM
The commercial license for RakNet is only $99, which isn't bad, but they allow for bargaining or a pay as you go plan.

But performance wise, RakNet is amazing.

SushiBox
12-02-2008, 09:53 PM
Ok, I finally ran into some trouble :sweatdrop:

I tried adding in the bind for the NetworkManager. Here are the files I created and filled up as you showed.

NetworkManager.h
NetworkManger.cpp
NetworkManagerBindings.h
NetworkManagerBindings.cpp

I tried adding OpenNetwork( PORT, IP ) and CloseNetwork(). It compiled fine with no errors, but when I went to go run the application, I got an assertion error. After finding where, this is what it said in the source:



// if you get caught in this assert you are
// trying to use an unregistered type
assert(crep && "you are trying to use an unregistered type");


If you need to see any source I have written so far, let me know which file cause there is a lot.

For those who are wondering about the two commands I have added, OpenNetwork will allow your game to connect to the server on the selected IP and PORT. Would be useful to call on startup. CloseNetwork will send a disconnect to the server to let it know we are logging off, would be useful to call after the database update on exit.

I know its not much, but its slow and stead Client/Server communications using LUA scripting for NovaShell.

Seth
12-03-2008, 12:16 AM
I tried adding OpenNetwork( PORT, IP ) and CloseNetwork(). It compiled fine with no errors, but when I went to go run the application, I got an assertion error.

Are PORT or IP custom structures/classes? If so, you would have to also define those in luabind before you can use them.

SushiBox
12-03-2008, 12:27 AM
Well here is the function for the connect (some of it)

NetworkManager.cpp


void NetworkManager::OpenNetwork ( int PORT, const char *IPADDRESS )
{
LogMsg( "Initializing Server Connection..." );

unsigned char GetPacketIdentifier(Packet *packet);
unsigned char packetIdentifier;

SocketDescriptor s2 ( CLIENTPORT, 0 );

rakPeer2->Startup ( 500, 0, &s2, 1 );
rakPeer2->Connect ( IPADDRESS, PORT, 0, 0, 0 );
rakPeer2->SetOccasionalPing(true);

Packet* packet = rakPeer2->Receive();

packetIdentifier = GetPacketIdentifier( packet );

switch ( packetIdentifier )
{
case ID_CONNECTION_ATTEMPT_FAILED:
LogError( "Connection Attempt Failed!" );
exit ( 1 );
break;

case ID_CONNECTION_REQUEST_ACCEPTED:
LogMsg( "Connection Request Accepted! " );
break;
}

rakPeer2->DeallocatePacket(packet);
}



and...

NetworkManagerBindings.cpp


#include "AppPrecomp.h"
#include "NetworkManagerBindings.h"
#include "NetworkManager.h"

#ifndef WIN32
//windows already has this in the precompiled header for speed, I couldn't get that to work on mac..
#include <luabind/luabind.hpp>
#include <luabind/operator.hpp>
#endif

using namespace luabind;

void luabindNetwork(lua_State *pState)
{
module(pState)
[
class_<NetworkManager>("NetworkManager")

.def("OpenNetwork", &NetworkManager::OpenNetwork)
.def("CloseNetwork", &NetworkManager::CloseNetwork)
];
}


As you can see, Port and IP are just variables used in there.

SushiBox
12-03-2008, 12:51 AM
Ok nevermind, I got it fixed and the command works like a charm in LUA!!!

The problem was, I didn't call
luabindNetwork(pLuaState);

Looks like im well on my way!

harrio
12-03-2008, 01:05 AM
hey sushi,

glad to see continued progress. i hope you remain motivated to see it through.

seth, understandably, never implemented this because it was not necessary for the project game he was working on. there were small murmurs from time to time for networking, but no one stepped up to do it. so i am elated that you have taken up the challenge.

i hope you can smoothly work through whatever criticism you may encounter here for your choice of method and implementation. i personally would not knock the only choice, unless i was ready to implement an alternative.

i wish you much success in your ' charge of the network brigade '.

SushiBox
12-03-2008, 03:09 AM
Thanks for the awesome feedback Harrio, I have started implementing more and more functions. Right now I am working on the Send functions for sending packets.

The only thing I'm worried about, is making a versatile server...

Edit: I got the data form of the send packet function. I trimmed it way down for ease of use... Lets say you want to send the string "Hello World" to the server. Here is the Lua command.



GetNetworkManager:Open ( 1234, "127.0.0.1" );
GetNetworkManager:SendPacketData ( "Hello World!", 3, 0 ); // 1 = Fast UDP, 2 = UDP, 3 = TCP
GetNetworkManager:Close ( );


Works like a charm!

harrio
12-04-2008, 12:26 AM
hey sushi,

methinks you may definately be onto something. because i actually almost understand what you were referring to in your lua code.

if you can get a solid-cerebrum like mine to nearly recognize something, than i'm sure you are on the way to making many others here, seth included, very happy.

caveman checkerz might just become a reality...lol.

keep swinging sushi...

SushiBox
12-04-2008, 12:48 AM
Thanks again Harrio, I have added more Network functionalities. Here is my little update: :)

I have added encryption support, just type the command and your connections will be encrypted with a few different methods including SHA-128 and RSA. Here are a list of all the new functions:



// Added
GetNetworkManager:EnableSecurity(); // Generates a key and encrypts packet and connection data for network security. Must be called before Open();

GetNetworkManager:DisableSecurity(); // Kinda self explanatory, turns off the security.

GetNetworkManager:EnableCustomSecurity( Key1, Key2, Key3, Key4 ); // Allows users to encrypt their packets and connections with a specified key. For hardcore enthusiasts.

GetNetworkManager:BroadcastPacketData( "Hello World!", "TCP", 0 ); // Sends this packet to everyone on the network, not just the server.

// Changed

GetNetworkManager:SendPacketData( "Hello World!", "TCP", 0 ); // Now the 2nd parameter takes the string instead of just a number. You can easily change the method of sending data by just changing the parameter. "Fast_UDP", "UDP" and "TCP" are the selections.


I am still working away here on the source! Any feedback or requests are most defiantly welcome!

Here is the total function list:




GetNetworkManager:Open( 1234, "127.0.0.1" );
GetNetworkManager:Close();
GetNetworkManager:EnableSecurity();
GetNetworkManager:EnableCustomSecurity( Key1, Key2, Key3, Key4 );
GetNetworkManager:DisableSecurity();
GetNetworkManager:SendPacketData( "Hello World!", "TCP", 0 );
GetNetworkManager:BroadcastPacketData( "Hello World!", "TCP", 0 );

harrio
12-04-2008, 05:04 AM
hey sushi,

it looks like you are really cruising along. i didn't even expect encryption.

i don't know enough as of yet to even know what to request.

will this be able to support voice chat or is that asking too much?

i'm really glad to see you crushing along at such a fast pace. i hope the others here that know more than me, which is just about everyone, give you some good feedback and requests. i would hate to hear critics on the back end when they have a chance to be helpful now.

keep crushing...the cavemen are getting restless...lol

SushiBox
12-04-2008, 07:49 PM
Voice is very possible!

I am still trying to figure out how people are going to do the server!!! People may have to create their own, until I get around to making a versatile enough one.

harrio
12-04-2008, 08:09 PM
hey sushi,

coolness on the voice. trash talking cavemen rule.

do you have any links to good tuts on learning the basics of writing server code?

also, i play around from time to time with vpn networking, aka hamachi vpn, will the code your working on accommodate lan-like connections via vpn as well as internet? or will you have to code for both events individually? i know some games have lan 'awareness'. don't know if i phrased that right. apologies if this ends up being a stupid/ill-informed question.

thanks again for the possiblity of voice. that sounds really interesting.

is it just me or does anyone else think that if sushi & seth can crack this network nut that novashell becomes a major player overnight in the 2d game engine gathering. i may toss my torque game builder license all together. even though i have not messed with it much since discovering novashell anyway.

way to go sushi...

SushiBox
12-04-2008, 08:30 PM
Lan would be very possible with some of the already existing functions! The whole thing about this networking conversion, I actually plan to release it under my own engine. I am heavily modding Novashell, it just seems like unless me and Seth could literally work together, I don't see why I wouldn't do my own fork.

I will however release a update package for Novashell but the source may not be included under the Novashell name.

To answer your question, you would need to program the server with RakNet, but this wont be needed for LAN capabilities. I am looking for someone who may wanna script up connection screens and everything.

harrio
12-04-2008, 09:45 PM
hey sushi,

ah, ok, now i understand. still cool.

so what will you be calling your engine?

will you parallel the novashell updates or eventually split off entirely from it?

still sounds really exciting.

alas, i don't know enough to help you, or i would have contributed more to this forum already.

keep at it...

SushiBox
12-04-2008, 10:57 PM
The Engine will be called Sylerean Engine! Based off my project Sylerean Online, which is my MMORPG project that will use Sylerean Engine.

As for updates, it all really depends on what Seth thinks about all of this... I am going to add more than Networking to the engine. I don't plan on just leeching updates from Seth ha ha.

harrio
12-05-2008, 06:14 PM
hey sushi,

that sounds cool.

adding networking is no small thing. at least not in my eyes. so i think you are making a major contribution to the engine.

i definately hope you and seth can work together to the benefit of novashell.

the cavemen are getting restless...lol

harrio
12-25-2008, 09:33 PM
hey sushi,

i know it's the holiday season and all. so whenever you get a chance, no rush, how about an update on the sylerean engine aka novashell networking.

harrio
06-05-2009, 06:01 PM
bumpity...bump

harrio
07-11-2009, 12:01 AM
bumpity...bump...bump...any progress sushi?