Skip to content

Commit

Permalink
make the parameterised constructors protected so nobody can construct…
Browse files Browse the repository at this point in the history
… a half-initialised paragraph (this actually found a bug)
  • Loading branch information
braindigitalis committed Aug 20, 2024
1 parent 7d07ba9 commit f3f9055
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
35 changes: 18 additions & 17 deletions include/ssod/paragraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,23 +231,6 @@ struct paragraph {
*/
~paragraph() = default;

/**
* Construct a paragraph with existing data.
* @note Does not parse the content, this is done asynchronously via the parse method.
* @param data Paragraph content
* @param current Current player
*/
paragraph(const std::string& data, player& current);

/**
* Construct a paragraph from paragraph id
* @note Does not parse the content, this is done asynchronously via the parse method.
* @param paragraph_id Paragraph id in database
* @param current Current player
* @param user_id Discord user id
*/
paragraph(uint32_t paragraph_id, player& current, dpp::snowflake user_id);

/**
* Given a current paragraph id, return true if the next id is a valid move,
* or false if it isn't. Used as a double check against cheating.
Expand All @@ -274,6 +257,24 @@ struct paragraph {
*/
static dpp::task<paragraph> create(const std::string& data, player& current);

protected:
/**
* Construct a paragraph with existing data.
* @note Does not parse the content, this is done asynchronously via the parse method.
* @param data Paragraph content
* @param current Current player
*/
paragraph(const std::string& data, player& current);

/**
* Construct a paragraph from paragraph id
* @note Does not parse the content, this is done asynchronously via the parse method.
* @param paragraph_id Paragraph id in database
* @param current Current player
* @param user_id Discord user id
*/
paragraph(uint32_t paragraph_id, player& current, dpp::snowflake user_id);

/**
* Parse paragraph content, this may take some time to complete as it has to interpret the content
* and retrieve it from the database.
Expand Down
2 changes: 1 addition & 1 deletion src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1359,7 +1359,7 @@ dpp::task<void> continue_game(const dpp::interaction_create_t& event, player p)
* that says "Turn to X" which were an anti-cheat holdover from book-form content.
*/
while (location.words == 0 && location.navigation_links.size() > 0 && (location.navigation_links[0].type == nav_type_autolink || location.navigation_links[0].type == nav_type_link)) {
location = paragraph(location.navigation_links[0].paragraph, p, event.command.usr.id);
location = co_await paragraph::create(location.navigation_links[0].paragraph, p, event.command.usr.id);
p.paragraph = location.id;
}

Expand Down

0 comments on commit f3f9055

Please sign in to comment.