Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
CNetServerWorker Class Reference

Network server worker thread. More...

#include <NetServer.h>

Public Member Functions

bool SendMessage (ENetPeer *peer, const CNetMessage *message)
 Send a message to the given network peer. More...
 
bool Broadcast (const CNetMessage *message)
 Send a message to all clients who have completed the full connection process (i.e. More...
 

Private Member Functions

 NONCOPYABLE (CNetServerWorker)
 
 CNetServerWorker (int autostartPlayers)
 
 ~CNetServerWorker ()
 
bool SetupConnection ()
 Begin listening for network connections. More...
 
void AssignPlayer (int playerID, const CStr &guid)
 Call from the GUI to update the player assignments. More...
 
void StartGame ()
 Call from the GUI to notify all clients that they should start loading the game. More...
 
void UpdateGameAttributes (const CScriptValRooted &attrs)
 Call from the GUI to update the game setup attributes. More...
 
CStrW DeduplicatePlayerName (const CStrW &original)
 Make a player name unique, if it matches any existing session's name. More...
 
ScriptInterfaceGetScriptInterface ()
 Get the script context used for game attributes. More...
 
void SetTurnLength (u32 msecs)
 Set the turn length to a fixed value. More...
 
void AddPlayer (const CStr &guid, const CStrW &name)
 
void RemovePlayer (const CStr &guid)
 
void SendPlayerAssignments ()
 
void SetupSession (CNetServerSession *session)
 
bool HandleConnect (CNetServerSession *session)
 
void OnUserJoin (CNetServerSession *session)
 
void OnUserLeave (CNetServerSession *session)
 
void CheckGameLoadStatus (CNetServerSession *changedSession)
 
void ConstructPlayerAssignmentMessage (CPlayerAssignmentMessage &message)
 
void HandleMessageReceive (const CNetMessage *message, CNetServerSession *session)
 
void Run ()
 
bool RunStep ()
 

Static Private Member Functions

static CStrW SanitisePlayerName (const CStrW &original)
 Make a player name 'nicer' by limiting the length and removing forbidden characters etc. More...
 
static bool OnClientHandshake (void *context, CFsmEvent *event)
 
static bool OnAuthenticate (void *context, CFsmEvent *event)
 
static bool OnInGame (void *context, CFsmEvent *event)
 
static bool OnChat (void *context, CFsmEvent *event)
 
static bool OnLoadedGame (void *context, CFsmEvent *event)
 
static bool OnJoinSyncingLoadedGame (void *context, CFsmEvent *event)
 
static bool OnDisconnect (void *context, CFsmEvent *event)
 
static void * RunThread (void *data)
 

Private Attributes

ScriptInterfacem_ScriptInterface
 Internal script context for (de)serializing script messages, and for storing game attributes. More...
 
PlayerAssignmentMap m_PlayerAssignments
 
CScriptValRooted m_GameAttributes
 
int m_AutostartPlayers
 
ENetHostm_Host
 
std::vector< CNetServerSession * > m_Sessions
 
CNetStatsTablem_Stats
 
NetServerState m_State
 
CStrW m_ServerName
 
CStrW m_WelcomeMessage
 
u32 m_NextHostID
 
CNetServerTurnManagerm_ServerTurnManager
 
std::vector< std::vector
< CSimulationMessage > > 
m_SavedCommands
 A copy of all simulation commands received so far, indexed by turn number, to simplify support for rejoining etc. More...
 
std::string m_JoinSyncFile
 The latest copy of the simulation state, received from an existing client when a new client has asked to rejoin the game. More...
 
pthread_t m_WorkerThread
 
CMutex m_WorkerMutex
 
bool m_Shutdown
 
std::vector< std::pair< int,
CStr > > 
m_AssignPlayerQueue
 
std::vector< bool > m_StartGameQueue
 
std::vector< std::string > m_GameAttributesQueue
 
std::vector< u32m_TurnLengthQueue
 

Friends

class CNetServer
 
class CNetFileReceiveTask_ServerRejoin
 

Detailed Description

Network server worker thread.

(This is run in a thread so that client/server communication is not delayed by the host player's framerate - the only delay should be the network latency.)

Thread-safety:

Definition at line 160 of file NetServer.h.

Constructor & Destructor Documentation

CNetServerWorker::CNetServerWorker ( int  autostartPlayers)
private

Definition at line 111 of file NetServer.cpp.

CNetServerWorker::~CNetServerWorker ( )
private

Definition at line 125 of file NetServer.cpp.

Member Function Documentation

void CNetServerWorker::AddPlayer ( const CStr &  guid,
const CStrW &  name 
)
private

Definition at line 481 of file NetServer.cpp.

void CNetServerWorker::AssignPlayer ( int  playerID,
const CStr &  guid 
)
private

Call from the GUI to update the player assignments.

The given GUID will be (re)assigned to the given player ID. Any player currently using that ID will be unassigned. The changes will be propagated to all clients.

Definition at line 549 of file NetServer.cpp.

bool CNetServerWorker::Broadcast ( const CNetMessage message)

Send a message to all clients who have completed the full connection process (i.e.

are in the pre-game or in-game states).

Definition at line 197 of file NetServer.cpp.

void CNetServerWorker::CheckGameLoadStatus ( CNetServerSession changedSession)
private

Definition at line 824 of file NetServer.cpp.

void CNetServerWorker::ConstructPlayerAssignmentMessage ( CPlayerAssignmentMessage &  message)
private

Definition at line 565 of file NetServer.cpp.

CStrW CNetServerWorker::DeduplicatePlayerName ( const CStrW &  original)
private

Make a player name unique, if it matches any existing session's name.

Definition at line 890 of file NetServer.cpp.

ScriptInterface & CNetServerWorker::GetScriptInterface ( )
private

Get the script context used for game attributes.

Definition at line 587 of file NetServer.cpp.

bool CNetServerWorker::HandleConnect ( CNetServerSession session)
private

Definition at line 448 of file NetServer.cpp.

void CNetServerWorker::HandleMessageReceive ( const CNetMessage message,
CNetServerSession session 
)
private

Definition at line 392 of file NetServer.cpp.

CNetServerWorker::NONCOPYABLE ( CNetServerWorker  )
private
bool CNetServerWorker::OnAuthenticate ( void *  context,
CFsmEvent event 
)
staticprivate

Definition at line 621 of file NetServer.cpp.

bool CNetServerWorker::OnChat ( void *  context,
CFsmEvent event 
)
staticprivate

Definition at line 730 of file NetServer.cpp.

bool CNetServerWorker::OnClientHandshake ( void *  context,
CFsmEvent event 
)
staticprivate

Definition at line 598 of file NetServer.cpp.

bool CNetServerWorker::OnDisconnect ( void *  context,
CFsmEvent event 
)
staticprivate

Definition at line 812 of file NetServer.cpp.

bool CNetServerWorker::OnInGame ( void *  context,
CFsmEvent event 
)
staticprivate

Definition at line 692 of file NetServer.cpp.

bool CNetServerWorker::OnJoinSyncingLoadedGame ( void *  context,
CFsmEvent event 
)
staticprivate

Definition at line 761 of file NetServer.cpp.

bool CNetServerWorker::OnLoadedGame ( void *  context,
CFsmEvent event 
)
staticprivate

Definition at line 746 of file NetServer.cpp.

void CNetServerWorker::OnUserJoin ( CNetServerSession session)
private

Definition at line 457 of file NetServer.cpp.

void CNetServerWorker::OnUserLeave ( CNetServerSession session)
private

Definition at line 470 of file NetServer.cpp.

void CNetServerWorker::RemovePlayer ( const CStr &  guid)
private

Definition at line 542 of file NetServer.cpp.

void CNetServerWorker::Run ( )
private

Definition at line 228 of file NetServer.cpp.

bool CNetServerWorker::RunStep ( )
private

Definition at line 254 of file NetServer.cpp.

void * CNetServerWorker::RunThread ( void *  data)
staticprivate

Definition at line 219 of file NetServer.cpp.

CStrW CNetServerWorker::SanitisePlayerName ( const CStrW &  original)
staticprivate

Make a player name 'nicer' by limiting the length and removing forbidden characters etc.

Definition at line 868 of file NetServer.cpp.

bool CNetServerWorker::SendMessage ( ENetPeer peer,
const CNetMessage message 
)

Send a message to the given network peer.

Definition at line 188 of file NetServer.cpp.

void CNetServerWorker::SendPlayerAssignments ( )
private

Definition at line 580 of file NetServer.cpp.

void CNetServerWorker::SetTurnLength ( u32  msecs)
private

Set the turn length to a fixed value.

TODO: we should replace this with some adaptive lag-dependent computation.

Definition at line 592 of file NetServer.cpp.

bool CNetServerWorker::SetupConnection ( )
private

Begin listening for network connections.

Returns
true on success, false on error (e.g. port already in use)

Definition at line 157 of file NetServer.cpp.

void CNetServerWorker::SetupSession ( CNetServerSession session)
private

Definition at line 418 of file NetServer.cpp.

void CNetServerWorker::StartGame ( )
private

Call from the GUI to notify all clients that they should start loading the game.

Definition at line 839 of file NetServer.cpp.

void CNetServerWorker::UpdateGameAttributes ( const CScriptValRooted attrs)
private

Call from the GUI to update the game setup attributes.

This must be called at least once before starting the game. The changes will be propagated to all clients.

Parameters
attrsgame attributes, in the script context of GetScriptInterface()

Definition at line 856 of file NetServer.cpp.

Friends And Related Function Documentation

friend class CNetFileReceiveTask_ServerRejoin
friend

Definition at line 180 of file NetServer.h.

friend class CNetServer
friend

Definition at line 179 of file NetServer.h.

Member Data Documentation

std::vector<std::pair<int, CStr> > CNetServerWorker::m_AssignPlayerQueue
private

Definition at line 312 of file NetServer.h.

int CNetServerWorker::m_AutostartPlayers
private

Definition at line 270 of file NetServer.h.

CScriptValRooted CNetServerWorker::m_GameAttributes
private

Definition at line 268 of file NetServer.h.

std::vector<std::string> CNetServerWorker::m_GameAttributesQueue
private

Definition at line 314 of file NetServer.h.

ENetHost* CNetServerWorker::m_Host
private

Definition at line 272 of file NetServer.h.

std::string CNetServerWorker::m_JoinSyncFile
private

The latest copy of the simulation state, received from an existing client when a new client has asked to rejoin the game.

Definition at line 297 of file NetServer.h.

u32 CNetServerWorker::m_NextHostID
private

Definition at line 282 of file NetServer.h.

PlayerAssignmentMap CNetServerWorker::m_PlayerAssignments
private

Definition at line 266 of file NetServer.h.

std::vector<std::vector<CSimulationMessage> > CNetServerWorker::m_SavedCommands
private

A copy of all simulation commands received so far, indexed by turn number, to simplify support for rejoining etc.

TODO: verify this doesn't use too much RAM.

Definition at line 291 of file NetServer.h.

ScriptInterface* CNetServerWorker::m_ScriptInterface
private

Internal script context for (de)serializing script messages, and for storing game attributes.

(TODO: we shouldn't bother deserializing (except for debug printing of messages), we should just forward messages blindly and efficiently.)

Definition at line 264 of file NetServer.h.

CStrW CNetServerWorker::m_ServerName
private

Definition at line 279 of file NetServer.h.

CNetServerTurnManager* CNetServerWorker::m_ServerTurnManager
private

Definition at line 284 of file NetServer.h.

std::vector<CNetServerSession*> CNetServerWorker::m_Sessions
private

Definition at line 273 of file NetServer.h.

bool CNetServerWorker::m_Shutdown
private

Definition at line 309 of file NetServer.h.

std::vector<bool> CNetServerWorker::m_StartGameQueue
private

Definition at line 313 of file NetServer.h.

NetServerState CNetServerWorker::m_State
private

Definition at line 277 of file NetServer.h.

CNetStatsTable* CNetServerWorker::m_Stats
private

Definition at line 275 of file NetServer.h.

std::vector<u32> CNetServerWorker::m_TurnLengthQueue
private

Definition at line 315 of file NetServer.h.

CStrW CNetServerWorker::m_WelcomeMessage
private

Definition at line 280 of file NetServer.h.

CMutex CNetServerWorker::m_WorkerMutex
private

Definition at line 307 of file NetServer.h.

pthread_t CNetServerWorker::m_WorkerThread
private

Definition at line 306 of file NetServer.h.


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