Pyrogenesis
trunk
|
Network client. More...
#include <NetClient.h>
Public Member Functions | |
CNetClient (CGame *game, bool isLocalClient) | |
Construct a client associated with the given game object. More... | |
virtual | ~CNetClient () |
void | TraceMember (JSTracer *trc) |
void | SetUserName (const CStrW &username) |
Set the user's name that will be displayed to all players. More... | |
CStr | GetGUID () const |
Returns the GUID of the local client. More... | |
bool | SetupConnection (const CStr &server, const u16 port) |
Set up a connection to the remote networked server. More... | |
void | DestroyConnection () |
Destroy the connection to the server. More... | |
void | Poll () |
Poll the connection for messages from the server and process them, and send any queued messages. More... | |
void | CheckServerConnection () |
Locally triggers a GUI message if the connection to the server is being lost or has bad latency. More... | |
void | Flush () |
Flush any queued outgoing network messages. More... | |
void | GuiPoll (JS::MutableHandleValue) |
Retrieves the next queued GUI message, and removes it from the queue. More... | |
void | PushGuiMessage (const JS::HandleValue message) |
Add a message to the queue, to be read by GuiPoll. More... | |
std::string | TestReadGuiMessages () |
Return a concatenation of all messages in the GUI queue, for test cases to easily verify the queue contents. More... | |
ScriptInterface & | GetScriptInterface () |
Get the script interface associated with this network client, which is equivalent to the one used by the CGame in the constructor. More... | |
bool | SendMessage (const CNetMessage *message) |
Send a message to the server. More... | |
void | HandleConnect () |
Call when the network connection has been successfully initiated. More... | |
void | HandleDisconnect (u32 reason) |
Call when the network connection has been lost. More... | |
bool | HandleMessage (CNetMessage *message) |
Call when a message has been received from the network. More... | |
void | LoadFinished () |
Call when the game has started and all data files have been loaded, to signal to the server that we are ready to begin the game. More... | |
void | SendGameSetupMessage (JS::MutableHandleValue attrs, ScriptInterface &scriptInterface) |
void | SendAssignPlayerMessage (const int playerID, const CStr &guid) |
void | SendChatMessage (const std::wstring &text) |
void | SendReadyMessage (const int status) |
void | SendClearAllReadyMessage () |
void | SendStartGameMessage () |
void | SendRejoinedMessage () |
Call when the client has rejoined a running match and finished the loading screen. More... | |
void | SendKickPlayerMessage (const CStrW &playerName, bool ban) |
Call to kick/ban a client. More... | |
void | SendPausedMessage (bool pause) |
Call when the client has paused or unpaused the game. More... | |
Public Member Functions inherited from CFsm | |
CFsm (void) | |
virtual | ~CFsm (void) |
virtual void | Setup (void) |
Constructs the state machine. More... | |
void | Shutdown (void) |
Clear event, action and condition lists and reset state machine. More... | |
void | AddState (unsigned int state) |
CFsmEvent * | AddEvent (unsigned int eventType) |
CFsmTransition * | AddTransition (unsigned int state, unsigned int eventType, unsigned int nextState) |
CFsmTransition * | AddTransition (unsigned int state, unsigned int eventType, unsigned int nextState, void *pAction, void *pContext) |
CFsmTransition * | GetTransition (unsigned int state, unsigned int eventType) const |
CFsmTransition * | GetEventTransition (unsigned int eventType) const |
void | SetFirstState (unsigned int firstState) |
void | SetCurrState (unsigned int state) |
unsigned int | GetCurrState (void) const |
void | SetNextState (unsigned int nextState) |
unsigned int | GetNextState (void) const |
const StateSet & | GetStates (void) const |
const EventMap & | GetEvents (void) const |
const TransitionList & | GetTransitions (void) const |
bool | Update (unsigned int eventType, void *pEventData) |
bool | IsValidState (unsigned int state) const |
bool | IsValidEvent (unsigned int eventType) const |
virtual bool | IsDone (void) const |
Static Public Member Functions | |
static void | Trace (JSTracer *trc, void *data) |
We assume that adding a tracing function that's only called during GC is better for performance than using a PersistentRooted<T> where each value needs to be added to the root set. More... | |
Private Member Functions | |
NONCOPYABLE (CNetClient) | |
void | SetAndOwnSession (CNetClientSession *session) |
Take ownership of a session object, and use it for all network communication. More... | |
void | PostPlayerAssignmentsToScript () |
Push a message onto the GUI queue listing the current player assignments. More... | |
Static Private Member Functions | |
static bool | OnConnect (void *context, CFsmEvent *event) |
static bool | OnHandshake (void *context, CFsmEvent *event) |
static bool | OnHandshakeResponse (void *context, CFsmEvent *event) |
static bool | OnAuthenticate (void *context, CFsmEvent *event) |
static bool | OnChat (void *context, CFsmEvent *event) |
static bool | OnReady (void *context, CFsmEvent *event) |
static bool | OnGameSetup (void *context, CFsmEvent *event) |
static bool | OnPlayerAssignment (void *context, CFsmEvent *event) |
static bool | OnInGame (void *context, CFsmEvent *event) |
static bool | OnGameStart (void *context, CFsmEvent *event) |
static bool | OnJoinSyncStart (void *context, CFsmEvent *event) |
static bool | OnJoinSyncEndCommandBatch (void *context, CFsmEvent *event) |
static bool | OnRejoined (void *context, CFsmEvent *event) |
static bool | OnKicked (void *context, CFsmEvent *event) |
static bool | OnClientTimeout (void *context, CFsmEvent *event) |
static bool | OnClientPerformance (void *context, CFsmEvent *event) |
static bool | OnClientsLoading (void *context, CFsmEvent *event) |
static bool | OnClientPaused (void *context, CFsmEvent *event) |
static bool | OnLoadedGame (void *context, CFsmEvent *event) |
Private Attributes | |
CGame * | m_Game |
CStrW | m_UserName |
CNetClientSession * | m_Session |
Current network session (or NULL if not connected) More... | |
CNetClientTurnManager * | m_ClientTurnManager |
Turn manager associated with the current game (or NULL if we haven't started the game yet) More... | |
u32 | m_HostID |
Unique-per-game identifier of this client, used to identify the sender of simulation commands. More... | |
bool | m_Rejoin |
True if the player is currently rejoining or has already rejoined the game. More... | |
bool | m_IsLocalClient |
Whether to prevent the client of the host from timing out. More... | |
JS::PersistentRootedValue | m_GameAttributes |
Latest copy of game setup attributes heard from the server. More... | |
PlayerAssignmentMap | m_PlayerAssignments |
Latest copy of player assignments heard from the server. More... | |
CStr | m_GUID |
Globally unique identifier to distinguish users beyond the lifetime of a single network session. More... | |
std::deque< JS::Heap< JS::Value > > | m_GuiMessageQueue |
Queue of messages for GuiPoll. More... | |
std::string | m_JoinSyncBuffer |
Serialized game state received when joining an in-progress game. More... | |
std::time_t | m_LastConnectionCheck |
Time when the server was last checked for timeouts and bad latency. More... | |
Friends | |
class | CNetFileReceiveTask_ClientRejoin |
Network client.
This code is run by every player (including the host, if they are not a dedicated server). It provides an interface between the GUI, the network (via CNetClientSession), and the game (via CGame and CNetClientTurnManager).
CNetClient::CNetClient | ( | CGame * | game, |
bool | isLocalClient | ||
) |
Construct a client associated with the given game object.
The game must exist for the lifetime of this object.
|
virtual |
void CNetClient::CheckServerConnection | ( | ) |
Locally triggers a GUI message if the connection to the server is being lost or has bad latency.
void CNetClient::DestroyConnection | ( | ) |
Destroy the connection to the server.
This client probably cannot be used again.
void CNetClient::Flush | ( | ) |
Flush any queued outgoing network messages.
This should be called soon after sending a group of messages that may be batched together.
|
inline |
Returns the GUID of the local client.
Used for distinguishing observers.
ScriptInterface & CNetClient::GetScriptInterface | ( | ) |
Get the script interface associated with this network client, which is equivalent to the one used by the CGame in the constructor.
void CNetClient::GuiPoll | ( | JS::MutableHandleValue | ret | ) |
Retrieves the next queued GUI message, and removes it from the queue.
The returned value is in the GetScriptInterface() JS context.
This is the only mechanism for the networking code to send messages to the GUI - it is pull-based (instead of push) so the engine code does not need to know anything about the code structure of the GUI scripts.
The structure of the messages is { "type": "...", ... }
. The exact types and associated data are not specified anywhere - the implementation and GUI scripts must make the same assumptions.
void CNetClient::HandleConnect | ( | ) |
Call when the network connection has been successfully initiated.
void CNetClient::HandleDisconnect | ( | u32 | reason | ) |
Call when the network connection has been lost.
bool CNetClient::HandleMessage | ( | CNetMessage * | message | ) |
Call when a message has been received from the network.
void CNetClient::LoadFinished | ( | ) |
Call when the game has started and all data files have been loaded, to signal to the server that we are ready to begin the game.
|
private |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
void CNetClient::Poll | ( | ) |
Poll the connection for messages from the server and process them, and send any queued messages.
This must be called frequently (i.e. once per frame).
|
private |
Push a message onto the GUI queue listing the current player assignments.
void CNetClient::PushGuiMessage | ( | const JS::HandleValue | message | ) |
Add a message to the queue, to be read by GuiPoll.
The script value must be in the GetScriptInterface() JS context.
void CNetClient::SendAssignPlayerMessage | ( | const int | playerID, |
const CStr & | guid | ||
) |
void CNetClient::SendChatMessage | ( | const std::wstring & | text | ) |
void CNetClient::SendClearAllReadyMessage | ( | ) |
void CNetClient::SendGameSetupMessage | ( | JS::MutableHandleValue | attrs, |
ScriptInterface & | scriptInterface | ||
) |
void CNetClient::SendKickPlayerMessage | ( | const CStrW & | playerName, |
bool | ban | ||
) |
Call to kick/ban a client.
bool CNetClient::SendMessage | ( | const CNetMessage * | message | ) |
Send a message to the server.
message | message to send |
void CNetClient::SendPausedMessage | ( | bool | pause | ) |
Call when the client has paused or unpaused the game.
void CNetClient::SendReadyMessage | ( | const int | status | ) |
void CNetClient::SendRejoinedMessage | ( | ) |
Call when the client has rejoined a running match and finished the loading screen.
void CNetClient::SendStartGameMessage | ( | ) |
|
private |
Take ownership of a session object, and use it for all network communication.
bool CNetClient::SetupConnection | ( | const CStr & | server, |
const u16 | port | ||
) |
Set up a connection to the remote networked server.
server | IP address or host name to connect to |
void CNetClient::SetUserName | ( | const CStrW & | username | ) |
Set the user's name that will be displayed to all players.
This must not be called after the connection setup.
std::string CNetClient::TestReadGuiMessages | ( | ) |
Return a concatenation of all messages in the GUI queue, for test cases to easily verify the queue contents.
|
inlinestatic |
We assume that adding a tracing function that's only called during GC is better for performance than using a PersistentRooted<T> where each value needs to be added to the root set.
void CNetClient::TraceMember | ( | JSTracer * | trc | ) |
|
friend |
|
private |
Turn manager associated with the current game (or NULL if we haven't started the game yet)
|
private |
|
private |
Latest copy of game setup attributes heard from the server.
|
private |
Globally unique identifier to distinguish users beyond the lifetime of a single network session.
|
private |
Queue of messages for GuiPoll.
|
private |
Unique-per-game identifier of this client, used to identify the sender of simulation commands.
|
private |
Whether to prevent the client of the host from timing out.
|
private |
Serialized game state received when joining an in-progress game.
|
private |
Time when the server was last checked for timeouts and bad latency.
|
private |
Latest copy of player assignments heard from the server.
|
private |
True if the player is currently rejoining or has already rejoined the game.
|
private |
Current network session (or NULL if not connected)
|
private |