2022-01-09 17:05:04 +01:00
|
|
|
#include "mourne_root.h"
|
2021-10-30 22:48:02 +02:00
|
|
|
|
2022-02-05 23:02:06 +01:00
|
|
|
#include "web/http/request.h"
|
2021-10-30 22:48:02 +02:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
2022-02-05 23:02:06 +01:00
|
|
|
#include "web/file_cache.h"
|
2021-10-30 22:48:02 +02:00
|
|
|
|
2022-01-09 17:05:04 +01:00
|
|
|
#include "core/os/arg_parser.h"
|
2022-02-05 23:02:06 +01:00
|
|
|
#include "core/os/platform.h"
|
2021-10-30 22:48:02 +02:00
|
|
|
|
2022-02-05 23:02:06 +01:00
|
|
|
#include "database/database_manager.h"
|
2021-10-30 22:48:02 +02:00
|
|
|
|
2022-02-05 23:02:06 +01:00
|
|
|
#include "web/html/html_builder.h"
|
|
|
|
#include "web/http/http_session.h"
|
|
|
|
#include "web/http/session_manager.h"
|
2021-10-30 22:48:02 +02:00
|
|
|
|
2022-02-05 23:02:06 +01:00
|
|
|
#include "web_modules/admin_panel/admin_panel.h"
|
|
|
|
#include "web_modules/users/user.h"
|
|
|
|
#include "web_modules/users/user_controller.h"
|
2021-10-30 22:48:02 +02:00
|
|
|
|
2022-01-09 17:05:04 +01:00
|
|
|
#include "mourne_user_controller.h"
|
|
|
|
|
|
|
|
#include "assignments/assignment_initializer.h"
|
2021-11-14 14:19:13 +01:00
|
|
|
#include "buildings/building_initializer.h"
|
2021-11-14 13:59:02 +01:00
|
|
|
#include "village/village_initializer.h"
|
2021-12-18 11:23:59 +01:00
|
|
|
#include "weather/weather_initializer.h"
|
2021-11-14 13:59:02 +01:00
|
|
|
|
2022-01-09 17:05:04 +01:00
|
|
|
void MourneRoot::handle_request_main(Request *request) {
|
|
|
|
if (process_middlewares(request)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (try_send_wwwroot_file(request)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// this is a hack, until I have a simple index node, or port contentcontroller.
|
|
|
|
if (request->get_path_segment_count() == 0) {
|
|
|
|
index(request);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
WebNode *handler = get_request_handler_child(request);
|
|
|
|
|
|
|
|
if (!handler) {
|
|
|
|
request->send_error(404);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
add_menu(request, MENUENTRY_NEWS);
|
2022-02-10 17:20:23 +01:00
|
|
|
request->push_path();
|
2022-01-09 17:05:04 +01:00
|
|
|
handler->handle_request_main(request);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MourneRoot::is_logged_in(Request *request) {
|
|
|
|
if (!request->session.is_valid()) {
|
2021-10-31 10:19:23 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-10-31 02:07:50 +01:00
|
|
|
Ref<User> u = request->reference_data["user"];
|
|
|
|
|
2021-10-31 02:11:47 +01:00
|
|
|
return u.is_valid();
|
2021-10-31 02:07:50 +01:00
|
|
|
}
|
|
|
|
|
2022-01-09 17:05:04 +01:00
|
|
|
void MourneRoot::index(Request *request) {
|
2021-10-31 02:07:50 +01:00
|
|
|
ENSURE_LOGIN(request);
|
|
|
|
|
2021-10-30 22:48:02 +02:00
|
|
|
add_menu(request, MENUENTRY_NEWS);
|
|
|
|
|
2021-10-30 23:33:37 +02:00
|
|
|
/*
|
|
|
|
<?php if (isset($hero)): ?>
|
|
|
|
<link rel="stylesheet" type="text/css" href="<?=base_url('css/hero.css'); ?>">
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
|
|
<?php if ($userlevel > 2): ?>
|
|
|
|
<link rel="stylesheet" type="text/css" href="<?=base_url('css/admin.css'); ?>">
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
|
|
<?php if ($page == 'mail'): ?>
|
|
|
|
<link rel="stylesheet" type="text/css" href="<?=base_url('css/mail.css'); ?>">
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
|
|
<?php if ($resources): ?>
|
|
|
|
<script src="<?=base_url('js/resource.js'); ?>"></script>
|
|
|
|
<?php endif; ?>
|
|
|
|
*/
|
|
|
|
|
2022-01-09 17:05:04 +01:00
|
|
|
// dynamic_cast<ListPage *>(instance)->index(request);
|
2021-10-30 22:48:02 +02:00
|
|
|
request->body += "test";
|
|
|
|
request->compile_and_send_body();
|
|
|
|
}
|
|
|
|
|
2022-01-09 17:05:04 +01:00
|
|
|
void MourneRoot::add_menu(Request *request, const MenuEntries index) {
|
2021-10-30 22:48:02 +02:00
|
|
|
request->head += menu_head;
|
2021-10-30 23:33:37 +02:00
|
|
|
|
|
|
|
HTMLBuilder b;
|
|
|
|
|
|
|
|
HTMLTag *t;
|
|
|
|
|
2021-11-14 22:55:25 +01:00
|
|
|
int userlevel = 0;
|
|
|
|
|
2022-01-09 17:05:04 +01:00
|
|
|
if (request->session.is_valid()) {
|
2021-11-14 22:55:25 +01:00
|
|
|
Ref<User> user = request->reference_data["user"];
|
|
|
|
|
|
|
|
if (user.is_valid()) {
|
|
|
|
userlevel = user->rank;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (userlevel > 4) {
|
|
|
|
request->head += admin_headers;
|
|
|
|
}
|
|
|
|
|
2021-10-31 02:11:47 +01:00
|
|
|
/*
|
2021-10-30 23:33:37 +02:00
|
|
|
<?php if ($weather): ?>
|
|
|
|
<div class="menu_base <?=$weather['css']; ?>">
|
|
|
|
<?php else: ?>
|
|
|
|
<div class="menu_base">
|
|
|
|
<?php endif; ?>
|
|
|
|
*/
|
|
|
|
|
|
|
|
b.div()->cls("menu_base");
|
|
|
|
{
|
|
|
|
b.div()->cls("left");
|
|
|
|
{
|
|
|
|
b.div()->cls("menu_news");
|
|
|
|
{
|
|
|
|
b.a()->href("/news/index");
|
|
|
|
b.w("News");
|
|
|
|
b.ca();
|
|
|
|
}
|
|
|
|
b.cdiv();
|
|
|
|
|
|
|
|
b.div()->cls("menu_mail");
|
|
|
|
{
|
|
|
|
b.a()->href("/mail/inbox");
|
|
|
|
b.w("Mails");
|
2022-01-09 17:05:04 +01:00
|
|
|
// if ($newmail) echo '!';
|
2021-10-30 23:33:37 +02:00
|
|
|
b.ca();
|
|
|
|
}
|
|
|
|
b.cdiv();
|
|
|
|
|
|
|
|
b.div()->cls("menu_hero");
|
|
|
|
{
|
|
|
|
b.a()->href("/hero/selected");
|
|
|
|
b.w("Hero");
|
|
|
|
b.ca();
|
|
|
|
}
|
|
|
|
b.cdiv();
|
|
|
|
|
|
|
|
b.div()->cls("menu_village");
|
|
|
|
{
|
|
|
|
b.a()->href("/village/selected");
|
2022-01-09 17:05:04 +01:00
|
|
|
b.w("Village"); // villagename
|
2021-10-30 23:33:37 +02:00
|
|
|
b.ca();
|
|
|
|
}
|
|
|
|
b.cdiv();
|
|
|
|
|
|
|
|
b.div()->cls("menu_sel_village");
|
|
|
|
{
|
|
|
|
b.a()->href("/village/select");
|
|
|
|
b.w("v");
|
|
|
|
b.ca();
|
|
|
|
}
|
|
|
|
b.cdiv();
|
|
|
|
|
|
|
|
/*
|
|
|
|
<?php if ($alliancename): ?>
|
|
|
|
<div class="menu_alliance">
|
|
|
|
<a href="<?=site_url($menu_alliance); ?>">[<?=$alliancename; ?>]</a>
|
|
|
|
</div>
|
|
|
|
<?php endif; ?>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
<?php if ($weather): ?>
|
|
|
|
<div class="weather">
|
|
|
|
<abbr title="<?=$weather['description']; ?>"><?=$weather['name']; ?></abbr>
|
|
|
|
</div>
|
|
|
|
<?php endif; ?>
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
b.cdiv();
|
|
|
|
|
|
|
|
b.div()->cls("right");
|
|
|
|
{
|
2021-11-14 22:55:25 +01:00
|
|
|
if (userlevel > 4) {
|
|
|
|
b.div()->cls("menu_gm");
|
|
|
|
{
|
|
|
|
b.a()->href("/gm")->f()->w("GM")->ca();
|
|
|
|
}
|
|
|
|
b.cdiv();
|
|
|
|
}
|
2021-10-30 23:33:37 +02:00
|
|
|
|
2021-11-14 22:55:25 +01:00
|
|
|
if (userlevel > 5) {
|
|
|
|
b.div()->cls("menu_admin");
|
|
|
|
{
|
|
|
|
b.a()->href("/admin")->f()->w("Admin")->ca();
|
|
|
|
}
|
|
|
|
b.cdiv();
|
|
|
|
}
|
2021-10-30 23:33:37 +02:00
|
|
|
|
|
|
|
b.div()->cls("menu_alliance_menu");
|
|
|
|
{
|
|
|
|
b.a()->href("/alliance/alliance_menu");
|
|
|
|
b.w("Alliances");
|
|
|
|
b.ca();
|
|
|
|
}
|
|
|
|
b.cdiv();
|
|
|
|
|
|
|
|
b.div()->cls("menu_forum");
|
|
|
|
{
|
|
|
|
b.a()->href("/forum/index");
|
|
|
|
b.w("Forum");
|
|
|
|
b.ca();
|
|
|
|
}
|
|
|
|
b.cdiv();
|
|
|
|
|
|
|
|
b.div()->cls("menu_settings");
|
|
|
|
{
|
|
|
|
b.a()->href("/user/settings");
|
|
|
|
b.w("Settings");
|
|
|
|
b.ca();
|
|
|
|
}
|
|
|
|
b.cdiv();
|
|
|
|
|
|
|
|
b.div()->cls("menu_logout");
|
|
|
|
{
|
|
|
|
b.a()->href("/user/logout");
|
|
|
|
b.w("Logout");
|
|
|
|
b.ca();
|
|
|
|
}
|
|
|
|
b.cdiv();
|
|
|
|
}
|
|
|
|
b.cdiv();
|
|
|
|
|
|
|
|
b.div()->cls("nofloat");
|
|
|
|
b.cdiv();
|
|
|
|
}
|
2021-10-31 02:11:47 +01:00
|
|
|
|
2021-10-30 23:33:37 +02:00
|
|
|
b.cdiv();
|
|
|
|
b.div()->cls("main");
|
|
|
|
b.write_tag();
|
|
|
|
|
|
|
|
request->body += b.result;
|
|
|
|
|
2021-10-30 22:48:02 +02:00
|
|
|
request->footer = footer;
|
|
|
|
}
|
|
|
|
|
2022-01-09 17:05:04 +01:00
|
|
|
void MourneRoot::setup_middleware() {
|
|
|
|
_middlewares.push_back(Ref<SessionSetupMiddleware>(new SessionSetupMiddleware()));
|
|
|
|
_middlewares.push_back(Ref<UserSessionSetupMiddleware>(new UserSessionSetupMiddleware()));
|
2021-10-30 22:48:02 +02:00
|
|
|
}
|
|
|
|
|
2022-02-05 23:02:06 +01:00
|
|
|
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();
|
2021-11-14 13:59:02 +01:00
|
|
|
}
|
2022-02-05 23:02:06 +01:00
|
|
|
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();
|
2021-10-30 22:48:02 +02:00
|
|
|
}
|
|
|
|
|
2022-01-09 17:05:04 +01:00
|
|
|
void MourneRoot::compile_menu() {
|
2021-10-30 22:48:02 +02:00
|
|
|
HTMLBuilder bh;
|
|
|
|
|
|
|
|
bh.meta()->charset_utf_8();
|
2021-10-30 23:33:37 +02:00
|
|
|
bh.meta()->name("description")->content("RPG browsergame");
|
|
|
|
bh.meta()->name("keywords")->content("RPG,browsergame,Mourne,game,play");
|
|
|
|
bh.title();
|
|
|
|
bh.w("Mourne");
|
|
|
|
bh.ctitle();
|
|
|
|
|
|
|
|
bh.link()->rel_stylesheet()->href("/css/base.css");
|
|
|
|
bh.link()->rel_stylesheet()->href("/css/menu.css");
|
2021-10-30 22:48:02 +02:00
|
|
|
bh.write_tag();
|
|
|
|
|
|
|
|
menu_head = bh.result;
|
|
|
|
|
2021-11-14 22:55:25 +01:00
|
|
|
bh.result = "";
|
|
|
|
bh.link()->rel("stylesheet")->type("text/css")->href("/css/admin.css")->f()->f();
|
|
|
|
|
|
|
|
admin_headers = bh.result;
|
|
|
|
|
2021-10-30 22:48:02 +02:00
|
|
|
HTMLBuilder bf;
|
|
|
|
|
|
|
|
bf.cdiv();
|
|
|
|
bf.footer();
|
|
|
|
bf.cfooter();
|
|
|
|
|
|
|
|
footer = bf.result;
|
|
|
|
}
|
|
|
|
|
2022-01-09 17:05:04 +01:00
|
|
|
MourneRoot::MourneRoot() :
|
|
|
|
WebRoot() {
|
2021-10-30 22:48:02 +02:00
|
|
|
|
2021-11-14 14:19:13 +01:00
|
|
|
BuildingInitializer::allocate_all();
|
2021-11-14 13:59:02 +01:00
|
|
|
VillageInitializer::allocate_all();
|
2021-12-18 10:56:07 +01:00
|
|
|
AssignmentInitializer::allocate_all();
|
2021-12-18 11:23:59 +01:00
|
|
|
WeatherInitializer::allocate_all();
|
2021-11-14 13:59:02 +01:00
|
|
|
|
2021-11-14 21:37:04 +01:00
|
|
|
_admin_panel = new AdminPanel();
|
2022-01-09 17:05:04 +01:00
|
|
|
_admin_panel->set_uri_segment("admin");
|
2021-11-14 21:37:04 +01:00
|
|
|
_admin_panel->register_admin_controller("buildings", BuildingController::get_singleton());
|
2021-12-18 11:19:29 +01:00
|
|
|
_admin_panel->register_admin_controller("assignments", AssignmentController::get_singleton());
|
2021-12-18 11:23:59 +01:00
|
|
|
_admin_panel->register_admin_controller("weather", WeatherController::get_singleton());
|
2021-11-14 22:12:32 +01:00
|
|
|
|
2022-01-09 17:05:04 +01:00
|
|
|
_user_controller = new MourneUserController();
|
|
|
|
_user_controller->set_uri_segment("user");
|
|
|
|
// user_manager->set_path("./users/");
|
|
|
|
add_child(_user_controller);
|
|
|
|
|
|
|
|
add_child(_admin_panel);
|
|
|
|
|
2021-11-14 22:12:32 +01:00
|
|
|
HTMLBuilder b;
|
|
|
|
|
|
|
|
b.link()->rel("stylesheet")->type("text/css")->href("/css/base.css")->f()->f();
|
|
|
|
b.link()->rel("stylesheet")->type("text/css")->href("/css/admin.css")->f()->f();
|
|
|
|
|
|
|
|
_admin_panel->set_default_header(b.result);
|
2021-11-14 21:37:04 +01:00
|
|
|
|
2021-11-14 22:18:20 +01:00
|
|
|
b.result = "";
|
|
|
|
b.div()->cls("back")->f()->a()->href("/")->f()->w("<--- Back")->ca()->cdiv();
|
|
|
|
b.br();
|
|
|
|
|
2021-11-14 22:25:53 +01:00
|
|
|
_admin_panel->set_default_main_body_top(b.result);
|
2021-11-14 22:18:20 +01:00
|
|
|
|
2021-10-30 22:48:02 +02:00
|
|
|
compile_menu();
|
|
|
|
}
|
|
|
|
|
2022-01-09 17:05:04 +01:00
|
|
|
MourneRoot::~MourneRoot() {
|
2021-11-14 13:59:02 +01:00
|
|
|
VillageInitializer::free_all();
|
2021-11-14 14:19:13 +01:00
|
|
|
BuildingInitializer::free_all();
|
2021-12-18 10:56:07 +01:00
|
|
|
AssignmentInitializer::free_all();
|
2021-12-18 11:23:59 +01:00
|
|
|
WeatherInitializer::free_all();
|
2021-10-30 22:48:02 +02:00
|
|
|
}
|
|
|
|
|
2022-01-09 17:05:04 +01:00
|
|
|
String MourneRoot::menu_head = "";
|
|
|
|
String MourneRoot::admin_headers = "";
|
|
|
|
String MourneRoot::footer = "";
|