nNetServer Class Reference
[Network/Multiplayer Subsystem]
#include <nnetserver.h>
Inheritance diagram for nNetServer:

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< ClientContext > | clientArray |
| bool | isOpen |
| bool | isStarted |
| nIpcServer * | ipcServer |
Classes | |
| class | ClientContext |
Member Enumeration Documentation
|
|
client status enum
Definition at line 69 of file nnetserver.h. |
Constructor & Destructor Documentation
|
|
constructor
Definition at line 13 of file nnetserver_main.cc. |
|
|
destructor
Definition at line 24 of file nnetserver_main.cc. |
Member Function Documentation
|
|
set the communication port name
Definition at line 278 of file nnetserver.h. |
|
|
get the communication port name
Definition at line 289 of file nnetserver.h. |
|
|
begin configuring client info
Definition at line 299 of file nnetserver.h. |
|
||||||||||||
|
set client guid
Definition at line 310 of file nnetserver.h. |
|
||||||||||||
|
set client player name
Definition at line 322 of file nnetserver.h. |
|
|
finish configuring client info
Definition at line 333 of file nnetserver.h. |
|
|
get number of clients
Definition at line 343 of file nnetserver.h. |
|
|
get guid of client at index
Definition at line 353 of file nnetserver.h. |
|
|
get client player status at index
Definition at line 363 of file nnetserver.h. |
|
|
get client connection status
Definition at line 373 of file nnetserver.h. |
|
|
open the network session
Definition at line 36 of file nnetserver_main.cc. |
|
|
close the network session
Definition at line 64 of file nnetserver_main.cc. |
|
|
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. |
|
|
return true if server is open Return true if net server is open. Definition at line 384 of file nnetserver.h. |
|
|
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. |
|
||||||||||||
|
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. |
|
|
perform protocol specific OnStart() action Handle protocol specific OnStart() actions. Should be overwritten by subclasses. Definition at line 217 of file nnetserver_main.cc. |
|
||||||||||||
|
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
|
|
Definition at line 153 of file nnetserver.h. |
|
|
Definition at line 154 of file nnetserver.h. |
|
|
Definition at line 155 of file nnetserver.h. |
|
|
Definition at line 156 of file nnetserver.h. |
|
|
Definition at line 157 of file nnetserver.h. |
The documentation for this class was generated from the following files: