Rehti MMORPG  1.0.0
Rehti MMORPG is a free and open source MMORPG game.
Server Class Reference

Main class for the server. More...

#include <Server.hpp>

Collaboration diagram for Server:
Collaboration graph

Public Member Functions

 Server ()
 
void acceptConnections ()
 Function to accept new connections from clients, runs on a seperate thread. More...
 
void processMessages ()
 Server's main loop for processing messages. More...
 
void handleMessage (const Message &msg)
 Function to parse and act upon messages received from clients. More...
 

Private Member Functions

void ticker ()
 Timer function that is used to start server ticks, runs on a separate thread. More...
 
void tick ()
 Function that updates the gamestate on each server tick, called by ticker() More...
 
void sendGameState ()
 Sends the current gamestate to connected clients. More...
 
void initGameState ()
 Initializes the gamestate and gameworld. More...
 
bool loadPlayer (std::string username, std::string password, const std::shared_ptr< Connection > &connection)
 Loads a player's data from the database and adds the player to the game. More...
 
void savePlayer (int playerId)
 Saves a player's data to the database. More...
 

Private Attributes

boost::asio::io_context ioContextM
 
boost::asio::ip::tcp::acceptor acceptorM
 
std::vector< std::shared_ptr< Connection > > connectionsM
 
MessageQueue messagesM
 
std::thread ioThreadM
 
std::thread acceptThreadM
 
std::thread tickThreadM
 
boost::asio::executor_work_guard< boost::asio::io_context::executor_type > workGuardM
 
GameWorld gameWorldM
 
DatabaseManager dbManagerM
 

Detailed Description

Main class for the server.

Constructor & Destructor Documentation

◆ Server()

Server::Server ( )
Here is the call graph for this function:

Member Function Documentation

◆ acceptConnections()

void Server::acceptConnections ( )

Function to accept new connections from clients, runs on a seperate thread.

Here is the caller graph for this function:

◆ handleMessage()

void Server::handleMessage ( const Message &  msg)

Function to parse and act upon messages received from clients.

Parameters
msg
Here is the call graph for this function:
Here is the caller graph for this function:

◆ initGameState()

void Server::initGameState ( )
private

Initializes the gamestate and gameworld.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadPlayer()

bool Server::loadPlayer ( std::string  username,
std::string  password,
const std::shared_ptr< Connection > &  connection 
)
private

Loads a player's data from the database and adds the player to the game.

Parameters
username
password
connection
Returns
True if player was loaded successfully, false otherwise
Here is the call graph for this function:
Here is the caller graph for this function:

◆ processMessages()

void Server::processMessages ( )

Server's main loop for processing messages.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ savePlayer()

void Server::savePlayer ( int  playerId)
private

Saves a player's data to the database.

Parameters
playerId
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendGameState()

void Server::sendGameState ( )
private

Sends the current gamestate to connected clients.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tick()

void Server::tick ( )
private

Function that updates the gamestate on each server tick, called by ticker()

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ticker()

void Server::ticker ( )
private

Timer function that is used to start server ticks, runs on a separate thread.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ acceptorM

boost::asio::ip::tcp::acceptor Server::acceptorM
private

◆ acceptThreadM

std::thread Server::acceptThreadM
private

◆ connectionsM

std::vector<std::shared_ptr<Connection> > Server::connectionsM
private

◆ dbManagerM

DatabaseManager Server::dbManagerM
private

◆ gameWorldM

GameWorld Server::gameWorldM
private

◆ ioContextM

boost::asio::io_context Server::ioContextM
private

◆ ioThreadM

std::thread Server::ioThreadM
private

◆ messagesM

MessageQueue Server::messagesM
private

◆ tickThreadM

std::thread Server::tickThreadM
private

◆ workGuardM

boost::asio::executor_work_guard<boost::asio::io_context::executor_type> Server::workGuardM
private

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