newspeoplefor developersdocumentationdownloads

nNetServer Class Reference
[Network/Multiplayer Subsystem]

#include <nnetserver.h>

Inheritance diagram for nNetServer:

nRoot nObject nNode nReferenced nSignalEmitter NetServerDemo List of all members.

Detailed Description

A server in a multiplayer session. Should be subclasses for specific applications or protocols.

After the session server has collected information about the network clients and the player has hit the start button, the session server should configure the net server object with the clients which are expected to join (with "localclient" being a special shortcut connection to the local nnetclient object). After the configuration the game server should be opened, after which the server will wait for the clients to connect. Once all clients are connected, the IsStarted() flag will turn true, and communication can begin.

The net server is a simple message distributor. It either sends messages to all clients, or replicates messages from one client to all other clients. Specific communication protocols and behavior should be implemented in subclasses.

This is the net client/server protocol:

    ---
    client: "~joinsession clientGuid"
    server: "~joinaccepted" OR "~joindenied"

A client requestes to join the server. A client must send a guid to the server for authentification. This must be one of the guids set by nNetServer::SetClientGuid(). This guid is usually the result of the session setup process. The server answers with a ~joinaccepted or ~joindenied.

    ---
    server: "~start"
    client: ---

This message is sent by the server once to all clients, when all clients have connected.

    ---
    server: "~closesession"
    client: ---

This is sent by the server to all clients when the session is ended by the host. Only the host may close the session. No reply is expected from the clients.

(C) 2003 RadonLabs GmbH

Definition at line 65 of file nnetserver.h.


Public Types

enum  ClientStatus {
  Invalid,
  Waiting,
  Connected,
  Timeout
}
 client status enum More...

Public Member Functions

 nNetServer ()
 constructor
virtual ~nNetServer ()
 destructor
void SetPortName (const char *name)
 set the communication port name
const char * GetPortName () const
 get the communication port name
void BeginClients (int numClients)
 begin configuring client info
void SetClientGuid (int clientIndex, const char *clientGuid)
 set client guid
void SetClientPlayerName (int clientIndex, const char *name)
 set client player name
void EndClients ()
 finish configuring client info
int GetNumClients () const
 get number of clients
const char * GetClientGuidAt (int index) const
 get guid of client at index
const char * GetClientPlayerNameAt (int index) const
 get client player status at index
ClientStatus GetClientStatusAt (int index) const
 get client connection status
bool Open ()
 open the network session
void Close ()
 close the network session
void Trigger ()
 per-frame-trigger
bool IsOpen () const
 return true if server is open
bool IsStarted () const
 return true if session is started (all clients have connected)

Protected Member Functions

virtual bool HandleMessage (int fromClientId, const char *msg)
 handle a custom message (handled by subclass)
virtual void OnStart ()
 perform protocol specific OnStart() action
void HandleJoinSessionRequest (int clientId, const char *clientGuid)
 handle a join session request from a client

Protected Attributes

nString portName
nArray< ClientContextclientArray
bool isOpen
bool isStarted
nIpcServeripcServer

Classes

class  ClientContext

Member Enumeration Documentation

enum nNetServer::ClientStatus
 

client status enum

Enumerator:
Invalid 
Waiting 
Connected 
Timeout 

Definition at line 69 of file nnetserver.h.


Constructor & Destructor Documentation

nNetServer::nNetServer  ) 
 

constructor

Definition at line 13 of file nnetserver_main.cc.

nNetServer::~nNetServer  )  [virtual]
 

destructor

Definition at line 24 of file nnetserver_main.cc.


Member Function Documentation

void nNetServer::SetPortName const char *  name  )  [inline]
 

set the communication port name

Definition at line 278 of file nnetserver.h.

const char * nNetServer::GetPortName  )  const [inline]
 

get the communication port name

Definition at line 289 of file nnetserver.h.

void nNetServer::BeginClients int  numClients  )  [inline]
 

begin configuring client info

Definition at line 299 of file nnetserver.h.

void nNetServer::SetClientGuid int  clientIndex,
const char *  clientGuid
[inline]
 

set client guid

Definition at line 310 of file nnetserver.h.

void nNetServer::SetClientPlayerName int  clientIndex,
const char *  name
[inline]
 

set client player name

Definition at line 322 of file nnetserver.h.

void nNetServer::EndClients  )  [inline]
 

finish configuring client info

Definition at line 333 of file nnetserver.h.

int nNetServer::GetNumClients  )  const [inline]
 

get number of clients

Definition at line 343 of file nnetserver.h.

const char * nNetServer::GetClientGuidAt int  index  )  const [inline]
 

get guid of client at index

Definition at line 353 of file nnetserver.h.

const char * nNetServer::GetClientPlayerNameAt int  index  )  const [inline]
 

get client player status at index

Definition at line 363 of file nnetserver.h.

nNetServer::ClientStatus nNetServer::GetClientStatusAt int  index  )  const [inline]
 

get client connection status

Definition at line 373 of file nnetserver.h.

bool nNetServer::Open  ) 
 

open the network session

Definition at line 36 of file nnetserver_main.cc.

void nNetServer::Close  ) 
 

close the network session

Definition at line 64 of file nnetserver_main.cc.

void nNetServer::Trigger void   ) 
 

per-frame-trigger

Process pending messages. This must be called frequently (i.e. once per frame) while the network server is open.

Definition at line 95 of file nnetserver_main.cc.

bool nNetServer::IsOpen  )  const [inline]
 

return true if server is open

Return true if net server is open.

Definition at line 384 of file nnetserver.h.

bool nNetServer::IsStarted  )  const [inline]
 

return true if session is started (all clients have connected)

Return true if all clients have connected.

Definition at line 395 of file nnetserver.h.

bool nNetServer::HandleMessage int  fromClientId,
const char *  msg
[protected, virtual]
 

handle a custom message (handled by subclass)

Handle a custom message. This method should be overwritten by subclasses to check to process specific custom messages.

Reimplemented in NetServerDemo.

Definition at line 205 of file nnetserver_main.cc.

void nNetServer::OnStart  )  [protected, virtual]
 

perform protocol specific OnStart() action

Handle protocol specific OnStart() actions. Should be overwritten by subclasses.

Definition at line 217 of file nnetserver_main.cc.

void nNetServer::HandleJoinSessionRequest int  clientId,
const char *  clientGuid
[protected]
 

handle a join session request from a client

Handle a join session request message from a client. This checks if the provided guid matches one of the pre-configured guid's, and if this is the case, a "~joinaccepted" message is returned, otherwise, a "~joindenied".

Definition at line 174 of file nnetserver_main.cc.


Member Data Documentation

nString nNetServer::portName [protected]
 

Definition at line 153 of file nnetserver.h.

nArray<ClientContext> nNetServer::clientArray [protected]
 

Definition at line 154 of file nnetserver.h.

bool nNetServer::isOpen [protected]
 

Definition at line 155 of file nnetserver.h.

bool nNetServer::isStarted [protected]
 

Definition at line 156 of file nnetserver.h.

nIpcServer* nNetServer::ipcServer [protected]
 

Definition at line 157 of file nnetserver.h.


The documentation for this class was generated from the following files:

Copyright © 1999-2005 by the contributing authors. Ideas, requests, problems: Send feedback.