Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
|
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 (bool useLobbyAuth) | |
~CNetServerWorker () | |
bool | CheckPassword (const std::string &password, const std::string &salt) const |
void | SetPassword (const CStr &hashedPassword) |
void | SetControllerSecret (const std::string &secret) |
bool | SetupConnection (const u16 port) |
Begin listening for network connections. More... | |
void | AssignPlayer (int playerID, const CStr &guid) |
The given GUID will be (re)assigned to the given player ID. More... | |
void | StartGame (const CStr &initAttribs) |
Switch in game mode and notify all clients to start the game. More... | |
CStrW | DeduplicatePlayerName (const CStrW &original) |
Make a player name unique, if it matches any existing session's name. More... | |
const ScriptInterface & | GetScriptInterface () |
Get the script context used for init attributes. More... | |
void | SetTurnLength (u32 msecs) |
Set the turn length to a fixed value. More... | |
void | ProcessLobbyAuth (const CStr &name, const CStr &token) |
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 | SendHolePunchingMessage (const CStr &ip, u16 port) |
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 (CNetServerSession *session, CFsmEvent *event) |
static bool | OnAuthenticate (CNetServerSession *session, CFsmEvent *event) |
static bool | OnSimulationCommand (CNetServerSession *session, CFsmEvent *event) |
static bool | OnSyncCheck (CNetServerSession *session, CFsmEvent *event) |
static bool | OnEndCommandBatch (CNetServerSession *session, CFsmEvent *event) |
static bool | OnChat (CNetServerSession *session, CFsmEvent *event) |
static bool | OnReady (CNetServerSession *session, CFsmEvent *event) |
static bool | OnClearAllReady (CNetServerSession *session, CFsmEvent *event) |
static bool | OnGameSetup (CNetServerSession *session, CFsmEvent *event) |
static bool | OnAssignPlayer (CNetServerSession *session, CFsmEvent *event) |
static bool | OnGameStart (CNetServerSession *session, CFsmEvent *event) |
static bool | OnLoadedGame (CNetServerSession *session, CFsmEvent *event) |
static bool | OnJoinSyncingLoadedGame (CNetServerSession *session, CFsmEvent *event) |
static bool | OnRejoined (CNetServerSession *session, CFsmEvent *event) |
static bool | OnKickPlayer (CNetServerSession *session, CFsmEvent *event) |
static bool | OnDisconnect (CNetServerSession *session, CFsmEvent *event) |
static bool | OnClientPaused (CNetServerSession *session, CFsmEvent *event) |
static void | SetupUPnP () |
Try to find a UPnP root on the network and setup port forwarding. More... | |
static void | RunThread (CNetServerWorker *data) |
Private Attributes | |
ScriptInterface * | m_ScriptInterface |
Internal script context for (de)serializing script messages, and for storing init attributes. More... | |
PlayerAssignmentMap | m_PlayerAssignments |
JS::PersistentRootedValue | m_InitAttributes |
Stores the most current init attributes. More... | |
const bool | m_LobbyAuth |
Whether this match requires lobby authentication. More... | |
ENetHost * | m_Host |
std::vector< CNetServerSession * > | m_Sessions |
CNetStatsTable * | m_Stats |
NetServerState | m_State |
CStrW | m_ServerName |
std::vector< u32 > | m_BannedIPs |
std::vector< CStrW > | m_BannedPlayers |
CStr | m_Password |
std::vector< CStr > | m_PausingPlayers |
Holds the GUIDs of all currently paused players. More... | |
u32 | m_NextHostID |
CNetServerTurnManager * | m_ServerTurnManager |
CStr | m_ControllerGUID |
The GUID of the client in control of the game (the 'host' from the players' perspective). More... | |
std::string | m_ControllerSecret |
The 'secret' used to identify the controller of the game. More... | |
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... | |
std::thread | m_UPnPThread |
std::thread | m_WorkerThread |
std::mutex | m_WorkerMutex |
bool | m_Shutdown |
std::vector< bool > | m_StartGameQueue |
std::vector< std::string > | m_InitAttributesQueue |
std::vector< std::pair< CStr, CStr > > | m_LobbyAuthQueue |
std::vector< u32 > | m_TurnLengthQueue |
Friends | |
class | CNetServer |
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 |
The given GUID will be (re)assigned to the given player ID.
Any player currently using that ID will be unassigned.
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 |
|
private |
Make a player name unique, if it matches any existing session's name.
|
private |
Get the script context used for init 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 |
|
staticprivate |
|
staticprivate |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
staticprivate |
|
staticprivate |
Make a player name 'nicer' by limiting the length and removing forbidden characters etc.
|
private |
bool CNetServerWorker::SendMessage | ( | ENetPeer * | peer, |
const CNetMessage * | message | ||
) |
Send a message to the given network peer.
|
private |
|
private |
|
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 |
Switch in game mode and notify all clients to start the game.
|
friend |
|
private |
|
private |
|
private |
The GUID of the client in control of the game (the 'host' from the players' perspective).
|
private |
The 'secret' used to identify the controller of the game.
|
private |
|
private |
Stores the most current init attributes.
NB: this is not guaranteed to be up-to-date until the server is LOADING or INGAME. At that point, the settings are frozen and ought to be identical to the simulation Init Attributes.
|
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 |
Whether this match requires lobby authentication.
|
private |
|
private |
|
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 init 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 |