3D Networked Game

18 views
Skip to first unread message

gameTime

unread,
Feb 16, 2011, 11:46:52 AM2/16/11
to lidgren-network
Hi all,

I'm developing a 3D networked game with the help of the Lidgren
networking library and am now quite comfortable with most of the 3D
aspects of XNA, however I am still trying to comprehend how the
networking will be implemented into the game.

The main objective of the game is to fly a jet aircraft around a 3D
world and shoot down enemy planes (which will be controlled by other
players across the network).

What I have planned to do so far is detailed below, but I know that
there is most likely mistakes and things I havn't thought about. What
I'm hoping is that someone can point out the flaws and I especially
need some help with point number 4.:

1. Declare client and server vars like so in the root of the main game
class:

NetClient client;
NetServer server;

2. Have code like this in the Update method:

if (client != null || server != null)
{
UpdateNetwork();
}
else
{
//If H key is pressed call the HostClicked method
if (keyBoardState.IsKeyDown(Keys.H))
{
HostClicked();
}
//If C key is pressed call the ClientClicked
method
if (keyBoardState.IsKeyDown(Keys.N))
{
ClientClicked();
}
}

3. The HostClicked and ClientClicked methods look like this:

public void HostClicked()
{
Console.WriteLine("This is the host!!");

NetPeerConfiguration config = new
NetPeerConfiguration("test"); //must be the same on client and host
config.Port = 14242;
//set the maximum connects
config.MaximumConnections = 32;
NetServer server = new NetServer(config);
server.Start();
}

public void ClientClicked()
{
Console.WriteLine("Acting as client!!");

NetPeerConfiguration config = new
NetPeerConfiguration("test"); //must be the same on client and host

config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
client = new NetClient(config);
client.Start();

client.DiscoverLocalPeers(14242);
}

4. Then the UpdateNetwork method should update the game accordingly
depending on whether the player selected the host or client option.

So:
if (client != null)
// do client stuff here
// client should send and receive position updates of game objects
if (server!= null)
// do server stuff here
// server should update all connected clients

So basically I'd like some guidance on how to implement all this. If
anything is unclear please ask.
Thanks in advance.

lidgren

unread,
Feb 16, 2011, 12:06:09 PM2/16/11
to lidgren-network
That sounds reasonable.

You could consider always running client and optionally running server
too (when hosting) to simplify the client part (all players are
treated equal, regardless if they are host or not).

--michael
Reply all
Reply to author
Forward
0 new messages