R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
Client Class Reference

R-Type client application. More...

#include <Client.hpp>

Collaboration diagram for Client:
Collaboration graph

Public Member Functions

 Client (const std::string &playerName, const std::string &host, uint16_t port, bool isSpectator=false)
 Constructor.
 
 Client (const std::string &playerName, const std::string &username, const std::string &password, const std::string &host, uint16_t port)
 Constructor with authentication.
 
 ~Client ()
 Destructor - clean shutdown.
 
bool initialize ()
 Initialize client systems.
 
void run ()
 Run the client (Start Game Loop directly)
 
void stop ()
 Stop the client.
 
void SetCredentials (const std::string &username, const std::string &password)
 Update credentials for next connection attempt.
 
void SetServer (const std::string &host, uint16_t port)
 Set server address and port.
 
bool Connect ()
 Connect to the configured server.
 

Private Member Functions

bool connectToServer ()
 Connect to server.
 

Private Attributes

std::string _playerName
 
std::string _username
 
std::string _password
 
std::string _serverHost
 
uint16_t _serverPort
 
bool _isSpectator
 
std::unique_ptr< EventBus_eventBus
 
std::unique_ptr< Replicator_replicator
 
std::unique_ptr< GameLoop_gameLoop
 
bool _initialized = false
 

Detailed Description

R-Type client application.

Encapsulates the entire client:

Usage:

Client client("PlayerName", "127.0.0.1", 4242);
if (client.initialize()) {
client.run();
}
R-Type client application.
Definition Client.hpp:40

Definition at line 40 of file Client.hpp.

Constructor & Destructor Documentation

◆ Client() [1/2]

Client::Client ( const std::string &  playerName,
const std::string &  host,
uint16_t  port,
bool  isSpectator = false 
)

Constructor.

Parameters
playerNamePlayer's name
hostServer hostname/IP
portServer port
isSpectatorWhether this client is in spectator mode

Definition at line 10 of file Client.cpp.

◆ Client() [2/2]

Client::Client ( const std::string &  playerName,
const std::string &  username,
const std::string &  password,
const std::string &  host,
uint16_t  port 
)

Constructor with authentication.

Parameters
playerNamePlayer's display name
usernameUsername for authentication
passwordPassword for authentication
hostServer hostname/IP
portServer port

Definition at line 18 of file Client.cpp.

◆ ~Client()

Client::~Client ( )

Destructor - clean shutdown.

Definition at line 27 of file Client.cpp.

References _gameLoop, _replicator, deinitializeNetworking(), and LOG_INFO.

Here is the call graph for this function:

Member Function Documentation

◆ Connect()

bool Client::Connect ( )

Connect to the configured server.

Returns
true if connection successful, false otherwise

Definition at line 85 of file Client.cpp.

References connectToServer().

Referenced by run().

Here is the call graph for this function:

◆ connectToServer()

bool Client::connectToServer ( )
private

Connect to server.

Returns
true if connection successful

Definition at line 89 of file Client.cpp.

References _password, _playerName, _replicator, _serverHost, _serverPort, _username, LOG_ERROR, and LOG_INFO.

Referenced by Connect().

◆ initialize()

bool Client::initialize ( )

Initialize client systems.

Returns
true if initialization successful

Definition at line 38 of file Client.cpp.

References _eventBus, _gameLoop, _initialized, _isSpectator, _playerName, _replicator, initializeNetworking(), LOG_ERROR, and LOG_INFO.

Here is the call graph for this function:

◆ run()

void Client::run ( )

Run the client (Start Game Loop directly)

Definition at line 149 of file Client.cpp.

References _eventBus, _gameLoop, _initialized, _isSpectator, _playerName, Connect(), CONNECTION_FAILED, CONNECTION_SUCCESS, LOG_ERROR, LOG_INFO, SERVER_CONNECT, and SetServer().

Here is the call graph for this function:

◆ SetCredentials()

void Client::SetCredentials ( const std::string &  username,
const std::string &  password 
)

Update credentials for next connection attempt.

Definition at line 74 of file Client.cpp.

References _password, and _username.

◆ SetServer()

void Client::SetServer ( const std::string &  host,
uint16_t  port 
)

Set server address and port.

Parameters
hostServer hostname/IP
portServer port

Definition at line 79 of file Client.cpp.

References _serverHost, _serverPort, and LOG_INFO.

Referenced by run().

◆ stop()

void Client::stop ( )

Stop the client.

Definition at line 197 of file Client.cpp.

References _gameLoop, and LOG_INFO.

Member Data Documentation

◆ _eventBus

std::unique_ptr<EventBus> Client::_eventBus
private

Definition at line 115 of file Client.hpp.

Referenced by initialize(), and run().

◆ _gameLoop

std::unique_ptr<GameLoop> Client::_gameLoop
private

Definition at line 117 of file Client.hpp.

Referenced by initialize(), run(), stop(), and ~Client().

◆ _initialized

bool Client::_initialized = false
private

Definition at line 119 of file Client.hpp.

Referenced by initialize(), and run().

◆ _isSpectator

bool Client::_isSpectator
private

Definition at line 113 of file Client.hpp.

Referenced by initialize(), and run().

◆ _password

std::string Client::_password
private

Definition at line 110 of file Client.hpp.

Referenced by connectToServer(), and SetCredentials().

◆ _playerName

std::string Client::_playerName
private

Definition at line 108 of file Client.hpp.

Referenced by connectToServer(), initialize(), and run().

◆ _replicator

std::unique_ptr<Replicator> Client::_replicator
private

Definition at line 116 of file Client.hpp.

Referenced by connectToServer(), initialize(), and ~Client().

◆ _serverHost

std::string Client::_serverHost
private

Definition at line 111 of file Client.hpp.

Referenced by connectToServer(), and SetServer().

◆ _serverPort

uint16_t Client::_serverPort
private

Definition at line 112 of file Client.hpp.

Referenced by connectToServer(), and SetServer().

◆ _username

std::string Client::_username
private

Definition at line 109 of file Client.hpp.

Referenced by connectToServer(), and SetCredentials().


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