Cavoke  1.1.0
A Platform for creating and hosting multiplayer turn-based board games
Loading...
Searching...
No Matches
game.cpp
1#include "game.h"
2#include <boost/filesystem.hpp>
3#include <string>
4
5namespace cavoke::server::model {
6
7Game::Game(const boost::filesystem::path &directory,
8 const GamesStorageConfig &game_storage_config)
9 : directory(directory),
10 logic_file(directory / LOGIC_FILE),
11 client_file(directory / CLIENT_FILE),
12 CLIENT_FILE(game_storage_config.zip_name),
13 LOGIC_FILE(game_storage_config.logic_name),
14 CONFIG_FILE(game_storage_config.config_name) {
15 json j = json::parse(std::ifstream(directory / CONFIG_FILE));
16 config = j.get<GameConfig>();
17}
18
20bool check_is_directory(const boost::filesystem::path &path) {
21 return exists(path) && is_directory(path);
22}
24bool check_is_regular_file(const boost::filesystem::path &path) {
25 return exists(path) && is_regular_file(path);
26}
28bool check_valid_game_config(const boost::filesystem::path &path) {
29 try { // slow?
30 json j = json::parse(std::ifstream(path));
31 auto conf = j.get<GameConfig>();
32 conf.validate();
33 return true;
34 } catch (...) {
35 return false;
36 }
37}
38
39bool Game::is_game_directory(const boost::filesystem::path &path,
40 const GamesStorageConfig &games_storage_config) {
41 return check_is_directory(path) &&
42 check_is_regular_file(path / games_storage_config.zip_name) &&
43 check_is_regular_file(path / games_storage_config.logic_name) &&
44 check_valid_game_config(path / games_storage_config.config_name);
45}
46
47} // namespace cavoke::server::model