Changeset View
Changeset View
Standalone View
Standalone View
source/network/NetServer.h
Show First 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
// The client has disconnected or been disconnected | // The client has disconnected or been disconnected | ||||
NSS_UNCONNECTED, | NSS_UNCONNECTED, | ||||
// The client has just connected and we're waiting for its handshake message, | // The client has just connected and we're waiting for its handshake message, | ||||
// to agree on the protocol version | // to agree on the protocol version | ||||
NSS_HANDSHAKE, | NSS_HANDSHAKE, | ||||
// The client has handshook and we're waiting for its lobby authentication message | |||||
NSS_LOBBY_AUTHENTICATE, | |||||
// The client has handshook and we're waiting for its authentication message, | // The client has handshook and we're waiting for its authentication message, | ||||
// to find its name and check its password etc | // to find its name and check its password etc | ||||
NSS_AUTHENTICATE, | NSS_AUTHENTICATE, | ||||
// The client has fully joined, and is in the pregame setup stage | // The client has fully joined, and is in the pregame setup stage | ||||
// or is loading the game. | // or is loading the game. | ||||
// Server must be in SERVER_STATE_PREGAME or SERVER_STATE_LOADING. | // Server must be in SERVER_STATE_PREGAME or SERVER_STATE_LOADING. | ||||
NSS_PREGAME, | NSS_PREGAME, | ||||
Show All 17 Lines | |||||
{ | { | ||||
NONCOPYABLE(CNetServer); | NONCOPYABLE(CNetServer); | ||||
public: | public: | ||||
/** | /** | ||||
* Construct a new network server. | * Construct a new network server. | ||||
* @param autostartPlayers if positive then StartGame will be called automatically | * @param autostartPlayers if positive then StartGame will be called automatically | ||||
* once this many players are connected (intended for the command-line testing mode). | * once this many players are connected (intended for the command-line testing mode). | ||||
*/ | */ | ||||
CNetServer(int autostartPlayers = -1); | CNetServer(bool useLobbyAuth = false, int autostartPlayers = -1); | ||||
~CNetServer(); | ~CNetServer(); | ||||
/** | /** | ||||
* Begin listening for network connections. | * Begin listening for network connections. | ||||
* This function is synchronous (it won't return until the connection is established). | * This function is synchronous (it won't return until the connection is established). | ||||
* @return true on success, false on error (e.g. port already in use) | * @return true on success, false on error (e.g. port already in use) | ||||
*/ | */ | ||||
Show All 13 Lines | public: | ||||
void UpdateGameAttributes(JS::MutableHandleValue attrs, const ScriptInterface& scriptInterface); | void UpdateGameAttributes(JS::MutableHandleValue attrs, const ScriptInterface& scriptInterface); | ||||
/** | /** | ||||
* Set the turn length to a fixed value. | * Set the turn length to a fixed value. | ||||
* TODO: we should replace this with some adapative lag-dependent computation. | * TODO: we should replace this with some adapative lag-dependent computation. | ||||
*/ | */ | ||||
void SetTurnLength(u32 msecs); | void SetTurnLength(u32 msecs); | ||||
void OnLobbyAuth(const CStr& name, const CStr& token); | |||||
elexis: (Proposing to use the same name that the hostName is renamed to, lobbyUsername or whatever) | |||||
Not Done Inline Actions
That are two totally different things, so no. Imarok: > (Proposing to use the same name that the hostName is renamed to, lobbyUsername or whatever)… | |||||
Not Done Inline ActionsIt's the lobby playername of the joining client, right? IMO should still have the lobby, xmpp, jid or whatever in there so people aren't left clueless elexis: It's the lobby playername of the joining client, right? IMO should still have the lobby, xmpp… | |||||
void SendHolePunchingMessage(const CStr& ip, u16 port); | void SendHolePunchingMessage(const CStr& ip, u16 port); | ||||
private: | private: | ||||
CNetServerWorker* m_Worker; | CNetServerWorker* m_Worker; | ||||
}; | }; | ||||
/** | /** | ||||
* Network server worker thread. | * Network server worker thread. | ||||
Show All 28 Lines | public: | ||||
* Send a message to all clients who match one of the given states. | * Send a message to all clients who match one of the given states. | ||||
*/ | */ | ||||
bool Broadcast(const CNetMessage* message, const std::vector<NetServerSessionState>& targetStates); | bool Broadcast(const CNetMessage* message, const std::vector<NetServerSessionState>& targetStates); | ||||
private: | private: | ||||
friend class CNetServer; | friend class CNetServer; | ||||
friend class CNetFileReceiveTask_ServerRejoin; | friend class CNetFileReceiveTask_ServerRejoin; | ||||
CNetServerWorker(int autostartPlayers); | CNetServerWorker(bool useLobbyAuth, int autostartPlayers); | ||||
~CNetServerWorker(); | ~CNetServerWorker(); | ||||
/** | /** | ||||
* Begin listening for network connections. | * Begin listening for network connections. | ||||
* @return true on success, false on error (e.g. port already in use) | * @return true on success, false on error (e.g. port already in use) | ||||
*/ | */ | ||||
bool SetupConnection(const u16 port); | bool SetupConnection(const u16 port); | ||||
Show All 33 Lines | private: | ||||
*/ | */ | ||||
const ScriptInterface& GetScriptInterface(); | const ScriptInterface& GetScriptInterface(); | ||||
/** | /** | ||||
* Set the turn length to a fixed value. | * Set the turn length to a fixed value. | ||||
* TODO: we should replace this with some adaptive lag-dependent computation. | * TODO: we should replace this with some adaptive lag-dependent computation. | ||||
*/ | */ | ||||
void SetTurnLength(u32 msecs); | void SetTurnLength(u32 msecs); | ||||
Done Inline Actions\n above, -\n below I guess elexis: \n above, -\n below I guess | |||||
Not Done Inline ActionsI think just +\n is better. Imarok: I think just +\n is better. | |||||
void ProcessLobbyAuth(const CStr& name, const CStr& token); | |||||
void AddPlayer(const CStr& guid, const CStrW& name); | void AddPlayer(const CStr& guid, const CStrW& name); | ||||
void RemovePlayer(const CStr& guid); | void RemovePlayer(const CStr& guid); | ||||
void SendPlayerAssignments(); | void SendPlayerAssignments(); | ||||
void ClearAllPlayerReady(); | void ClearAllPlayerReady(); | ||||
void SetupSession(CNetServerSession* session); | void SetupSession(CNetServerSession* session); | ||||
bool HandleConnect(CNetServerSession* session); | bool HandleConnect(CNetServerSession* session); | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | private: | ||||
PlayerAssignmentMap m_PlayerAssignments; | PlayerAssignmentMap m_PlayerAssignments; | ||||
/** | /** | ||||
* Stores the most current game attributes. | * Stores the most current game attributes. | ||||
*/ | */ | ||||
JS::PersistentRootedValue m_GameAttributes; | JS::PersistentRootedValue m_GameAttributes; | ||||
int m_AutostartPlayers; | int m_AutostartPlayers; | ||||
bool m_LobbyAuth; | |||||
ENetHost* m_Host; | ENetHost* m_Host; | ||||
std::vector<CNetServerSession*> m_Sessions; | std::vector<CNetServerSession*> m_Sessions; | ||||
CNetStatsTable* m_Stats; | CNetStatsTable* m_Stats; | ||||
NetServerState m_State; | NetServerState m_State; | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | #endif | ||||
static void* RunThread(void* data); | static void* RunThread(void* data); | ||||
void Run(); | void Run(); | ||||
bool RunStep(); | bool RunStep(); | ||||
pthread_t m_WorkerThread; | pthread_t m_WorkerThread; | ||||
CMutex m_WorkerMutex; | CMutex m_WorkerMutex; | ||||
bool m_Shutdown; // protected by m_WorkerMutex | // protected by m_WorkerMutex | ||||
bool m_Shutdown; | |||||
// Queues for messages sent by the game thread: | // Queues for messages sent by the game thread (protected by m_WorkerMutex): | ||||
std::vector<bool> m_StartGameQueue; // protected by m_WorkerMutex | std::vector<bool> m_StartGameQueue; | ||||
std::vector<std::string> m_GameAttributesQueue; // protected by m_WorkerMutex | std::vector<std::string> m_GameAttributesQueue; | ||||
std::vector<u32> m_TurnLengthQueue; // protected by m_WorkerMutex | std::vector<std::pair<CStr, CStr>> m_LobbyAuthQueue; | ||||
std::vector<u32> m_TurnLengthQueue; | |||||
Done Inline Actions(comment quadruplication) elexis: (comment quadruplication) | |||||
}; | }; | ||||
/// Global network server for the standard game | /// Global network server for the standard game | ||||
extern CNetServer *g_NetServer; | extern CNetServer *g_NetServer; | ||||
#endif // NETSERVER_H | #endif // NETSERVER_H |
Wildfire Games · Phabricator
(Proposing to use the same name that the hostName is renamed to, lobbyUsername or whatever)