Updated the engine.

This commit is contained in:
Relintai 2022-02-05 23:02:06 +01:00
parent 108665d430
commit 4f1e8ea1c1
22 changed files with 183 additions and 222 deletions

2
HEADS
View File

@ -1 +1 @@
{"engine": {"master": "0c6c20bd64ebe3a9fe798af793f3181aeb3fd0e5"}}
{"engine": {"master": "f711d413d63b9a8145c854032252c7805aa083a0"}}

View File

@ -1,12 +1,12 @@
#include "assignment_controller.h"
#include "core/html/form_validator.h"
#include "core/html/html_builder.h"
#include "core/http/cookie.h"
#include "core/http/http_enums.h"
#include "core/http/http_session.h"
#include "core/http/request.h"
#include "core/http/session_manager.h"
#include "web/html/form_validator.h"
#include "web/html/html_builder.h"
#include "web/http/cookie.h"
#include "web/http/http_enums.h"
#include "web/http/http_session.h"
#include "web/http/request.h"
#include "web/http/session_manager.h"
#include "assignment_model.h"
@ -166,11 +166,14 @@ void AssignmentController::admin_render_assignment(Request *request, Ref<Assignm
request->body += b.result;
}
void AssignmentController::migrate() {
AssignmentModel::get_singleton()->migrate();
void AssignmentController::create_table() {
AssignmentModel::get_singleton()->create_table();
}
void AssignmentController::add_default_data() {
AssignmentModel::get_singleton()->add_default_data();
void AssignmentController::drop_table() {
AssignmentModel::get_singleton()->drop_table();
}
void AssignmentController::create_default_entries() {
AssignmentModel::get_singleton()->create_default_entries();
}
AssignmentController *AssignmentController::get_singleton() {

View File

@ -4,7 +4,7 @@
#include "core/string.h"
#include "core/containers/vector.h"
#include "modules/admin_panel/admin_node.h"
#include "web_modules/admin_panel/admin_node.h"
#include "assignment.h"
@ -25,8 +25,9 @@ public:
void admin_render_assignment_list(Request *request);
void admin_render_assignment(Request *request, Ref<Assignment> assignment);
void migrate();
virtual void add_default_data();
void create_table();
void drop_table();
void create_default_entries();
static AssignmentController *get_singleton();

View File

@ -1,12 +1,12 @@
#include "assignment_model.h"
#include "core/database/database.h"
#include "core/database/database_manager.h"
#include "core/database/query_builder.h"
#include "core/database/query_result.h"
#include "core/database/table_builder.h"
#include "database/database.h"
#include "database/database_manager.h"
#include "database/query_builder.h"
#include "database/query_result.h"
#include "database/table_builder.h"
#include "core/hash/sha256.h"
#include "crypto/hash/sha256.h"
#include "assignment.h"
@ -224,12 +224,8 @@ void AssignmentModel::drop_table() {
tb->run_query();
}
void AssignmentModel::migrate() {
drop_table();
create_table();
}
void AssignmentModel::add_default_data() {
void AssignmentModel::create_default_entries() {
String table_columns = "id, unitid, max, bonus_per_assigned, spellid, req_tech, mod_max_food, mod_max_wood, mod_max_stone, mod_max_iron, mod_max_mana, mod_rate_food, mod_rate_wood, mod_rate_stone, mod_rate_iron, mod_rate_mana, mod_percent_food, mod_percent_wood, mod_percent_stone, mod_percent_iron, mod_percent_mana, description";
Ref<QueryBuilder> qb = DatabaseManager::get_singleton()->ddb->get_query_builder();

View File

@ -20,10 +20,9 @@ public:
virtual void parse_row(Ref<QueryResult> &result, Ref<Assignment> &assignment);
virtual void create_table();
virtual void drop_table();
virtual void migrate();
virtual void add_default_data();
void create_table();
void drop_table();
void create_default_entries();
static AssignmentModel *get_singleton();

View File

@ -1,12 +1,12 @@
#include "building_controller.h"
#include "core/html/form_validator.h"
#include "core/html/html_builder.h"
#include "core/http/cookie.h"
#include "core/http/http_enums.h"
#include "core/http/http_session.h"
#include "core/http/request.h"
#include "core/http/session_manager.h"
#include "web/html/form_validator.h"
#include "web/html/html_builder.h"
#include "web/http/cookie.h"
#include "web/http/http_enums.h"
#include "web/http/http_session.h"
#include "web/http/request.h"
#include "web/http/session_manager.h"
#include "building_model.h"
@ -274,11 +274,14 @@ void BuildingController::admin_render_building(Request *request, Ref<Building> b
request->body += b.result;
}
void BuildingController::migrate() {
BuildingModel::get_singleton()->migrate();
void BuildingController::create_table() {
BuildingModel::get_singleton()->create_table();
}
void BuildingController::add_default_data() {
BuildingModel::get_singleton()->add_default_data();
void BuildingController::drop_table() {
BuildingModel::get_singleton()->drop_table();
}
void BuildingController::create_default_entries() {
BuildingModel::get_singleton()->create_default_entries();
}
BuildingController *BuildingController::get_singleton() {

View File

@ -4,7 +4,7 @@
#include "core/string.h"
#include "core/containers/vector.h"
#include "modules/admin_panel/admin_node.h"
#include "web_modules/admin_panel/admin_node.h"
#include "building.h"
@ -25,8 +25,9 @@ public:
void admin_render_building_list(Request *request);
void admin_render_building(Request *request, Ref<Building> building);
void migrate();
virtual void add_default_data();
void create_table();
void drop_table();
void create_default_entries();
static BuildingController *get_singleton();

View File

@ -1,12 +1,12 @@
#include "building_model.h"
#include "core/database/database.h"
#include "core/database/database_manager.h"
#include "core/database/query_builder.h"
#include "core/database/query_result.h"
#include "core/database/table_builder.h"
#include "database/database.h"
#include "database/database_manager.h"
#include "database/query_builder.h"
#include "database/query_result.h"
#include "database/table_builder.h"
#include "core/hash/sha256.h"
#include "crypto/hash/sha256.h"
#include "building.h"
@ -307,12 +307,8 @@ void BuildingModel::drop_table() {
tb->run_query();
}
void BuildingModel::migrate() {
drop_table();
create_table();
}
void BuildingModel::add_default_data() {
void BuildingModel::create_default_entries() {
String table_columns = "id, name, description, icon, rank, next_rank, time_to_build, creates, num_creates, score, defense, ability, cost_food, cost_wood, cost_stone, cost_iron, cost_mana, mod_max_food, mod_max_wood, mod_max_stone, mod_max_iron, mod_max_mana, mod_rate_food, mod_rate_wood, mod_rate_stone, mod_rate_iron, mod_rate_mana, mod_percent_food, mod_percent_wood, mod_percent_stone, mod_percent_iron, mod_percent_mana, assignment1, assignment2, assignment3, assignment4, assignment5, req_tech, tech_group, tech_secondary_group";
Ref<QueryBuilder> qb = DatabaseManager::get_singleton()->ddb->get_query_builder();

View File

@ -20,10 +20,9 @@ public:
virtual void parse_row(Ref<QueryResult> &result, Ref<Building> &building);
virtual void create_table();
virtual void drop_table();
virtual void migrate();
virtual void add_default_data();
void create_table();
void drop_table();
void create_default_entries();
static BuildingModel *get_singleton();

View File

@ -1,23 +1,23 @@
#include "mourne_root.h"
#include "core/http/request.h"
#include "web/http/request.h"
#include <iostream>
#include "core/file_cache.h"
#include "web/file_cache.h"
#include "core/os/platform.h"
#include "core/os/arg_parser.h"
#include "core/os/platform.h"
#include "core/database/database_manager.h"
#include "database/database_manager.h"
#include "core/html/html_builder.h"
#include "core/http/http_session.h"
#include "core/http/session_manager.h"
#include "web/html/html_builder.h"
#include "web/http/http_session.h"
#include "web/http/session_manager.h"
#include "modules/admin_panel/admin_panel.h"
#include "modules/users/user.h"
#include "modules/users/user_controller.h"
#include "web_modules/admin_panel/admin_panel.h"
#include "web_modules/users/user.h"
#include "web_modules/users/user_controller.h"
#include "mourne_user_controller.h"
@ -252,28 +252,31 @@ void MourneRoot::setup_middleware() {
_middlewares.push_back(Ref<UserSessionSetupMiddleware>(new UserSessionSetupMiddleware()));
}
void MourneRoot::migrate() {
BuildingController::get_singleton()->migrate();
VillageController::get_singleton()->migrate();
AssignmentController::get_singleton()->migrate();
WeatherController::get_singleton()->migrate();
if (Platform::get_singleton()->arg_parser.has_arg("-u")) {
printf("Creating test users.\n");
_user_controller->create_test_users();
}
if (Platform::get_singleton()->arg_parser.has_arg("-d")) {
printf("Adding data.\n");
add_default_data();
}
void MourneRoot::create_table() {
// TODO move these to the node system and remove from here
BuildingController::get_singleton()->create_table();
VillageController::get_singleton()->create_table();
AssignmentController::get_singleton()->create_table();
WeatherController::get_singleton()->create_table();
}
void MourneRoot::add_default_data() {
BuildingController::get_singleton()->add_default_data();
VillageController::get_singleton()->add_default_data();
AssignmentController::get_singleton()->add_default_data();
WeatherController::get_singleton()->add_default_data();
void MourneRoot::drop_table() {
BuildingController::get_singleton()->drop_table();
VillageController::get_singleton()->drop_table();
AssignmentController::get_singleton()->drop_table();
WeatherController::get_singleton()->drop_table();
}
void MourneRoot::udpate_table() {
// TODO move these to the node system and remove from here
BuildingController::get_singleton()->udpate_table();
AssignmentController::get_singleton()->udpate_table();
WeatherController::get_singleton()->udpate_table();
}
void MourneRoot::create_default_entries() {
// TODO move these to the node system and remove from here
BuildingController::get_singleton()->create_default_entries();
VillageController::get_singleton()->create_default_entries();
AssignmentController::get_singleton()->create_default_entries();
WeatherController::get_singleton()->create_default_entries();
}
void MourneRoot::compile_menu() {

View File

@ -1,16 +1,11 @@
#ifndef MOURNE_ROOT_H
#define MOURNE_ROOT_H
//#include "core/http/web_application.h"
#include "core/http/web_root.h"
//#include "web/http/web_application.h"
#include "web/http/web_root.h"
#include "core/object.h"
#include "core/string.h"
#include "modules/list_page/list_page.h"
#include "modules/message_page/message_page.h"
#include "modules/paged_article/paged_article.h"
#include "modules/paged_list/paged_list.h"
class AdminPanel;
class RBACController;
class RBACModel;
@ -55,8 +50,10 @@ public:
virtual void setup_middleware();
virtual void migrate();
virtual void add_default_data();
void create_table();
void drop_table();
void udpate_table();
void create_default_entries();
void compile_menu();

View File

@ -1,11 +1,11 @@
#include "mourne_user_controller.h"
#include "core/html/form_validator.h"
#include "core/html/html_builder.h"
#include "core/http/cookie.h"
#include "core/http/http_session.h"
#include "core/http/request.h"
#include "core/http/session_manager.h"
#include "web/html/form_validator.h"
#include "web/html/html_builder.h"
#include "web/http/cookie.h"
#include "web/http/http_session.h"
#include "web/http/request.h"
#include "web/http/session_manager.h"
void MourneUserController::render_login_request_default(Request *request, LoginRequestData *data) {
HTMLBuilder b;
@ -182,7 +182,7 @@ void MourneUserController::render_settings_request(Ref<User> &user, Request *req
request->compile_and_send_body();
}
void MourneUserController::create_test_users() {
void MourneUserController::create_default_entries() {
Ref<User> user;
user = create_user();

View File

@ -1,10 +1,10 @@
#ifndef MOURNE_USER_CONTROLLER_H
#define MOURNE_USER_CONTROLLER_H
#include "modules/users/user_controller.h"
#include "web_modules/users/user_controller.h"
#include <string>
#include "modules/users/user.h"
#include "web_modules/users/user.h"
class Request;
class FormValidator;
@ -18,7 +18,7 @@ public:
void render_already_logged_in_error(Request *request);
void render_settings_request(Ref<User> &user, Request *request, SettingsRequestData *data);
virtual void create_test_users();
void create_default_entries();
MourneUserController();
~MourneUserController();

View File

@ -1,22 +1,25 @@
#include "village_controller.h"
#include "core/html/form_validator.h"
#include "core/html/html_builder.h"
#include "core/http/cookie.h"
#include "core/http/http_session.h"
#include "core/http/request.h"
#include "core/http/session_manager.h"
#include "web/html/form_validator.h"
#include "web/html/html_builder.h"
#include "web/http/cookie.h"
#include "web/http/http_session.h"
#include "web/http/request.h"
#include "web/http/session_manager.h"
#include "village_model.h"
void VillageController::handle_request_default(Request *request) {
}
void VillageController::migrate() {
VillageModel::get_singleton()->migrate();
void VillageController::create_table() {
VillageModel::get_singleton()->create_table();
}
void VillageController::add_default_data() {
VillageModel::get_singleton()->add_default_data();
void VillageController::drop_table() {
VillageModel::get_singleton()->drop_table();
}
void VillageController::create_default_entries() {
VillageModel::get_singleton()->create_default_entries();
}
VillageController *VillageController::get_singleton() {

View File

@ -15,8 +15,9 @@ class VillageController : public Object {
RCPP_OBJECT(VillageController, Object);
public:
void migrate();
virtual void add_default_data();
void create_table();
void drop_table();
void create_default_entries();
virtual void handle_request_default(Request *request);

View File

@ -1,12 +1,12 @@
#include "village_model.h"
#include "core/database/database.h"
#include "core/database/database_manager.h"
#include "core/database/query_builder.h"
#include "core/database/query_result.h"
#include "core/database/table_builder.h"
#include "database/database.h"
#include "database/database_manager.h"
#include "database/query_builder.h"
#include "database/query_result.h"
#include "database/table_builder.h"
#include "core/hash/sha256.h"
#include "crypto/hash/sha256.h"
#define VILLAGE_TABLE_NAME "villages"
#define VILLAGE_RESOURCES_TABLE_NAME "village_resources"
@ -208,16 +208,11 @@ void VillageModel::drop_table() {
tb->run_query();
}
void VillageModel::migrate() {
drop_table();
create_table();
}
void VillageModel::add_default_data() {
void VillageModel::create_default_entries() {
}
VillageModel *VillageModel::get_singleton() {
return _self;
}

View File

@ -12,8 +12,7 @@ class VillageModel : public Object {
public:
virtual void create_table();
virtual void drop_table();
virtual void migrate();
virtual void add_default_data();
virtual void create_default_entries();
static VillageModel *get_singleton();

View File

@ -1,12 +1,12 @@
#include "weather_controller.h"
#include "core/html/form_validator.h"
#include "core/html/html_builder.h"
#include "core/http/cookie.h"
#include "core/http/http_enums.h"
#include "core/http/http_session.h"
#include "core/http/request.h"
#include "core/http/session_manager.h"
#include "web/html/form_validator.h"
#include "web/html/html_builder.h"
#include "web/http/cookie.h"
#include "web/http/http_enums.h"
#include "web/http/http_session.h"
#include "web/http/request.h"
#include "web/http/session_manager.h"
#include "weather_model.h"
@ -156,11 +156,14 @@ void WeatherController::admin_render_weather(Request *request, Ref<Weather> weat
request->body += b.result;
}
void WeatherController::migrate() {
WeatherModel::get_singleton()->migrate();
void WeatherController::create_table() {
WeatherModel::get_singleton()->create_table();
}
void WeatherController::add_default_data() {
WeatherModel::get_singleton()->add_default_data();
void WeatherController::drop_table() {
WeatherModel::get_singleton()->drop_table();
}
void WeatherController::create_default_entries() {
WeatherModel::get_singleton()->create_default_entries();
}
WeatherController *WeatherController::get_singleton() {

View File

@ -4,7 +4,7 @@
#include "core/string.h"
#include "core/containers/vector.h"
#include "modules/admin_panel/admin_node.h"
#include "web_modules/admin_panel/admin_node.h"
#include "weather.h"
@ -25,8 +25,9 @@ public:
void admin_render_weather_list(Request *request);
void admin_render_weather(Request *request, Ref<Weather> weather);
void migrate();
virtual void add_default_data();
void create_table();
void drop_table();
void create_default_entries();
static WeatherController *get_singleton();

View File

@ -1,12 +1,12 @@
#include "weather_model.h"
#include "core/database/database.h"
#include "core/database/database_manager.h"
#include "core/database/query_builder.h"
#include "core/database/query_result.h"
#include "core/database/table_builder.h"
#include "database/database.h"
#include "database/database_manager.h"
#include "database/query_builder.h"
#include "database/query_result.h"
#include "database/table_builder.h"
#include "core/hash/sha256.h"
#include "crypto/hash/sha256.h"
#include "weather.h"
@ -195,12 +195,8 @@ void WeatherModel::drop_table() {
tb->run_query();
}
void WeatherModel::migrate() {
drop_table();
create_table();
}
void WeatherModel::add_default_data() {
void WeatherModel::create_default_entries() {
String table_columns = "id, name, description, art, css, effect, mod_max_food, mod_max_wood, mod_max_stone, mod_max_iron, mod_max_mana, mod_percent_food, mod_percent_wood, mod_percent_stone, mod_percent_iron, mod_percent_mana";
Ref<QueryBuilder> qb = DatabaseManager::get_singleton()->ddb->get_query_builder();

View File

@ -20,10 +20,9 @@ public:
virtual void parse_row(Ref<QueryResult> &result, Ref<Weather> &weather);
virtual void create_table();
virtual void drop_table();
virtual void migrate();
virtual void add_default_data();
void create_table();
void drop_table();
void create_default_entries();
static WeatherModel *get_singleton();

View File

@ -1,35 +1,14 @@
#include <string.h>
#include <iostream>
#include <string>
#include "core/file_cache.h"
#include "core/http/web_root.h"
#include "app/mourne_root.h"
#include "database/db_init.h"
#include "core/settings/settings.h"
#include "core/settings/db_settings.h"
#include "core/http/session_manager.h"
#include "modules/drogon/drogon_web_server.h"
//Backends
#include "backends/hash_hashlib/setup.h"
#include "modules/users/user.h"
#include "core/os/platform.h"
#include "platform/platform_initializer.h"
#include "core/settings/settings.h"
#include "database/database_manager.h"
#include "database_modules/db_settings/db_settings.h"
#include "web/file_cache.h"
#include "web/http/session_manager.h"
#include "web_backends/drogon/drogon_web_server.h"
#include "core/database/database_manager.h"
void initialize_backends() {
initialize_database_backends();
backend_hash_hashlib_install_providers();
}
#include "rcpp_framework.h"
void create_databases() {
DatabaseManager *dbm = DatabaseManager::get_singleton();
@ -40,25 +19,13 @@ void create_databases() {
}
int main(int argc, char **argv, char **envp) {
PlatformInitializer::allocate_all();
PlatformInitializer::arg_setup(argc, argv, envp);
initialize_backends();
::SessionManager *session_manager = new ::SessionManager();
DBSettings *settings = new DBSettings(true);
// settings->parse_file("settings.json");
FileCache *file_cache = new FileCache(true);
file_cache->wwwroot = "./www";
file_cache->wwwroot_refresh_cache();
DatabaseManager *dbm = new DatabaseManager();
RCPPFramework::create_and_init(argc, argv, envp);
RCPPFramework::get_singleton()->www_root = "./www";
create_databases();
DrogonWebServer *app = new DrogonWebServer();
RCPPFramework::get_singleton()->manage_object(app);
MourneRoot *app_root = new MourneRoot();
app_root->setup();
@ -67,29 +34,28 @@ int main(int argc, char **argv, char **envp) {
bool migrate = Platform::get_singleton()->arg_parser.has_arg("-m");
if (!migrate) {
settings->load();
session_manager->load_sessions();
RCPPFramework::get_singleton()->load();
printf("Initialized!\n");
RLOG_MSG("Initialized!\n");
app->add_listener("127.0.0.1", 8080);
LOG_INFO << "Server running on 127.0.0.1:8080";
RLOG_MSG("Server running on 127.0.0.1:8080");
app->run();
} else {
printf("Running migrations.\n");
RLOG_MSG("Running migrations.\n");
settings->migrate();
session_manager->migrate();
app_root->migrate();
RCPPFramework::get_singleton()->migrate();
bool seed_db = Platform::get_singleton()->arg_parser.has_arg("-s");
if (seed_db) {
RLOG_MSG("Seeding database.\n");
}
app_root->migrate(true, seed_db);
}
delete app;
delete dbm;
delete file_cache;
delete settings;
delete session_manager;
PlatformInitializer::free_all();
RCPPFramework::destroy();
return 0;
}