31 #include <unordered_map> 38 class CPlayerAssignmentMessage;
147 void OnLobbyAuth(
const CStr& name,
const CStr& token);
184 bool IsBanned(
const std::string& username)
const;
227 void KickPlayer(
const CStrW& playerName,
const bool ban);
232 bool Broadcast(
const CNetMessage* message,
const std::vector<NetServerSessionState>& targetStates);
241 bool CheckPassword(
const std::string& password,
const std::string& salt)
const;
257 void AssignPlayer(
int playerID,
const CStr& guid);
267 static CStrW SanitisePlayerName(
const CStrW& original);
272 CStrW DeduplicatePlayerName(
const CStrW& original);
285 void ProcessLobbyAuth(
const CStr& name,
const CStr& token);
287 void AddPlayer(
const CStr& guid,
const CStrW& name);
288 void RemovePlayer(
const CStr& guid);
289 void SendPlayerAssignments();
298 static bool OnClientHandshake(
void* context,
CFsmEvent* event);
299 static bool OnAuthenticate(
void* context,
CFsmEvent* event);
300 static bool OnSimulationCommand(
void* context,
CFsmEvent* event);
301 static bool OnSyncCheck(
void* context,
CFsmEvent* event);
302 static bool OnEndCommandBatch(
void* context,
CFsmEvent* event);
303 static bool OnChat(
void* context,
CFsmEvent* event);
304 static bool OnReady(
void* context,
CFsmEvent* event);
305 static bool OnClearAllReady(
void* context,
CFsmEvent* event);
306 static bool OnGameSetup(
void* context,
CFsmEvent* event);
307 static bool OnAssignPlayer(
void* context,
CFsmEvent* event);
308 static bool OnGameStart(
void* context,
CFsmEvent* event);
309 static bool OnLoadedGame(
void* context,
CFsmEvent* event);
310 static bool OnJoinSyncingLoadedGame(
void* context,
CFsmEvent* event);
311 static bool OnRejoined(
void* context,
CFsmEvent* event);
312 static bool OnKickPlayer(
void* context,
CFsmEvent* event);
313 static bool OnDisconnect(
void* context,
CFsmEvent* event);
314 static bool OnClientPaused(
void* context,
CFsmEvent* event);
324 void ConstructPlayerAssignmentMessage(CPlayerAssignmentMessage& message);
331 void CheckClientConnections();
411 #if CONFIG2_MINIUPNPC 415 static void SetupUPnP();
439 #endif // NETSERVER_H void UpdateInitAttributes(JS::MutableHandleValue attrs, const ScriptRequest &rq)
Call from the GUI to update the game setup attributes.
Definition: NetServer.cpp:1723
void SetControllerSecret(const std::string &secret)
Definition: NetServer.cpp:1711
std::thread m_UPnPThread
Definition: NetServer.h:416
ScriptInterface * m_ScriptInterface
Internal script context for (de)serializing script messages, and for storing init attributes...
Definition: NetServer.h:341
void StartGame()
Call from the GUI to asynchronously notify all clients that they should start loading the game...
Definition: NetServer.cpp:1717
std::map< CStr, PlayerAssignment > PlayerAssignmentMap
Definition: NetHost.h:54
CStr m_ControllerGUID
The GUID of the client in control of the game (the 'host' from the players' perspective).
Definition: NetServer.h:383
std::vector< CStr > m_PausingPlayers
Holds the GUIDs of all currently paused players.
Definition: NetServer.h:374
CNetServer(bool useLobbyAuth=false)
Construct a new network server.
Definition: NetServer.cpp:1622
u16 GetPublicPort() const
Return the externally accessible port.
Definition: NetServer.cpp:1653
JS::PersistentRootedValue m_InitAttributes
Stores the most current init attributes.
Definition: NetServer.h:350
void SetPassword(const CStr &password)
Definition: NetServer.cpp:1704
std::vector< std::vector< CSimulationMessage > > m_SavedCommands
A copy of all simulation commands received so far, indexed by turn number, to simplify support for re...
Definition: NetServer.h:395
struct _ENetHost ENetHost
Definition: NetClient.h:37
uint16_t u16
Definition: types.h:38
std::string m_JoinSyncFile
The latest copy of the simulation state, received from an existing client when a new client has asked...
Definition: NetServer.h:401
Represents a signal in the state machine that a change has occurred.
Definition: FSM.h:52
bool CheckPasswordAndIncrement(const std::string &username, const std::string &password, const std::string &salt)
Check if password is valid.
Definition: NetServer.cpp:1682
Async task for receiving the initial game state to be forwarded to another client that is rejoining a...
Definition: NetServer.cpp:95
std::vector< CStrW > m_BannedPlayers
Definition: NetServer.h:367
u32 m_NextHostID
Definition: NetServer.h:376
std::vector< std::string > m_InitAttributesQueue
Definition: NetServer.h:431
Definition: NetServer.h:61
u16 GetLocalPort() const
Return the serving port on the local machine.
Definition: NetServer.cpp:1658
Definition: NetServer.h:81
Definition: NetServer.h:85
struct _ENetPeer ENetPeer
Definition: NetHost.h:30
CStr m_Password
Definition: NetServer.h:196
NetServerState
Definition: NetServer.h:46
Definition: NetServer.h:90
std::time_t m_LastConnectionCheck
Time when the clients connections were last checked for timeouts and latency.
Definition: NetServer.h:406
void SetTurnLength(u32 msecs)
Set the turn length to a fixed value.
Definition: NetServer.cpp:1739
uint32_t u32
Definition: types.h:39
bool IsBanned(const std::string &username) const
Check if user reached certain number of failed attempts.
Definition: NetServer.cpp:1698
bool SetConnectionDataViaSTUN()
Definition: NetServer.cpp:1673
Various declarations shared by networking code.
bool m_Shutdown
Definition: NetServer.h:427
~CNetServer()
Definition: NetServer.cpp:1628
ENetHost * m_Host
Definition: NetServer.h:357
void KickPlayer(const CStrW &playerName, bool ban)
Definition: JSInterface_Network.cpp:231
NetServerSessionState
Server session representation of client state.
Definition: NetServer.h:71
void ClearAllPlayerReady()
Definition: JSInterface_Network.cpp:252
std::string m_ControllerSecret
The 'secret' used to identify the controller of the game.
Definition: NetServer.h:388
Network server interface.
Definition: NetServer.h:107
ENet connection statistics profiler table.
Definition: NetStats.h:38
std::vector< bool > m_StartGameQueue
Definition: NetServer.h:430
const bool m_LobbyAuth
Whether this match requires lobby authentication.
Definition: NetServer.h:355
bool UseLobbyAuth() const
Definition: NetServer.cpp:1638
std::vector< u32 > m_TurnLengthQueue
Definition: NetServer.h:433
std::vector< CNetServerSession * > m_Sessions
Definition: NetServer.h:358
Definition: NetServer.h:98
The base class for all network messages exchanged within the game.
Definition: NetMessage.h:32
CStr m_PublicIp
Definition: NetServer.h:195
void OnLobbyAuth(const CStr &name, const CStr &token)
Definition: NetServer.cpp:1733
Definition: NetServer.h:58
CNetServerWorker * m_Worker
Definition: NetServer.h:191
std::vector< std::pair< CStr, CStr > > m_LobbyAuthQueue
Definition: NetServer.h:432
u16 m_PublicPort
Definition: NetServer.h:194
CStr m_Password
Definition: NetServer.h:369
bool m_UseSTUN
Definition: NetServer.h:193
CNetStatsTable * m_Stats
Definition: NetServer.h:360
void SendHolePunchingMessage(const CStr &ip, u16 port)
Definition: NetServer.cpp:1745
std::vector< u32 > m_BannedIPs
Definition: NetServer.h:366
NetServerState m_State
Definition: NetServer.h:362
std::unordered_map< std::string, int > m_FailedAttempts
Definition: NetServer.h:197
Abstraction around a SpiderMonkey JS::Realm.
Definition: ScriptInterface.h:71
Definition: NetServer.h:50
Definition: NetServer.h:74
bool GetUseSTUN() const
Definition: NetServer.cpp:1633
std::mutex m_WorkerMutex
Definition: NetServer.h:424
CStrW m_ServerName
Definition: NetServer.h:364
Spidermonkey maintains some 'local' state via the JSContext* object.
Definition: ScriptRequest.h:59
CNetServerTurnManager * m_ServerTurnManager
Definition: NetServer.h:378
PlayerAssignmentMap m_PlayerAssignments
Definition: NetServer.h:343
Definition: NetServer.h:65
Network server worker thread.
Definition: NetServer.h:212
The server's end of a network session.
Definition: NetSession.h:154
const bool m_LobbyAuth
Definition: NetServer.h:192
Definition: NetServer.h:94
bool SetupConnection(const u16 port)
Begin listening for network connections.
Definition: NetServer.cpp:1643
std::thread m_WorkerThread
Definition: NetServer.h:423
CStr GetPublicIp() const
Return the externally accessible IP.
Definition: NetServer.cpp:1648
The server-side counterpart to CNetClientTurnManager.
Definition: NetServerTurnManager.h:37
CNetServer * g_NetServer
Global network server for the standard game.
Definition: NetServer.cpp:80
Definition: NetServer.h:55
Special message type for simulation commands.
Definition: NetMessage.h:113
static Status Run(const Operation &op, const Parameters &p=Parameters(), const CompletedHook &completedHook=CompletedHook(), const IssueHook &issueHook=IssueHook())
Definition: io.h:243
Definition: NetServer.h:78
void SetConnectionData(const CStr &ip, u16 port)
Definition: NetServer.cpp:1666