Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/network/NetClient.h
/* Copyright (C) 2020 Wildfire Games. | /* Copyright (C) 2021 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | public: | ||||
/** | /** | ||||
* Returns the GUID of the local client. | * Returns the GUID of the local client. | ||||
* Used for distinguishing observers. | * Used for distinguishing observers. | ||||
*/ | */ | ||||
CStr GetGUID() const { return m_GUID; } | CStr GetGUID() const { return m_GUID; } | ||||
/** | /** | ||||
* Set connection data to the remote networked server. | |||||
* @param address IP address or host name to connect to | |||||
*/ | |||||
void SetupServerData(CStr address, u16 port, bool stun); | |||||
/** | |||||
* Set up a connection to the remote networked server. | * Set up a connection to the remote networked server. | ||||
* @param server IP address or host name to connect to | * Must call SetupServerData first. | ||||
* @return true on success, false on connection failure | |||||
*/ | |||||
bool SetupConnection(ENetHost* enetClient); | |||||
/** | |||||
* Connect to the remote networked server using lobby. | |||||
* Push netstatus messages on failure. | |||||
* @return true on success, false on connection failure | * @return true on success, false on connection failure | ||||
*/ | */ | ||||
bool SetupConnection(const CStr& server, const u16 port, ENetHost* enetClient); | bool TryToConnect(const CStr& hostJID); | ||||
/** | /** | ||||
* Destroy the connection to the server. | * Destroy the connection to the server. | ||||
* This client probably cannot be used again. | * This client probably cannot be used again. | ||||
*/ | */ | ||||
void DestroyConnection(); | void DestroyConnection(); | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | public: | ||||
* Call when the client has paused or unpaused the game. | * Call when the client has paused or unpaused the game. | ||||
*/ | */ | ||||
void SendPausedMessage(bool pause); | void SendPausedMessage(bool pause); | ||||
/** | /** | ||||
* @return Whether the NetClient is shutting down. | * @return Whether the NetClient is shutting down. | ||||
*/ | */ | ||||
bool ShouldShutdown() const; | bool ShouldShutdown() const; | ||||
/** | |||||
* Called when fetching connection data from the host failed, to inform JS code. | |||||
*/ | |||||
void HandleGetServerDataFailed(const CStr& error); | |||||
private: | private: | ||||
void SendAuthenticateMessage(); | void SendAuthenticateMessage(); | ||||
// Net message / FSM transition handlers | // Net message / FSM transition handlers | ||||
static bool OnConnect(void* context, CFsmEvent* event); | static bool OnConnect(void* context, CFsmEvent* event); | ||||
static bool OnHandshake(void* context, CFsmEvent* event); | static bool OnHandshake(void* context, CFsmEvent* event); | ||||
static bool OnHandshakeResponse(void* context, CFsmEvent* event); | static bool OnHandshakeResponse(void* context, CFsmEvent* event); | ||||
Show All 23 Lines | private: | ||||
/** | /** | ||||
* Push a message onto the GUI queue listing the current player assignments. | * Push a message onto the GUI queue listing the current player assignments. | ||||
*/ | */ | ||||
void PostPlayerAssignmentsToScript(); | void PostPlayerAssignmentsToScript(); | ||||
CGame *m_Game; | CGame *m_Game; | ||||
CStrW m_UserName; | CStrW m_UserName; | ||||
CStr m_HostingPlayerName; | CStr m_HostingPlayerName; | ||||
CStr m_ServerAddress; | |||||
u16 m_ServerPort; | |||||
bool m_UseSTUN; | |||||
/// Current network session (or NULL if not connected) | /// Current network session (or NULL if not connected) | ||||
CNetClientSession* m_Session; | CNetClientSession* m_Session; | ||||
std::thread m_PollingThread; | std::thread m_PollingThread; | ||||
/// Turn manager associated with the current game (or NULL if we haven't started the game yet) | /// Turn manager associated with the current game (or NULL if we haven't started the game yet) | ||||
CNetClientTurnManager* m_ClientTurnManager; | CNetClientTurnManager* m_ClientTurnManager; | ||||
Show All 33 Lines |
Wildfire Games · Phabricator