Pyrogenesis
trunk
|
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... | |
void | KickPlayer (const CStrW &playerName, const bool ban) |
Disconnects a player from gamesetup or session. More... | |
bool | Broadcast (const CNetMessage *message, const std::vector< NetServerSessionState > &targetStates) |
Send a message to all clients who match one of the given states. More... | |
Private Member Functions | |
NONCOPYABLE (CNetServerWorker) | |
CNetServerWorker (int autostartPlayers) | |
~CNetServerWorker () | |
bool | SetupConnection (const u16 port) |
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 (JS::MutableHandleValue 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... | |
ScriptInterface & | GetScriptInterface () |
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 | ClearAllPlayerReady () |
void | SetupSession (CNetServerSession *session) |
bool | HandleConnect (CNetServerSession *session) |
void | OnUserJoin (CNetServerSession *session) |
void | OnUserLeave (CNetServerSession *session) |
bool | CheckGameLoadStatus (CNetServerSession *changedSession) |
Checks if all clients have finished loading. More... | |
void | ConstructPlayerAssignmentMessage (CPlayerAssignmentMessage &message) |
void | HandleMessageReceive (const CNetMessage *message, CNetServerSession *session) |
void | CheckClientConnections () |
Send a network warning if the connection to a client is being lost or has bad latency. More... | |
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 | OnReady (void *context, CFsmEvent *event) |
static bool | OnClearAllReady (void *context, CFsmEvent *event) |
static bool | OnGameSetup (void *context, CFsmEvent *event) |
static bool | OnAssignPlayer (void *context, CFsmEvent *event) |
static bool | OnStartGame (void *context, CFsmEvent *event) |
static bool | OnLoadedGame (void *context, CFsmEvent *event) |
static bool | OnJoinSyncingLoadedGame (void *context, CFsmEvent *event) |
static bool | OnRejoined (void *context, CFsmEvent *event) |
static bool | OnKickPlayer (void *context, CFsmEvent *event) |
static bool | OnDisconnect (void *context, CFsmEvent *event) |
static bool | OnClientPaused (void *context, CFsmEvent *event) |
static void * | SetupUPnP (void *) |
Try to find a UPnP root on the network and setup port forwarding. More... | |
static void * | RunThread (void *data) |
Private Attributes | |
ScriptInterface * | m_ScriptInterface |
Internal script context for (de)serializing script messages, and for storing game attributes. More... | |
PlayerAssignmentMap | m_PlayerAssignments |
JS::PersistentRootedValue | m_GameAttributes |
Stores the most current game attributes. More... | |
int | m_AutostartPlayers |
ENetHost * | m_Host |
std::vector< CNetServerSession * > | m_Sessions |
CNetStatsTable * | m_Stats |
NetServerState | m_State |
CStrW | m_ServerName |
CStrW | m_WelcomeMessage |
std::vector< u32 > | m_BannedIPs |
std::vector< CStrW > | m_BannedPlayers |
std::vector< CStr > | m_PausingPlayers |
Holds the GUIDs of all currently paused players. More... | |
u32 | m_NextHostID |
CNetServerTurnManager * | m_ServerTurnManager |
CStr | m_HostGUID |
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... | |
std::time_t | m_LastConnectionCheck |
Time when the clients connections were last checked for timeouts and latency. More... | |
pthread_t | m_UPnPThread |
pthread_t | m_WorkerThread |
CMutex | m_WorkerMutex |
bool | m_Shutdown |
std::vector< bool > | m_StartGameQueue |
std::vector< std::string > | m_GameAttributesQueue |
std::vector< u32 > | m_TurnLengthQueue |
Friends | |
class | CNetServer |
class | CNetFileReceiveTask_ServerRejoin |
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:
|
private |
|
private |
|
private |
|
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.
bool CNetServerWorker::Broadcast | ( | const CNetMessage * | message, |
const std::vector< NetServerSessionState > & | targetStates | ||
) |
Send a message to all clients who match one of the given states.
|
private |
Send a network warning if the connection to a client is being lost or has bad latency.
|
private |
Checks if all clients have finished loading.
If so informs the clients about that and change the server state.
Returns if all clients finished loading.
|
private |
|
private |
|
private |
Make a player name unique, if it matches any existing session's name.
|
private |
Get the script context used for game attributes.
|
private |
|
private |
void CNetServerWorker::KickPlayer | ( | const CStrW & | playerName, |
const bool | ban | ||
) |
Disconnects a player from gamesetup or session.
|
private |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
private |
|
private |
|
private |
|
private |
|
private |
|
staticprivate |
|
staticprivate |
Make a player name 'nicer' by limiting the length and removing forbidden characters etc.
bool CNetServerWorker::SendMessage | ( | ENetPeer * | peer, |
const CNetMessage * | message | ||
) |
Send a message to the given network peer.
|
private |
|
private |
Set the turn length to a fixed value.
TODO: we should replace this with some adaptive lag-dependent computation.
|
private |
Begin listening for network connections.
|
private |
|
staticprivate |
Try to find a UPnP root on the network and setup port forwarding.
|
private |
Call from the GUI to notify all clients that they should start loading the game.
|
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.
attrs | game attributes, in the script context of GetScriptInterface() |
|
friend |
|
friend |
|
private |
|
private |
|
private |
|
private |
Stores the most current game attributes.
|
private |
|
private |
|
private |
|
private |
The latest copy of the simulation state, received from an existing client when a new client has asked to rejoin the game.
|
private |
Time when the clients connections were last checked for timeouts and latency.
|
private |
|
private |
Holds the GUIDs of all currently paused players.
|
private |
|
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.
|
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.)
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |