Cavoke  1.1.0
A Platform for creating and hosting multiplayer turn-based board games
Loading...
Searching...
No Matches
cavoke::server::model::GameSessionAccessObject Struct Reference

#include <game_session.h>

Classes

struct  GameSessionInfo
 Serializable representation of session for client. More...
 
struct  PlayerInfo
 Serializable representation of participant for client. More...
 
struct  UserInfo
 

Public Types

enum  SessionStatus { NOT_STARTED = 0 , RUNNING = 1 , FINISHED = 2 }
 

Public Member Functions

 GameSessionAccessObject (drogon::orm::DbClientPtr dbClient=drogon::app().getDbClient())
 
 GameSessionAccessObject (std::string session_id, GameConfig game_config, drogon::orm::DbClientPtr dbClient=drogon::app().getDbClient())
 
void add_user (const std::string &user_id, std::optional< int > player_id={})
 Adds given user to the session into given or minimal available position.
 
void remove_user (const std::string &user_id)
 Removes given user.
 
void set_role (const std::string &user_id, int new_role)
 Changes game role for given user.
 
void delete_session ()
 Delete current session.
 
void leave_session (const std::string &user_id)
 Leave current session (and transfer host/delete session)
 
void start (const json &game_settings)
 Marks session as starts.
 
void update_status (bool is_terminal)
 
int get_player_id (const std::string &user_id) const
 
std::string get_host () const
 
bool is_player (const std::string &user_id) const
 
bool is_host (const std::string &user_id) const
 
std::string get_user_id (int player_id) const
 
GameSessionInfo get_session_info () const
 Generates an info object (representation for client)
 
std::vector< int > get_occupied_positions () const
 
std::vector< PlayerInfoget_players () const
 

Static Public Member Functions

static drogon_model::cavoke_orm::Sessions get_snapshot (const std::string &session_id)
 Fetches current session information from the DB.
 
static GameSessionInfo make_session_info (const drogon_model::cavoke_orm::Sessions &session, const drogon_model::cavoke_orm::Statuses &status, std::vector< PlayerInfo > players)
 Builds a session info from a session.
 

Detailed Description

Access object for a game session. The fields of sessions may be spontaneously changed in another instance of the server. Therefore this class only provides methods to fetch DB data. Drogon ORM struct serves as the data holder.

Definition at line 31 of file game_session.h.

Member Enumeration Documentation

◆ SessionStatus

enum cavoke::server::model::GameSessionAccessObject::SessionStatus

Definition at line 32 of file game_session.h.

Constructor & Destructor Documentation

◆ GameSessionAccessObject() [1/2]

cavoke::server::model::GameSessionAccessObject::GameSessionAccessObject ( drogon::orm::DbClientPtr  dbClient = drogon::app().getDbClient())
inlineexplicit

Definition at line 33 of file game_session.h.

◆ GameSessionAccessObject() [2/2]

cavoke::server::model::GameSessionAccessObject::GameSessionAccessObject ( std::string  session_id,
GameConfig  game_config,
drogon::orm::DbClientPtr  dbClient = drogon::app().getDbClient() 
)
inlineexplicit

Definition at line 37 of file game_session.h.

Member Function Documentation

◆ add_user()

void cavoke::server::model::GameSessionAccessObject::add_user ( const std::string &  user_id,
std::optional< int >  player_id = {} 
)

Adds given user to the session into given or minimal available position.

Adds given user to session. Throws an exception if user already in this session, session has already started or too many players in a session

Definition at line 17 of file game_session.cpp.

◆ delete_session()

void cavoke::server::model::GameSessionAccessObject::delete_session ( )

Delete current session.

Definition at line 244 of file game_session.cpp.

◆ get_host()

std::string cavoke::server::model::GameSessionAccessObject::get_host ( ) const

Definition at line 178 of file game_session.cpp.

◆ get_occupied_positions()

std::vector< int > cavoke::server::model::GameSessionAccessObject::get_occupied_positions ( ) const

Definition at line 114 of file game_session.cpp.

◆ get_player_id()

int cavoke::server::model::GameSessionAccessObject::get_player_id ( const std::string &  user_id) const

Gets player id for user. Throws an exception if user not in this session

Definition at line 74 of file game_session.cpp.

◆ get_players()

std::vector< GameSessionAccessObject::PlayerInfo > cavoke::server::model::GameSessionAccessObject::get_players ( ) const

Definition at line 132 of file game_session.cpp.

◆ get_session_info()

GameSessionAccessObject::GameSessionInfo cavoke::server::model::GameSessionAccessObject::get_session_info ( ) const

Generates an info object (representation for client)

Definition at line 108 of file game_session.cpp.

◆ get_snapshot()

drogon_model::cavoke_orm::Sessions cavoke::server::model::GameSessionAccessObject::get_snapshot ( const std::string &  session_id)
static

Fetches current session information from the DB.

Definition at line 196 of file game_session.cpp.

◆ get_user_id()

std::string cavoke::server::model::GameSessionAccessObject::get_user_id ( int  player_id) const

Gets user id for player. Throws an exception if player not in this session

Definition at line 92 of file game_session.cpp.

◆ is_host()

bool cavoke::server::model::GameSessionAccessObject::is_host ( const std::string &  user_id) const

Definition at line 182 of file game_session.cpp.

◆ is_player()

bool cavoke::server::model::GameSessionAccessObject::is_player ( const std::string &  user_id) const

Definition at line 169 of file game_session.cpp.

◆ leave_session()

void cavoke::server::model::GameSessionAccessObject::leave_session ( const std::string &  user_id)

Leave current session (and transfer host/delete session)

Definition at line 250 of file game_session.cpp.

◆ make_session_info()

GameSessionAccessObject::GameSessionInfo cavoke::server::model::GameSessionAccessObject::make_session_info ( const drogon_model::cavoke_orm::Sessions &  session,
const drogon_model::cavoke_orm::Statuses &  status,
std::vector< PlayerInfo players 
)
static

Builds a session info from a session.

Definition at line 205 of file game_session.cpp.

◆ remove_user()

void cavoke::server::model::GameSessionAccessObject::remove_user ( const std::string &  user_id)

Removes given user.

Definition at line 215 of file game_session.cpp.

◆ set_role()

void cavoke::server::model::GameSessionAccessObject::set_role ( const std::string &  user_id,
int  new_role 
)

Changes game role for given user.

Definition at line 225 of file game_session.cpp.

◆ start()

void cavoke::server::model::GameSessionAccessObject::start ( const json &  game_settings)

Marks session as starts.

Definition at line 155 of file game_session.cpp.

◆ update_status()

void cavoke::server::model::GameSessionAccessObject::update_status ( bool  is_terminal)

Updates current session status using given is_terminal value. Finishes if terminal, Rewrites status if not. This is required for transaction isolation, so that is_terminal correlates with the session status.

Definition at line 186 of file game_session.cpp.


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