2021-10-30 22:48:02 +02:00
|
|
|
#include "mourne_application.h"
|
|
|
|
|
|
|
|
#include "core/http/request.h"
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include "core/file_cache.h"
|
|
|
|
|
|
|
|
#include "core/http/handler_instance.h"
|
|
|
|
|
|
|
|
#include "core/database/database_manager.h"
|
|
|
|
|
|
|
|
#include "core/html/html_builder.h"
|
|
|
|
#include "core/http/http_session.h"
|
|
|
|
#include "core/http/session_manager.h"
|
|
|
|
|
|
|
|
#include "modules/users/user.h"
|
|
|
|
#include "modules/users/user_controller.h"
|
2021-11-14 21:37:04 +01:00
|
|
|
#include "modules/admin_panel/admin_panel.h"
|
2021-10-30 22:48:02 +02:00
|
|
|
|
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-10-31 02:11:47 +01:00
|
|
|
bool MourneApplication::is_logged_in(Request *request) {
|
2021-10-31 10:19:23 +01:00
|
|
|
if (!request->session) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-10-30 22:48:02 +02:00
|
|
|
void MourneApplication::index(Object *instance, 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; ?>
|
|
|
|
*/
|
|
|
|
|
2021-10-30 22:48:02 +02:00
|
|
|
//dynamic_cast<ListPage *>(instance)->index(request);
|
|
|
|
request->body += "test";
|
|
|
|
request->compile_and_send_body();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MourneApplication::session_middleware_func(Object *instance, Request *request) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void MourneApplication::add_menu(Request *request, const MenuEntries index) {
|
|
|
|
request->head += menu_head;
|
2021-10-30 23:33:37 +02:00
|
|
|
|
|
|
|
HTMLBuilder b;
|
|
|
|
|
|
|
|
HTMLTag *t;
|
|
|
|
|
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");
|
|
|
|
//if ($newmail) echo '!';
|
|
|
|
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");
|
|
|
|
b.w("Village"); //villagename
|
|
|
|
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");
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
<?php if ($userlevel > 4): ?>
|
|
|
|
<div class="menu_gm">
|
|
|
|
<a href="<?=site_url($link_gm); ?>">GM</a>
|
|
|
|
</div>
|
|
|
|
<?php endif; ?>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
<?php if ($userlevel > 5): //dev+?>
|
|
|
|
<div class="menu_admin">
|
|
|
|
<a href="<?=site_url($link_admin); ?>">Admin</a>
|
|
|
|
</div>
|
|
|
|
<?php endif; ?>
|
|
|
|
*/
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MourneApplication::village_page_func(Object *instance, Request *request) {
|
|
|
|
add_menu(request, MENUENTRY_VILLAGE);
|
|
|
|
|
|
|
|
//dynamic_cast<ListPage *>(instance)->index(request);
|
|
|
|
request->body += "test";
|
|
|
|
request->compile_and_send_body();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MourneApplication::user_page_func(Object *instance, Request *request) {
|
2021-10-31 02:11:47 +01:00
|
|
|
if (is_logged_in(request)) {
|
|
|
|
add_menu(request, MENUENTRY_SETTINGS);
|
|
|
|
}
|
2021-10-30 22:48:02 +02:00
|
|
|
|
|
|
|
UserController::get_singleton()->handle_request_default(request);
|
|
|
|
}
|
|
|
|
|
2021-11-14 21:37:04 +01:00
|
|
|
void MourneApplication::admin_page_func(Object *instance, Request *request) {
|
|
|
|
AdminPanel::get_singleton()->handle_request_main(request);
|
|
|
|
}
|
|
|
|
|
2021-10-30 22:48:02 +02:00
|
|
|
void MourneApplication::setup_routes() {
|
|
|
|
DWebApplication::setup_routes();
|
|
|
|
|
|
|
|
index_func = HandlerInstance(index);
|
|
|
|
main_route_map["village"] = HandlerInstance(village_page_func);
|
|
|
|
main_route_map["user"] = HandlerInstance(user_page_func);
|
2021-11-14 21:37:04 +01:00
|
|
|
main_route_map["admin"] = HandlerInstance(admin_page_func);
|
2021-10-30 22:48:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MourneApplication::setup_middleware() {
|
|
|
|
middlewares.push_back(HandlerInstance(::SessionManager::session_setup_middleware));
|
|
|
|
middlewares.push_back(HandlerInstance(::UserController::user_session_setup_middleware));
|
|
|
|
|
|
|
|
DWebApplication::setup_middleware();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MourneApplication::migrate() {
|
2021-11-14 14:19:13 +01:00
|
|
|
BuildingController::get_singleton()->migrate();
|
2021-11-14 13:59:02 +01:00
|
|
|
VillageController::get_singleton()->migrate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MourneApplication::add_default_data() {
|
2021-11-14 14:19:13 +01:00
|
|
|
BuildingController::get_singleton()->add_default_data();
|
2021-11-14 13:59:02 +01:00
|
|
|
VillageController::get_singleton()->add_default_data();
|
2021-10-30 22:48:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MourneApplication::compile_menu() {
|
|
|
|
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;
|
|
|
|
|
|
|
|
HTMLBuilder bf;
|
|
|
|
|
|
|
|
bf.cdiv();
|
|
|
|
bf.footer();
|
|
|
|
bf.cfooter();
|
|
|
|
|
|
|
|
footer = bf.result;
|
|
|
|
}
|
|
|
|
|
|
|
|
MourneApplication::MourneApplication() :
|
|
|
|
DWebApplication() {
|
|
|
|
|
2021-11-14 14:19:13 +01:00
|
|
|
BuildingInitializer::allocate_all();
|
2021-11-14 13:59:02 +01:00
|
|
|
VillageInitializer::allocate_all();
|
|
|
|
|
2021-11-14 21:37:04 +01:00
|
|
|
_admin_panel = new AdminPanel();
|
|
|
|
_admin_panel->register_admin_controller("buildings", BuildingController::get_singleton());
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
MourneApplication::~MourneApplication() {
|
2021-11-14 21:37:04 +01:00
|
|
|
delete _admin_panel;
|
2021-11-14 13:59:02 +01:00
|
|
|
|
|
|
|
VillageInitializer::free_all();
|
2021-11-14 14:19:13 +01:00
|
|
|
BuildingInitializer::free_all();
|
2021-10-30 22:48:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string MourneApplication::menu_head = "";
|
|
|
|
std::string MourneApplication::footer = "";
|