31#include <unordered_map>
38class 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);
240 bool CheckPassword(
const std::string& password,
const std::string& salt)
const;
286 void AddPlayer(
const CStr& guid,
const CStrW& name);
struct _ENetHost ENetHost
Definition: NetClient.h:37
Various declarations shared by networking code.
struct _ENetPeer ENetPeer
Definition: NetHost.h:30
std::map< CStr, PlayerAssignment > PlayerAssignmentMap
Definition: NetHost.h:54
CNetServer * g_NetServer
Global network server for the standard game.
Definition: NetServer.cpp:82
NetServerSessionState
Server session representation of client state.
Definition: NetServer.h:72
@ NSS_AUTHENTICATE
Definition: NetServer.h:85
@ NSS_INGAME
Definition: NetServer.h:98
@ NSS_PREGAME
Definition: NetServer.h:90
@ NSS_HANDSHAKE
Definition: NetServer.h:78
@ NSS_LOBBY_AUTHENTICATE
Definition: NetServer.h:81
@ NSS_UNCONNECTED
Definition: NetServer.h:74
@ NSS_JOIN_SYNCING
Definition: NetServer.h:94
NetServerState
Definition: NetServer.h:47
@ SERVER_STATE_INGAME
Definition: NetServer.h:61
@ SERVER_STATE_UNCONNECTED
Definition: NetServer.h:50
@ SERVER_STATE_POSTGAME
Definition: NetServer.h:65
@ SERVER_STATE_PREGAME
Definition: NetServer.h:55
@ SERVER_STATE_LOADING
Definition: NetServer.h:58
Represents a signal in the state machine that a change has occurred.
Definition: FSM.h:33
The base class for all network messages exchanged within the game.
Definition: NetMessage.h:33
The server's end of a network session.
Definition: NetSession.h:155
The server-side counterpart to CNetClientTurnManager.
Definition: NetServerTurnManager.h:38
Network server worker thread.
Definition: NetServer.h:213
void OnUserJoin(CNetServerSession *session)
Definition: NetServer.cpp:698
ScriptInterface * m_ScriptInterface
Internal script context for (de)serializing script messages, and for storing init attributes.
Definition: NetServer.h:340
void SetupSession(CNetServerSession *session)
Definition: NetServer.cpp:641
NONCOPYABLE(CNetServerWorker)
~CNetServerWorker()
Definition: NetServer.cpp:112
static bool OnChat(CNetServerSession *session, CFsmEvent *event)
Definition: NetServer.cpp:1222
static bool OnDisconnect(CNetServerSession *session, CFsmEvent *event)
Definition: NetServer.cpp:1438
std::vector< std::string > m_InitAttributesQueue
Definition: NetServer.h:430
static bool OnGameSetup(CNetServerSession *session, CFsmEvent *event)
Definition: NetServer.cpp:1269
static bool OnSyncCheck(CNetServerSession *session, CFsmEvent *event)
Definition: NetServer.cpp:1197
void SendPlayerAssignments()
Definition: NetServer.cpp:854
static bool OnEndCommandBatch(CNetServerSession *session, CFsmEvent *event)
Definition: NetServer.cpp:1209
u32 m_NextHostID
Definition: NetServer.h:375
CStrW m_ServerName
Definition: NetServer.h:363
std::vector< std::pair< CStr, CStr > > m_LobbyAuthQueue
Definition: NetServer.h:431
void SetPassword(const CStr &hashedPassword)
Definition: NetServer.cpp:147
static bool OnClearAllReady(CNetServerSession *session, CFsmEvent *event)
Definition: NetServer.cpp:1257
bool Broadcast(const CNetMessage *message, const std::vector< NetServerSessionState > &targetStates)
Send a message to all clients who match one of the given states.
Definition: NetServer.cpp:357
static bool OnJoinSyncingLoadedGame(CNetServerSession *session, CFsmEvent *event)
Definition: NetServer.cpp:1348
static bool OnClientPaused(CNetServerSession *session, CFsmEvent *event)
Definition: NetServer.cpp:1449
void StartGame(const CStr &initAttribs)
Switch in game mode and notify all clients to start the game.
Definition: NetServer.cpp:1502
void SetTurnLength(u32 msecs)
Set the turn length to a fixed value.
Definition: NetServer.cpp:866
void Run()
Definition: NetServer.cpp:381
static bool OnKickPlayer(CNetServerSession *session, CFsmEvent *event)
Definition: NetServer.cpp:1424
void OnUserLeave(CNetServerSession *session)
Definition: NetServer.cpp:707
std::vector< u32 > m_BannedIPs
Definition: NetServer.h:365
CNetServerTurnManager * m_ServerTurnManager
Definition: NetServer.h:377
void AddPlayer(const CStr &guid, const CStrW &name)
Definition: NetServer.cpp:722
const bool m_LobbyAuth
Whether this match requires lobby authentication.
Definition: NetServer.h:354
std::vector< CStrW > m_BannedPlayers
Definition: NetServer.h:366
static void RunThread(CNetServerWorker *data)
Definition: NetServer.cpp:374
void SendHolePunchingMessage(const CStr &ip, u16 port)
Definition: NetServer.cpp:1586
static bool OnAssignPlayer(CNetServerSession *session, CFsmEvent *event)
Definition: NetServer.cpp:1292
CStrW DeduplicatePlayerName(const CStrW &original)
Make a player name unique, if it matches any existing session's name.
Definition: NetServer.cpp:1561
CStr m_ControllerGUID
The GUID of the client in control of the game (the 'host' from the players' perspective).
Definition: NetServer.h:382
std::thread m_UPnPThread
Definition: NetServer.h:415
bool CheckGameLoadStatus(CNetServerSession *changedSession)
Checks if all clients have finished loading.
Definition: NetServer.cpp:1485
PlayerAssignmentMap m_PlayerAssignments
Definition: NetServer.h:342
static CStrW SanitisePlayerName(const CStrW &original)
Make a player name 'nicer' by limiting the length and removing forbidden characters etc.
Definition: NetServer.cpp:1539
ENetHost * m_Host
Definition: NetServer.h:356
NetServerState m_State
Definition: NetServer.h:361
static bool OnAuthenticate(CNetServerSession *session, CFsmEvent *event)
Definition: NetServer.cpp:937
static bool OnReady(CNetServerSession *session, CFsmEvent *event)
Definition: NetServer.cpp:1237
std::time_t m_LastConnectionCheck
Time when the clients connections were last checked for timeouts and latency.
Definition: NetServer.h:405
bool SendMessage(ENetPeer *peer, const CNetMessage *message)
Send a message to the given network peer.
Definition: NetServer.cpp:348
void RemovePlayer(const CStr &guid)
Definition: NetServer.cpp:774
bool m_Shutdown
Definition: NetServer.h:426
CNetStatsTable * m_Stats
Definition: NetServer.h:359
bool RunStep()
Definition: NetServer.cpp:406
static bool OnLoadedGame(CNetServerSession *session, CFsmEvent *event)
Definition: NetServer.cpp:1318
std::vector< bool > m_StartGameQueue
Definition: NetServer.h:429
std::vector< u32 > m_TurnLengthQueue
Definition: NetServer.h:432
const ScriptInterface & GetScriptInterface()
Get the script context used for init attributes.
Definition: NetServer.cpp:861
std::mutex m_WorkerMutex
Definition: NetServer.h:423
static bool OnGameStart(CNetServerSession *session, CFsmEvent *event)
Definition: NetServer.cpp:1305
std::thread m_WorkerThread
Definition: NetServer.h:422
void KickPlayer(const CStrW &playerName, const bool ban)
Disconnects a player from gamesetup or session.
Definition: NetServer.cpp:790
void ProcessLobbyAuth(const CStr &name, const CStr &token)
Definition: NetServer.cpp:872
bool SetupConnection(const u16 port)
Begin listening for network connections.
Definition: NetServer.cpp:165
void HandleMessageReceive(const CNetMessage *message, CNetServerSession *session)
Definition: NetServer.cpp:616
static void SetupUPnP()
Try to find a UPnP root on the network and setup port forwarding.
Definition: NetServer.cpp:201
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:394
CNetServerWorker(bool useLobbyAuth)
Definition: NetServer.cpp:98
CStr m_Password
Definition: NetServer.h:368
void ClearAllPlayerReady()
Definition: NetServer.cpp:781
std::vector< CNetServerSession * > m_Sessions
Definition: NetServer.h:357
JS::PersistentRootedValue m_InitAttributes
Stores the most current init attributes.
Definition: NetServer.h:349
void AssignPlayer(int playerID, const CStr &guid)
The given GUID will be (re)assigned to the given player ID.
Definition: NetServer.cpp:822
void SetControllerSecret(const std::string &secret)
Definition: NetServer.cpp:153
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:400
void CheckClientConnections()
Send a network warning if the connection to a client is being lost or has bad latency.
Definition: NetServer.cpp:562
std::vector< CStr > m_PausingPlayers
Holds the GUIDs of all currently paused players.
Definition: NetServer.h:373
bool CheckPassword(const std::string &password, const std::string &salt) const
Definition: NetServer.cpp:159
bool HandleConnect(CNetServerSession *session)
Definition: NetServer.cpp:683
static bool OnSimulationCommand(CNetServerSession *session, CFsmEvent *event)
Definition: NetServer.cpp:1160
void ConstructPlayerAssignmentMessage(CPlayerAssignmentMessage &message)
Definition: NetServer.cpp:838
static bool OnClientHandshake(CNetServerSession *session, CFsmEvent *event)
Definition: NetServer.cpp:890
std::string m_ControllerSecret
The 'secret' used to identify the controller of the game.
Definition: NetServer.h:387
static bool OnRejoined(CNetServerSession *session, CFsmEvent *event)
Definition: NetServer.cpp:1400
Network server interface.
Definition: NetServer.h:108
CStr m_PublicIp
Definition: NetServer.h:195
void UpdateInitAttributes(JS::MutableHandleValue attrs, const ScriptRequest &rq)
Call from the GUI to update the game setup attributes.
Definition: NetServer.cpp:1696
void SetPassword(const CStr &password)
Definition: NetServer.cpp:1677
void SetTurnLength(u32 msecs)
Set the turn length to a fixed value.
Definition: NetServer.cpp:1712
u16 GetPublicPort() const
Return the externally accessible port.
Definition: NetServer.cpp:1626
bool GetUseSTUN() const
Definition: NetServer.cpp:1606
CNetServerWorker * m_Worker
Definition: NetServer.h:191
u16 GetLocalPort() const
Return the serving port on the local machine.
Definition: NetServer.cpp:1631
void StartGame()
Call from the GUI to asynchronously notify all clients that they should start loading the game.
Definition: NetServer.cpp:1690
bool m_UseSTUN
Definition: NetServer.h:193
void OnLobbyAuth(const CStr &name, const CStr &token)
Definition: NetServer.cpp:1706
bool IsBanned(const std::string &username) const
Check if user reached certain number of failed attempts.
Definition: NetServer.cpp:1671
void SetConnectionData(const CStr &ip, u16 port)
Definition: NetServer.cpp:1639
bool CheckPasswordAndIncrement(const std::string &username, const std::string &password, const std::string &salt)
Check if password is valid.
Definition: NetServer.cpp:1655
bool SetupConnection(const u16 port)
Begin listening for network connections.
Definition: NetServer.cpp:1616
bool SetConnectionDataViaSTUN()
Definition: NetServer.cpp:1646
void SetControllerSecret(const std::string &secret)
Definition: NetServer.cpp:1684
CStr m_Password
Definition: NetServer.h:196
~CNetServer()
Definition: NetServer.cpp:1601
bool UseLobbyAuth() const
Definition: NetServer.cpp:1611
std::unordered_map< std::string, int > m_FailedAttempts
Definition: NetServer.h:197
CNetServer(bool useLobbyAuth=false)
Construct a new network server.
Definition: NetServer.cpp:1595
const bool m_LobbyAuth
Definition: NetServer.h:192
CStr GetPublicIp() const
Return the externally accessible IP.
Definition: NetServer.cpp:1621
void SendHolePunchingMessage(const CStr &ip, u16 port)
Definition: NetServer.cpp:1718
u16 m_PublicPort
Definition: NetServer.h:194
ENet connection statistics profiler table.
Definition: NetStats.h:39
Special message type for simulation commands.
Definition: NetMessage.h:114
Abstraction around a SpiderMonkey JS::Realm.
Definition: ScriptInterface.h:72
Spidermonkey maintains some 'local' state via the JSContext* object.
Definition: ScriptRequest.h:60
uint16_t u16
Definition: types.h:38
uint32_t u32
Definition: types.h:39