80 static void Trace(JSTracer *trc,
void *data)
139 bool TryToConnect(
const CStr& hostJID,
bool localNetwork);
173 void GuiPoll(JS::MutableHandleValue);
179 template<
typename... Args>
184 JS::RootedValue message(rq.
cx);
354 #endif // NETCLIENT_H void PushGuiMessage(Args const &... args)
Add a message to the queue, to be read by GuiPoll.
Definition: NetClient.h:180
The container that holds the rules, resources and attributes of the game.
Definition: Game.h:42
CStr m_ServerAddress
Definition: NetClient.h:306
JSContext * cx
Definition: ScriptRequest.h:92
void DestroyConnection()
Destroy the connection to the server.
Definition: NetClient.cpp:338
Manages states, events, actions and transitions between states.
Definition: FSM.h:168
CStr m_HostJID
Definition: NetClient.h:305
void SendAssignPlayerMessage(const int playerID, const CStr &guid)
Definition: NetClient.cpp:489
std::map< CStr, PlayerAssignment > PlayerAssignmentMap
Definition: NetHost.h:54
static bool OnRejoined(void *context, CFsmEvent *event)
Definition: NetClient.cpp:858
bool m_UseSTUN
Definition: NetClient.h:308
std::thread m_PollingThread
Definition: NetClient.h:324
std::time_t m_LastConnectionCheck
Time when the server was last checked for timeouts and bad latency.
Definition: NetClient.h:348
void HandleGetServerDataFailed(const CStr &error)
Called when fetching connection data from the host failed, to inform JS code.
Definition: NetClient.cpp:223
const ScriptInterface & GetScriptInterface()
Get the script interface associated with this network client, which is equivalent to the one used by ...
Definition: NetClient.cpp:424
CNetClientTurnManager * m_ClientTurnManager
Turn manager associated with the current game (or NULL if we haven't started the game yet) ...
Definition: NetClient.h:327
std::string m_ControllerSecret
The 'secret' used to identify the controller of the game.
Definition: NetClient.h:316
struct _ENetHost ENetHost
Definition: NetClient.h:37
uint16_t u16
Definition: types.h:38
Represents a signal in the state machine that a change has occurred.
Definition: FSM.h:52
virtual ~CNetClient()
Definition: NetClient.cpp:158
CNetClientSession * m_Session
Current network session (or NULL if not connected)
Definition: NetClient.h:322
static bool OnAuthenticateRequest(void *context, CFsmEvent *event)
Definition: NetClient.cpp:694
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:588
bool IsController() const
Definition: NetClient.h:101
u16 m_ServerPort
Definition: NetClient.h:307
static bool OnChat(void *context, CFsmEvent *event)
Definition: NetClient.cpp:724
void GuiPoll(JS::MutableHandleValue)
Retrieves the next queued GUI message, and removes it from the queue.
Definition: NetClient.cpp:396
Definition: NetClient.h:43
Definition: NetClient.h:42
void SendKickPlayerMessage(const CStrW &playerName, bool ban)
Call to kick/ban a client.
Definition: NetClient.cpp:530
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:408
static bool OnClientTimeout(void *context, CFsmEvent *event)
Definition: NetClient.cpp:887
static bool OnHandshake(void *context, CFsmEvent *event)
Definition: NetClient.cpp:650
static bool OnLoadedGame(void *context, CFsmEvent *event)
Definition: NetClient.cpp:963
static bool OnInGame(void *context, CFsmEvent *event)
Definition: NetClient.cpp:984
bool m_IsController
Note that this is just a "gui hint" with no actual impact on being controller.
Definition: NetClient.h:319
void HandleConnect()
Call when the network connection has been successfully initiated.
Definition: NetClient.cpp:463
static bool OnAuthenticate(void *context, CFsmEvent *event)
Definition: NetClient.cpp:703
void SetupConnectionViaLobby()
Request connection information over the lobby.
Definition: NetClient.cpp:209
void HandleDisconnect(u32 reason)
Call when the network connection has been lost.
Definition: NetClient.cpp:468
void PostPlayerAssignmentsToScript()
Push a message onto the GUI queue listing the current player assignments.
Definition: NetClient.cpp:429
bool SendMessage(const CNetMessage *message)
Send a message to the server.
Definition: NetClient.cpp:455
Definition: NetClient.h:46
uint32_t u32
Definition: types.h:39
static bool OnReady(void *context, CFsmEvent *event)
Definition: NetClient.cpp:739
Various declarations shared by networking code.
CNetClient(CGame *game)
Construct a client associated with the given game object.
Definition: NetClient.cpp:86
void SendPausedMessage(bool pause)
Call when the client has paused or unpaused the game.
Definition: NetClient.cpp:538
static bool OnConnect(void *context, CFsmEvent *event)
Definition: NetClient.cpp:637
PlayerAssignmentMap m_PlayerAssignments
Latest copy of player assignments heard from the server.
Definition: NetClient.h:336
void SetAndOwnSession(CNetClientSession *session)
Take ownership of a session object, and use it for all network communication.
Definition: NetClient.cpp:332
void SetGamePassword(const CStr &hashedPassword)
Set the game password.
Definition: NetClient.cpp:186
CGame * m_Game
Definition: NetClient.h:302
static bool OnPlayerAssignment(void *context, CFsmEvent *event)
Definition: NetClient.cpp:768
u32 m_HostID
Unique-per-game identifier of this client, used to identify the sender of simulation commands...
Definition: NetClient.h:330
void SendAuthenticateMessage()
Definition: NetClient.cpp:628
Definition: NetClient.h:47
JS::Value CreateObject(const ScriptRequest &rq)
Create a plain object (i.e.
Definition: Object.h:214
void SetUserName(const CStrW &username)
Set the user's name that will be displayed to all players.
Definition: NetClient.cpp:174
CStrW m_UserName
Definition: NetClient.h:303
bool SetupConnection(ENetHost *enetClient)
Set up a connection to the remote networked server.
Definition: NetClient.cpp:199
static bool OnJoinSyncEndCommandBatch(void *context, CFsmEvent *event)
Definition: NetClient.cpp:842
void SetupServerData(CStr address, u16 port, bool stun)
Set connection data to the remote networked server.
Definition: NetClient.cpp:214
void SendRejoinedMessage()
Call when the client has rejoined a running match and finished the loading screen.
Definition: NetClient.cpp:524
static bool OnGameSetup(void *context, CFsmEvent *event)
Definition: NetClient.cpp:754
void SendGameSetupMessage(JS::MutableHandleValue attrs, const ScriptInterface &scriptInterface)
Definition: NetClient.cpp:482
void TraceMember(JSTracer *trc)
Definition: NetClient.cpp:168
Definition: NetClient.h:45
CStr m_GUID
Globally unique identifier to distinguish users beyond the lifetime of a single network session...
Definition: NetClient.h:339
void SendReadyMessage(const int status)
Definition: NetClient.cpp:504
void Poll()
Poll the connection for messages from the server and process them, and send any queued messages...
Definition: NetClient.cpp:353
std::string m_JoinSyncBuffer
Serialized game state received when joining an in-progress game.
Definition: NetClient.h:345
The base class for all network messages exchanged within the game.
Definition: NetMessage.h:32
CStr GetGUID() const
Returns the GUID of the local client.
Definition: NetClient.h:113
bool HandleMessage(CNetMessage *message)
Call when a message has been received from the network.
Definition: NetClient.cpp:545
static bool OnClientsLoading(void *context, CFsmEvent *event)
Definition: NetClient.cpp:930
static bool OnJoinSyncStart(void *context, CFsmEvent *event)
Definition: NetClient.cpp:826
std::deque< JS::Heap< JS::Value > > m_GuiMessageQueue
Queue of messages for GuiPoll.
Definition: NetClient.h:342
Async task for receiving the initial game state when rejoining an in-progress network game...
Definition: NetClient.cpp:59
Network client.
Definition: NetClient.h:59
void SendChatMessage(const std::wstring &text)
Definition: NetClient.cpp:497
static bool OnKicked(void *context, CFsmEvent *event)
Definition: NetClient.cpp:872
Implementation of CTurnManager for network clients.
Definition: NetClientTurnManager.h:29
static bool OnGameStart(void *context, CFsmEvent *event)
Definition: NetClient.cpp:796
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:80
bool TryToConnect(const CStr &hostJID, bool localNetwork)
Connect to the remote networked server using lobby.
Definition: NetClient.cpp:235
static bool OnClientPaused(void *context, CFsmEvent *event)
Definition: NetClient.cpp:948
Definition: NetClient.h:48
static bool OnClientPerformance(void *context, CFsmEvent *event)
Definition: NetClient.cpp:905
void SendClearAllReadyMessage()
Definition: NetClient.cpp:511
void SetHostJID(const CStr &jid)
Store the JID of the host.
Definition: NetClient.cpp:181
Abstraction around a SpiderMonkey JS::Realm.
Definition: ScriptInterface.h:71
bool m_Rejoin
True if the player is currently rejoining or has already rejoined the game.
Definition: NetClient.h:333
void SendStartGameMessage(const CStr &initAttribs)
Definition: NetClient.cpp:517
CNetClient * g_NetClient
Global network client for the standard game.
Definition: NetClient.cpp:53
CStr m_Password
Password to join the game.
Definition: NetClient.h:313
bool ShouldShutdown() const
Definition: NetClient.h:49
Spidermonkey maintains some 'local' state via the JSContext* object.
Definition: ScriptRequest.h:59
void SetControllerSecret(const std::string &secret)
Definition: NetClient.cpp:193
The client end of a network session.
Definition: NetSession.h:67
Definition: NetClient.h:44
bool error(JSContext *cx, uint argc, JS::Value *vp)
Definition: ScriptInterface.cpp:172
void CheckServerConnection()
Locally triggers a GUI message if the connection to the server is being lost or has bad latency...
Definition: NetClient.cpp:364
static bool OnHandshakeResponse(void *context, CFsmEvent *event)
Definition: NetClient.cpp:665