From 731f45f63d43e1b50ddf3631a79dc5a06faa66bb Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 14 Nov 2021 11:45:34 +0100 Subject: [PATCH] Village management skeleton classes. --- SConstruct | 1 + app/village/village.cpp | 9 +++++ app/village/village.h | 16 ++++++++ app/village/village_controller.cpp | 34 ++++++++++++++++ app/village/village_controller.h | 29 ++++++++++++++ app/village/village_model.cpp | 63 ++++++++++++++++++++++++++++++ app/village/village_model.h | 26 ++++++++++++ 7 files changed, 178 insertions(+) create mode 100644 app/village/village.cpp create mode 100644 app/village/village.h create mode 100644 app/village/village_controller.cpp create mode 100644 app/village/village_controller.h create mode 100644 app/village/village_model.cpp create mode 100644 app/village/village_model.h diff --git a/SConstruct b/SConstruct index 83aecb8..6a1d5dc 100644 --- a/SConstruct +++ b/SConstruct @@ -33,6 +33,7 @@ import traceback folders = [ 'app', + 'app/village', ] module_folders = [ diff --git a/app/village/village.cpp b/app/village/village.cpp new file mode 100644 index 0000000..ce2ca97 --- /dev/null +++ b/app/village/village.cpp @@ -0,0 +1,9 @@ +#include "village.h" + +Village::Village() : + Resource() { + +} + +Village::~Village() { +} diff --git a/app/village/village.h b/app/village/village.h new file mode 100644 index 0000000..2307ce6 --- /dev/null +++ b/app/village/village.h @@ -0,0 +1,16 @@ +#ifndef VILLAGE_H +#define VILLAGE_H + +#include "core/string.h" + +#include "core/resource.h" + +class Village : public Resource { + RCPP_OBJECT(Village, Resource); + +public: + Village(); + ~Village(); +}; + +#endif \ No newline at end of file diff --git a/app/village/village_controller.cpp b/app/village/village_controller.cpp new file mode 100644 index 0000000..1d33485 --- /dev/null +++ b/app/village/village_controller.cpp @@ -0,0 +1,34 @@ +#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" + + +void VillageController::handle_request_default(Request *request) { +} + +VillageController *VillageController::get_singleton() { + return _self; +} + +VillageController::VillageController() : + Object() { + + if (_self) { + printf("VillageController::VillageController(): Error! self is not null!/n"); + } + + _self = this; +} + +VillageController::~VillageController() { + if (_self == this) { + _self = nullptr; + } +} + +VillageController *VillageController::_self = nullptr; diff --git a/app/village/village_controller.h b/app/village/village_controller.h new file mode 100644 index 0000000..454d4e2 --- /dev/null +++ b/app/village/village_controller.h @@ -0,0 +1,29 @@ +#ifndef VILLAGE_CONTROLLER_H +#define VILLAGE_CONTROLLER_H + +#include "core/string.h" +#include "core/containers/vector.h" + +#include "core/object.h" + +#include "village.h" + +class Request; +class FormValidator; + +class VillageController : public Object { + RCPP_OBJECT(VillageController, Object); + +public: + virtual void handle_request_default(Request *request); + + static VillageController *get_singleton(); + + VillageController(); + ~VillageController(); + +protected: + static VillageController *_self; +}; + +#endif \ No newline at end of file diff --git a/app/village/village_model.cpp b/app/village/village_model.cpp new file mode 100644 index 0000000..4a21c8b --- /dev/null +++ b/app/village/village_model.cpp @@ -0,0 +1,63 @@ +#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 "core/hash/sha256.h" + +#define VILLAGE_TABLE_NAME "village" + +void VillageModel::create_table() { + Ref tb = DatabaseManager::get_singleton()->ddb->get_table_builder(); + + tb->create_table(VILLAGE_TABLE_NAME); + tb->integer("id")->auto_increment()->next_row(); + tb->varchar("username", 60)->not_null()->next_row(); + tb->varchar("email", 100)->not_null()->next_row(); + tb->integer("rank")->not_null()->next_row(); + tb->varchar("pre_salt", 100)->next_row(); + tb->varchar("post_salt", 100)->next_row(); + tb->varchar("password_hash", 100)->next_row(); + tb->integer("banned")->next_row(); + tb->varchar("password_reset_token", 100)->next_row(); + tb->integer("locked")->next_row(); + tb->primary_key("id"); + tb->ccreate_table(); + tb->run_query(); + //tb->print(); +} +void VillageModel::drop_table() { + Ref tb = DatabaseManager::get_singleton()->ddb->get_table_builder(); + + tb->drop_table_if_exists(VILLAGE_TABLE_NAME)->run_query(); +} +void VillageModel::migrate() { + drop_table(); + create_table(); +} + + +VillageModel *VillageModel::get_singleton() { + return _self; +} + +VillageModel::VillageModel() : + Object() { + + if (_self) { + printf("VillageModel::VillageModel(): Error! self is not null!/n"); + } + + _self = this; +} + +VillageModel::~VillageModel() { + if (_self == this) { + _self = nullptr; + } +} + +VillageModel *VillageModel::_self = nullptr; diff --git a/app/village/village_model.h b/app/village/village_model.h new file mode 100644 index 0000000..4fbabd8 --- /dev/null +++ b/app/village/village_model.h @@ -0,0 +1,26 @@ +#ifndef VILLAGE_MODEL_H +#define VILLAGE_MODEL_H + +#include "core/string.h" +#include "core/containers/vector.h" + +#include "core/object.h" + +class VillageModel : public Object { + RCPP_OBJECT(VillageModel, Object); + +public: + virtual void create_table(); + virtual void drop_table(); + virtual void migrate(); + + static VillageModel *get_singleton(); + + VillageModel(); + ~VillageModel(); + +protected: + static VillageModel *_self; +}; + +#endif \ No newline at end of file