Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
CNetServer Class Reference

Network server interface. More...

#include <NetServer.h>

Collaboration diagram for CNetServer:

Public Member Functions

 CNetServer (bool useLobbyAuth=false)
 Construct a new network server. More...
 
 ~CNetServer ()
 
bool SetupConnection (const u16 port)
 Begin listening for network connections. More...
 
void StartGame ()
 Call from the GUI to asynchronously notify all clients that they should start loading the game. More...
 
void UpdateInitAttributes (JS::MutableHandleValue attrs, const ScriptRequest &rq)
 Call from the GUI to update the game setup attributes. More...
 
void SetTurnLength (u32 msecs)
 Set the turn length to a fixed value. More...
 
bool UseLobbyAuth () const
 
void OnLobbyAuth (const CStr &name, const CStr &token)
 
void SendHolePunchingMessage (const CStr &ip, u16 port)
 
void SetConnectionData (const CStr &ip, u16 port)
 
bool SetConnectionDataViaSTUN ()
 
bool GetUseSTUN () const
 
CStr GetPublicIp () const
 Return the externally accessible IP. More...
 
u16 GetPublicPort () const
 Return the externally accessible port. More...
 
u16 GetLocalPort () const
 Return the serving port on the local machine. More...
 
bool CheckPasswordAndIncrement (const std::string &username, const std::string &password, const std::string &salt)
 Check if password is valid. More...
 
bool IsBanned (const std::string &username) const
 Check if user reached certain number of failed attempts. More...
 
void SetPassword (const CStr &password)
 
void SetControllerSecret (const std::string &secret)
 

Private Member Functions

 NONCOPYABLE (CNetServer)
 

Private Attributes

CNetServerWorkerm_Worker
 
const bool m_LobbyAuth
 
bool m_UseSTUN
 
u16 m_PublicPort
 
CStr m_PublicIp
 
CStr m_Password
 
std::unordered_map< std::string, int > m_FailedAttempts
 

Detailed Description

Network server interface.

Handles all the coordination between players. One person runs this object, and every player (including the host) connects their CNetClient to it.

The actual work is performed by CNetServerWorker in a separate thread.

Constructor & Destructor Documentation

◆ CNetServer()

CNetServer::CNetServer ( bool  useLobbyAuth = false)

Construct a new network server.

once this many players are connected (intended for the command-line testing mode).

◆ ~CNetServer()

CNetServer::~CNetServer ( )

Member Function Documentation

◆ CheckPasswordAndIncrement()

bool CNetServer::CheckPasswordAndIncrement ( const std::string &  username,
const std::string &  password,
const std::string &  salt 
)

Check if password is valid.

If is not, increase number of failed attempts of the lobby user. This is used without established direct session with the client, to prevent brute force attacks when guessing password trying to get connection data from the host.

Returns
true iff password is valid

◆ GetLocalPort()

u16 CNetServer::GetLocalPort ( ) const

Return the serving port on the local machine.

◆ GetPublicIp()

CStr CNetServer::GetPublicIp ( ) const

Return the externally accessible IP.

◆ GetPublicPort()

u16 CNetServer::GetPublicPort ( ) const

Return the externally accessible port.

◆ GetUseSTUN()

bool CNetServer::GetUseSTUN ( ) const

◆ IsBanned()

bool CNetServer::IsBanned ( const std::string &  username) const

Check if user reached certain number of failed attempts.

See also
m_BanAfterNumberOfTries
CheckPasswordAndBan

◆ NONCOPYABLE()

CNetServer::NONCOPYABLE ( CNetServer  )
private

◆ OnLobbyAuth()

void CNetServer::OnLobbyAuth ( const CStr &  name,
const CStr &  token 
)

◆ SendHolePunchingMessage()

void CNetServer::SendHolePunchingMessage ( const CStr &  ip,
u16  port 
)

◆ SetConnectionData()

void CNetServer::SetConnectionData ( const CStr &  ip,
u16  port 
)

◆ SetConnectionDataViaSTUN()

bool CNetServer::SetConnectionDataViaSTUN ( )

◆ SetControllerSecret()

void CNetServer::SetControllerSecret ( const std::string &  secret)

◆ SetPassword()

void CNetServer::SetPassword ( const CStr &  password)

◆ SetTurnLength()

void CNetServer::SetTurnLength ( u32  msecs)

Set the turn length to a fixed value.

TODO: we should replace this with some adapative lag-dependent computation.

◆ SetupConnection()

bool CNetServer::SetupConnection ( const u16  port)

Begin listening for network connections.

This function is synchronous (it won't return until the connection is established).

Returns
true on success, false on error (e.g. port already in use)

◆ StartGame()

void CNetServer::StartGame ( )

Call from the GUI to asynchronously notify all clients that they should start loading the game.

UpdateInitAttributes must be called at least once.

◆ UpdateInitAttributes()

void CNetServer::UpdateInitAttributes ( JS::MutableHandleValue  attrs,
const ScriptRequest rq 
)

Call from the GUI to update the game setup attributes.

The changes won't be propagated to clients until game start.

Parameters
attrsinit attributes, in the script context of rq

◆ UseLobbyAuth()

bool CNetServer::UseLobbyAuth ( ) const

Member Data Documentation

◆ m_FailedAttempts

std::unordered_map<std::string, int> CNetServer::m_FailedAttempts
private

◆ m_LobbyAuth

const bool CNetServer::m_LobbyAuth
private

◆ m_Password

CStr CNetServer::m_Password
private

◆ m_PublicIp

CStr CNetServer::m_PublicIp
private

◆ m_PublicPort

u16 CNetServer::m_PublicPort
private

◆ m_UseSTUN

bool CNetServer::m_UseSTUN
private

◆ m_Worker

CNetServerWorker* CNetServer::m_Worker
private

The documentation for this class was generated from the following files: