![]() |
Cavoke
1.1.0
A Platform for creating and hosting multiplayer turn-based board games
|
#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< PlayerInfo > | get_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. | |
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.
enum cavoke::server::model::GameSessionAccessObject::SessionStatus |
Definition at line 32 of file game_session.h.
|
inlineexplicit |
Definition at line 33 of file game_session.h.
|
inlineexplicit |
Definition at line 37 of file game_session.h.
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.
void cavoke::server::model::GameSessionAccessObject::delete_session | ( | ) |
Delete current session.
Definition at line 244 of file game_session.cpp.
std::string cavoke::server::model::GameSessionAccessObject::get_host | ( | ) | const |
Definition at line 178 of file game_session.cpp.
std::vector< int > cavoke::server::model::GameSessionAccessObject::get_occupied_positions | ( | ) | const |
Definition at line 114 of file game_session.cpp.
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.
std::vector< GameSessionAccessObject::PlayerInfo > cavoke::server::model::GameSessionAccessObject::get_players | ( | ) | const |
Definition at line 132 of file game_session.cpp.
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.
|
static |
Fetches current session information from the DB.
Definition at line 196 of file game_session.cpp.
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.
bool cavoke::server::model::GameSessionAccessObject::is_host | ( | const std::string & | user_id | ) | const |
Definition at line 182 of file game_session.cpp.
bool cavoke::server::model::GameSessionAccessObject::is_player | ( | const std::string & | user_id | ) | const |
Definition at line 169 of file game_session.cpp.
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.
|
static |
Builds a session info from a session.
Definition at line 205 of file game_session.cpp.
void cavoke::server::model::GameSessionAccessObject::remove_user | ( | const std::string & | user_id | ) |
Removes given user.
Definition at line 215 of file game_session.cpp.
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.
void cavoke::server::model::GameSessionAccessObject::start | ( | const json & | game_settings | ) |
Marks session as starts.
Definition at line 155 of file game_session.cpp.
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.