78 static void Trace(JSTracer *trc,
void *data)
137 bool TryToConnect(
const CStr& hostJID,
bool localNetwork);
171 void GuiPoll(JS::MutableHandleValue);
177 template<
typename... Args>
182 JS::RootedValue message(rq.
cx);
struct _ENetHost ENetHost
Definition: NetClient.h:37
@ NCS_UNCONNECTED
Definition: NetClient.h:42
@ NCS_PREGAME
Definition: NetClient.h:46
@ NCS_JOIN_SYNCING
Definition: NetClient.h:48
@ NCS_CONNECT
Definition: NetClient.h:43
@ NCS_LOADING
Definition: NetClient.h:47
@ NCS_AUTHENTICATE
Definition: NetClient.h:45
@ NCS_INGAME
Definition: NetClient.h:49
@ NCS_HANDSHAKE
Definition: NetClient.h:44
CNetClient * g_NetClient
Global network client for the standard game.
Definition: NetClient.cpp:54
Various declarations shared by networking code.
std::map< CStr, PlayerAssignment > PlayerAssignmentMap
Definition: NetHost.h:54
Represents a signal in the state machine that a change has occurred.
Definition: FSM.h:33
Manages states, events, actions and transitions between states.
Definition: FSM.h:68
The container that holds the rules, resources and attributes of the game.
Definition: Game.h:43
The client end of a network session.
Definition: NetSession.h:68
Implementation of CTurnManager for network clients.
Definition: NetClientTurnManager.h:30
Network client.
Definition: NetClient.h:60
void CheckServerConnection()
Locally triggers a GUI message if the connection to the server is being lost or has bad latency.
Definition: NetClient.cpp:332
static bool OnGameSetup(CNetClient *client, CFsmEvent *event)
Definition: NetClient.cpp:713
static bool OnJoinSyncStart(CNetClient *client, CFsmEvent *event)
Definition: NetClient.cpp:782
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 ...
Definition: NetClient.h:78
static bool OnKicked(CNetClient *client, CFsmEvent *event)
Definition: NetClient.cpp:834
static bool OnJoinSyncEndCommandBatch(CNetClient *client, CFsmEvent *event)
Definition: NetClient.cpp:807
static bool OnInGame(CNetClient *client, CFsmEvent *event)
Definition: NetClient.cpp:939
static bool OnGameStart(CNetClient *client, CFsmEvent *event)
Definition: NetClient.cpp:753
void SendAssignPlayerMessage(const int playerID, const CStr &guid)
Definition: NetClient.cpp:457
const ScriptInterface & GetScriptInterface()
Get the script interface associated with this network client, which is equivalent to the one used by ...
Definition: NetClient.cpp:392
std::deque< JS::Heap< JS::Value > > m_GuiMessageQueue
Queue of messages for GuiPoll.
Definition: NetClient.h:340
std::string TestReadGuiMessages()
Return a concatenation of all messages in the GUI queue, for test cases to easily verify the queue co...
Definition: NetClient.cpp:376
bool m_UseSTUN
Definition: NetClient.h:306
CStrW m_UserName
Definition: NetClient.h:301
CStr GetGUID() const
Returns the GUID of the local client.
Definition: NetClient.h:111
void PushGuiMessage(Args const &... args)
Add a message to the queue, to be read by GuiPoll.
Definition: NetClient.h:178
static bool OnConnect(CNetClient *client, CFsmEvent *event)
Definition: NetClient.cpp:605
static bool OnClientsLoading(CNetClient *client, CFsmEvent *event)
Definition: NetClient.cpp:889
CStr m_ServerAddress
Definition: NetClient.h:304
void SendKickPlayerMessage(const CStrW &playerName, bool ban)
Call to kick/ban a client.
Definition: NetClient.cpp:498
static bool OnClientPaused(CNetClient *client, CFsmEvent *event)
Definition: NetClient.cpp:906
std::string m_JoinSyncBuffer
Serialized game state received when joining an in-progress game.
Definition: NetClient.h:343
static bool OnClientTimeout(CNetClient *client, CFsmEvent *event)
Definition: NetClient.cpp:848
void GuiPoll(JS::MutableHandleValue)
Retrieves the next queued GUI message, and removes it from the queue.
Definition: NetClient.cpp:364
bool IsController() const
Definition: NetClient.h:99
static bool OnAuthenticate(CNetClient *client, CFsmEvent *event)
Definition: NetClient.cpp:665
void PostPlayerAssignmentsToScript()
Push a message onto the GUI queue listing the current player assignments.
Definition: NetClient.cpp:397
std::thread m_PollingThread
Definition: NetClient.h:322
void SetupConnectionViaLobby()
Request connection information over the lobby.
Definition: NetClient.cpp:177
static bool OnReady(CNetClient *client, CFsmEvent *event)
Definition: NetClient.cpp:699
static bool OnAuthenticateRequest(CNetClient *client, CFsmEvent *event)
Definition: NetClient.cpp:657
void SendGameSetupMessage(JS::MutableHandleValue attrs, const ScriptInterface &scriptInterface)
Definition: NetClient.cpp:450
CStr m_HostJID
Definition: NetClient.h:303
void SendRejoinedMessage()
Call when the client has rejoined a running match and finished the loading screen.
Definition: NetClient.cpp:492
virtual ~CNetClient()
Definition: NetClient.cpp:126
bool SetupConnection(ENetHost *enetClient)
Set up a connection to the remote networked server.
Definition: NetClient.cpp:167
static bool OnPlayerAssignment(CNetClient *client, CFsmEvent *event)
Definition: NetClient.cpp:726
bool SendMessage(const CNetMessage *message)
Send a message to the server.
Definition: NetClient.cpp:423
std::string m_ControllerSecret
The 'secret' used to identify the controller of the game.
Definition: NetClient.h:314
void DestroyConnection()
Destroy the connection to the server.
Definition: NetClient.cpp:306
u32 m_HostID
Unique-per-game identifier of this client, used to identify the sender of simulation commands.
Definition: NetClient.h:328
void SetHostJID(const CStr &jid)
Store the JID of the host.
Definition: NetClient.cpp:149
void SendReadyMessage(const int status)
Definition: NetClient.cpp:472
CStr m_GUID
Globally unique identifier to distinguish users beyond the lifetime of a single network session.
Definition: NetClient.h:337
void SendStartGameMessage(const CStr &initAttribs)
Definition: NetClient.cpp:485
static bool OnChat(CNetClient *client, CFsmEvent *event)
Definition: NetClient.cpp:685
CStr m_Password
Password to join the game.
Definition: NetClient.h:311
u16 m_ServerPort
Definition: NetClient.h:305
static bool OnRejoined(CNetClient *client, CFsmEvent *event)
Definition: NetClient.cpp:821
static bool OnClientPerformance(CNetClient *client, CFsmEvent *event)
Definition: NetClient.cpp:865
bool m_Rejoin
True if the player is currently rejoining or has already rejoined the game.
Definition: NetClient.h:331
void HandleDisconnect(u32 reason)
Call when the network connection has been lost.
Definition: NetClient.cpp:436
bool ShouldShutdown() const
CNetClient(CGame *game)
Construct a client associated with the given game object.
Definition: NetClient.cpp:56
void TraceMember(JSTracer *trc)
Definition: NetClient.cpp:136
CNetClientSession * m_Session
Current network session (or NULL if not connected)
Definition: NetClient.h:320
void LoadFinished()
Call when the game has started and all data files have been loaded, to signal to the server that we a...
Definition: NetClient.cpp:556
static bool OnHandshake(CNetClient *client, CFsmEvent *event)
Definition: NetClient.cpp:616
void SetGamePassword(const CStr &hashedPassword)
Set the game password.
Definition: NetClient.cpp:154
bool TryToConnect(const CStr &hostJID, bool localNetwork)
Connect to the remote networked server using lobby.
Definition: NetClient.cpp:203
static bool OnLoadedGame(CNetClient *client, CFsmEvent *event)
Definition: NetClient.cpp:920
bool HandleMessage(CNetMessage *message)
Call when a message has been received from the network.
Definition: NetClient.cpp:513
void SendClearAllReadyMessage()
Definition: NetClient.cpp:479
void Poll()
Poll the connection for messages from the server and process them, and send any queued messages.
Definition: NetClient.cpp:321
std::time_t m_LastConnectionCheck
Time when the server was last checked for timeouts and bad latency.
Definition: NetClient.h:346
void HandleConnect()
Call when the network connection has been successfully initiated.
Definition: NetClient.cpp:431
void SendChatMessage(const std::wstring &text)
Definition: NetClient.cpp:465
void SetupServerData(CStr address, u16 port, bool stun)
Set connection data to the remote networked server.
Definition: NetClient.cpp:182
void SetUserName(const CStrW &username)
Set the user's name that will be displayed to all players.
Definition: NetClient.cpp:142
bool m_IsController
Note that this is just a "gui hint" with no actual impact on being controller.
Definition: NetClient.h:317
void HandleGetServerDataFailed(const CStr &error)
Called when fetching connection data from the host failed, to inform JS code.
Definition: NetClient.cpp:191
PlayerAssignmentMap m_PlayerAssignments
Latest copy of player assignments heard from the server.
Definition: NetClient.h:334
void SendAuthenticateMessage()
Definition: NetClient.cpp:596
void SetAndOwnSession(CNetClientSession *session)
Take ownership of a session object, and use it for all network communication.
Definition: NetClient.cpp:300
static bool OnHandshakeResponse(CNetClient *client, CFsmEvent *event)
Definition: NetClient.cpp:629
void SetControllerSecret(const std::string &secret)
Definition: NetClient.cpp:161
void SendPausedMessage(bool pause)
Call when the client has paused or unpaused the game.
Definition: NetClient.cpp:506
CGame * m_Game
Definition: NetClient.h:300
CNetClientTurnManager * m_ClientTurnManager
Turn manager associated with the current game (or NULL if we haven't started the game yet)
Definition: NetClient.h:325
The base class for all network messages exchanged within the game.
Definition: NetMessage.h:33
Abstraction around a SpiderMonkey JS::Realm.
Definition: ScriptInterface.h:72
Spidermonkey maintains some 'local' state via the JSContext* object.
Definition: ScriptRequest.h:60
JSContext * cx
Definition: ScriptRequest.h:92
JS::Value CreateObject(const ScriptRequest &rq)
Create a plain object (i.e.
Definition: Object.h:214
bool error(JSContext *cx, uint argc, JS::Value *vp)
Definition: ScriptInterface.cpp:173
uint16_t u16
Definition: types.h:38
uint32_t u32
Definition: types.h:39