Ran a code formatter on most of the old php to fix indents in vscode.

This commit is contained in:
Relintai 2021-11-14 11:02:22 +01:00
parent 8cd215e0f1
commit aa2664c200
42 changed files with 8688 additions and 9167 deletions

File diff suppressed because it is too large Load Diff

View File

@ -2,21 +2,20 @@
class Alliance extends MO_Controller
{
function __construct()
{
parent::__construct();
}
public function __construct()
{
parent::__construct();
}
function index()
{
}
public function index()
{
}
function alliance_menu()
{
$this->headers('alliance');
$this->footer();
}
public function alliance_menu()
{
$this->headers('alliance');
$this->footer();
}
}
//nowhitesp
//nowhitesp

File diff suppressed because it is too large Load Diff

View File

@ -2,77 +2,70 @@
class Changelog extends MO_Controller
{
function __construct()
{
parent::__construct();
}
function show()
{
$this->load->model('changelog_model');
$data['versions'] = $this->changelog_model->get_versions();
$data['commits'] = $this->changelog_model->get_commits();
$data['userlevel'] = $this->userlevel;
$data['required_userlevel'] = 4;
$this->headers();
$this->load->view('changelog/changelog', $data);
$this->footer();
}
function add_new_version()
{
if (!$this->userlevel > 4)
show404();
$this->load->library('form_validation');
$this->form_validation->set_rules('text', 'Text', 'required');
if (!$this->form_validation->run())
public function __construct()
{
$this->load->view('changelog/new_version');
parent::__construct();
}
else
public function show()
{
$this->load->model('changelog_model');
$this->load->model('changelog_model');
$text = $this->input->post('text');
$this->changelog_model->new_version($text);
$data['versions'] = $this->changelog_model->get_versions();
$data['commits'] = $this->changelog_model->get_commits();
$data['userlevel'] = $this->userlevel;
$data['required_userlevel'] = 4;
$this->load->helper('url');
redirect('changelog/show');
$this->headers();
$this->load->view('changelog/changelog', $data);
$this->footer();
}
}
function add_new_commit()
{
if (!$this->userlevel > 4)
show404();
$this->load->library('form_validation');
$this->form_validation->set_rules('text', 'Text', 'required');
if (!$this->form_validation->run())
{
$this->load->view('changelog/new_commit');
}
else
public function add_new_version()
{
$this->load->model('changelog_model');
if (!$this->userlevel > 4) {
show404();
}
$text = $this->input->post('text');
$this->changelog_model->new_commit($text);
$this->load->library('form_validation');
$this->load->helper('url');
redirect('changelog/show');
$this->form_validation->set_rules('text', 'Text', 'required');
if (!$this->form_validation->run()) {
$this->load->view('changelog/new_version');
} else {
$this->load->model('changelog_model');
$text = $this->input->post('text');
$this->changelog_model->new_version($text);
$this->load->helper('url');
redirect('changelog/show');
}
}
}
public function add_new_commit()
{
if (!$this->userlevel > 4) {
show404();
}
$this->load->library('form_validation');
$this->form_validation->set_rules('text', 'Text', 'required');
if (!$this->form_validation->run()) {
$this->load->view('changelog/new_commit');
} else {
$this->load->model('changelog_model');
$text = $this->input->post('text');
$this->changelog_model->new_commit($text);
$this->load->helper('url');
redirect('changelog/show');
}
}
}
//nowhitesp

View File

@ -1,23 +1,22 @@
<?php
class Cron extends CI_Controller
{
//no session stuff needed for this class, so it extends from CI_Controller.
//no session stuff needed for this class, so it extends from CI_Controller.
function __construct()
{
parent::__construct();
}
public function __construct()
{
parent::__construct();
}
function aiattack()
{
//check for useragent and stuff like that
public function aiattack()
{
//check for useragent and stuff like that
$this->load->model('ai_model');
$this->load->model('ai_model');
$a = $this->ai_model->attack();
echo $a;
}
$a = $this->ai_model->attack();
echo $a;
}
}
//nowhitesp
//nowhitesp

View File

@ -2,19 +2,18 @@
class Forum extends MO_Controller
{
function __construct()
{
parent::__construct();
}
public function __construct()
{
parent::__construct();
}
function index()
{
$this->headers('forum');
public function index()
{
$this->headers('forum');
$this->load->view('forum/notimpl');
$this->footer();
}
$this->load->view('forum/notimpl');
$this->footer();
}
}
//nowhitesp
//nowhitesp

View File

@ -2,16 +2,16 @@
class Gm extends MO_Controller
{
function __construct()
{
parent::__construct();
}
public function __construct()
{
parent::__construct();
}
function gm_panel()
{
$this->headers('gm');
public function gm_panel()
{
$this->headers('gm');
$this->footer();
}
$this->footer();
}
}
//nowhitesp
//nowhitesp

View File

@ -2,212 +2,192 @@
class Hero extends MO_Controller
{
function __construct()
{
parent::__construct('hero');
}
function index()
{
$this->load->helper('url');
redirect('hero/selected');
}
function selected($page = 'stats', $d1 = FALSE, $d2 = FALSE, $d3 = FALSE, $d4 = FALSE)
{
$this->headers('hero');
if ($page != 'stats' && $page != 'inventory' && $page != 'talents' && $page != 'spells' &&
$page != 'actionbars')
public function __construct()
{
$page = 'stats';
parent::__construct('hero');
}
$this->load->view('hero/hero_menu');
public function index()
{
$this->load->helper('url');
redirect('hero/selected');
}
public function selected($page = 'stats', $d1 = false, $d2 = false, $d3 = false, $d4 = false)
{
$this->headers('hero');
if ($page != 'stats' && $page != 'inventory' && $page != 'talents' && $page != 'spells' &&
$page != 'actionbars') {
$page = 'stats';
}
$this->load->view('hero/hero_menu');
if ($page == 'stats')
{
$data['hero'] = $this->hero;
if ($page == 'stats') {
$data['hero'] = $this->hero;
$data['hpp'] = floor(($this->hero['health'] / $this->hero['max_health']) * 100);
$data['mpp'] = floor(($this->hero['mana'] / $this->hero['max_mana']) * 100);
$data['exp'] = floor(($this->hero['experience'] /1000) * 100);
$data['hpp'] = floor(($this->hero['health'] / $this->hero['max_health']) * 100);
$data['mpp'] = floor(($this->hero['mana'] / $this->hero['max_mana']) * 100);
$data['exp'] = floor(($this->hero['experience'] /1000) * 100);
//STUB!
$data['experience'] = 10000;
//STUB!
$data['experience'] = 10000;
$this->load->view('hero/stats', $data);
}
elseif ($page == 'inventory')
{
$this->load->model('item_model');
$this->load->view('hero/stats', $data);
} elseif ($page == 'inventory') {
$this->load->model('item_model');
if ($d1 !== FALSE && $d2 !== FALSE && $d3 !== FALSE && $d4 !== FALSE)
{
$this->item_model->set_hero($this->hero);
if ($d1 !== false && $d2 !== false && $d3 !== false && $d4 !== false) {
$this->item_model->set_hero($this->hero);
$res['message'] = $this->item_model->swap($d1, $d2, $d3, $d4);
$res['message'] = $this->item_model->swap($d1, $d2, $d3, $d4);
if ($res['message'] === TRUE)
$this->hero = $this->item_model->get_hero();
if ($res['message'] === true) {
$this->hero = $this->item_model->get_hero();
}
$d1 = FALSE;
$d2 = FALSE;
//we doesn't care about d3,d4 that isn't used in views
}
$d1 = false;
$d2 = false;
//we doesn't care about d3,d4 that isn't used in views
}
$data = $this->item_model->get_inventory($this->hero['id']);
$data = $this->item_model->get_inventory($this->hero['id']);
$data['hero'] = $this->hero;
$data['hero'] = $this->hero;
$data['d1'] = $d1;
$data['d2'] = $d2;
$data['d1'] = $d1;
$data['d2'] = $d2;
$res['inventory'] = $this->load->view('hero/inventory', $data, TRUE);
$res['equipment'] = $this->load->view('hero/character', $data, TRUE);
$res['inventory'] = $this->load->view('hero/inventory', $data, true);
$res['equipment'] = $this->load->view('hero/character', $data, true);
$this->load->view('hero/inventory_view', $res);
}
elseif ($page == 'talents')
{
}
elseif ($page == 'spells')
{
}
elseif ($page == 'actionbars')
{
$this->load->view('hero/inventory_view', $res);
} elseif ($page == 'talents') {
} elseif ($page == 'spells') {
} elseif ($page == 'actionbars') {
}
$this->footer();
}
$this->footer();
}
function create()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('name', 'Name', 'required|alpha|callback_chhn');
$this->form_validation->set_rules('gender', 'Gender', 'required|greater_than[0]|less_than[3]|integer');
//less than!
$this->form_validation->set_rules('class', 'Class', 'required|integer|greater_than[0]|less_than[10]');
if (!$this->form_validation->run())
public function create()
{
$this->headers('hero', 1);
$this->load->library('form_validation');
$this->form_validation->set_rules('name', 'Name', 'required|alpha|callback_chhn');
$this->form_validation->set_rules('gender', 'Gender', 'required|greater_than[0]|less_than[3]|integer');
//less than!
$this->form_validation->set_rules('class', 'Class', 'required|integer|greater_than[0]|less_than[10]');
if (!$this->form_validation->run()) {
$this->headers('hero', 1);
$this->load->view('hero/create');
$this->load->view('hero/create');
$this->footer();
}
else
{
$this->load->model('hero_model');
$this->footer();
} else {
$this->load->model('hero_model');
$data['name'] = $this->input->post('name');
$data['gender'] = $this->input->post('gender');
$data['class'] = $this->input->post('class');
$data['name'] = $this->input->post('name');
$data['gender'] = $this->input->post('gender');
$data['class'] = $this->input->post('class');
$this->hero_model->create($data, $this->userid);
$this->hero_model->create($data, $this->userid);
$this->load->helper('url');
redirect('hero/selected');
$this->load->helper('url');
redirect('hero/selected');
}
}
}
function select()
{
$this->load->model('hero_model');
$this->load->library('form_validation');
$this->form_validation->set_rules('heroid', 'Heroid', 'required');
if (!$this->form_validation->run())
public function select()
{
$this->headers('hero');
$this->load->model('hero_model');
$this->load->library('form_validation');
$data['heroes'] = $this->hero_model->get_heroes($this->userid);
$this->form_validation->set_rules('heroid', 'Heroid', 'required');
$this->load->view('hero/select', $data);
if (!$this->form_validation->run()) {
$this->headers('hero');
$this->footer();
$data['heroes'] = $this->hero_model->get_heroes($this->userid);
$this->load->view('hero/select', $data);
$this->footer();
} else {
$heroid = $this->input->post('heroid');
$this->hero_model->select_hero($heroid, $this->userid);
$this->load->helper('url');
redirect('hero/selected');
}
}
else
public function delete($id = false)
{
$heroid = $this->input->post('heroid');
$this->load->helper('url');
$this->hero_model->select_hero($heroid, $this->userid);
if (!$id || !is_numeric($id)) {
redirect('hero/select');
}
$this->load->helper('url');
redirect('hero/selected');
$this->load->model('hero_model');
$this->load->library('form_validation');
$this->form_validation->set_rules('confirm', 'Confirm', 'required|callback_delete_check');
if (!$this->form_validation->run()) {
$data['id'] = $id;
$data['hero'] = $this->hero_model->get_hero($id, $this->userid);
if (!$data['hero']) {
redirect('hero/select');
}
$this->headers('hero');
$this->load->view('hero/delete_confirm', $data);
$this->footer();
} else {
$this->hero_model->delete_hero($id, $this->userid);
redirect('hero/select');
}
}
}
function delete($id = FALSE)
{
$this->load->helper('url');
if (!$id || !is_numeric($id))
redirect('hero/select');
$this->load->model('hero_model');
$this->load->library('form_validation');
$this->form_validation->set_rules('confirm', 'Confirm', 'required|callback_delete_check');
if (!$this->form_validation->run())
public function addstat()
{
$data['id'] = $id;
$data['hero'] = $this->hero_model->get_hero($id, $this->userid);
if (!$data['hero'])
redirect('hero/select');
$this->headers('hero');
$this->load->view('hero/delete_confirm', $data);
$this->footer();
}
else
{
$this->hero_model->delete_hero($id, $this->userid);
redirect('hero/select');
}
}
function addstat()
{
//hero's stat view calls this with a form the hidden field's name is attrid
//hero's stat view calls this with a form the hidden field's name is attrid
//1 agi, 2 str, 3 stam, 4 int, 5 spirit
}
function chhn($name)
{
$this->load->model('hero_model');
$a = $this->hero_model->hero_name_is_unique($name);
if (!$a)
{
$this->form_validation->set_message('chhn', 'Name already taken.');
return FALSE;
}
else
public function chhn($name)
{
return TRUE;
$this->load->model('hero_model');
$a = $this->hero_model->hero_name_is_unique($name);
if (!$a) {
$this->form_validation->set_message('chhn', 'Name already taken.');
return false;
} else {
return true;
}
}
}
function delete_check($chk)
{
if ($chk == "DELETE")
return TRUE;
public function delete_check($chk)
{
if ($chk == "DELETE") {
return true;
}
$this->form_validation->set_message('delete_check', 'You have to spell DELETE, exactly, and uppercase.');
return FALSE;
}
$this->form_validation->set_message('delete_check', 'You have to spell DELETE, exactly, and uppercase.');
return false;
}
}
//nowhitesp
//nowhitesp

View File

@ -2,163 +2,144 @@
class Mail extends MO_Controller
{
function __construct()
{
parent::__construct();
}
function index()
{
$this->load->helper('url');
redirect('mail/inbox');
}
function inbox()
{
$this->headers('mail');
$this->load->model('mail_model');
$data['mails'] = $this->mail_model->get_inbox($this->userid, $this->new_mail);
$this->load->view('mail/inbox', $data);
$this->footer();
}
function compose($id = 0)
{
$this->headers('mail');
$this->load->model('mail_model');
$this->load->library('form_validation');
$d['draft'] = FALSE;
if ($id && is_numeric($id))
public function __construct()
{
$d['draft'] = $this->mail_model->get_draft($id, $this->userid);
parent::__construct();
}
$this->form_validation->set_rules('name', 'Username', 'required');
$this->form_validation->set_rules('subject', 'Subject', 'required');
$this->form_validation->set_rules('message', 'Message', 'required');
if (!$this->form_validation->run())
public function index()
{
$this->load->view('mail/new', $d);
}
else
{
$send = $this->input->post('send');
$draft = $this->input->post('draft');
$data['name'] = $this->input->post('name');
$data['subject'] = $this->input->post('subject');
$data['message'] = $this->input->post('message');
if ($send)
{
$this->mail_model->send_message($data, $this->userid);
}
else
{
$this->mail_model->save_draft($data, $this->userid);
}
$this->load->helper('url');
redirect('mail/inbox');
}
$this->footer();
}
function del_draft($id = 0)
{
if ($id && is_numeric($id))
public function inbox()
{
$this->load->model("mail_model");
$this->mail_model->delete_draft($id, $this->userid);
$this->headers('mail');
$this->load->model('mail_model');
$data['mails'] = $this->mail_model->get_inbox($this->userid, $this->new_mail);
$this->load->view('mail/inbox', $data);
$this->footer();
}
$this->load->helper('url');
redirect('mail/drafts');
}
function drafts()
{
$this->load->model('mail_model');
$this->headers('mail');
$data['mails'] = $this->mail_model->get_drafts($this->userid);
$this->load->view('mail/drafts', $data);
$this->footer();
}
function read($id = 0)
{
if (!$id || !is_numeric($id))
public function compose($id = 0)
{
$this->load->helper('url');
redirect('mail/inbox');
$this->headers('mail');
$this->load->model('mail_model');
$this->load->library('form_validation');
$d['draft'] = false;
if ($id && is_numeric($id)) {
$d['draft'] = $this->mail_model->get_draft($id, $this->userid);
}
$this->form_validation->set_rules('name', 'Username', 'required');
$this->form_validation->set_rules('subject', 'Subject', 'required');
$this->form_validation->set_rules('message', 'Message', 'required');
if (!$this->form_validation->run()) {
$this->load->view('mail/new', $d);
} else {
$send = $this->input->post('send');
$draft = $this->input->post('draft');
$data['name'] = $this->input->post('name');
$data['subject'] = $this->input->post('subject');
$data['message'] = $this->input->post('message');
if ($send) {
$this->mail_model->send_message($data, $this->userid);
} else {
$this->mail_model->save_draft($data, $this->userid);
}
}
$this->footer();
}
$this->load->model('mail_model');
$this->headers('mail');
$data['mail'] = $this->mail_model->get_mail($id, $this->userid);
$this->load->view('mail/read', $data);
$this->footer();
}
function sent()
{
$this->headers('mail');
$this->load->model('mail_model');
$data['mails'] = $this->mail_model->get_all_sent($this->userid);
$this->load->view('mail/sent', $data);
$this->footer();
}
function sread($id = 0)
{
if (!$id || !is_numeric($id))
public function del_draft($id = 0)
{
$this->load->helper('url');
redirect('mail/inbox');
if ($id && is_numeric($id)) {
$this->load->model("mail_model");
$this->mail_model->delete_draft($id, $this->userid);
}
$this->load->helper('url');
redirect('mail/drafts');
}
$this->load->model('mail_model');
public function drafts()
{
$this->load->model('mail_model');
$this->headers('mail');
$this->headers('mail');
$data['mail'] = $this->mail_model->get_sent($id, $this->userid);
$data['mails'] = $this->mail_model->get_drafts($this->userid);
$this->load->view('mail/sread', $data);
$this->load->view('mail/drafts', $data);
$this->footer();
$this->footer();
}
}
public function read($id = 0)
{
if (!$id || !is_numeric($id)) {
$this->load->helper('url');
redirect('mail/inbox');
}
function friends()
{
$this->headers('mail');
$this->load->model('mail_model');
$this->footer();
}
$this->headers('mail');
$data['mail'] = $this->mail_model->get_mail($id, $this->userid);
$this->load->view('mail/read', $data);
$this->footer();
}
public function sent()
{
$this->headers('mail');
$this->load->model('mail_model');
$data['mails'] = $this->mail_model->get_all_sent($this->userid);
$this->load->view('mail/sent', $data);
$this->footer();
}
public function sread($id = 0)
{
if (!$id || !is_numeric($id)) {
$this->load->helper('url');
redirect('mail/inbox');
}
$this->load->model('mail_model');
$this->headers('mail');
$data['mail'] = $this->mail_model->get_sent($id, $this->userid);
$this->load->view('mail/sread', $data);
$this->footer();
}
public function friends()
{
$this->headers('mail');
$this->footer();
}
}
//nowhitesp

View File

@ -2,67 +2,60 @@
class News extends MO_Controller
{
public function index($page = 1)
{
if (!$this->check_login()) return;
$this->load->model('news_model');
$data['admin'] = FALSE;
if ($this->userlevel > 3)
public function index($page = 1)
{
$data['admin'] = TRUE;
if (!$this->check_login()) {
return;
}
$this->load->model('news_model');
$data['admin'] = false;
if ($this->userlevel > 3) {
$data['admin'] = true;
}
$data['news'] = $this->news_model->get_news($page);
$this->headers();
$this->load->view('news/news', $data);
$this->footer();
}
$data['news'] = $this->news_model->get_news($page);
$this->headers();
$this->load->view('news/news', $data);
$this->footer();
}
public function add()
{
if ($this->userlevel < 3) show_404();
$this->load->library('form_validation');
$this->form_validation->set_rules('text', 'Text', 'required');
if (!$this->form_validation->run())
public function add()
{
$this->load->helper(array('form', 'url'));
if ($this->userlevel < 3) {
show_404();
}
$this->headers();
$this->load->view('news/add');
$this->footer();
}
else
{
$this->load->model('news_model');
if ($this->news_model->add_news($this->input->post('text'), $this->username))
{
$this->load->view('news/add_success');
}
else
{
$this->load->view('db_error');
}
$this->load->library('form_validation');
$this->form_validation->set_rules('text', 'Text', 'required');
if (!$this->form_validation->run()) {
$this->load->helper(array('form', 'url'));
$this->headers();
$this->load->view('news/add');
$this->footer();
} else {
$this->load->model('news_model');
if ($this->news_model->add_news($this->input->post('text'), $this->username)) {
$this->load->view('news/add_success');
} else {
$this->load->view('db_error');
}
}
}
}
public function delete($nid)
{
if (!$this->userlevel < 3) show_404();
}
public function delete($nid)
{
if (!$this->userlevel < 3) {
show_404();
}
}
}
//nowhitesp

View File

@ -2,138 +2,137 @@
class User extends MO_Controller
{
public function __construct()
{
parent::__construct();
}
function __construct()
{
parent::__construct();
}
public function login()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
function login()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
//is_unique[users.username]
//is_unique[users.username]
//xss_validation
//xss_validation
//TODO figure rules out
$this->form_validation->set_rules('username', 'Username',
'required');
//TODO figure rules out
$this->form_validation->set_rules(
'username',
'Username',
'required'
);
//password callback -> $this->input->post('username'), after xss filter
$this->form_validation->set_rules('password', 'Password',
'required|callback_login_check');
//password callback -> $this->input->post('username'), after xss filter
$this->form_validation->set_rules(
'password',
'Password',
'required|callback_login_check'
);
if ($this->form_validation->run() == FALSE)
{
$this->load->view('login/login');
if ($this->form_validation->run() == false) {
$this->load->view('login/login');
} else {
$this->load->helper('url');
redirect('news/index');
//$this->load->view('login/success');
}
}
else
public function register()
{
$this->load->helper('url');
redirect('news/index');
//$this->load->view('login/success');
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
//is_unique[users.username]
//xss_clean
$this->form_validation->set_rules(
'username',
'Username',
'required|min_length[4]|max_length[32]|callback_register_username_check'
);
$this->form_validation->set_rules(
'password',
'Password',
'required|min_length[5]|matches[password_check]'
);
$this->form_validation->set_rules('password_check', 'Password check', 'required');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email|matches[email_check]');
$this->form_validation->set_rules('email_check', 'Email_check', 'required');
//$this->form_validation->set_rules('license', 'License', 'required');
if ($this->form_validation->run() == false) {
$this->load->view('register/register');
} else {
if ($this->register_write()) {
$this->load->view('register/success');
}
}
}
}
function register()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
//is_unique[users.username]
//xss_clean
$this->form_validation->set_rules('username', 'Username',
'required|min_length[4]|max_length[32]|callback_register_username_check');
$this->form_validation->set_rules('password', 'Password',
'required|min_length[5]|matches[password_check]');
$this->form_validation->set_rules('password_check', 'Password check', 'required');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email|matches[email_check]');
$this->form_validation->set_rules('email_check', 'Email_check', 'required');
//$this->form_validation->set_rules('license', 'License', 'required');
if ($this->form_validation->run() == FALSE)
public function logout()
{
$this->load->view('register/register');
}
else
{
if ($this->register_write())
{
$this->load->view('register/success');
}
}
}
$this->session->unset_userdata('userid');
function logout()
{
$this->session->unset_userdata('userid');
$this->load->helper('url');
redirect('user/login');
$this->load->helper('url');
redirect('user/login');
//TODO make it look cool
//TODO make it look cool
//$this->load->view('redirect_to_login');
}
function register_username_check($attr)
{
$this->load->model('user_model');
if ($this->user_model->reg_username_check($attr))
{
return TRUE;
}
else
public function register_username_check($attr)
{
$this->form_validation->set_message('register_username_check', 'Username already exists!');
return FALSE;
$this->load->model('user_model');
if ($this->user_model->reg_username_check($attr)) {
return true;
} else {
$this->form_validation->set_message('register_username_check', 'Username already exists!');
return false;
}
}
}
function register_write()
{
$data['username'] = $this->input->post('username');
$data['password'] = md5($this->input->post('password'));
$data['email'] = $this->input->post('email');
$this->load->model('user_model');
return $this->user_model->reg_write($data);
}
function login_check($attr)
{
$data['username'] = $this->input->post('username');
$data['password'] = md5($attr);
$this->load->model('user_model');
if ($this->user_model->login_check($data))
public function register_write()
{
$this->session->set_userdata('userid',
$this->user_model->get_userid($data['username']));
$data['username'] = $this->input->post('username');
$data['password'] = md5($this->input->post('password'));
$data['email'] = $this->input->post('email');
return TRUE;
$this->load->model('user_model');
return $this->user_model->reg_write($data);
}
else
{
return FALSE;
}
}
function settings()
{
$this->headers('settings');
public function login_check($attr)
{
$data['username'] = $this->input->post('username');
$data['password'] = md5($attr);
$this->load->model('user_model');
if ($this->user_model->login_check($data)) {
$this->session->set_userdata(
'userid',
$this->user_model->get_userid($data['username'])
);
return true;
} else {
return false;
}
}
public function settings()
{
$this->headers('settings');
$this->footer();
}
$this->footer();
}
}//login class
//nowhitesp
//nowhitesp

View File

@ -2,261 +2,246 @@
class Village extends MO_Controller
{
function __construct()
{
parent::__construct();
}
function index()
{
$this->load->helper('url');
redirect('village/selected');
}
//function for testing, this will be handled when registering, and with npcs
function create_village()
{
$this->load->model('village_model');
$this->village_model->create_village($this->userid, $this->username);
}
function selected()
{
$this->load->model('village_model');
$this->headers('village');
$build['buildings'] = $this->village_model->get_buildings($this->villageid);
$event['event'] = $this->_filter_events('next', 'all');
$this->load->view('village/next_event', $event);
$this->load->view('village/grid', $build);
$this->footer();
}
function map($x = FALSE, $y = FALSE)
{
$this->load->model('map_model');
$action = $this->input->post('action');
if ($action == 'xy')
public function __construct()
{
$px = $this->input->post('x');
$py = $this->input->post('y');
if (is_numeric($px) && is_numeric($py))
{
$x = $px;
$y = $py;
}
}
elseif ($action == 'name')
{
$name = $this->input->post('name');
$rep = array(';', "\"", "'", ',', '(', ')');
$name = str_replace($rep, ' ', $name);
if ($name)
{
$co = $this->map_model->get_village_by_name($name);
if ($co)
{
$x = $co['X'];
$y = $co['Y'];
}
}
parent::__construct();
}
$this->load->model('map_model');
if (!$x && !$y)
public function index()
{
$coords = $this->map_model->get_village_coords($this->villageid);
$x = $coords['X'];
$y = $coords['Y'];
}
else
{
if ($x < 7)
$x = 7;
if ($y < 7)
$y = 7;
if ($x > 235)
$x = 235;
if ($y > 235)
$y = 235;
$this->load->helper('url');
redirect('village/selected');
}
$data['x'] = $x;
$data['y'] = $y;
$data['map'] = $this->map_model->get_map($x, $y);
$this->headers('village');
$this->load->view('village/map', $data);
$this->footer();
}
function units()
{
$this->load->model('unit_model');
$data['units'] = $this->unit_model->get_village_units($this->villageid);
$this->headers('village');
$this->load->view('village/units', $data);
$this->footer();
}
function log($action = 'list', $id = 0)
{
if ($action != 'list' && $action != 'view' && $action != 'delete')
$action = 'list';
if (!is_numeric($id))
//function for testing, this will be handled when registering, and with npcs
public function create_village()
{
$action = 'list';
$id = 0;
$this->load->model('village_model');
$this->village_model->create_village($this->userid, $this->username);
}
$this->load->model('log_model');
if ($action == 'list')
public function selected()
{
$this->headers('village');
$this->load->model('village_model');
$data['logs'] = $this->log_model->get_combat_logs($this->villageid);
$this->load->view('village/log/list', $data);
$this->headers('village');
$this->footer();
$build['buildings'] = $this->village_model->get_buildings($this->villageid);
$event['event'] = $this->_filter_events('next', 'all');
$this->load->view('village/next_event', $event);
$this->load->view('village/grid', $build);
$this->footer();
}
if ($action == 'view')
public function map($x = false, $y = false)
{
$this->headers('village');
$this->load->model('map_model');
$action = $this->input->post('action');
$data['log'] = $this->log_model->get_combat_log($id, $this->villageid);
$this->load->view('village/log/combat', $data);
if ($action == 'xy') {
$px = $this->input->post('x');
$py = $this->input->post('y');
$this->footer();
if (is_numeric($px) && is_numeric($py)) {
$x = $px;
$y = $py;
}
} elseif ($action == 'name') {
$name = $this->input->post('name');
$rep = array(';', "\"", "'", ',', '(', ')');
$name = str_replace($rep, ' ', $name);
if ($name) {
$co = $this->map_model->get_village_by_name($name);
if ($co) {
$x = $co['X'];
$y = $co['Y'];
}
}
}
$this->load->model('map_model');
if (!$x && !$y) {
$coords = $this->map_model->get_village_coords($this->villageid);
$x = $coords['X'];
$y = $coords['Y'];
} else {
if ($x < 7) {
$x = 7;
}
if ($y < 7) {
$y = 7;
}
if ($x > 235) {
$x = 235;
}
if ($y > 235) {
$y = 235;
}
}
$data['x'] = $x;
$data['y'] = $y;
$data['map'] = $this->map_model->get_map($x, $y);
$this->headers('village');
$this->load->view('village/map', $data);
$this->footer();
}
if ($action == 'delete')
public function units()
{
$this->log_model->delete_combat_log($id, $this->villageid);
$this->load->model('unit_model');
$this->load->helper('url');
redirect('village/log');
}
}
$data['units'] = $this->unit_model->get_village_units($this->villageid);
function select()
{
$this->load->model('village_model');
$this->load->library('form_validation');
$this->headers('village');
$this->form_validation->set_rules('id', 'ID', 'is_natural|required');
$this->load->view('village/units', $data);
if (!$this->form_validation->run())
{
$this->headers('village');
$data['villages'] = $this->village_model->get_villages($this->userid);
$this->load->view('village/select', $data);
$this->footer();
}
else
{
$id = $this->input->post('id');
$this->village_model->select_village($id, $this->userid);
$this->load->helper('url');
redirect('village/selected');
}
}
function events()
{
$this->headers('village');
$data['event'] = $this->_filter_events('all', 'all');
$this->load->view('village/events', $data);
$this->footer();
}
function settings($id = 0)
{
$this->load->model('village_model');
if (!is_numeric($id) || !$id)
{
$this->load->heper('url');
redirect('village/selected');
$this->footer();
}
$village = $this->village_model->get_village($id);
if ($village['userid'] != $this->userid)
public function log($action = 'list', $id = 0)
{
$this->load->heper('url');
redirect('village/selected');
if ($action != 'list' && $action != 'view' && $action != 'delete') {
$action = 'list';
}
if (!is_numeric($id)) {
$action = 'list';
$id = 0;
}
$this->load->model('log_model');
if ($action == 'list') {
$this->headers('village');
$data['logs'] = $this->log_model->get_combat_logs($this->villageid);
$this->load->view('village/log/list', $data);
$this->footer();
}
if ($action == 'view') {
$this->headers('village');
$data['log'] = $this->log_model->get_combat_log($id, $this->villageid);
$this->load->view('village/log/combat', $data);
$this->footer();
}
if ($action == 'delete') {
$this->log_model->delete_combat_log($id, $this->villageid);
$this->load->helper('url');
redirect('village/log');
}
}
$this->load->library('form_validation');
$this->form_validation->set_rules('name', 'Name',
'required|alpha|is_unique[ai_villages.name]');
if (!$this->form_validation->run())
public function select()
{
$this->headers('village');
$this->load->model('village_model');
$this->load->library('form_validation');
$data['id'] = $id;
$data['village'] = $village;
$this->form_validation->set_rules('id', 'ID', 'is_natural|required');
$this->load->view('village/settings', $data);
$this->footer();
if (!$this->form_validation->run()) {
$this->headers('village');
$data['villages'] = $this->village_model->get_villages($this->userid);
$this->load->view('village/select', $data);
$this->footer();
} else {
$id = $this->input->post('id');
$this->village_model->select_village($id, $this->userid);
$this->load->helper('url');
redirect('village/selected');
}
}
else
public function events()
{
$data['id'] = $id;
$name = $this->input->post('name');
$data['ai'] = $this->input->post('ai');
$this->headers('village');
$data['name'] = ucfirst(strtolower($name));
$data['event'] = $this->_filter_events('all', 'all');
$this->village_model->apply_settings($data);
$this->load->view('village/events', $data);
$this->footer();
}
public function settings($id = 0)
{
$this->load->model('village_model');
if (!is_numeric($id) || !$id) {
$this->load->heper('url');
redirect('village/selected');
}
$village = $this->village_model->get_village($id);
if ($village['userid'] != $this->userid) {
$this->load->heper('url');
redirect('village/selected');
}
$this->load->library('form_validation');
$this->form_validation->set_rules(
'name',
'Name',
'required|alpha|is_unique[ai_villages.name]'
);
if (!$this->form_validation->run()) {
$this->headers('village');
$data['id'] = $id;
$data['village'] = $village;
$this->load->view('village/settings', $data);
$this->footer();
} else {
$data['id'] = $id;
$name = $this->input->post('name');
$data['ai'] = $this->input->post('ai');
$data['name'] = ucfirst(strtolower($name));
$this->village_model->apply_settings($data);
$this->load->helper('url');
redirect('village/select');
$this->load->helper('url');
redirect('village/select');
}
}
}
function event_update()
{
//TODO for ajax, but maybe it will be solved with APE
}
function list_all()
{
}
public function event_update()
{
//TODO for ajax, but maybe it will be solved with APE
}
public function list_all()
{
}
}
//nowhitesp
//nowhitesp

View File

@ -2,429 +2,384 @@
class MO_Controller extends CI_Controller
{
public $userid;
public $username;
public $language;
public $userlevel;
public $villageid;
public $village_name;
public $resources;
public $events;
public $building;
public $village_data;
public $weather;
public $userid;
public $username;
public $language;
public $userlevel;
public $villageid;
public $village_name;
public $resources;
public $events;
public $building;
public $village_data;
public $weather;
//hero stuff
public $hero;
//hero stuff
public $hero;
public $new_mail;
public $new_log;
public $new_mail;
public $new_log;
function __construct($page = 'village')
{
parent::__construct();
$this->weather = FALSE;
$this->resources = FALSE;
$this->hero = FALSE;
public function __construct($page = 'village')
{
parent::__construct();
$this->weather = false;
$this->resources = false;
$this->hero = false;
$this->_manage_session($page);
}
$this->_manage_session($page);
}
public function _manage_session($page)
{
$this->userid = 0;
public function _manage_session($page)
{
$this->userid = 0;
//this should be solved with db!
//this should be solved with db!
// if (!$this->session->userdata('language'))
// $this->session->set_userdata('language', 'english');
// $this->language = $this->session->userdata('language');
$this->language = 'english';
$this->language = 'english';
if ($this->session->userdata('userid'))
$this->userid = $this->session->userdata('userid');
if ($this->session->userdata('userid')) {
$this->userid = $this->session->userdata('userid');
}
$this->load->model('mo_common_model');
$this->load->model('mo_common_model');
if ($this->userid)
{
$data = $this->mo_common_model->get_userdata($this->userid);
if ($this->userid) {
$data = $this->mo_common_model->get_userdata($this->userid);
$this->userlevel = $data['userlevel'];
$this->username = $data['username'];
$this->new_mail = $data['new_mail'];
$this->userlevel = $data['userlevel'];
$this->username = $data['username'];
$this->new_mail = $data['new_mail'];
if ($page == 'village')
{
$mdata = $this->mo_common_model->get_village_data($this->userid);
if ($page == 'village') {
$mdata = $this->mo_common_model->get_village_data($this->userid);
$this->villageid = $mdata['id'];
$this->villagename = $mdata['name'];
$this->new_log = $mdata['new_log'];
$this->villageid = $mdata['id'];
$this->villagename = $mdata['name'];
$this->new_log = $mdata['new_log'];
$this->village_data = $mdata;
}
$this->village_data = $mdata;
}
if ($page == 'hero')
{
$this->hero = $this->mo_common_model->get_hero_data($this->userid);
}
}
}
public function check_login()
{
if ($this->userid == 0)
{
$this->load->helper('url');
redirect('user/login');
if ($page == 'hero') {
$this->hero = $this->mo_common_model->get_hero_data($this->userid);
}
}
}
return TRUE;
}
public function headers($page = 'village', $slotid = 0)
{
$data['username'] = $this->username;
$data['userid'] = $this->userid;
$data['userlevel'] = $this->userlevel;
$data['newmail'] = $this->new_mail;
$data['page'] = $page;
if ($page != 'hero')
public function check_login()
{
$data['villagename'] = $this->villagename;
$data['newlog'] = $this->new_log;
if ($this->userid == 0) {
$this->load->helper('url');
redirect('user/login');
}
if ($page == 'building' || $page == 'village' || $page == 'build' || $page == 'build_in_progress' ||
$page == 'mail')
{
$this->_update();
}
//this has to be done like this, since this function will redirect if nothing in the slot
if ($page == 'building')
$this->_get_slot_building($slotid);
if ($page != 'do')
{
$data['weather'] = $this->weather;
$data['resources'] = $this->_prep_res_js();
$this->load->view('parts/header', $data);
$this->load->view('menu', $data);
$this->load->view('parts/js_res', $data);
}
if ($page == 'building' || $page == 'village' || $page == 'build' || $page == 'build_in_progress' ||
$page == 'mail')
{
$res['res'] = $this->resources;
$this->load->view('village/resources', $res);
}
if ($page == 'mail')
{
$this->load->view('mail/menu');
}
if ($page == 'village')
{
$this->load->view('village/menu');
}
if ($page == 'building')
{
$data['building'] = $this->building;
$data['slotid'] = $slotid;
$this->load->view('building/header', $data);
$this->load->view('building/menu', $data);
}
if ($page == 'do')
{
$this->_update();
if ($slotid)
$this->_get_slot_building($slotid);
}
return true;
}
elseif ($page == 'hero')
public function headers($page = 'village', $slotid = 0)
{
if (!$this->hero && !$slotid)
{
$this->load->helper('url');
redirect('hero/create');
return;
}
$data['username'] = $this->username;
$data['userid'] = $this->userid;
$data['userlevel'] = $this->userlevel;
$data['newmail'] = $this->new_mail;
$data['page'] = $page;
$data['hero'] = $this->hero;
$data['weather'] = FALSE;
$data['resources'] = FALSE;
$this->load->view('parts/header', $data);
$this->load->view('menu', $data);
$this->load->view('hero/menu', $data);
if ($page != 'hero') {
$data['villagename'] = $this->villagename;
$data['newlog'] = $this->new_log;
if ($page == 'building' || $page == 'village' || $page == 'build' || $page == 'build_in_progress' ||
$page == 'mail') {
$this->_update();
}
//this has to be done like this, since this function will redirect if nothing in the slot
if ($page == 'building') {
$this->_get_slot_building($slotid);
}
if ($page != 'do') {
$data['weather'] = $this->weather;
$data['resources'] = $this->_prep_res_js();
$this->load->view('parts/header', $data);
$this->load->view('menu', $data);
$this->load->view('parts/js_res', $data);
}
if ($page == 'building' || $page == 'village' || $page == 'build' || $page == 'build_in_progress' ||
$page == 'mail') {
$res['res'] = $this->resources;
$this->load->view('village/resources', $res);
}
if ($page == 'mail') {
$this->load->view('mail/menu');
}
if ($page == 'village') {
$this->load->view('village/menu');
}
if ($page == 'building') {
$data['building'] = $this->building;
$data['slotid'] = $slotid;
$this->load->view('building/header', $data);
$this->load->view('building/menu', $data);
}
if ($page == 'do') {
$this->_update();
if ($slotid) {
$this->_get_slot_building($slotid);
}
}
} elseif ($page == 'hero') {
if (!$this->hero && !$slotid) {
$this->load->helper('url');
redirect('hero/create');
return;
}
$data['hero'] = $this->hero;
$data['weather'] = false;
$data['resources'] = false;
$this->load->view('parts/header', $data);
$this->load->view('menu', $data);
$this->load->view('hero/menu', $data);
}
}
}
public function _get_slot_building($slotid = 0)
{
if (!$slotid)
return;
public function _get_slot_building($slotid = 0)
{
if (!$slotid) {
return;
}
if ($this->building)
return;
if ($this->building) {
return;
}
$this->load->model('building_model');
$this->building = $this->building_model->get_slot_building($slotid, $this->villageid);
$this->load->model('building_model');
$this->building = $this->building_model->get_slot_building($slotid, $this->villageid);
//this is commented out, because get_slot_building cannot return FALSE lol
//this is commented out, because get_slot_building cannot return FALSE lol
// if (!$this->building)
// {
// $this->load->helper('url');
// redirect('village/selected');
//}
}
public function _get_resources()
{
if ($this->resources)
return;
$this->load->model('resource_model');
$this->resources = $this->resource_model->get_resources($this->villageid);
}
public function _update()
{
$this->load->model('event_model');
if ($this->resources || $this->events || $this->weather)
return;
//event model returns resources, and events, and weather
$data = $this->event_model->update($this->village_data, TRUE);
$this->resources = $data['resources'];
$this->events = $data['events'];
$this->weather = $data['weather'];
}
public function footer()
{
$this->load->view('parts/footer');
}
/*
filter events, based on type and filter, and order it ASC
type -> 'next', 'type', 'all'
if type == 'type' you have to provide an event type
filter -> 'all', 'slot'
if filter == 'slot' you have to provide slotid
next -> TRUE/FALSE
only return the next event, this is here, so every type can be asked to return the next one
this is primarily here, so when events like EVENT_BUILD needed, since there aren't going to be 2
*/
public function _filter_events($type, $filter, $slotid = 0, $ev_type = 0, $next = FALSE)
{
//means no events
if (!$this->events)
return FALSE;
$data = FALSE;
if ($type == 'all')
{
if ($filter == 'slot')
{
foreach ($this->events as $row)
{
if ($row['slotid'] == $slotid)
{
$data[] = $row;
}
}
}
else
{
$data = $this->events;
}
}
if ($type == 'type')
public function _get_resources()
{
if ($filter == 'all')
{
foreach ($this->events as $row)
{
if ($row['type'] == $ev_type)
{
$data[] = $row;
}
}
}
else
{
foreach ($this->events as $row)
{
if ($row['type'] == $ev_type && $row['slotid'] == $slotid)
{
$data[] = $row;
}
}
}
if ($this->resources) {
return;
}
$this->load->model('resource_model');
$this->resources = $this->resource_model->get_resources($this->villageid);
}
if ($type == 'next')
public function _update()
{
if ($filter == 'all')
{
$last_end = 99999999999;
$smallest = FALSE;
foreach ($this->events as $row)
{
if ($row['end'] < $last_end)
{
$last_end = $row['end'];
$smallest = $row;
}
}
$this->load->model('event_model');
return $smallest;
}
else
{
$last_end = 99999999999;
$smallest = FALSE;
foreach ($this->events as $row)
{
if ($row['end'] < $last_end && $row['slotid'] == $slotid)
{
$last_end = $row['end'];
$smallest = $row;
}
}
if ($this->resources || $this->events || $this->weather) {
return;
}
return $smallest;
}
//event model returns resources, and events, and weather
$data = $this->event_model->update($this->village_data, true);
$this->resources = $data['resources'];
$this->events = $data['events'];
$this->weather = $data['weather'];
}
//order it
if ($data)
public function footer()
{
$last_end = 99999999999;
$last['id'] = FALSE;
$smallest = FALSE;
for ($i = 0; $i < sizeof($data); $i++)
{
foreach ($data as $row)
{
//accounting for events ending at the same time
if ($row['end'] <= $last_end && $last['id'] != $row['id'])
{
$smallest = $row;
}
}
$ret[] = $smallest;
$last_end = $smallest['end'];
$last = $smallest;
}
if (!$next)
return $ret;
else
return $ret[0];
$this->load->view('parts/footer');
}
return FALSE;
}
/*
filter events, based on type and filter, and order it ASC
type -> 'next', 'type', 'all'
if type == 'type' you have to provide an event type
filter -> 'all', 'slot'
if filter == 'slot' you have to provide slotid
next -> TRUE/FALSE
only return the next event, this is here, so every type can be asked to return the next one
this is primarily here, so when events like EVENT_BUILD needed, since there aren't going to be 2
*/
function _prep_res_js()
{
if (!$this->resources)
return FALSE;
$res = $this->resources;
//determining which have the lowest rate
$a[] = $res['food'];
$a[] = $res['wood'];
$a[] = $res['stone'];
$a[] = $res['iron'];
$a[] = $res['mana'];
$last = $a[0];
$index = 0;
for ($i = 0; $i < 5; $i++)
public function _filter_events($type, $filter, $slotid = 0, $ev_type = 0, $next = false)
{
if ($a[$i] < $last)
{
$last = $a[$i];
$index = $i;
}
//means no events
if (!$this->events) {
return false;
}
$data = false;
if ($type == 'all') {
if ($filter == 'slot') {
foreach ($this->events as $row) {
if ($row['slotid'] == $slotid) {
$data[] = $row;
}
}
} else {
$data = $this->events;
}
}
if ($type == 'type') {
if ($filter == 'all') {
foreach ($this->events as $row) {
if ($row['type'] == $ev_type) {
$data[] = $row;
}
}
} else {
foreach ($this->events as $row) {
if ($row['type'] == $ev_type && $row['slotid'] == $slotid) {
$data[] = $row;
}
}
}
}
if ($type == 'next') {
if ($filter == 'all') {
$last_end = 99999999999;
$smallest = false;
foreach ($this->events as $row) {
if ($row['end'] < $last_end) {
$last_end = $row['end'];
$smallest = $row;
}
}
return $smallest;
} else {
$last_end = 99999999999;
$smallest = false;
foreach ($this->events as $row) {
if ($row['end'] < $last_end && $row['slotid'] == $slotid) {
$last_end = $row['end'];
$smallest = $row;
}
}
return $smallest;
}
}
//order it
if ($data) {
$last_end = 99999999999;
$last['id'] = false;
$smallest = false;
for ($i = 0; $i < sizeof($data); $i++) {
foreach ($data as $row) {
//accounting for events ending at the same time
if ($row['end'] <= $last_end && $last['id'] != $row['id']) {
$smallest = $row;
}
}
$ret[] = $smallest;
$last_end = $smallest['end'];
$last = $smallest;
}
if (!$next) {
return $ret;
} else {
return $ret[0];
}
}
return false;
}
//comberting back numerical index
switch ($index)
public function _prep_res_js()
{
if (!$this->resources) {
return false;
}
$res = $this->resources;
//determining which have the lowest rate
$a[] = $res['food'];
$a[] = $res['wood'];
$a[] = $res['stone'];
$a[] = $res['iron'];
$a[] = $res['mana'];
$last = $a[0];
$index = 0;
for ($i = 0; $i < 5; $i++) {
if ($a[$i] < $last) {
$last = $a[$i];
$index = $i;
}
}
//comberting back numerical index
switch ($index) {
case 0:
$s_index = 'food';
break;
$s_index = 'food';
break;
case 1:
$s_index = 'wood';
break;
$s_index = 'wood';
break;
case 2:
$s_index = 'stone';
break;
$s_index = 'stone';
break;
case 3:
$s_index = 'iron';
break;
$s_index = 'iron';
break;
case 4:
$s_index = 'mana';
break;
$s_index = 'mana';
break;
default:
$s_index = 'food';
break;
$s_index = 'food';
break;
}
//calculating the rate it brings 1 resource
$num_tick = 0.1;
$rate = 'rate_' . $s_index;
//calculating the rate it brings 1 resource
$num_tick = 0.1;
$rate = 'rate_' . $s_index;
while (TRUE)
{
if (($res[$rate] * $num_tick) > 1)
break;
while (true) {
if (($res[$rate] * $num_tick) > 1) {
break;
}
$num_tick += 0.1;
$num_tick += 0.1;
}
$res['rate_food'] *= $num_tick;
$res['rate_wood'] *= $num_tick;
$res['rate_stone'] *= $num_tick;
$res['rate_iron'] *= $num_tick;
$res['rate_mana'] *= $num_tick;
$res['timer_tick'] = (1000 * $num_tick);
return $res;
}
$res['rate_food'] *= $num_tick;
$res['rate_wood'] *= $num_tick;
$res['rate_stone'] *= $num_tick;
$res['rate_iron'] *= $num_tick;
$res['rate_mana'] *= $num_tick;
$res['timer_tick'] = (1000 * $num_tick);
return $res;
}
}//MO_Controller
//nowhitesp

File diff suppressed because it is too large Load Diff

View File

@ -1,30 +1,30 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
if ( ! function_exists('gender'))
{
function gender($gender = '')
{
if ($gender == 1)
return 'Male';
else
return 'Female';
}
<?php if (! defined('BASEPATH')) {
exit('No direct script access allowed');
}
if ( ! function_exists('class_name'))
{
function class_name($id = 0)
{
switch ($id)
if (! function_exists('gender')) {
function gender($gender = '')
{
case 1:
return 'Warrior';
case 2:
return 'Rogue';
case 3:
return 'Archer';
default:
return 'Error';
if ($gender == 1) {
return 'Male';
} else {
return 'Female';
}
}
}
}
}
if (! function_exists('class_name')) {
function class_name($id = 0)
{
switch ($id) {
case 1:
return 'Warrior';
case 2:
return 'Rogue';
case 3:
return 'Archer';
default:
return 'Error';
}
}
}

View File

@ -1,29 +1,27 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
<?php if (! defined('BASEPATH')) {
exit('No direct script access allowed');
}
//means set_selected
if (!function_exists('ss'))
{
function ss($d1, $d2, $o1, $o2)
{
if ($o1 == $d1 && $o2 == $d2)
if (!function_exists('ss')) {
function ss($d1, $d2, $o1, $o2)
{
if ($d1 == 'eq')
return 'equipment_entry_selected';
else
return 'inventory_entry_selected';
if ($o1 == $d1 && $o2 == $d2) {
if ($d1 == 'eq') {
return 'equipment_entry_selected';
} else {
return 'inventory_entry_selected';
}
}
}
}
}
//quality_(in)inventory
if (!function_exists('qi'))
{
function qi($row)
{
if ($row)
if (!function_exists('qi')) {
function qi($row)
{
switch ($row['quality'])
{
if ($row) {
switch ($row['quality']) {
case (0):
return 'iv_quality_really_poor';
case (1):
@ -39,19 +37,16 @@ if (!function_exists('qi'))
case (6):
return 'iv_quality_omg';
}
}
}
}
}
//quality_(in)character('s view)
if (!function_exists('qc'))
{
function qc($equipment, $id)
{
if ($equipment[$id])
if (!function_exists('qc')) {
function qc($equipment, $id)
{
switch ($equipment[$id]['quality'])
{
if ($equipment[$id]) {
switch ($equipment[$id]['quality']) {
case (0):
return 'eq_quality_really_poor';
case (1):
@ -67,180 +62,163 @@ if (!function_exists('qc'))
case (6):
return 'eq_quality_omg';
}
}
}
}
}
if (!function_exists('can_be_equipped'))
{
function can_be_equipped($item, $hero)
{
if (!$item)
return FALSE;
if (!function_exists('can_be_equipped')) {
function can_be_equipped($item, $hero)
{
if (!$item) {
return false;
}
$data['can'] = FALSE;
$data['message'] = '';
$data['allowed_slot1'] = FALSE;
$data['allowed_slot2'] = FALSE;
$data['two_handed'] = FALSE;
$data['can'] = false;
$data['message'] = '';
$data['allowed_slot1'] = false;
$data['allowed_slot2'] = false;
$data['two_handed'] = false;
if ($item['type'] != 1)
{
$data['message'] = 'That item cannot be equipped.';
return $data;
}
if ($item['type'] != 1) {
$data['message'] = 'That item cannot be equipped.';
return $data;
}
if ($item['req_class'] != 0 && $item['req_class'] != $hero['class'])
{
$data['message'] = 'You can never use that item.';
return $data;
}
if ($item['req_class'] != 0 && $item['req_class'] != $hero['class']) {
$data['message'] = 'You can never use that item.';
return $data;
}
if ($item['req_level'] > $hero['level'])
{
$data['message'] = 'Your level is too low to use that item.';
return $data;
}
if ($item['req_level'] > $hero['level']) {
$data['message'] = 'Your level is too low to use that item.';
return $data;
}
if ($item['subtype'] == 6)
{
$data['can'] = TRUE;
$data['allowed_slot1'] = 6;
return $data;
}
elseif ($item['subtype'] == 12)
{
$data['can'] = TRUE;
$data['allowed_slot1'] = 12;
$data['allowed_slot2'] = 13;
return $data;
}
elseif ($item['subtype'] == 14)
{
$data['can'] = TRUE;
$data['allowed_slot1'] = 14;
$data['allowed_slot2'] = 15;
return $data;
}
elseif ($item['subtype'] == 19)
{
if ($hero['class'] == 2)
{
$data['can'] = TRUE;
$data['allowed_slot1'] = 19;
return $data;
}
}
if ($item['subtype'] == 6) {
$data['can'] = true;
$data['allowed_slot1'] = 6;
return $data;
} elseif ($item['subtype'] == 12) {
$data['can'] = true;
$data['allowed_slot1'] = 12;
$data['allowed_slot2'] = 13;
return $data;
} elseif ($item['subtype'] == 14) {
$data['can'] = true;
$data['allowed_slot1'] = 14;
$data['allowed_slot2'] = 15;
return $data;
} elseif ($item['subtype'] == 19) {
if ($hero['class'] == 2) {
$data['can'] = true;
$data['allowed_slot1'] = 19;
return $data;
}
}
$datatype = array(
$datatype = array(
//warrior
'1' => array(0, 1, 2, 3, 4),
//rogue
'2' => array(0, 1, 2, FALSE, FALSE),
'2' => array(0, 1, 2, false, false),
//archer
'3' => array(0, 1, 2, 3, FALSE));
'3' => array(0, 1, 2, 3, false));
$dataeqslots = array(
$dataeqslots = array(
//head
'0' => array(0, FALSE),
'0' => array(0, false),
//neck
'1' => array(1, FALSE),
'1' => array(1, false),
//shoulder
'2' => array(2, FALSE),
'2' => array(2, false),
//back
'3' => array(3, FALSE),
'3' => array(3, false),
//chest
'4' => array(4, FALSE),
'4' => array(4, false),
//shirt
'5' => array(5, FALSE),
'5' => array(5, false),
//bracer
'7' => array(7, FALSE),
'7' => array(7, false),
//gloves
'8' => array(8, FALSE),
'8' => array(8, false),
//belt
'9' => array(9, FALSE),
'9' => array(9, false),
//legs
'10' => array(10, FALSE),
'10' => array(10, false),
//foots
'11' => array(11, FALSE),
'11' => array(11, false),
);
//this means every item, whose subsubtype means the type (like cloth)
if ($item['subtype'] >= 0 && $item['subtype'] < 6 || $item['subtype'] > 6 && $item['subtype'] < 12)
{
if ($datatype[$hero['class']][$item['subsubtype']] !== FALSE)
{
$data['can'] = TRUE;
$data['allowed_slot1'] = $dataeqslots[$item['subtype']][0];
$data['allowed_slot2'] = $dataeqslots[$item['subtype']][1];
return $data;
}
else
{
$data['can'] = FALSE;
$data['message'] = "You don't have the required proficiency to use that item.";
return $data;
}
}
//this means every item, whose subsubtype means the type (like cloth)
if ($item['subtype'] >= 0 && $item['subtype'] < 6 || $item['subtype'] > 6 && $item['subtype'] < 12) {
if ($datatype[$hero['class']][$item['subsubtype']] !== false) {
$data['can'] = true;
$data['allowed_slot1'] = $dataeqslots[$item['subtype']][0];
$data['allowed_slot2'] = $dataeqslots[$item['subtype']][1];
return $data;
} else {
$data['can'] = false;
$data['message'] = "You don't have the required proficiency to use that item.";
return $data;
}
}
$dataclasswep = array(
$dataclasswep = array(
//warrior
'1' => array(FALSE, FALSE, FALSE, FALSE, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, FALSE, FALSE, FALSE, 20, FALSE),
'1' => array(false, false, false, false, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, false, false, false, 20, false),
//rogue
'2' => array(FALSE, 2, 3, 4, 5, 6, 7, FALSE, 9, 10,
11, FALSE, 13, 14, 15, FALSE, FALSE, FALSE, FALSE, FALSE, 21),
'2' => array(false, 2, 3, 4, 5, 6, 7, false, 9, 10,
11, false, 13, 14, 15, false, false, false, false, false, 21),
//archer
'3' => array(FALSE, 2, 3, 4, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE, FALSE, 13, 14, 15, 16, 17, 18, 19, FALSE, FALSE)
'3' => array(false, 2, 3, 4, false, false, false, false, false, false,
false, false, 13, 14, 15, 16, 17, 18, 19, false, false)
);
//array(first slot, second slot, two Handed)
$datawep = array(
//array(first slot, second slot, two Handed)
$datawep = array(
//staff
'1' => array(16, FALSE, TRUE),
'1' => array(16, false, true),
//dagger one, main, off
'2' => array(16, 17, FALSE),
'3' => array(16, FALSE, FALSE),
'4' => array(17, FALSE, FALSE),
'2' => array(16, 17, false),
'3' => array(16, false, false),
'4' => array(17, false, false),
//mace one main, off, 2h
'5' => array(16, 17, FALSE),
'6' => array(16, FALSE, FALSE),
'7' => array(17, FALSE, FALSE),
'8' => array(16, FALSE, TRUE),
'5' => array(16, 17, false),
'6' => array(16, false, false),
'7' => array(17, false, false),
'8' => array(16, false, true),
//axe one, main, off, 2h
'9' => array(16, 17, FALSE),
'10' => array(16, FALSE, FALSE),
'11' => array(17, FALSE, FALSE),
'12' => array(16, FALSE, TRUE),
'9' => array(16, 17, false),
'10' => array(16, false, false),
'11' => array(17, false, false),
'12' => array(16, false, true),
//sword one, main, off, 2h
'13' => array(16, 17, FALSE),
'14' => array(16, FALSE, FALSE),
'15' => array(17, FALSE, FALSE),
'16' => array(16, FALSE, TRUE),
'13' => array(16, 17, false),
'14' => array(16, false, false),
'15' => array(17, false, false),
'16' => array(16, false, true),
//bow, crossbow, gun
'17' => array(18, 17, FALSE),
'18' => array(18, FALSE, FALSE),
'19' => array(18, FALSE, FALSE),
'17' => array(18, 17, false),
'18' => array(18, false, false),
'19' => array(18, false, false),
//?? warri, rogue ranged
'20' => array(18, FALSE, FALSE),
'21' => array(18, FALSE, FALSE)
'20' => array(18, false, false),
'21' => array(18, false, false)
);
if ($item['subtype'] == 16)
{
if ($dataclasswep[$hero['class']][$item['subsubtype']] !== FALSE)
{
$data['can'] = TRUE;
$data['allowed_slot1'] = $datawep[$item['subsubtype']][0];
$data['allowed_slot2'] = $datawep[$item['subsubtype']][1];
$data['two_handed'] = $datawep[$item['subsubtype']][2];
return $data;
}
}
if ($item['subtype'] == 16) {
if ($dataclasswep[$hero['class']][$item['subsubtype']] !== false) {
$data['can'] = true;
$data['allowed_slot1'] = $datawep[$item['subsubtype']][0];
$data['allowed_slot2'] = $datawep[$item['subsubtype']][1];
$data['two_handed'] = $datawep[$item['subsubtype']][2];
return $data;
}
}
$data['can'] = FALSE;
$data['message'] = 'You cannot use that item.';
return $data;
}
}
$data['can'] = false;
$data['message'] = 'You cannot use that item.';
return $data;
}
}

View File

@ -1,16 +1,20 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
if ( ! function_exists('ev_type'))
{
function ev_type($ev)
{
if ($ev == 'build')
return 0;
if ($ev == 'upgrade')
return 1;
if ($ev == 'create')
return 2;
}
<?php if (! defined('BASEPATH')) {
exit('No direct script access allowed');
}
if (! function_exists('ev_type')) {
function ev_type($ev)
{
if ($ev == 'build') {
return 0;
}
if ($ev == 'upgrade') {
return 1;
}
if ($ev == 'create') {
return 2;
}
}
}

View File

@ -1,24 +1,24 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
<?php if (! defined('BASEPATH')) {
exit('No direct script access allowed');
}
//using different helper for images, so they can be easily relocated to like different servers etc...
if ( ! function_exists('isite_url'))
{
function isite_url($uri = '')
{
$CI =& get_instance();
return $CI->config->site_url($uri);
}
if (! function_exists('isite_url')) {
function isite_url($uri = '')
{
$CI =& get_instance();
return $CI->config->site_url($uri);
}
}
//addign img/prefix, so I don't have to in every call
if ( ! function_exists('ibase_url'))
{
function ibase_url($uri = '')
{
$muri = 'img/' . $uri;
$CI =& get_instance();
return $CI->config->base_url($muri);
}
}
if (! function_exists('ibase_url')) {
function ibase_url($uri = '')
{
$muri = 'img/' . $uri;
$CI =& get_instance();
return $CI->config->base_url($muri);
}
}

View File

@ -1,145 +1,127 @@
<?php
class Ai_model extends MO_Model
{
protected $settings;
protected $settings;
function __construct()
{
parent::__construct();
}
function attack()
{
$this->parse_settings();
if (!$this->settings['on'])
return 'AI is off';
$sql = "SELECT * FROM ai_villages WHERE attacked='0'";
$q = $this->db->query($sql);
$ai_village_not_attacked = $q->num_rows();
$log = "ai_villages query returned " . $ai_village_not_attacked . " rows. \n";
$ai_villages = $q->result_array();
$attacking_num = $this->settings['max_attack_village_limit'];
//determining how much will attack
if ($this->settings['attack_village_rand'])
public function __construct()
{
$a = rand(0, $this->settings['attack_village_rand']);
$attacking_num -= $a;
parent::__construct();
}
$log .= $attacking_num . " villages attacking. \n";
$reset = FALSE;
//resetting ai_villages's attack field if everything will be set to attacked
if ($ai_village_not_attacked < $attacking_num)
public function attack()
{
$attacking_num = $ai_village_not_attacked;
$this->parse_settings();
$reset = TRUE;
}
if (!$this->settings['on']) {
return 'AI is off';
}
//determining which villages are going to attack
for ($i = 0; $i < $attacking_num; $i++)
{
$found = FALSE;
$sql = "SELECT * FROM ai_villages WHERE attacked='0'";
while (!$found)
{
foreach ($ai_villages as $row)
{
$r = rand(1, 100);
$q = $this->db->query($sql);
if ($r > 50 && !isset($s[$row['id']]))
{
$s[$row['id']] = TRUE;
$data[] = $row;
$found = TRUE;
break;
}
}
}
}
$ai_village_not_attacked = $q->num_rows();
//saving to the db that they are attacked
if (!$reset)
{
$sql = "UPDATE ai_villages SET attacked='1' WHERE ";
$log = "ai_villages query returned " . $ai_village_not_attacked . " rows. \n";
$first = TRUE;
foreach ($data as $row)
{
if ($first)
$first = FALSE;
else
$sql .= " OR ";
$sql .= "id='" . $row['id'] . "'";
}
$ai_villages = $q->result_array();
$this->db->query($sql);
}
else
{
$sql = "UPDATE ai_villages SET attacked='0'";
$this->db->query($sql);
$log .= "ai_villages's attacked field reseted.\n";
}
$attacking_num = $this->settings['max_attack_village_limit'];
//getting ai_units
$sql = "SELECT * FROM ai_units";
$q = $this->db->query($sql);
$num_ai_units = $q->num_rows();
$res = $q->result_array();
//determining how much will attack
if ($this->settings['attack_village_rand']) {
$a = rand(0, $this->settings['attack_village_rand']);
$attacking_num -= $a;
}
if ($this->settings['ai_unit_max_diff'] < $num_ai_units)
{
$num = 0;
$d = FALSE;
$log .= $attacking_num . " villages attacking. \n";
$reset = false;
while ($num != $this->settings['ai_unit_max_diff'])
{
foreach ($res as $row)
{
if (!isset($d[$row['id']]))
{
$r = rand(1,50);
if ($r > 50)
{
$ai_units[] = $row;
$d[$row['id']] = TRUE;
$num++;
break;
}
}
}
}
}
else
{
$ai_units = $res;
}
//resetting ai_villages's attack field if everything will be set to attacked
if ($ai_village_not_attacked < $attacking_num) {
$attacking_num = $ai_village_not_attacked;
//adding villages to log
$log .= "Attacking villages: \n";
foreach ($data as $row)
{
$log .= $row['name'] . "(" .$row['X'] . " " . $row['Y'] . ") \n";
}
$reset = true;
}
//sending attackers
foreach ($data as $row)
{
$sql = "SELECT map.X,map.Y,villages.*
//determining which villages are going to attack
for ($i = 0; $i < $attacking_num; $i++) {
$found = false;
while (!$found) {
foreach ($ai_villages as $row) {
$r = rand(1, 100);
if ($r > 50 && !isset($s[$row['id']])) {
$s[$row['id']] = true;
$data[] = $row;
$found = true;
break;
}
}
}
}
//saving to the db that they are attacked
if (!$reset) {
$sql = "UPDATE ai_villages SET attacked='1' WHERE ";
$first = true;
foreach ($data as $row) {
if ($first) {
$first = false;
} else {
$sql .= " OR ";
}
$sql .= "id='" . $row['id'] . "'";
}
$this->db->query($sql);
} else {
$sql = "UPDATE ai_villages SET attacked='0'";
$this->db->query($sql);
$log .= "ai_villages's attacked field reseted.\n";
}
//getting ai_units
$sql = "SELECT * FROM ai_units";
$q = $this->db->query($sql);
$num_ai_units = $q->num_rows();
$res = $q->result_array();
if ($this->settings['ai_unit_max_diff'] < $num_ai_units) {
$num = 0;
$d = false;
while ($num != $this->settings['ai_unit_max_diff']) {
foreach ($res as $row) {
if (!isset($d[$row['id']])) {
$r = rand(1, 50);
if ($r > 50) {
$ai_units[] = $row;
$d[$row['id']] = true;
$num++;
break;
}
}
}
}
} else {
$ai_units = $res;
}
//adding villages to log
$log .= "Attacking villages: \n";
foreach ($data as $row) {
$log .= $row['name'] . "(" .$row['X'] . " " . $row['Y'] . ") \n";
}
//sending attackers
foreach ($data as $row) {
$sql = "SELECT map.X,map.Y,villages.*
FROM map
LEFT JOIN villages ON (map.villageid=villages.id AND map.type='3')
WHERE (map.type = 3 AND
@ -148,162 +130,155 @@ class Ai_model extends MO_Model
AND map.Y > '" . ($row['Y'] - 24) . "'
AND map.Y < '" . ($row['Y'] + 24) . "')";
$q = $this->db->query($sql);
$q = $this->db->query($sql);
//no villages in range
if (!$q->num_rows())
continue;
//no villages in range
if (!$q->num_rows()) {
continue;
}
$log .= $row['name'] . " is attacking: \n";
$log .= $row['name'] . " is attacking: \n";
$res = $q->result_array();
//sending attackers
foreach ($res as $rrow)
{
if ($rrow['ai_on'] || $rrow['ai_flagged'])
{
$log .= "Sending attackers to: " . $rrow['name'] . "[" . $rrow['id'] . "]";
$log .= " (S: " . $rrow['score'] . ")\n";
$log .= "Sent: \n";
$res = $q->result_array();
//sending attackers
foreach ($res as $rrow) {
if ($rrow['ai_on'] || $rrow['ai_flagged']) {
$log .= "Sending attackers to: " . $rrow['name'] . "[" . $rrow['id'] . "]";
$log .= " (S: " . $rrow['score'] . ")\n";
$log .= "Sent: \n";
foreach ($ai_units as $unit)
{
$a = ($rrow['score'] / $unit['rate']) / $unit['per_score'];
$num = floor($a);
foreach ($ai_units as $unit) {
$a = ($rrow['score'] / $unit['rate']) / $unit['per_score'];
$num = floor($a);
$log .= $unit['name'] . "->" . $num . "\n";
$log .= $unit['name'] . "->" . $num . "\n";
$send[] = array('unitid' => $unit['id'],
'num' => $num);
}
$send[] = array('unitid' => $unit['id'],
'num' => $num);
}
$this->send_attack($send, $row, $rrow);
}
}
$this->send_attack($send, $row, $rrow);
}
}
}
$this->load->helper('file');
$f = './logs/ai_log/log_' . time() . '.txt';
write_file($f, $log);
return $log;
}
$this->load->helper('file');
$f = './logs/ai_log/log_' . time() . '.txt';
write_file($f, $log);
return $log;
}
function send_attack($send, $ai_village, $village)
{
$villageid = $village['id'];
$sql = "SELECT max(attackid) AS attackid FROM attacks WHERE villageid='$villageid'";
$q = $this->db->query($sql);
$res = $q->row_array();
if ($res['attackid'])
public function send_attack($send, $ai_village, $village)
{
$atkid = ($res['attackid'] + 1);
}
else
$atkid = 1;
$villageid = $village['id'];
$first = TRUE;
$sql = "INSERT INTO attacks VALUES";
foreach ($send as $row)
$sql = "SELECT max(attackid) AS attackid FROM attacks WHERE villageid='$villageid'";
$q = $this->db->query($sql);
$res = $q->row_array();
if ($res['attackid']) {
$atkid = ($res['attackid'] + 1);
} else {
$atkid = 1;
}
$first = true;
$sql = "INSERT INTO attacks VALUES";
foreach ($send as $row) {
if ($first) {
$first = false;
} else {
$sql .= ',';
}
$sql .= "(default, '$villageid', '$atkid', '" . $row['unitid'] . "', '" . $row['num']. "')";
}
$sql .= ";";
$this->db->query($sql);
//calculate distance
$dist = sqrt(pow($ai_village['X'] - $village['X'], 2) + pow($ai_village['Y'] - $village['Y'], 2));
//15 min 1 square
$time = $dist * 900;
$r = rand(3600, 10800);
$end = $time + $r;
//todo remove
$end = 20;
//attack random sides
$dir = rand(1, 4);
$ev['villageid'] = $villageid;
$ev['slotid'] = 0;
$ev['type'] = parent::EVENT_ATTACK;
$ev['time'] = $end;
$ev['data1'] = $atkid;
$ev['data2'] = $dir;
$this->add_event($ev);
}
public function parse_settings()
{
if ($first)
$first = FALSE;
else
$sql .= ',';
$sql = "SELECT * FROM ai_settings";
$sql .= "(default, '$villageid', '$atkid', '" . $row['unitid'] . "', '" . $row['num']. "')";
$q = $this->db->query($sql);
$res = $q->result_array();
foreach ($res as $row) {
$data[$row['setting']] = $row['value'];
}
$this->settings = $data;
}
$sql .= ";";
$this->db->query($sql);
//calculate distance
$dist = sqrt(pow($ai_village['X'] - $village['X'], 2) + pow($ai_village['Y'] - $village['Y'], 2));
//15 min 1 square
$time = $dist * 900;
$r = rand(3600, 10800);
$end = $time + $r;
//todo remove
$end = 20;
//attack random sides
$dir = rand(1, 4);
$ev['villageid'] = $villageid;
$ev['slotid'] = 0;
$ev['type'] = parent::EVENT_ATTACK;
$ev['time'] = $end;
$ev['data1'] = $atkid;
$ev['data2'] = $dir;
$this->add_event($ev);
}
function parse_settings()
{
$sql = "SELECT * FROM ai_settings";
$q = $this->db->query($sql);
$res = $q->result_array();
foreach ($res as $row)
public function get_unit_list_drop_admin()
{
$data[$row['setting']] = $row['value'];
$sql = "SELECT * FROM ai_units";
$q = $this->db->query($sql);
$res = $q->result_array();
$data[0] = 'Nothing';
foreach ($res as $row) {
$data[$row['id']] = $row['name'];
}
return $data;
}
$this->settings = $data;
}
function get_unit_list_drop_admin()
{
$sql = "SELECT * FROM ai_units";
$q = $this->db->query($sql);
$res = $q->result_array();
$data[0] = 'Nothing';
foreach ($res as $row)
public function list_units_admin()
{
$data[$row['id']] = $row['name'];
$sql = "SELECT * FROM ai_units";
$q = $this->db->query($sql);
return $q->result_array();
}
return $data;
}
public function get_unit_admin($id)
{
$sql = "SELECT * FROM ai_units WHERE id='$id'";
$q = $this->db->query($sql);
function list_units_admin()
{
$sql = "SELECT * FROM ai_units";
return $q->row_array();
}
$q = $this->db->query($sql);
return $q->result_array();
}
function get_unit_admin($id)
{
$sql = "SELECT * FROM ai_units WHERE id='$id'";
$q = $this->db->query($sql);
return $q->row_array();
}
function add_unit_admin($data)
{
$sql = "INSERT INTO ai_units
public function add_unit_admin($data)
{
$sql = "INSERT INTO ai_units
VALUES(default,
'" . $data['name'] . "',
'" . $data['icon'] . "',
@ -317,14 +292,14 @@ class Ai_model extends MO_Model
'" . $data['strong_against'] . "',
'" . $data['weak_against'] . "')";
$this->db->query($sql);
$this->db->query($sql);
$this->_create_sql($sql);
}
$this->_create_sql($sql);
}
function edit_unit_admin($data)
{
$sql = "UPDATE ai_units
public function edit_unit_admin($data)
{
$sql = "UPDATE ai_units
SET name='" . $data['name'] . "',
icon='" . $data['icon'] . "',
ability='" . $data['ability'] . "',
@ -338,52 +313,52 @@ class Ai_model extends MO_Model
weak_against='" . $data['weak_against'] . "'
WHERE id='" . $data['id'] . "'";
$this->db->query($sql);
$this->db->query($sql);
$this->_create_sql($sql);
}
$this->_create_sql($sql);
}
function get_settings_list_admin()
{
$sql = "SELECT * FROM ai_settings";
public function get_settings_list_admin()
{
$sql = "SELECT * FROM ai_settings";
$q = $this->db->query($sql);
$q = $this->db->query($sql);
return $q->result_array();
}
return $q->result_array();
}
function get_setting_admin($id)
{
$sql = "SELECT * FROM ai_settings WHERE id='$id'";
$q = $this->db->query($sql);
public function get_setting_admin($id)
{
$sql = "SELECT * FROM ai_settings WHERE id='$id'";
$q = $this->db->query($sql);
return $q->row_array();
}
return $q->row_array();
}
function edit_setting_admin($data)
{
$sql = "UPDATE ai_settings
public function edit_setting_admin($data)
{
$sql = "UPDATE ai_settings
SET setting='" . $data['setting'] . "',
value='" . $data['value'] . "',
description='" . $data['description'] . "'
WHERE id='" . $data['id'] . "'";
$this->db->query($sql);
$this->db->query($sql);
$this->_create_sql($sql);
}
$this->_create_sql($sql);
}
function add_setting_admin($data)
{
$sql = "INSERT INTO ai_settings
public function add_setting_admin($data)
{
$sql = "INSERT INTO ai_settings
VALUES(default,
'" . $data['setting'] . "',
'" . $data['value'] . "' ,
'" . $data['description'] . "')";
$this->db->query($sql);
$this->db->query($sql);
$this->_create_sql($sql);
}
$this->_create_sql($sql);
}
}
//nowhitesp
//nowhitesp

View File

@ -2,230 +2,235 @@
class Assignment_model extends MO_Model
{
function __construct()
{
parent::__construct();
}
public function __construct()
{
parent::__construct();
}
function assign_unit($assid, $num, $slotid, $res, $villageid, $userid)
{
$this->set_resources($res);
public function assign_unit($assid, $num, $slotid, $res, $villageid, $userid)
{
$this->set_resources($res);
//check if there is building in that slot
$sql = "SELECT buildings.* FROM village_buildings
//check if there is building in that slot
$sql = "SELECT buildings.* FROM village_buildings
INNER JOIN buildings ON village_buildings.buildingid=buildings.id
WHERE slotid='$slotid' AND villageid='$villageid'";
$q = $this->db->query($sql);
$q = $this->db->query($sql);
if (!$q->num_rows())
return 1;
if (!$q->num_rows()) {
return 1;
}
$building = $q->row_array();
$building = $q->row_array();
//check if there is already an assignment in which case we just deassign
//in this case num will be 0 unless they play with the form,
//but we shouldn't care about that since the user can write 0 into the form
$sql = "SELECT * FROM building_assignments
//check if there is already an assignment in which case we just deassign
//in this case num will be 0 unless they play with the form,
//but we shouldn't care about that since the user can write 0 into the form
$sql = "SELECT * FROM building_assignments
WHERE assignmentid='$assid'
AND slotid='$slotid'
AND villageid='$villageid'";
$q = $this->db->query($sql);
$q = $this->db->query($sql);
if ($q->num_rows())
{
//the user wants to just deassign
$ass = $q->row_array();
if ($q->num_rows()) {
//the user wants to just deassign
$ass = $q->row_array();
//delete assignment
$sql = "DELETE FROM building_assignments WHERE id='" . $ass['id'] . "'";
$this->db->query($sql);
//delete assignment
$sql = "DELETE FROM building_assignments WHERE id='" . $ass['id'] . "'";
$this->db->query($sql);
//giving back units
//getting units
$sql = "SELECT * FROM village_units
//giving back units
//getting units
$sql = "SELECT * FROM village_units
WHERE villageid='$villageid'
AND userid='$userid'";
$q = $this->db->query($sql);
$q = $this->db->query($sql);
if ($q->num_rows())
{
$units = $q->result_array();
}
else
{
$units = FALSE;
}
if ($q->num_rows()) {
$units = $q->result_array();
} else {
$units = false;
}
$found = FALSE;
$found = false;
if ($units)
{
foreach ($units as $row)
{
if ($row['unitid'] == $ass['unitid'])
{
$found = TRUE;
$fdata = $row['id'];
}
}
}
if ($units) {
foreach ($units as $row) {
if ($row['unitid'] == $ass['unitid']) {
$found = true;
$fdata = $row['id'];
}
}
}
if ($found)
{
$sql = "UPDATE village_units
if ($found) {
$sql = "UPDATE village_units
SET unitcount = unitcount + '". $ass['num_unit'] . "'
WHERE id='$fdata'";
}
else
{
$sql = "INSERT INTO village_units
} else {
$sql = "INSERT INTO village_units
VALUES(default, '$userid', '$villageid',
'" . $ass['unitid'] . "', '" . $ass['num_unit'] . "')";
}
}
$this->db->query($sql);
$this->db->query($sql);
//substract the bonuses
$this->substract_modifiers($assid, $villageid, 'assignment',
$ass['num_bonus']);
//substract the bonuses
$this->substract_modifiers(
$assid,
$villageid,
'assignment',
$ass['num_bonus']
);
$this->write_resources();
$this->write_resources();
//taking away spells
$sql = "DELETE FROM building_spells
//taking away spells
$sql = "DELETE FROM building_spells
WHERE assignmentid='$assid'
AND slotid='$slotid'
AND villageid='$villageid'";
$this->db->query($sql);
$this->db->query($sql);
return 0;
}
return 0;
}
//check if assignment exists
$sql = "SELECT * FROM assignments WHERE id='$assid'";
$q = $this->db->query($sql);
//check if assignment exists
$sql = "SELECT * FROM assignments WHERE id='$assid'";
$q = $this->db->query($sql);
if (!$q->num_rows())
return 2;
if (!$q->num_rows()) {
return 2;
}
$ass = $q->row_array();
$ass = $q->row_array();
//checking technology
if ($ass['req_tech'])
if (!$this->has_req_tech($ass['req_tech'], $villageid, $slotid))
return 3;
//check if building has that assignment
if (!($building['assignment1'] == $ass['id'] ||
$building['assignment2'] == $ass['id'] ||
$building['assignment3'] == $ass['id'] ||
$building['assignment4'] == $ass['id'] ||
$building['assignment5'] == $ass['id']))
return 3;
//checking technology
if ($ass['req_tech']) {
if (!$this->has_req_tech($ass['req_tech'], $villageid, $slotid)) {
return 3;
}
}
//check if building has that assignment
if (!($building['assignment1'] == $ass['id'] ||
$building['assignment2'] == $ass['id'] ||
$building['assignment3'] == $ass['id'] ||
$building['assignment4'] == $ass['id'] ||
$building['assignment5'] == $ass['id'])) {
return 3;
}
//getting unit
$sql = "SELECT * FROM village_units
//getting unit
$sql = "SELECT * FROM village_units
WHERE unitid='" . $ass['unitid'] . "'
AND userid='$userid'";
$q = $this->db->query($sql);
$q = $this->db->query($sql);
if (!$q->num_rows())
return 4;
if (!$q->num_rows()) {
return 4;
}
$unit = $q->row_array();
$unit = $q->row_array();
//it probably shouldn't happen but who knows
if (!$unit['unitcount'])
return 5;
//it probably shouldn't happen but who knows
if (!$unit['unitcount']) {
return 5;
}
//if the user just clicks on the assign we should assign max
if (!$num)
$num = $ass['max'];
//if the user just clicks on the assign we should assign max
if (!$num) {
$num = $ass['max'];
}
//we shouldn't assign more than allowed
if ($ass['max'] < $num)
$num = $ass['max'];
//we shouldn't assign more than allowed
if ($ass['max'] < $num) {
$num = $ass['max'];
}
//determining how much can be assigned
if ($unit['unitcount'] < $num)
$num = $unit['unitcount'];
//determining how much can be assigned
if ($unit['unitcount'] < $num) {
$num = $unit['unitcount'];
}
//determining number of bonuses granted
$num_bonus = floor(($num / $ass['bonus_per_assigned']));
//determining number of bonuses granted
$num_bonus = floor(($num / $ass['bonus_per_assigned']));
$count = ($unit['unitcount'] - $num);
$count = ($unit['unitcount'] - $num);
//updating unit field in db
if ($count <= 0)
{
$sql = "DELETE FROM village_units WHERE id='" . $unit['id'] . "'";
}
else
{
$sql = "UPDATE village_units
//updating unit field in db
if ($count <= 0) {
$sql = "DELETE FROM village_units WHERE id='" . $unit['id'] . "'";
} else {
$sql = "UPDATE village_units
SET unitcount=unitcount - '$num'
WHERE id='" . $unit['id'] . "'";
}
}
$this->db->query($sql);
$this->db->query($sql);
//adding assignment
$sql = "INSERT INTO building_assignments
//adding assignment
$sql = "INSERT INTO building_assignments
VALUES(default, '$villageid', '$slotid', '" . $unit['unitid'] . "',
'$num', '" . $assid . "', '$num_bonus')";
$this->db->query($sql);
$this->db->query($sql);
//grant resource bonus
$this->add_modifiers($assid, $villageid, 'assignment', $num_bonus);
$this->write_resources();
//grant resource bonus
$this->add_modifiers($assid, $villageid, 'assignment', $num_bonus);
$this->write_resources();
//assignment has spell
if (!$ass['spellid'])
return 0;
//assignment has spell
if (!$ass['spellid']) {
return 0;
}
/*
//only give spells if bonus is granted
if (!$num_bonus)
return 0;
*/
/*
//only give spells if bonus is granted
if (!$num_bonus)
return 0;
*/
//only give spell if max unit assigned
if (!($ass['max'] == $num))
return 0;
//only give spell if max unit assigned
if (!($ass['max'] == $num)) {
return 0;
}
//granting spell
$sql = "INSERT INTO building_spells
//granting spell
$sql = "INSERT INTO building_spells
VALUES(default, '$villageid', '$slotid', '$assid',
'" . $ass['spellid'] . "')";
$this->db->query($sql);
$this->db->query($sql);
return 0;
}
return 0;
}
function get_assignments($slotid, $villageid, $userid)
{
if ($slotid > parent::TOTAL_BUILDINGS)
return 1; //that shouldn't happen
public function get_assignments($slotid, $villageid, $userid)
{
if ($slotid > parent::TOTAL_BUILDINGS) {
return 1;
} //that shouldn't happen
$sql = "SELECT buildings.* FROM village_buildings
$sql = "SELECT buildings.* FROM village_buildings
INNER JOIN buildings ON village_buildings.buildingid = buildings.id
WHERE village_buildings.slotid='$slotid'
AND village_buildings.villageid='$villageid'";
$q = $this->db->query($sql);
$q = $this->db->query($sql);
if (!$q->num_rows())
return 2; //nothing in that slot
if (!$q->num_rows()) {
return 2;
} //nothing in that slot
$res = $q->row_array();
$res = $q->row_array();
//getting assignment data
$sql = "SELECT assignments.*,units.name
//getting assignment data
$sql = "SELECT assignments.*,units.name
FROM assignments
INNER JOIN units ON assignments.unitid=units.id
WHERE assignments.id='" . $res['assignment1'] . "'
@ -234,97 +239,87 @@ class Assignment_model extends MO_Model
OR assignments.id='" . $res['assignment4'] . "'
OR assignments.id='" . $res['assignment5'] . "'";
$q = $this->db->query($sql);
$q = $this->db->query($sql);
if (!$q->num_rows())
{
$data['assigndata'] = FALSE; //building doesn't have assignments
return $data;
}
if (!$q->num_rows()) {
$data['assigndata'] = false; //building doesn't have assignments
return $data;
}
$adata = $q->result_array();
$adata = $q->result_array();
$tech = $this->get_village_technologies($villageid, $slotid);
$tech = $this->get_village_technologies($villageid, $slotid);
foreach ($adata as $row)
{
if ($this->have_technology($tech, $row['req_tech']))
$data['assigndata'][] = $row;
}
foreach ($adata as $row) {
if ($this->have_technology($tech, $row['req_tech'])) {
$data['assigndata'][] = $row;
}
}
if (!isset($data['assigndata']))
{
$data['assigndata'] = FALSE;
return $data;
}
if (!isset($data['assigndata'])) {
$data['assigndata'] = false;
return $data;
}
//getting assigned data
$sql = "SELECT * FROM building_assignments
//getting assigned data
$sql = "SELECT * FROM building_assignments
WHERE slotid='$slotid'
AND villageid='$villageid'";
$q = $this->db->query($sql);
$q = $this->db->query($sql);
if (!$q->num_rows())
{
$data['assigned'] = FALSE;
}
else
{
$data['assigned'] = $q->result_array();
}
if (!$q->num_rows()) {
$data['assigned'] = false;
} else {
$data['assigned'] = $q->result_array();
}
$data['building'] = $res;
$data['building'] = $res;
//getting units
$sql = "SELECT * FROM village_units
//getting units
$sql = "SELECT * FROM village_units
WHERE villageid='$villageid'
AND userid='$userid'";
$q = $this->db->query($sql);
$q = $this->db->query($sql);
if ($q->num_rows)
{
$data['units'] = $q->result_array();
}
else
{
$data['units'] = FALSE;
if ($q->num_rows) {
$data['units'] = $q->result_array();
} else {
$data['units'] = false;
}
return $data;
}
return $data;
}
function get_assignment_list_drop_admin()
{
$sql = "SELECT * FROM assignments";
$q = $this->db->query($sql);
$res = $q->result_array();
$data[0] = 'Nothing';
foreach ($res as $row)
public function get_assignment_list_drop_admin()
{
$data[$row['id']] = $row['description'];
$sql = "SELECT * FROM assignments";
$q = $this->db->query($sql);
$res = $q->result_array();
$data[0] = 'Nothing';
foreach ($res as $row) {
$data[$row['id']] = $row['description'];
}
return $data;
}
return $data;
}
public function get_assignments_admin()
{
$sql = "SELECT * FROM assignments";
function get_assignments_admin()
{
$sql = "SELECT * FROM assignments";
$q = $this->db->query($sql);
$q = $this->db->query($sql);
return $q->result_array();
}
return $q->result_array();
}
function add_assignment_admin($data)
{
$sql = "INSERT INTO assignments
public function add_assignment_admin($data)
{
$sql = "INSERT INTO assignments
VALUES (default,
'" . $data['unitid'] . "',
'" . $data['max'] . "',
@ -348,14 +343,14 @@ class Assignment_model extends MO_Model
'" . $data['mod_percent_mana'] . "',
'" . $data['description'] . "')";
$this->db->query($sql);
$this->db->query($sql);
$this->_create_sql($sql);
}
$this->_create_sql($sql);
}
function edit_assignment_admin($data)
{
$sql = "UPDATE assignments
public function edit_assignment_admin($data)
{
$sql = "UPDATE assignments
SET unitid='" . $data['unitid'] . "',
max='" . $data['max'] . "',
bonus_per_assigned='" . $data['bonus_per_assigned'] . "',
@ -379,18 +374,18 @@ class Assignment_model extends MO_Model
description='" . $data['description'] . "'
WHERE id='" . $data['id'] . "'";
$this->db->query($sql);
$this->db->query($sql);
$this->_create_sql($sql);
}
$this->_create_sql($sql);
}
function get_assignment_admin($id)
{
$sql = "SELECT * FROM assignments WHERE id='$id'";
public function get_assignment_admin($id)
{
$sql = "SELECT * FROM assignments WHERE id='$id'";
$q = $this->db->query($sql);
$q = $this->db->query($sql);
return $q->row_array();
}
return $q->row_array();
}
}
//nowhitesp

View File

@ -1,173 +1,162 @@
<?php
class Building_model extends MO_Model
{
function __construct()
{
parent::__construct();
}
public function __construct()
{
parent::__construct();
}
function get_building($buildingid)
{
$sql = "SELECT * FROM buildings WHERE id='$buildingid'";
$q = $this->db->query($sql);
public function get_building($buildingid)
{
$sql = "SELECT * FROM buildings WHERE id='$buildingid'";
$q = $this->db->query($sql);
if ($q->num_rows())
return $q->row_array();
if ($q->num_rows()) {
return $q->row_array();
}
return FALSE;
}
return false;
}
function set_build_in_progress($slotid, $villageid)
{
$sql = "INSERT INTO village_buildings
public function set_build_in_progress($slotid, $villageid)
{
$sql = "INSERT INTO village_buildings
VALUES(default, '$villageid', '$slotid', '2')";
$this->db->query($sql);
}
$this->db->query($sql);
}
function building_list($villageid)
{
$sql = "SELECT * FROM buildings
public function building_list($villageid)
{
$sql = "SELECT * FROM buildings
WHERE rank='1'";
$q = $this->db->query($sql);
$res = $q->result_array();
$q = $this->db->query($sql);
$res = $q->result_array();
$sql = "SELECT * FROM village_buildings WHERE villageid='$villageid'";
$q = $this->db->query($sql);
$vb = $q->result_array();
$sql = "SELECT * FROM village_buildings WHERE villageid='$villageid'";
$q = $this->db->query($sql);
$vb = $q->result_array();
//checking requirements
foreach ($res as $row)
{
if ($this->can_build($villageid, $row, $vb, FALSE))
{
$build[] = $row;
}
//checking requirements
foreach ($res as $row) {
if ($this->can_build($villageid, $row, $vb, false)) {
$build[] = $row;
}
}
//requirements are met
$tech = $this->get_village_technologies($villageid);
foreach ($build as $row) {
if ($row['req_tech']) {
foreach ($tech as $trow) {
if ($row['req_tech'] == $trow['technologyid']) {
$data[] = $row;
break;
}
}
} else {
$data[] = $row;
}
}
return $data;
}
//requirements are met
$tech = $this->get_village_technologies($villageid);
foreach ($build as $row)
//returns 0 if upgrade in progress
//returns 1 if technology requirement not met
//returns 2 if not enough resources
//returns 3 if can be built
public function can_be_upgraded($event, $res, $building, $villageid, $query = false)
{
if ($row['req_tech'])
{
foreach ($tech as $trow)
{
if ($row['req_tech'] == $trow['technologyid'])
{
$data[] = $row;
break;
}
}
}
else
{
$data[] = $row;
}
}
return $data;
}
//returns 0 if upgrade in progress
//returns 1 if technology requirement not met
//returns 2 if not enough resources
//returns 3 if can be built
function can_be_upgraded($event, $res, $building, $villageid, $query = FALSE)
{
if ($query)
{
//this means we have to get building from the db,
if ($query) {
//this means we have to get building from the db,
//and $building is only the id
}
//check if upgrade in progress
//we can just do this, since event is filtered to update events
if ($event) {
return 0;
}
if (!$this->has_req_tech($building['req_tech'], $villageid)) {
return 1;
}
if ($res['food'] < $building['cost_food'] ||
$res['wood'] < $building['cost_wood'] ||
$res['stone'] < $building['cost_stone'] ||
$res['iron'] < $building['cost_iron'] ||
$res['mana'] < $building['cost_mana']) {
return 2;
}
//can be built
return 3;
}
//check if upgrade in progress
//we can just do this, since event is filtered to update events
if ($event)
public function can_build($villageid, $buildingid, $data = 0, $is_buildingid = true)
{
return 0;
//STUB requirements aren't implemented
return true;
}
if (!$this->has_req_tech($building['req_tech'], $villageid))
return 1;
if ($res['food'] < $building['cost_food'] ||
$res['wood'] < $building['cost_wood'] ||
$res['stone'] < $building['cost_stone'] ||
$res['iron'] < $building['cost_iron'] ||
$res['mana'] < $building['cost_mana'])
public function is_valid_slot($slotid, $villageid)
{
return 2;
}
if ($slotid > parent::TOTAL_BUILDINGS) {
return false;
}
//can be built
return 3;
}
function can_build($villageid, $buildingid, $data = 0, $is_buildingid = TRUE)
{
//STUB requirements aren't implemented
return TRUE;
}
function is_valid_slot($slotid, $villageid)
{
if ($slotid > parent::TOTAL_BUILDINGS)
return FALSE;
$sql = "SELECT id FROM village_buildings
$sql = "SELECT id FROM village_buildings
WHERE villageid='$villageid' AND slotid='$slotid'";
$q = $this->db->query($sql);
$q = $this->db->query($sql);
if ($q->num_rows())
return FALSE;
if ($q->num_rows()) {
return false;
}
return TRUE;
}
function get_building_ranks_admin()
{
$sql = "SELECT * FROM buildings WHERE id > 2";
$q = $this->db->query($sql);
$res = $q->result_array();
$data[0] = 'Nothing';
foreach ($res as $row)
{
if (!$row['next_rank'])
{
$name = $row['name'] . ' R: ' . $row['rank'];
$data[$row['id']] = $name;
}
return true;
}
return $data;
}
public function get_building_ranks_admin()
{
$sql = "SELECT * FROM buildings WHERE id > 2";
$q = $this->db->query($sql);
function list_buildings_admin()
{
$sql = "SELECT * FROM buildings";
$q = $this->db->query($sql);
$res = $q->result_array();
return $q->result_array();
}
$data[0] = 'Nothing';
function get_building_admin($id)
{
$sql = "SELECT * FROM buildings WHERE id='$id'";
$q = $this->db->query($sql);
foreach ($res as $row) {
if (!$row['next_rank']) {
$name = $row['name'] . ' R: ' . $row['rank'];
$data[$row['id']] = $name;
}
}
return $q->row_array();
}
return $data;
}
function edit_building_admin($data)
{
public function list_buildings_admin()
{
$sql = "SELECT * FROM buildings";
$q = $this->db->query($sql);
$sql = "UPDATE buildings
return $q->result_array();
}
public function get_building_admin($id)
{
$sql = "SELECT * FROM buildings WHERE id='$id'";
$q = $this->db->query($sql);
return $q->row_array();
}
public function edit_building_admin($data)
{
$sql = "UPDATE buildings
SET name='" . $data['name'] . "',
description='" . $data['description'] . "',
icon='" . $data['icon'] . "',
@ -209,14 +198,14 @@ class Building_model extends MO_Model
tech_secondary_group='" . $data['tech_secondary_group'] . "'
WHERE id='" . $data['id'] . "'";
$this->db->query($sql);
$this->db->query($sql);
$this->_create_sql($sql);
}
$this->_create_sql($sql);
}
function add_building_admin($data)
{
$sql = "INSERT INTO buildings VALUES(default,
public function add_building_admin($data)
{
$sql = "INSERT INTO buildings VALUES(default,
'" . $data['name'] . "',
'" . $data['description'] . "',
'" . $data['icon'] . "',
@ -257,9 +246,9 @@ class Building_model extends MO_Model
'" . $data['tech_group'] . "',
'" . $data['tech_secondary_group'] . "')";
$this->db->query($sql);
$this->db->query($sql);
$this->_create_sql($sql);
}
$this->_create_sql($sql);
}
}
//nowhitesp
//nowhitesp

View File

@ -2,54 +2,51 @@
class Changelog_model extends MO_Model
{
public function __construct()
{
parent::__construct();
}
function __construct()
{
parent::__construct();
}
public function new_version($version)
{
$time = time();
function new_version($version)
{
$time = time();
$sql = "INSERT INTO changelog_versions VALUES(default, '$version', '$time')";
$this->db->query($sql);
$this->_create_sql($sql);
}
$sql = "INSERT INTO changelog_versions VALUES(default, '$version', '$time')";
$this->db->query($sql);
$this->_create_sql($sql);
}
public function new_commit($text)
{
$time = time();
function new_commit($text)
{
$time = time();
$sql = "SELECT id FROM changelog_versions ORDER BY id DESC LIMIT 1";
$q = $this->db->query($sql);
$res = $q->row_array();
$versionid = $res['id'];
$sql = "SELECT id FROM changelog_versions ORDER BY id DESC LIMIT 1";
$q = $this->db->query($sql);
$res = $q->row_array();
$versionid = $res['id'];
$sql = "INSERT INTO changelog_commits VALUES(default, '$versionid', '$text', '$time')";
$this->db->query($sql);
$this->_create_sql($sql);
}
$sql = "INSERT INTO changelog_commits VALUES(default, '$versionid', '$text', '$time')";
$this->db->query($sql);
$this->_create_sql($sql);
}
function get_versions()
{
$sql = "SELECT * FROM changelog_versions ORDER BY timestamp DESC";
$q = $this->db->query($sql);
public function get_versions()
{
$sql = "SELECT * FROM changelog_versions ORDER BY timestamp DESC";
$q = $this->db->query($sql);
return $q->result_array();
}
return $q->result_array();
}
function get_commits()
{
$sql = "SELECT * FROM changelog_commits ORDER BY timestamp DESC";
$q = $this->db->query($sql);
public function get_commits()
{
$sql = "SELECT * FROM changelog_commits ORDER BY timestamp DESC";
$q = $this->db->query($sql);
return $q->result_array();
}
return $q->result_array();
}
}
//nowhitesp

View File

@ -1,10 +1,9 @@
<?php
class Cron_model extends MO_Model
{
function __construct()
{
parent::__construct();
}
public function __construct()
{
parent::__construct();
}
}
//nowhitesp
//nowhitesp

File diff suppressed because it is too large Load Diff

View File

@ -2,144 +2,147 @@
class Hero_model extends MO_Model
{
function __construct()
{
parent::__construct();
}
function get_heroes($userid)
{
$sql = "SELECT * FROM heroes WHERE userid = ? AND deleted = '0'";
$q = $this->db->query($sql, array($userid));
if ($q->num_rows())
return $q->result_array();
return FALSE;
}
function select_hero($id, $userid)
{
$sql = "SELECT userid,deleted FROM heroes WHERE id = ?";
$q = $this->db->query($sql, array($id));
if (!$q->num_rows())
return FALSE;
$res = $q->row_array();
if ($res['userid'] != $userid || $res['deleted'])
return FALSE;
$sql = "UPDATE heroes SET selected = 0 WHERE userid = ?";
$this->db->query($sql, array($userid));
$sql = "UPDATE heroes SET selected = 1 WHERE id = ?";
$this->db->query($sql, array($id));
return TRUE;
}
function get_hero($id, $userid)
{
$sql = "SELECT * FROM heroes WHERE id = ? AND userid = ?";
$q = $this->db->query($sql, array($id, $userid));
if ($q->num_rows())
return $q->row_array();
return FALSE;
}
function delete_hero($id, $userid)
{
$sql = "SELECT * FROM heroes WHERE id = ?";
$q = $this->db->query($sql, array($id));
if (!$q->num_rows())
return FALSE;
$res = $q->row_array();
if ($res['deleted'])
return FALSE;
if ($userid != $res['userid'])
return FALSE;
if ($res['selected'])
public function __construct()
{
$sql = "SELECT * FROM heroes WHERE userid = ? AND deleted = '0'";
$q = $this->db->query($sql, array($userid));
if (!$q->num_rows())
return TRUE;
$data = $q->result_array();
foreach ($data as $row)
{
if ($row['id'] != $id)
{
$sql = "UPDATE heroes SET selected = '1' WHERE id = ?";
$this->db->query($sql, array($row['id']));
break;
}
}
parent::__construct();
}
$sql = "UPDATE heroes SET deleted='1', delete_name = '" . $res['name'] . "', name=''
public function get_heroes($userid)
{
$sql = "SELECT * FROM heroes WHERE userid = ? AND deleted = '0'";
$q = $this->db->query($sql, array($userid));
if ($q->num_rows()) {
return $q->result_array();
}
return false;
}
public function select_hero($id, $userid)
{
$sql = "SELECT userid,deleted FROM heroes WHERE id = ?";
$q = $this->db->query($sql, array($id));
if (!$q->num_rows()) {
return false;
}
$res = $q->row_array();
if ($res['userid'] != $userid || $res['deleted']) {
return false;
}
$sql = "UPDATE heroes SET selected = 0 WHERE userid = ?";
$this->db->query($sql, array($userid));
$sql = "UPDATE heroes SET selected = 1 WHERE id = ?";
$this->db->query($sql, array($id));
return true;
}
public function get_hero($id, $userid)
{
$sql = "SELECT * FROM heroes WHERE id = ? AND userid = ?";
$q = $this->db->query($sql, array($id, $userid));
if ($q->num_rows()) {
return $q->row_array();
}
return false;
}
public function delete_hero($id, $userid)
{
$sql = "SELECT * FROM heroes WHERE id = ?";
$q = $this->db->query($sql, array($id));
if (!$q->num_rows()) {
return false;
}
$res = $q->row_array();
if ($res['deleted']) {
return false;
}
if ($userid != $res['userid']) {
return false;
}
if ($res['selected']) {
$sql = "SELECT * FROM heroes WHERE userid = ? AND deleted = '0'";
$q = $this->db->query($sql, array($userid));
if (!$q->num_rows()) {
return true;
}
$data = $q->result_array();
foreach ($data as $row) {
if ($row['id'] != $id) {
$sql = "UPDATE heroes SET selected = '1' WHERE id = ?";
$this->db->query($sql, array($row['id']));
break;
}
}
}
$sql = "UPDATE heroes SET deleted='1', delete_name = '" . $res['name'] . "', name=''
WHERE id = ?";
$this->db->query($sql, array($id));
$this->db->query($sql, array($id));
return TRUE;
}
// function get_hero_admin($id)? or gm?
function create($data, $userid)
{
$name = ucfirst(mb_strtolower($data['name'], 'UTF-8'));
if ($gender == 1)
{
$av = 'characters/base/male.png';
$avt = 'characters/base/male_thumb.png';
}
else
{
$av = 'characters/base/female.png';
$avt = 'characters/base/female_thumb.png';
return true;
}
$sql = "UPDATE heroes SET selected='0' WHERE userid = ?";
// function get_hero_admin($id)? or gm?
$this->db->query($sql, array($userid));
public function create($data, $userid)
{
$name = ucfirst(mb_strtolower($data['name'], 'UTF-8'));
$sql = "SELECT * FROM hero_templates WHERE id = ?";
if ($gender == 1) {
$av = 'characters/base/male.png';
$avt = 'characters/base/male_thumb.png';
} else {
$av = 'characters/base/female.png';
$avt = 'characters/base/female_thumb.png';
}
$q = $this->db->query($sql, array($data['class']));
$sql = "UPDATE heroes SET selected='0' WHERE userid = ?";
if (!$q->num_rows())
return FALSE;
$this->db->query($sql, array($userid));
$cd = $q->row_array();
$sql = "SELECT * FROM hero_templates WHERE id = ?";
//getting inventory template, and applying the stats
$q = $this->db->query($sql, array($data['class']));
if (!$q->num_rows()) {
return false;
}
$cd = $q->row_array();
//getting inventory template, and applying the stats
$sql = "INSERT INTO heroes
$sql = "INSERT INTO heroes
VALUES(default, '$userid', ?, default, default,
?, default, '" . $cd['max_health'] . "', '" . $cd['max_mana'] . "', '" . $cd['max_health'] . "',
'" . $cd['max_mana'] . "', default, default, '" . $cd['nomod_max_health'] . "',
@ -165,58 +168,61 @@ class Hero_model extends MO_Model
'" . $cd['nomod_heal_min'] . "', '" . $cd['nomod_heal_max'] . "', default, default, ?,
default, ?, ?, default, '')";
$this->db->query($sql, array($name, $data['class'], $data['gender'], $av, $avt));
$this->db->query($sql, array($name, $data['class'], $data['gender'], $av, $avt));
//add invertory here
//add invertory here
//add starter spells
//make actionbar entry
}
}
function hero_name_is_unique($name)
{
$name = ucfirst(mb_strtolower($name, 'UTF-8'));
public function hero_name_is_unique($name)
{
$name = ucfirst(mb_strtolower($name, 'UTF-8'));
$sql = "SELECT * FROM heroes WHERE name = ? LIMIT 0, 1";
$sql = "SELECT * FROM heroes WHERE name = ? LIMIT 0, 1";
$q = $this->db->query($sql, array($name));
$q = $this->db->query($sql, array($name));
if ($q->num_rows())
return FALSE;
else
return TRUE;
}
if ($q->num_rows()) {
return false;
} else {
return true;
}
}
function all_hero_templates_admin()
{
$sql = "SELECT * FROM hero_templates";
public function all_hero_templates_admin()
{
$sql = "SELECT * FROM hero_templates";
$q = $this->db->query($sql);
$q = $this->db->query($sql);
if ($q->num_rows())
return $q->result_array();
else
return FALSE;
}
if ($q->num_rows()) {
return $q->result_array();
} else {
return false;
}
}
function get_template_admin($id)
{
$sql = "SELECT * FROM hero_templates WHERE id = '$id'";
public function get_template_admin($id)
{
$sql = "SELECT * FROM hero_templates WHERE id = '$id'";
$q = $this->db->query($sql);
$q = $this->db->query($sql);
if ($q->num_rows())
return $q->row_array();
else
return FALSE;
}
if ($q->num_rows()) {
return $q->row_array();
} else {
return false;
}
}
function edit_template_admin($d)
{
$c = $this->template_calc_stats($d, 'edit');
public function edit_template_admin($d)
{
$c = $this->template_calc_stats($d, 'edit');
$sql = "UPDATE hero_templates
$sql = "UPDATE hero_templates
SET classname = '" . $d['classname'] . "',
nomod_max_health = '" . $d['nomod_max_health'] . "',
nomod_max_mana = '" . $d['nomod_max_mana'] . "',
@ -251,21 +257,21 @@ class Hero_model extends MO_Model
heal_max = '" . $c['heal_max'] . "'
WHERE id = '" . $d['id'] . "'";
$this->db->query($sql);
$this->db->query($sql);
$this->_create_sql($sql);
}
$this->_create_sql($sql);
}
function add_template_admin($d)
{
//0 armor is being added, because when adding a new class, eqipments shouldn't exists in db
public function add_template_admin($d)
{
//0 armor is being added, because when adding a new class, eqipments shouldn't exists in db
//think about this!
//maybe this is uniform in template and normal mode! or can be made uniform
$c = $this->template_calc_stats($d, 'add');
//think about this!
//maybe this is uniform in template and normal mode! or can be made uniform
$c = $this->template_calc_stats($d, 'add');
$sql = "INSERT INTO hero_templates
$sql = "INSERT INTO hero_templates
VALUES(default, '" . $d['classname'] . "', '" . $d['nomod_max_health'] . "',
'" . $d['nomod_max_mana'] . "', '" . $c['max_health'] . "',
'" . $c['max_mana'] . "', '" . $d['agility'] . "', '" . $d['strength'] . "',
@ -281,51 +287,50 @@ class Hero_model extends MO_Model
'" . $d['nomod_heal_min'] . "',
'" . $d['nomod_heal_max'] . "', '" . $c['heal_min'] . "', '" . $c['heal_max'] . "')";
$this->db->query($sql);
$this->db->query($sql);
$this->_create_sql($sql);
}
//this is for templates (calculating all stats)
//type can be add and edit -> edit does thing like armor calc, and damage
function template_calc_stats($d, $type)
{
$class = $d['classname'];
$c['max_health'] = $this->hero_stat($class, 'max_health', $d);
$c['max_mana'] = $this->hero_stat($class, 'max_mana', $d);
$c['attackpower'] = $this->hero_stat($class, 'attackpower', $d);
$c['crit'] = $this->hero_stat($class, 'crit', $d);
$c['parry'] = $this->hero_stat($class, 'parry', $d);
$c['dodge'] = $this->hero_stat($class, 'dodge', $d);
$c['damage_min'] = $this->hero_stat($class, 'damage_min', $d);
$c['damage_max'] = $this->hero_stat($class, 'damage_max', $d);
$c['ranged_damage_min'] = $this->hero_stat($class, 'ranged_damage_min', $d);
$c['ranged_damage_max'] = $this->hero_stat($class, 'ranged_damage_max', $d);
$c['heal_min'] = $this->hero_stat($class, 'heal_min', $d);
$c['heal_max'] = $this->hero_stat($class, 'heal_max', $d);
if ($type == 'edit')
{
//STUB
//armor, damage, heal from items
$c['armor'] = 0;
$c['nomod_damage_min'] = $d['nomod_damage_min'];
$c['nomod_damage_max'] = $d['nomod_damage_max'];
$c['nomod_ranged_damage_min'] = $d['nomod_ranged_damage_min'];
$c['nomod_ranged_damage_max'] = $d['nomod_ranged_damage_max'];
$c['nomod_heal_min'] = $d['nomod_heal_min'];
$c['nomod_heal_max'] = $d['nomod_heal_max'];
$this->_create_sql($sql);
}
return $c;
}
//this is for templates (calculating all stats)
//type can be add and edit -> edit does thing like armor calc, and damage
public function template_calc_stats($d, $type)
{
$class = $d['classname'];
$c['max_health'] = $this->hero_stat($class, 'max_health', $d);
$c['max_mana'] = $this->hero_stat($class, 'max_mana', $d);
$c['attackpower'] = $this->hero_stat($class, 'attackpower', $d);
$c['crit'] = $this->hero_stat($class, 'crit', $d);
$c['parry'] = $this->hero_stat($class, 'parry', $d);
$c['dodge'] = $this->hero_stat($class, 'dodge', $d);
$c['damage_min'] = $this->hero_stat($class, 'damage_min', $d);
$c['damage_max'] = $this->hero_stat($class, 'damage_max', $d);
$c['ranged_damage_min'] = $this->hero_stat($class, 'ranged_damage_min', $d);
$c['ranged_damage_max'] = $this->hero_stat($class, 'ranged_damage_max', $d);
$c['heal_min'] = $this->hero_stat($class, 'heal_min', $d);
$c['heal_max'] = $this->hero_stat($class, 'heal_max', $d);
if ($type == 'edit') {
//STUB
//armor, damage, heal from items
$c['armor'] = 0;
$c['nomod_damage_min'] = $d['nomod_damage_min'];
$c['nomod_damage_max'] = $d['nomod_damage_max'];
$c['nomod_ranged_damage_min'] = $d['nomod_ranged_damage_min'];
$c['nomod_ranged_damage_max'] = $d['nomod_ranged_damage_max'];
$c['nomod_heal_min'] = $d['nomod_heal_min'];
$c['nomod_heal_max'] = $d['nomod_heal_max'];
}
return $c;
}
}
//nowhitesp
//nowhitesp

View File

@ -1,298 +1,283 @@
<?php
class Image_model extends MO_Model
{
function __construct()
{
parent::__construct();
}
function apply_menu_images($data)
{
$path = './img/generated/';
$this->load->library('image_lib');
if ($data['apply_all'])
$this->prepare_dir('menu', $data['file'], $data['menu_group']);
else
$this->prepare_dir('menu', $data['file'], FALSE, $data['wm_text']);
if (!$data['apply_all'])
public function __construct()
{
$data['source_image'] = $path . $data['wm_text'] . '.png';
$this->image_lib->initialize($data);
$this->image_lib->watermark();
return;
parent::__construct();
}
//apply all is set
$menu_list = $this->get_menu_list($data['menu_group']);
$menu_file_list = $this->get_menu_file_list($data['menu_group']);
for ($i = 0; $i < sizeof($menu_list); $i++)
public function apply_menu_images($data)
{
$data['source_image'] = $path . $menu_file_list[$i] . '.png';
$data['wm_text'] = $menu_list[$i];
$path = './img/generated/';
$this->image_lib->initialize($data);
$this->image_lib->watermark();
$this->image_lib->clear();
}
}
$this->load->library('image_lib');
function prepare_dir($for, $sourcefile, $group = 1, $filename = FALSE)
{
$path = './img/generated/';
$source = './img/imggen/' . $sourcefile;
if ($data['apply_all']) {
$this->prepare_dir('menu', $data['file'], $data['menu_group']);
} else {
$this->prepare_dir('menu', $data['file'], false, $data['wm_text']);
}
$this->load->helper('file');
if (!$data['apply_all']) {
$data['source_image'] = $path . $data['wm_text'] . '.png';
delete_files($path, FALSE);
$this->image_lib->initialize($data);
if ($for == 'menu')
{
$img = read_file($source);
$this->image_lib->watermark();
if (!$filename)
{
$menu_list = $this->get_menu_file_list($group);
return;
}
foreach ($menu_list as $row)
{
$file = $path . $row . '.png';
//apply all is set
$menu_list = $this->get_menu_list($data['menu_group']);
$menu_file_list = $this->get_menu_file_list($data['menu_group']);
write_file($file, $img);
}
}
else
{
$file = $path . $filename . '.png';
for ($i = 0; $i < sizeof($menu_list); $i++) {
$data['source_image'] = $path . $menu_file_list[$i] . '.png';
$data['wm_text'] = $menu_list[$i];
write_file($file, $img);
}
$this->image_lib->initialize($data);
$this->image_lib->watermark();
$this->image_lib->clear();
}
}
}
public function prepare_dir($for, $sourcefile, $group = 1, $filename = false)
{
$path = './img/generated/';
$source = './img/imggen/' . $sourcefile;
function get_menu_list($group = 1)
{
if ($group == 1)
{
//select village vill be omitted since it will need a different style button with a ˇ
$data[] = 'News';
$data[] = 'Village';
$data[] = 'Select Village';
$data[] = 'Forum';
$data[] = 'Changelog';
$data[] = 'Settings';
$data[] = 'Logout';
$data[] = 'Forum Mod Panel';
$data[] = 'GM Panel';
$data[] = 'Admin Panel';
}
if ($group == 2)
{
$data[] = 'Stats';
$this->load->helper('file');
delete_files($path, false);
if ($for == 'menu') {
$img = read_file($source);
if (!$filename) {
$menu_list = $this->get_menu_file_list($group);
foreach ($menu_list as $row) {
$file = $path . $row . '.png';
write_file($file, $img);
}
} else {
$file = $path . $filename . '.png';
write_file($file, $img);
}
}
}
return $data;
}
public function get_menu_list($group = 1)
{
if ($group == 1) {
//select village vill be omitted since it will need a different style button with a ˇ
$data[] = 'News';
$data[] = 'Village';
$data[] = 'Select Village';
$data[] = 'Forum';
$data[] = 'Changelog';
$data[] = 'Settings';
$data[] = 'Logout';
$data[] = 'Forum Mod Panel';
$data[] = 'GM Panel';
$data[] = 'Admin Panel';
}
if ($group == 2) {
$data[] = 'Stats';
}
function get_menu_file_list($group = 1)
{
if ($group == 1)
{
//select village vill be omitted since it will need a different style button with a ˇ
$data[] = 'news';
$data[] = 'village';
$data[] = 'select_village';
$data[] = 'forum';
$data[] = 'changelog';
$data[] = 'settings';
$data[] = 'logout';
$data[] = 'forum_mod_panel';
$data[] = 'gm_panel';
$data[] = 'admin_panel';
}
if ($group == 2)
{
$data[] = 'stats';
return $data;
}
return $data;
}
public function get_menu_file_list($group = 1)
{
if ($group == 1) {
//select village vill be omitted since it will need a different style button with a ˇ
$data[] = 'news';
$data[] = 'village';
$data[] = 'select_village';
$data[] = 'forum';
$data[] = 'changelog';
$data[] = 'settings';
$data[] = 'logout';
$data[] = 'forum_mod_panel';
$data[] = 'gm_panel';
$data[] = 'admin_panel';
}
if ($group == 2) {
$data[] = 'stats';
}
function get_menu_group_list_drop()
{
$data = array(
return $data;
}
public function get_menu_group_list_drop()
{
$data = array(
'1' => 'main',
'2' => 'alt1');
return $data;
}
function apply_slot_images($data)
{
$path = './img/generated/';
$this->load->library('image_lib');
$this->prepare_dir('menu', $data['file'], FALSE, 'gen');
$data['source_image'] = $path . 'gen.png';
$this->image_lib->initialize($data);
$this->image_lib->watermark();
$this->image_lib->clear();
$data['wm_type'] = 'text';
$data['wm_text'] = $data['rank_text'];
$data['wm_font_size'] = $data['rank_font_size'];
$data['wm_vrt_alignment'] = $data['rank_v_align'];
$data['wm_hor_alignment'] = $data['rank_h_align'];
$data['wm_hor_offset'] = $data['rank_h_offset'];
$data['wm_vrt_offset'] = $data['rank_v_offset'];
$data['padding'] = $data['rank_padding'];
$this->image_lib->initialize($data);
$this->image_lib->watermark();
}
function get_file_list_drop()
{
$this->load->helper('directory');
$dir = directory_map('./img/imggen/', 1);
foreach ($dir as $row)
{
$a = explode('.', $row);
if (isset($a[1]))
if ($a[1] == 'png' || $a[1] == 'PNG')
$data[$row] = $row;
return $data;
}
return $data;
}
function get_font_list_drop()
{
$this->load->helper('directory');
$dir = directory_map('./system/fonts', 1);
foreach ($dir as $row)
public function apply_slot_images($data)
{
$a = explode('.', $row);
$path = './img/generated/';
if ($a[1] == 'ttf' || $a['1'] == 'TTF')
{
$data[$row] = $row;
}
$this->load->library('image_lib');
$this->prepare_dir('menu', $data['file'], false, 'gen');
$data['source_image'] = $path . 'gen.png';
$this->image_lib->initialize($data);
$this->image_lib->watermark();
$this->image_lib->clear();
$data['wm_type'] = 'text';
$data['wm_text'] = $data['rank_text'];
$data['wm_font_size'] = $data['rank_font_size'];
$data['wm_vrt_alignment'] = $data['rank_v_align'];
$data['wm_hor_alignment'] = $data['rank_h_align'];
$data['wm_hor_offset'] = $data['rank_h_offset'];
$data['wm_vrt_offset'] = $data['rank_v_offset'];
$data['padding'] = $data['rank_padding'];
$this->image_lib->initialize($data);
$this->image_lib->watermark();
}
return $data;
}
public function get_file_list_drop()
{
$this->load->helper('directory');
function get_v_align_drop()
{
$data = array(
$dir = directory_map('./img/imggen/', 1);
foreach ($dir as $row) {
$a = explode('.', $row);
if (isset($a[1])) {
if ($a[1] == 'png' || $a[1] == 'PNG') {
$data[$row] = $row;
}
}
}
return $data;
}
public function get_font_list_drop()
{
$this->load->helper('directory');
$dir = directory_map('./system/fonts', 1);
foreach ($dir as $row) {
$a = explode('.', $row);
if ($a[1] == 'ttf' || $a['1'] == 'TTF') {
$data[$row] = $row;
}
}
return $data;
}
public function get_v_align_drop()
{
$data = array(
'top' => 'top',
'middle' => 'middle',
'bottom' => 'bottom');
return $data;
}
return $data;
}
function get_h_align_drop()
{
$data = array(
public function get_h_align_drop()
{
$data = array(
'left' => 'left',
'center' => 'center',
'right' => 'right');
return $data;
}
function get_overlay_list_drop()
{
$this->load->helper('directory');
$dir = directory_map('./img/imggen/overlay/', 1);
foreach ($dir as $row)
return $data;
}
public function get_overlay_list_drop()
{
$data[$row] = $row;
$this->load->helper('directory');
$dir = directory_map('./img/imggen/overlay/', 1);
foreach ($dir as $row) {
$data[$row] = $row;
}
return $data;
}
return $data;
}
public function save_menu_data($data)
{
$a = 'type : ' . $data['wm_type'] . "\n";
$a .= 'quality: ' . $data['quality'] . "\n";
$a .= 'file: ' . $data['file'] . "\n";
$a .= 'padding: ' . $data['padding'] . "\n";
$a .= 'vert alignment: ' . $data['wm_vrt_alignment'] . "\n";
$a .= 'hor alignment: ' . $data['wm_hor_alignment'] . "\n";
$a .= 'hor offset: ' . $data['wm_hor_offset'] . "\n";
$a .= 'vert offset: ' . $data['wm_vrt_offset'] . "\n";
$a .= 'text: ' . $data['wm_text'] . "\n";
$a .= 'font path: ' . $data['wm_font_path'] . "\n";
$a .= 'font size: ' . $data['wm_font_size'] . "\n";
$a .= 'font color: ' . $data['wm_font_color'] . "\n";
$a .= 'shadow color: ' . $data['wm_shadow_color'] . "\n";
$a .= 'shadow_distance: ' . $data['wm_shadow_distance'] . "\n";
$a .= 'apply all: ' . $data['apply_all'] . "\n";
$a .= 'Menu Group: ' . $data['menu_group'] . "\n";
function save_menu_data($data)
{
$a = 'type : ' . $data['wm_type'] . "\n";
$a .= 'quality: ' . $data['quality'] . "\n";
$a .= 'file: ' . $data['file'] . "\n";
$a .= 'padding: ' . $data['padding'] . "\n";
$a .= 'vert alignment: ' . $data['wm_vrt_alignment'] . "\n";
$a .= 'hor alignment: ' . $data['wm_hor_alignment'] . "\n";
$a .= 'hor offset: ' . $data['wm_hor_offset'] . "\n";
$a .= 'vert offset: ' . $data['wm_vrt_offset'] . "\n";
$a .= 'text: ' . $data['wm_text'] . "\n";
$a .= 'font path: ' . $data['wm_font_path'] . "\n";
$a .= 'font size: ' . $data['wm_font_size'] . "\n";
$a .= 'font color: ' . $data['wm_font_color'] . "\n";
$a .= 'shadow color: ' . $data['wm_shadow_color'] . "\n";
$a .= 'shadow_distance: ' . $data['wm_shadow_distance'] . "\n";
$a .= 'apply all: ' . $data['apply_all'] . "\n";
$a .= 'Menu Group: ' . $data['menu_group'] . "\n";
$this->load->helper('file');
$this->load->helper('file');
write_file('./img/generated/settings.txt', $a);
}
write_file('./img/generated/settings.txt', $a);
}
public function save_slot_data($data)
{
$a = 'type : ' . $data['wm_type'] . "\n";
$a .= 'quality: ' . $data['quality'] . "\n";
$a .= 'file: ' . $data['file'] . "\n";
$a .= 'padding: ' . $data['padding'] . "\n";
$a .= 'vert alignment: ' . $data['wm_vrt_alignment'] . "\n";
$a .= 'hor alignment: ' . $data['wm_hor_alignment'] . "\n";
$a .= 'hor offset: ' . $data['wm_hor_offset'] . "\n";
$a .= 'vert offset: ' . $data['wm_vrt_offset'] . "\n";
$a .= 'text: ' . $data['wm_text'] . "\n";
$a .= 'font path: ' . $data['wm_font_path'] . "\n";
$a .= 'font size: ' . $data['wm_font_size'] . "\n";
$a .= 'font color: ' . $data['wm_font_color'] . "\n";
$a .= 'shadow color: ' . $data['wm_shadow_color'] . "\n";
$a .= 'shadow_distance: ' . $data['wm_shadow_distance'] . "\n";
$a .= '------------------------image---------------------------' . "\n";
$a .= 'overlay image: ' . $data['wm_overlay_path'] . "\n";
$a .= 'opacity: ' . $data['wm_opacity'] . "\n";
$a .= 'x transp: ' . $data['wm_x_transp'] . "\n";
$a .= 'y transp: ' . $data['wm_y_transp'] . "\n";
$a .= '------------------------rank----------------------------' . "\n";
$a .= 'text: ' . $data['rank_text'] . "\n";
$a .= 'font size: ' . $data['rank_font_size'] . "\n";
$a .= 'V align: ' . $data['rank_v_align'] . "\n";
$a .= 'H align: ' . $data['rank_h_align'] . "\n";
$a .= 'H offset: ' . $data['rank_h_offset'] . "\n";
$a .= 'V offset: ' . $data['rank_v_offset'] . "\n";
$a .= 'padding: ' . $data['rank_padding'] . "\n";
function save_slot_data($data)
{
$a = 'type : ' . $data['wm_type'] . "\n";
$a .= 'quality: ' . $data['quality'] . "\n";
$a .= 'file: ' . $data['file'] . "\n";
$a .= 'padding: ' . $data['padding'] . "\n";
$a .= 'vert alignment: ' . $data['wm_vrt_alignment'] . "\n";
$a .= 'hor alignment: ' . $data['wm_hor_alignment'] . "\n";
$a .= 'hor offset: ' . $data['wm_hor_offset'] . "\n";
$a .= 'vert offset: ' . $data['wm_vrt_offset'] . "\n";
$a .= 'text: ' . $data['wm_text'] . "\n";
$a .= 'font path: ' . $data['wm_font_path'] . "\n";
$a .= 'font size: ' . $data['wm_font_size'] . "\n";
$a .= 'font color: ' . $data['wm_font_color'] . "\n";
$a .= 'shadow color: ' . $data['wm_shadow_color'] . "\n";
$a .= 'shadow_distance: ' . $data['wm_shadow_distance'] . "\n";
$a .= '------------------------image---------------------------' . "\n";
$a .= 'overlay image: ' . $data['wm_overlay_path'] . "\n";
$a .= 'opacity: ' . $data['wm_opacity'] . "\n";
$a .= 'x transp: ' . $data['wm_x_transp'] . "\n";
$a .= 'y transp: ' . $data['wm_y_transp'] . "\n";
$a .= '------------------------rank----------------------------' . "\n";
$a .= 'text: ' . $data['rank_text'] . "\n";
$a .= 'font size: ' . $data['rank_font_size'] . "\n";
$a .= 'V align: ' . $data['rank_v_align'] . "\n";
$a .= 'H align: ' . $data['rank_h_align'] . "\n";
$a .= 'H offset: ' . $data['rank_h_offset'] . "\n";
$a .= 'V offset: ' . $data['rank_v_offset'] . "\n";
$a .= 'padding: ' . $data['rank_padding'] . "\n";
$this->load->helper('file');
$this->load->helper('file');
write_file('./img/generated/settings.txt', $a);
}
write_file('./img/generated/settings.txt', $a);
}
}
//nowhitesp
//nowhitesp

File diff suppressed because it is too large Load Diff

View File

@ -1,82 +1,83 @@
<?php
class Log_model extends MO_Model
{
function __construct()
{
parent::__construct();
}
function delete_combat_log($id, $villageid)
{
$sql = "SELECT * FROM combat_logs WHERE id='$id'";
$q = $this->db->query($sql);
if (!$q->num_rows())
return;
$res = $q->row_array();
if ($res['villageid'] != $villageid)
return;
$sql = "DELETE FROM combat_logs WHERE id='$id'";
$this->db->query($sql);
}
function get_combat_log($id, $villageid)
{
$sql = "SELECT * FROM combat_logs WHERE id='$id'";
$q = $this->db->query($sql);
if (!$q->num_rows())
return FALSE;
$res = $q->row_array();
if ($res['villageid'] != $villageid)
return FALSE;
if ($res['new'])
public function __construct()
{
$sql = "UPDATE combat_logs SET new='0' WHERE id='$id'";
$this->db->query($sql);
parent::__construct();
}
return $res;
}
function get_combat_logs($villageid)
{
$sql = "SELECT * FROM combat_logs WHERE villageid='$villageid' ORDER BY time DESC";
$q = $this->db->query($sql);
if (!$q->num_rows())
return FALSE;
$res = $q->result_array();
$new = FALSE;
foreach ($res as $row)
public function delete_combat_log($id, $villageid)
{
if ($row['new'])
{
$new = TRUE;
break;
}
$sql = "SELECT * FROM combat_logs WHERE id='$id'";
$q = $this->db->query($sql);
if (!$q->num_rows()) {
return;
}
$res = $q->row_array();
if ($res['villageid'] != $villageid) {
return;
}
$sql = "DELETE FROM combat_logs WHERE id='$id'";
$this->db->query($sql);
}
if (!$new)
public function get_combat_log($id, $villageid)
{
$sql = "UPDATE villages SET new_log='0' WHERE id='$villageid'";
$sql = "SELECT * FROM combat_logs WHERE id='$id'";
$this->db->query($sql);
$q = $this->db->query($sql);
if (!$q->num_rows()) {
return false;
}
$res = $q->row_array();
if ($res['villageid'] != $villageid) {
return false;
}
if ($res['new']) {
$sql = "UPDATE combat_logs SET new='0' WHERE id='$id'";
$this->db->query($sql);
}
return $res;
}
public function get_combat_logs($villageid)
{
$sql = "SELECT * FROM combat_logs WHERE villageid='$villageid' ORDER BY time DESC";
return $res;
}
$q = $this->db->query($sql);
if (!$q->num_rows()) {
return false;
}
$res = $q->result_array();
$new = false;
foreach ($res as $row) {
if ($row['new']) {
$new = true;
break;
}
}
if (!$new) {
$sql = "UPDATE villages SET new_log='0' WHERE id='$villageid'";
$this->db->query($sql);
}
return $res;
}
}
//nowhitesp
//nowhitesp

View File

@ -2,233 +2,235 @@
class Mail_model extends MO_Model
{
function __construct()
{
parent::__construct();
}
public function __construct()
{
parent::__construct();
}
function save_draft($data, $userid)
{
//values id, userid, friend, name, X, Y, time, subject, body
$sql = "INSERT INTO mail_drafts
public function save_draft($data, $userid)
{
//values id, userid, friend, name, X, Y, time, subject, body
$sql = "INSERT INTO mail_drafts
VALUES(default, '$userid', ?, ?, ?, ?, '" . time() . "', ?, ?)";
//friend, name, X, Y, subject, body
$this->db->query($sql, array(0, $data['name'], 0, 0, $data['subject'], $data['message']));
}
//friend, name, X, Y, subject, body
$this->db->query($sql, array(0, $data['name'], 0, 0, $data['subject'], $data['message']));
}
function get_drafts($userid)
{
$sql = "SELECT * FROM mail_drafts WHERE userid='$userid'";
public function get_drafts($userid)
{
$sql = "SELECT * FROM mail_drafts WHERE userid='$userid'";
$q = $this->db->query($sql);
$q = $this->db->query($sql);
if (!$q->num_rows())
return FALSE;
if (!$q->num_rows()) {
return false;
}
return $q->result_array();
}
return $q->result_array();
}
function get_draft($id, $userid)
{
$sql = "SELECT * FROM mail_drafts WHERE id = ?";
public function get_draft($id, $userid)
{
$sql = "SELECT * FROM mail_drafts WHERE id = ?";
$q = $this->db->query($sql, array($id));
$q = $this->db->query($sql, array($id));
if (!$q->num_rows())
return FALSE;
if (!$q->num_rows()) {
return false;
}
$res = $q->row_array();
$res = $q->row_array();
if ($res['userid'] != $userid)
return FALSE;
if ($res['userid'] != $userid) {
return false;
}
return $res;
}
return $res;
}
function delete_draft($id, $userid)
{
$sql = "DELETE FROM mail_drafts WHERE id = ? AND userid = ?";
public function delete_draft($id, $userid)
{
$sql = "DELETE FROM mail_drafts WHERE id = ? AND userid = ?";
$this->db->query($sql, array($id, $userid));
}
$this->db->query($sql, array($id, $userid));
}
function get_inbox($userid, $new)
{
$sql = "SELECT mails.*,users.username FROM mails
public function get_inbox($userid, $new)
{
$sql = "SELECT mails.*,users.username FROM mails
LEFT JOIN users on mails.sender=users.id
WHERE owner='$userid'
ORDER BY time DESC";
$q = $this->db->query($sql);
$q = $this->db->query($sql);
if (!$q->num_rows())
return FALSE;
if (!$q->num_rows()) {
return false;
}
$res = $q->result_array();
$res = $q->result_array();
if (!$new)
return $res;
if (!$new) {
return $res;
}
$found = FALSE;
foreach ($res as $row)
{
if ($row['new'])
{
$found = TRUE;
break;
}
$found = false;
foreach ($res as $row) {
if ($row['new']) {
$found = true;
break;
}
}
if ($found) {
return $res;
}
$sql = "UPDATE users SET new_mail='0' WHERE id='$userid'";
$this->db->query($sql);
return $res;
}
if ($found)
return $res;
$sql = "UPDATE users SET new_mail='0' WHERE id='$userid'";
$this->db->query($sql);
return $res;
}
function send_message($data, $userid)
{
$sql = "SELECT * FROM users WHERE username = ?";
$q = $this->db->query($sql, array($data['name']));
if (!$q->num_rows())
return;
$res = $q->row_array();
$data['subject'] = htmlspecialchars($data['subject'], ENT_HTML5, 'UTF-8');
if (strlen($data['subject']) >= 45)
$data['subject'] = (substr($data['subject'], 0, 45) . '...');
//determining line endings
$w = substr_count($data['message'], "\r\n");
if ($w)
$exp = "\r\n";
else
$exp = "\n";
$message = explode($exp, $data['message']);
if ($message)
public function send_message($data, $userid)
{
$d = "";
foreach ($message as $row)
{
if (strlen($row) > 70)
{
//split into multiple lines
for ($i = 0; $i <= (floor(strlen($row) / 70)); $i++)
{
$sub = substr($row, (0 + ($i * 70)), 70);
$sql = "SELECT * FROM users WHERE username = ?";
$d .= $sub;
$q = $this->db->query($sql, array($data['name']));
if (strlen($sub) == 70)
$d .= "«";
if (!$q->num_rows()) {
return;
}
$d .= "\r\n";
}
}
else
{
$d .= $row . "\r\n";
}
}
$res = $q->row_array();
$data['message'] = $d;
}
$data['subject'] = htmlspecialchars($data['subject'], ENT_HTML5, 'UTF-8');
$data['message'] = htmlspecialchars($data['message'], ENT_HTML5, 'UTF-8');
if (strlen($data['subject']) >= 45) {
$data['subject'] = (substr($data['subject'], 0, 45) . '...');
}
$breaks = array("\r\n", "\n");
$text = str_ireplace($breaks, "<br />", $data['message']);
//determining line endings
$w = substr_count($data['message'], "\r\n");
$sql = "INSERT INTO mails VALUES(default,
if ($w) {
$exp = "\r\n";
} else {
$exp = "\n";
}
$message = explode($exp, $data['message']);
if ($message) {
$d = "";
foreach ($message as $row) {
if (strlen($row) > 70) {
//split into multiple lines
for ($i = 0; $i <= (floor(strlen($row) / 70)); $i++) {
$sub = substr($row, (0 + ($i * 70)), 70);
$d .= $sub;
if (strlen($sub) == 70) {
$d .= "«";
}
$d .= "\r\n";
}
} else {
$d .= $row . "\r\n";
}
}
$data['message'] = $d;
}
$data['message'] = htmlspecialchars($data['message'], ENT_HTML5, 'UTF-8');
$breaks = array("\r\n", "\n");
$text = str_ireplace($breaks, "<br />", $data['message']);
$sql = "INSERT INTO mails VALUES(default,
'" . $res['id'] . "', '$userid', '" . time() . "', ?, ?, '1')";
$this->db->query($sql, array($data['subject'], $text));
$this->db->query($sql, array($data['subject'], $text));
$sql = "UPDATE users SET new_mail='1' WHERE id='" . $res['id'] . "'";
$sql = "UPDATE users SET new_mail='1' WHERE id='" . $res['id'] . "'";
$this->db->query($sql);
$this->db->query($sql);
//saving mail to sent
//id, userid, to_id, to, time, subject, body
$sql = "INSERT INTO mail_sent VALUES(default, ?, ?, ?, " . time(). ", ?, ?)";
//saving mail to sent
//id, userid, to_id, to, time, subject, body
$sql = "INSERT INTO mail_sent VALUES(default, ?, ?, ?, " . time(). ", ?, ?)";
$sent = array($userid, $res['id'], $res['username'], $data['subject'], $data['message']);
$sent = array($userid, $res['id'], $res['username'], $data['subject'], $data['message']);
$this->db->query($sql, $sent);
}
$this->db->query($sql, $sent);
}
function get_mail($id, $userid, $edit = FALSE)
{
//querying userid here, so if the user types a random id into the browser bar, it won't return anything
$sql = "SELECT mails.*,users.username FROM mails
public function get_mail($id, $userid, $edit = false)
{
//querying userid here, so if the user types a random id into the browser bar, it won't return anything
$sql = "SELECT mails.*,users.username FROM mails
LEFT JOIN users ON mails.sender=users.id
WHERE mails.id = ? AND mails.owner = ?";
$q = $this->db->query($sql, array($id, $userid));
$q = $this->db->query($sql, array($id, $userid));
if (!$q->num_rows())
return FALSE;
if (!$q->num_rows()) {
return false;
}
$res = $q->row_array();
$res = $q->row_array();
if ($res['new'])
{
//userid is correct we can query with just the id
$sql = "UPDATE mails SET new='0' WHERE id = ?";
if ($res['new']) {
//userid is correct we can query with just the id
$sql = "UPDATE mails SET new='0' WHERE id = ?";
$this->db->query($sql, array($id));
$this->db->query($sql, array($id));
}
if ($edit) {
//just in case
$breaks = array("<br />","<br>","<br/>");
$data['body'] = str_ireplace($breaks, "\r\n", $data['body']);
$data['body'] = htmlspecialchars_decode($data['body'], ENT_HTML5, 'UTF-8');
$data['subject'] = htmlspecialchars_decode($data['subject'], ENT_HTML5, 'UTF-8');
}
return $res;
}
if ($edit)
public function get_sent($id, $userid)
{
//just in case
$breaks = array("<br />","<br>","<br/>");
//querying userid here, so if the user types a random id into the browser bar, it won't return anything
$sql = "SELECT * FROM mail_sent WHERE id = ? AND userid = ?";
$data['body'] = str_ireplace($breaks, "\r\n", $data['body']);
$q = $this->db->query($sql, array($id, $userid));
$data['body'] = htmlspecialchars_decode($data['body'], ENT_HTML5, 'UTF-8');
$data['subject'] = htmlspecialchars_decode($data['subject'], ENT_HTML5, 'UTF-8');
if (!$q->num_rows()) {
return false;
}
return $q->row_array();
}
return $res;
}
function get_sent($id, $userid)
{
//querying userid here, so if the user types a random id into the browser bar, it won't return anything
$sql = "SELECT * FROM mail_sent WHERE id = ? AND userid = ?";
public function get_all_sent($userid)
{
$sql = "SELECT * FROM mail_sent WHERE userid = ?";
$q = $this->db->query($sql, array($id, $userid));
$q = $this->db->query($sql, array($userid));
if (!$q->num_rows())
return FALSE;
if (!$q->num_rows()) {
return false;
}
return $q->row_array();
}
function get_all_sent($userid)
{
$sql = "SELECT * FROM mail_sent WHERE userid = ?";
$q = $this->db->query($sql, array($userid));
if (!$q->num_rows())
return FALSE;
return $q->result_array();
}
return $q->result_array();
}
}
//nowhitesp
//nowhitesp

View File

@ -2,114 +2,115 @@
class Map_model extends MO_Model
{
function __construct()
{
parent::__construct();
}
public function __construct()
{
parent::__construct();
}
function get_village_by_name($name)
{
$sql = "SELECT id FROM villages WHERE name LIKE '%" . $name . "%'";
public function get_village_by_name($name)
{
$sql = "SELECT id FROM villages WHERE name LIKE '%" . $name . "%'";
$q = $this->db->query($sql);
$q = $this->db->query($sql);
if (!$q->num_rows())
return FALSE;
if (!$q->num_rows()) {
return false;
}
$res = $q->row_array();
$res = $q->row_array();
return $this->get_village_coords($res['id']);
}
return $this->get_village_coords($res['id']);
}
function get_village_coords($vid)
{
$sql = "SELECT * FROM map WHERE type='3' AND villageid='$vid'";
$q = $this->db->query($sql);
public function get_village_coords($vid)
{
$sql = "SELECT * FROM map WHERE type='3' AND villageid='$vid'";
$q = $this->db->query($sql);
return $q->row_array();
}
return $q->row_array();
}
function get_map($x, $y)
{
if ($x < 7)
$x = 7;
public function get_map($x, $y)
{
if ($x < 7) {
$x = 7;
}
if ($y < 7)
$y = 7;
if ($y < 7) {
$y = 7;
}
if ($x > 235)
$x = 235;
if ($x > 235) {
$x = 235;
}
if ($y > 235)
$y = 235;
if ($y > 235) {
$y = 235;
}
$minx = $x - 6;
$maxx = $x + 6;
$miny = $y - 6;
$maxy = $y + 6;
$minx = $x - 6;
$maxx = $x + 6;
$miny = $y - 6;
$maxy = $y + 6;
//< at max so it gets 12 rows and cols
$sql = "SELECT map.*,ai_villages.name AS ai_name,villages.name FROM map
//< at max so it gets 12 rows and cols
$sql = "SELECT map.*,ai_villages.name AS ai_name,villages.name FROM map
LEFT JOIN ai_villages ON map.villageid=ai_villages.id AND map.type='4'
LEFT JOIN villages ON map.villageid=villages.id AND map.type='3'
WHERE ((map.X >= '$minx') AND (map.X < '$maxx')
AND (map.Y >= '$miny') AND (map.Y < '$maxy'))";
$q = $this->db->query($sql);
$q = $this->db->query($sql);
$res = $q->result_array();
$res = $q->result_array();
//preprocess it, so view only have to do a foreach
for ($sy = $miny; $sy < ($miny + 12); $sy++)
{
for ($sx = $minx; $sx < ($minx + 12); $sx++)
{
foreach ($res as $row)
{
if (($row['X'] == $sx) && ($row['Y'] == $sy))
{
$data[] = $row;
break;
}
}
}
//preprocess it, so view only have to do a foreach
for ($sy = $miny; $sy < ($miny + 12); $sy++) {
for ($sx = $minx; $sx < ($minx + 12); $sx++) {
foreach ($res as $row) {
if (($row['X'] == $sx) && ($row['Y'] == $sy)) {
$data[] = $row;
break;
}
}
}
}
return $data;
}
return $data;
}
function get_map_list_admin()
{
$this->load->helper('directory');
$map = directory_map('./sql/map/', 1);
foreach ($map as $row)
public function get_map_list_admin()
{
$a = explode('.', $row);
$this->load->helper('directory');
if (isset($a[1]))
{
if ($a[1] == 'sql')
$data[] = $row;
}
}
$map = directory_map('./sql/map/', 1);
foreach ($map as $row) {
$a = explode('.', $row);
if (isset($a[1])) {
if ($a[1] == 'sql') {
$data[] = $row;
}
}
}
if (isset($data))
return $data;
else
return FALSE;
}
if (isset($data)) {
return $data;
} else {
return false;
}
}
function generate_map_admin()
{
//process ai village names (in different table) here
//they will be saved into a different file until everything here works correctly
//add .!
$a = "DROP TABLE IF EXISTS ai_villages; \n";
public function generate_map_admin()
{
//process ai village names (in different table) here
//they will be saved into a different file until everything here works correctly
//add .!
$a = "DROP TABLE IF EXISTS ai_villages; \n";
//create table
$a .= "CREATE TABLE IF NOT EXISTS `ai_villages` (
//create table
$a .= "CREATE TABLE IF NOT EXISTS `ai_villages` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` text NOT NULL,
`attacked` tinyint(4) NOT NULL,
@ -118,27 +119,24 @@ class Map_model extends MO_Model
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;";
$i = 1;
for ($x = 1; $x <= 240; $x++)
{
for ($y = 1; $y <= 240; $y++)
{
//if ai village space
if (!((($x + 24) % 48) || (($y + 24) % 48)))
{
$name = $this->_rand_ai_name();
$a .= "INSERT INTO ai_villages
$i = 1;
for ($x = 1; $x <= 240; $x++) {
for ($y = 1; $y <= 240; $y++) {
//if ai village space
if (!((($x + 24) % 48) || (($y + 24) % 48))) {
$name = $this->_rand_ai_name();
$a .= "INSERT INTO ai_villages
VALUES('$i', '$name', '0', '$x', '$y'); \n";
$i++;
}
}
}
$i++;
}
}
}
$a .= "DROP TABLE IF EXISTS map; \n";
$a .= "DROP TABLE IF EXISTS map; \n";
$a .= "CREATE TABLE IF NOT EXISTS `map` (
$a .= "CREATE TABLE IF NOT EXISTS `map` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`X` int(11) NOT NULL,
`Y` int(11) NOT NULL,
@ -148,147 +146,129 @@ class Map_model extends MO_Model
KEY `X` (`X`,`Y`,`type`,`villageid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;";
$a .= "\n";
$a .= "\n";
$sql = "SELECT * FROM villages";
$q = $this->db->query($sql);
$villages = $q->result_array();
$sql = "SELECT * FROM villages";
$q = $this->db->query($sql);
$villages = $q->result_array();
if ($villages)
{
foreach ($villages as $row)
{
$found = FALSE;
if ($villages) {
foreach ($villages as $row) {
$found = false;
while (!$found)
{
$vx = mt_rand(1, 240);
$vy = mt_rand(1, 240);
while (!$found) {
$vx = mt_rand(1, 240);
$vy = mt_rand(1, 240);
if (((($vx + 24) % 48) && (($vy + 24) % 48)))
{
//not in ai space
$vdata[] = array(
'id' => $row['id'],
'x' => $vx,
'y' => $vy);
if (((($vx + 24) % 48) && (($vy + 24) % 48))) {
//not in ai space
$vdata[] = array(
'id' => $row['id'],
'x' => $vx,
'y' => $vy);
$found = true;
}
}
$found = true;
}
}
}
} else {
$vdata = false;
}
}
}
else
$vdata = FALSE;
$villageid = 0;
$ai = 1;
$found = false;
$villageid = 0;
$ai = 1;
$found = FALSE;
$i = 1;
for ($x = 1; $x <= 240; $x++) {
for ($y = 1; $y <= 240; $y++) {
//if not ai village space
if (((($x + 24) % 48) || (($y + 24) % 48))) {
if ($vdata) {
foreach ($vdata as $row) {
if ($row['x'] == $x && $row['y'] == $y) {
$villageid = $row['id'];
$type = 3;
$found = true;
}
}
}
$i = 1;
for ($x = 1; $x <= 240; $x++)
{
for ($y = 1; $y <= 240; $y++)
{
//if not ai village space
if (((($x + 24) % 48) || (($y + 24) % 48)))
{
if ($vdata)
{
foreach ($vdata as $row)
{
if ($row['x'] == $x && $row['y'] == $y)
{
$villageid = $row['id'];
$type = 3;
$found = TRUE;
}
}
}
if (!$found) {
//check for village here, dont let this run when true
$r = rand(0, 100);
if ($r < 70) {
$type = 0;
} elseif ($r >= 70 && $r < 85) {
$type = 1;
} else {
$type = 2;
}
}
$found = false;
} else {
//ai village space
$type = 4;
$villageid = $ai;
$ai++;
}
if (!$found)
{
//check for village here, dont let this run when true
$r = rand(0, 100);
if ($r < 70)
$type = 0;
elseif ($r >= 70 && $r < 85)
$type = 1;
else
$type = 2;
}
$found = FALSE;
}
else
{
//ai village space
$type = 4;
$villageid = $ai;
$ai++;
}
$a .= "INSERT INTO map VALUES('$i', '$x', '$y', '$type', '$villageid');\n";
$villageid = 0;
$i++;
}
}
$a .= "INSERT INTO map VALUES('$i', '$x', '$y', '$type', '$villageid');\n";
$villageid = 0;
$i++;
}
$this->load->helper('file');
$f = './sql/map/map' . time() . '.sql';
write_file($f, $a);
}
$this->load->helper('file');
$f = './sql/map/map' . time() . '.sql';
write_file($f, $a);
}
function apply_map_admin($file)
{
$this->load->helper('file');
$f = readfile(('./sql/map/' . $file));
$sql = explode(';', $f);
foreach ($sql as $row)
public function apply_map_admin($file)
{
$this->db->query($row);
}
}
$this->load->helper('file');
function _rand_ai_name()
{
//they are in keyboard order from left to right, and top to bottom
$f = readfile(('./sql/map/' . $file));
//21 entries
$a = array('q', 'w', 'r', 't', 'z', 'p', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'y', 'x',
'c', 'v', 'b', 'n', 'm');
//5 entries
$b = array('e', 'u', 'i', 'o', 'a');
//ai village names should be between 4-6 chars
$length = rand(4, 6);
$str = '';
for ($i = 1; $i <= $length; $i++)
{
//start with $a
if ($i % 2)
{
if ($i == 1)
$str .= strtoupper($a[mt_rand(0,20)]);
else
$str .= $a[mt_rand(0, 20)];
}
else
$str .= $b[mt_rand(0, 4)];
$sql = explode(';', $f);
foreach ($sql as $row) {
$this->db->query($row);
}
}
return $str;
}
public function _rand_ai_name()
{
//they are in keyboard order from left to right, and top to bottom
//21 entries
$a = array('q', 'w', 'r', 't', 'z', 'p', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'y', 'x',
'c', 'v', 'b', 'n', 'm');
//5 entries
$b = array('e', 'u', 'i', 'o', 'a');
//ai village names should be between 4-6 chars
$length = rand(4, 6);
$str = '';
for ($i = 1; $i <= $length; $i++) {
//start with $a
if ($i % 2) {
if ($i == 1) {
$str .= strtoupper($a[mt_rand(0, 20)]);
} else {
$str .= $a[mt_rand(0, 20)];
}
} else {
$str .= $b[mt_rand(0, 4)];
}
}
return $str;
}
}
//nowhitesp
//nowhitesp

View File

@ -1,14 +1,10 @@
<?php
class Menu_model extends MO_Model
{
function __construct()
{
parent::__construct();
}
}
public function __construct()
{
parent::__construct();
}
}
//nowhitesp

View File

@ -2,72 +2,70 @@
class Mo_common_model extends MO_Model
{
function __construct()
{
parent::__construct();
}
public function __construct()
{
parent::__construct();
}
function get_hero_data($userid)
{
$sql = "SELECT * FROM heroes WHERE userid = ? AND selected = '1'";
public function get_hero_data($userid)
{
$sql = "SELECT * FROM heroes WHERE userid = ? AND selected = '1'";
$q = $this->db->query($sql, array($userid));
$q = $this->db->query($sql, array($userid));
if (!$q->num_rows())
return FALSE;
if (!$q->num_rows()) {
return false;
}
return $q->row_array();
}
return $q->row_array();
}
function get_userlevel($uid)
{
$sql = "SELECT userlevel FROM users WHERE id=$uid";
$q = $this->db->query($sql);
public function get_userlevel($uid)
{
$sql = "SELECT userlevel FROM users WHERE id=$uid";
$q = $this->db->query($sql);
$res = $q->row_array();
return $res['userlevel'];
$res = $q->row_array();
return $res['userlevel'];
}
}
public function get_username($uid)
{
$sql = "SELECT username FROM users WHERE id=$uid";
function get_username($uid)
{
$sql = "SELECT username FROM users WHERE id=$uid";
$q = $this->db->query($sql);
$q = $this->db->query($sql);
$res = $q->row_array();
$res = $q->row_array();
return $res['username'];
}
return $res['username'];
}
public function get_userdata($id)
{
$sql = "SELECT * FROM users WHERE id='$id'";
$q = $this->db->query($sql);
function get_userdata($id)
{
$sql = "SELECT * FROM users WHERE id='$id'";
$q = $this->db->query($sql);
return $q->row_array();
}
return $q->row_array();
public function get_villageid($userid)
{
$sql = "SELECT id FROM villages WHERE userid='$userid' AND selected='1'";
$q = $this->db->query($sql);
$res = $q->row_array();
}
function get_villageid($userid)
{
$sql = "SELECT id FROM villages WHERE userid='$userid' AND selected='1'";
$q = $this->db->query($sql);
$res = $q->row_array();
return $res['id'];
}
function get_village_data($uid)
{
$sql = "SELECT * FROM villages WHERE userid='$uid' AND selected='1'";
$q = $this->db->query($sql);
return $q->row_array();
}
return $res['id'];
}
public function get_village_data($uid)
{
$sql = "SELECT * FROM villages WHERE userid='$uid' AND selected='1'";
$q = $this->db->query($sql);
return $q->row_array();
}
}
//nowhitesp
//nowhitesp

View File

@ -2,31 +2,29 @@
class News_model extends MO_Model
{
public function get_news($page)
{
$p = ($page - 1) * 5;
function get_news($page)
{
$p = ($page - 1) * 5;
$sql = "SELECT * FROM news LIMIT $p, 5";
$sql = "SELECT * FROM news LIMIT $p, 5";
$q = $this->db->query($sql);
$q = $this->db->query($sql);
return $q->result_array();
}
return $q->result_array();
}
function add_news($text, $uname)
{
$sql = "INSERT INTO news VALUES(default, '$uname', '$text')";
return $this->db->query($sql);
}
function del_news($id)
{
$sql = "";
return $this->db->query($sql);
}
public function add_news($text, $uname)
{
$sql = "INSERT INTO news VALUES(default, '$uname', '$text')";
return $this->db->query($sql);
}
public function del_news($id)
{
$sql = "";
return $this->db->query($sql);
}
}
//nowhitesp

View File

@ -1,64 +1,58 @@
<?php
class Resource_model extends MO_Model
{
function __construct()
{
parent::__construct();
}
//calculates how much unit can be created with the available resources
//since where this is called I display resources, its passed from there
function calc_max_unit($unit, $max_num, $res)
{
for ($i = 1; $i <= $max_num; $i++)
public function __construct()
{
$res['food'] -= $unit['cost_food'];
$res['wood'] -= $unit['cost_wood'];
$res['stone'] -= $unit['cost_stone'];
$res['iron'] -= $unit['cost_iron'];
$res['mana'] -= $unit['cost_mana'];
//not sure if this is needed
if ($res['food'] < 0 && $res['wood'] < 0 &&
$res['stone'] < 0 && $res['iron'] < 0 &&
$res['mana'] < 0)
{
return ($i - 1);
}
if ($res['food'] < 0 || $res['wood'] < 0 ||
$res['stone'] < 0 || $res['iron'] < 0 ||
$res['mana'] < 0)
{
return ($i - 1);
}
parent::__construct();
}
return $max_num;
}
//calculates how much unit can be created with the available resources
//since where this is called I display resources, its passed from there
public function calc_max_unit($unit, $max_num, $res)
{
for ($i = 1; $i <= $max_num; $i++) {
$res['food'] -= $unit['cost_food'];
$res['wood'] -= $unit['cost_wood'];
$res['stone'] -= $unit['cost_stone'];
$res['iron'] -= $unit['cost_iron'];
$res['mana'] -= $unit['cost_mana'];
//not sure if this is needed
if ($res['food'] < 0 && $res['wood'] < 0 &&
$res['stone'] < 0 && $res['iron'] < 0 &&
$res['mana'] < 0) {
return ($i - 1);
}
if ($res['food'] < 0 || $res['wood'] < 0 ||
$res['stone'] < 0 || $res['iron'] < 0 ||
$res['mana'] < 0) {
return ($i - 1);
}
}
return $max_num;
}
function have_enough_resources_building($buildingid, $villageid)
{
$res = $this->get_resources($villageid);
public function have_enough_resources_building($buildingid, $villageid)
{
$res = $this->get_resources($villageid);
$sql = "SELECT * FROM buildings WHERE id='$buildingid'";
$q = $this->db->query($sql);
$building = $q->row_array();
$sql = "SELECT * FROM buildings WHERE id='$buildingid'";
$q = $this->db->query($sql);
$building = $q->row_array();
if ($res['food'] >= $building['cost_food'] &&
$res['wood'] >= $building['cost_wood'] &&
$res['stone'] >= $building['cost_stone'] &&
$res['iron'] >= $building['cost_iron'] &&
$res['mana'] >= $building['cost_mana'])
return TRUE;
if ($res['food'] >= $building['cost_food'] &&
$res['wood'] >= $building['cost_wood'] &&
$res['stone'] >= $building['cost_stone'] &&
$res['iron'] >= $building['cost_iron'] &&
$res['mana'] >= $building['cost_mana']) {
return true;
}
return FALSE;
}
return false;
}
}
//nowhitesp

View File

@ -1,17 +1,17 @@
<?php
class Spell_model extends MO_Model
{
function __construct()
{
parent::__construct();
}
public function __construct()
{
parent::__construct();
}
function use_spell($spellid, $slotid, $res, $villageid)
{
$this->resources = $res;
public function use_spell($spellid, $slotid, $res, $villageid)
{
$this->resources = $res;
//getting spell
$sql = "SELECT spells.*,building_spell_cooldowns.cooldown_end
//getting spell
$sql = "SELECT spells.*,building_spell_cooldowns.cooldown_end
FROM building_spells
LEFT JOIN spells ON building_spells.spellid=spells.id
LEFT JOIN building_spell_cooldowns
@ -22,63 +22,65 @@ class Spell_model extends MO_Model
AND building_spells.slotid='$slotid'
AND building_spells.spellid='$spellid'";
$q = $this->db->query($sql);
$q = $this->db->query($sql);
if (!$q->num_rows())
return 1;
if (!$q->num_rows()) {
return 1;
}
$spell = $q->row_array();
$spell = $q->row_array();
if ($spell['cooldown_end'])
return 2;
if ($spell['cooldown_end']) {
return 2;
}
if (!$this->check_resources($res, $spell))
return 3;
if (!$this->check_resources($res, $spell)) {
return 3;
}
//everything is fine
//substracting cost
$this->substract_resources($spell, $villageid);
//everything is fine
//substracting cost
$this->substract_resources($spell, $villageid);
//addign modofiers
$this->add_modifiers($spell['id'], $villageid, 'spell');
//addign modofiers
$this->add_modifiers($spell['id'], $villageid, 'spell');
$this->write_resources();
$this->write_resources();
if ($spell['weather_change_to'])
{
$sql = "UPDATE villages
if ($spell['weather_change_to']) {
$sql = "UPDATE villages
SET weather_change_to='" . $spell['weather_change_to'] . "'
WHERE id='$villageid'";
$this->db->query($sql);
}
$this->db->query($sql);
}
//do spelleffects here
//do spelleffects here
//adding cooldown
$cd = $spell['cooldown'] + time();
//adding cooldown
$cd = $spell['cooldown'] + time();
$sql = "INSERT INTO building_spell_cooldowns
$sql = "INSERT INTO building_spell_cooldowns
VALUES(default, '$villageid', '$slotid',
'" . $spell['id'] . "', '$cd')";
$this->db->query($sql);
$this->db->query($sql);
//adding spell_effect_end to events
$ev['type'] = 3;
$ev['villageid'] = $villageid;
$ev['slotid'] = $slotid;
$ev['time'] = $spell['duration'];
$ev['data1'] = $spell['id'];
//adding spell_effect_end to events
$ev['type'] = 3;
$ev['villageid'] = $villageid;
$ev['slotid'] = $slotid;
$ev['time'] = $spell['duration'];
$ev['data1'] = $spell['id'];
$this->add_event($ev);
}
$this->add_event($ev);
}
function get_spells($slotid, $villageid)
{
$this->update_spells($slotid, $villageid);
public function get_spells($slotid, $villageid)
{
$this->update_spells($slotid, $villageid);
$sql = "SELECT spells.*,building_spell_cooldowns.cooldown_end
$sql = "SELECT spells.*,building_spell_cooldowns.cooldown_end
FROM building_spells
LEFT JOIN spells ON building_spells.spellid=spells.id
LEFT JOIN building_spell_cooldowns
@ -88,79 +90,76 @@ class Spell_model extends MO_Model
WHERE building_spells.villageid='$villageid'
AND building_spells.slotid='$slotid'";
$q = $this->db->query($sql);
$q = $this->db->query($sql);
return $q->result_array();
}
return $q->result_array();
}
function update_spells($slotid, $villageid)
{
$sql = "SELECT * FROM building_spell_cooldowns
public function update_spells($slotid, $villageid)
{
$sql = "SELECT * FROM building_spell_cooldowns
WHERE slotid='$slotid'
AND villageid='$villageid'";
$q = $this->db->query($sql);
$q = $this->db->query($sql);
if (!$q->num_rows())
return;
if (!$q->num_rows()) {
return;
}
$spells = $q->result_array();
$time = time();
$spells = $q->result_array();
$time = time();
foreach ($spells as $row)
{
if ($row['cooldown_end'] <= $time)
{
$sql = "DELETE FROM building_spell_cooldowns
foreach ($spells as $row) {
if ($row['cooldown_end'] <= $time) {
$sql = "DELETE FROM building_spell_cooldowns
WHERE id='" . $row['id'] . "'";
$this->db->query($sql);
}
$this->db->query($sql);
}
}
}
}
function get_spell_mod_drop_admin()
{
//STUB
$data = array('0' => 'Nothing');
return $data;
}
function list_spells_admin()
{
$sql = "SELECT * FROM spells";
$q = $this->db->query($sql);
return $q->result_array();
}
function get_spell_list_drop_admin()
{
$sql = "SELECT * FROM spells";
$q = $this->db->query($sql);
$res = $q->result_array();
$data[0] = 'No Spell';
foreach ($res as $row)
public function get_spell_mod_drop_admin()
{
$data[$row['id']] = $row['description_admin'];
//STUB
$data = array('0' => 'Nothing');
return $data;
}
return $data;
}
public function list_spells_admin()
{
$sql = "SELECT * FROM spells";
$q = $this->db->query($sql);
function get_spell_admin($id)
{
$sql = "SELECT * FROM spells WHERE id='$id'";
$q = $this->db->query($sql);
return $q->result_array();
}
return $q->row_array();
}
public function get_spell_list_drop_admin()
{
$sql = "SELECT * FROM spells";
$q = $this->db->query($sql);
$res = $q->result_array();
function edit_spell_admin($data)
{
$data[0] = 'No Spell';
$sql = "UPDATE spells
foreach ($res as $row) {
$data[$row['id']] = $row['description_admin'];
}
return $data;
}
public function get_spell_admin($id)
{
$sql = "SELECT * FROM spells WHERE id='$id'";
$q = $this->db->query($sql);
return $q->row_array();
}
public function edit_spell_admin($data)
{
$sql = "UPDATE spells
SET effect='" . $data['effect'] . "',
duration='" . $data['duration'] . "',
cooldown='" . $data['cooldown'] . "',
@ -189,14 +188,14 @@ class Spell_model extends MO_Model
mod_percent_mana='" . $data['mod_percent_mana'] . "'
WHERE id='" . $data['id'] . "'";
$this->db->query($sql);
$this->db->query($sql);
$this->_create_sql($sql);
}
$this->_create_sql($sql);
}
function add_spell_admin($data)
{
$sql = "INSERT INTO spells VALUES(default,
public function add_spell_admin($data)
{
$sql = "INSERT INTO spells VALUES(default,
'" . $data['effect'] . "',
'" . $data['duration'] . "',
'" . $data['cooldown'] . "',
@ -224,17 +223,17 @@ class Spell_model extends MO_Model
'" . $data['mod_percent_iron'] . "',
'" . $data['mod_percent_mana'] . "')";
$this->db->query($sql);
$this->db->query($sql);
$this->_create_sql($sql);
}
$this->_create_sql($sql);
}
function get_spell_effects_admin()
{
//STUB!
$data = array('0' => 'No Effect');
public function get_spell_effects_admin()
{
//STUB!
$data = array('0' => 'No Effect');
return $data;
}
return $data;
}
}
//nowhitesp

View File

@ -2,147 +2,135 @@
class Sql_model extends MO_Model
{
function __construct()
{
parent::__construct();
}
public function __construct()
{
parent::__construct();
}
//updates the db version, to current time, only used when saving a change as sql which already in db
//like changes from phpmyadmin
//dummy function to call the inherited _update_db_version($time);
function update_db_version($time)
{
$this->_update_db_version($time);
}
//updates the db version, to current time, only used when saving a change as sql which already in db
//like changes from phpmyadmin
//dummy function to call the inherited _update_db_version($time);
public function update_db_version($time)
{
$this->_update_db_version($time);
}
//dummy function which uses inherited _create_sql($sql);
function create_sql($sql)
{
$this->_create_sql($sql);
}
//dummy function which uses inherited _create_sql($sql);
public function create_sql($sql)
{
$this->_create_sql($sql);
}
function get_db_version()
{
$sql = "SELECT version FROM db_version WHERE id='1'";
public function get_db_version()
{
$sql = "SELECT version FROM db_version WHERE id='1'";
$q = $this->db->query($sql);
$q = $this->db->query($sql);
$res = $q->row_array();
$res = $q->row_array();
return $res['version'];
}
return $res['version'];
}
function get_appliable_files()
{
$this->load->helper('file');
//$full_list = get_filenames('./sql');
public function get_appliable_files()
{
$this->load->helper('file');
//$full_list = get_filenames('./sql');
$this->load->helper('directory');
$full_list = directory_map('./sql', 1);
$this->load->helper('directory');
$full_list = directory_map('./sql', 1);
//get out the full db dumps
foreach ($full_list as $row)
{
if (substr_compare($row, 'db', 0, 2, TRUE) && substr_compare($row, 'map', 0, 3, TRUE) &&
substr_compare($row, 'old', 0, 3, TRUE) && substr_compare($row, 'index', 0, 5, TRUE))
{
$list[] = $row;
}
}
if (!isset($list))
return 0;
$ver = $this->get_db_version();
foreach ($list as $row)
{
$l = explode('.', $row);
if ($l[0] > $ver)
{
$data[] = $row;
}
}
if (!isset($data))
return 0;
//getting the max
$max = 0;
foreach ($data as $row)
{
$l = explode('.', $row);
if ($l[0] > $max)
{
$max = $l[0];
}
}
$smallest = $max;
$last_found = 0;
$ordered[] = $max . ".sql";
for ($i = 0; $i < (sizeof($data) - 1); $i++)
{
foreach ($data as $row)
{
$l = explode('.', $row);
if (($l[0] < $smallest) && ($l[0] > $last_found))
{
$smallest = $l[0];
$ord = $row;
//get out the full db dumps
foreach ($full_list as $row) {
if (substr_compare($row, 'db', 0, 2, true) && substr_compare($row, 'map', 0, 3, true) &&
substr_compare($row, 'old', 0, 3, true) && substr_compare($row, 'index', 0, 5, true)) {
$list[] = $row;
}
}
}
$last_found = $smallest;
$smallest = $max;
$ordered[$i] = $ord;
if (!isset($list)) {
return 0;
}
$ver = $this->get_db_version();
foreach ($list as $row) {
$l = explode('.', $row);
if ($l[0] > $ver) {
$data[] = $row;
}
}
if (!isset($data)) {
return 0;
}
//getting the max
$max = 0;
foreach ($data as $row) {
$l = explode('.', $row);
if ($l[0] > $max) {
$max = $l[0];
}
}
$smallest = $max;
$last_found = 0;
$ordered[] = $max . ".sql";
for ($i = 0; $i < (sizeof($data) - 1); $i++) {
foreach ($data as $row) {
$l = explode('.', $row);
if (($l[0] < $smallest) && ($l[0] > $last_found)) {
$smallest = $l[0];
$ord = $row;
}
}
$last_found = $smallest;
$smallest = $max;
$ordered[$i] = $ord;
}
if (isset($ordered)) {
return $ordered;
} else {
return 0;
}
}
if (isset($ordered))
public function apply_all_sql()
{
return $ordered;
}
else
{
return 0;
}
}
$this->load->helper('file');
function apply_all_sql()
{
$this->load->helper('file');
$list = $this->get_appliable_files();
$list = $this->get_appliable_files();
if (!$list) {
return;
}
if (!$list)
return;
for ($i = 0; $i < sizeof($list); $i++)
{
//reading file, then applying it to the db
$loc = './sql/' . $list[$i];
$sql = read_file($loc);
for ($i = 0; $i < sizeof($list); $i++) {
//reading file, then applying it to the db
$loc = './sql/' . $list[$i];
$sql = read_file($loc);
var_dump($loc);
var_dump($loc);
$this->db->query($sql);
$this->db->query($sql);
//TODO check if error happened, then stop everything
//check is not needed, it just throws the error
//TODO check if error happened, then stop everything
//check is not needed, it just throws the error
//update db_version
$ver = explode('.', $list[$i]);
$sqlv = "UPDATE db_version SET version='" . $ver[0] . "' WHERE id='1'";
$this->db->query($sqlv);
//update db_version
$ver = explode('.', $list[$i]);
$sqlv = "UPDATE db_version SET version='" . $ver[0] . "' WHERE id='1'";
$this->db->query($sqlv);
}
}
}
}
//nowhitesp

File diff suppressed because it is too large Load Diff

View File

@ -1,101 +1,101 @@
<?php
class Unit_model extends MO_Model
{
function __construct()
{
parent::__construct();
}
public function __construct()
{
parent::__construct();
}
function get_village_units($villageid)
{
$sql = "SELECT users.username,units.*,village_units.userid,village_units.unitcount
public function get_village_units($villageid)
{
$sql = "SELECT users.username,units.*,village_units.userid,village_units.unitcount
FROM village_units
LEFT JOIN users ON village_units.userid=users.id
LEFT JOIN units ON village_units.unitid=units.id
WHERE villageid='$villageid'";
$q = $this->db->query($sql);
$q = $this->db->query($sql);
//TODO order it!
//TODO order it!
return $q->result_array();
}
function get_unit($id)
{
$sql = "SELECT * FROM units WHERE id='$id'";
$q = $this->db->query($sql);
return $q->row_array();
}
//calculates how many units can be created (by lookin at events)
//nothing gets queried
function calc_max_unit_ev($unit_max, $unit_res, $event)
{
$in_progress = 0;
if ($event)
{
foreach ($event as $row)
{
$in_progress += $row['data2'];
}
return $q->result_array();
}
//if more are in progress that the building can make
if ($in_progress >= $unit_max)
return 0;
//calc how many can be made overall
$max = $unit_max - $in_progress;
//if less can be made because of events than the resources allow
if ($max <= $unit_res)
return $max;
//if events allow more than resources
if ($max > $unit_res)
return $unit_res;
return $max;
}
function list_create_mod_drop_admin()
{
//STUB
return array('0' => 'Nothing');
}
function list_units_admin()
{
$sql = "SELECT * FROM units";
$q = $this->db->query($sql);
return $q->result_array();
}
function get_unit_list_dropdown_admin()
{
$sql = "SELECT * FROM units";
$q = $this->db->query($sql);
$res = $q->result_array();
$data[0] = 'Nothing';
foreach ($res as $row)
public function get_unit($id)
{
$data[$row['id']] = $row['name'];
$sql = "SELECT * FROM units WHERE id='$id'";
$q = $this->db->query($sql);
return $q->row_array();
}
return $data;
}
//calculates how many units can be created (by lookin at events)
//nothing gets queried
public function calc_max_unit_ev($unit_max, $unit_res, $event)
{
$in_progress = 0;
function add_unit_admin($data)
{
$sql = "INSERT INTO units
if ($event) {
foreach ($event as $row) {
$in_progress += $row['data2'];
}
}
//if more are in progress that the building can make
if ($in_progress >= $unit_max) {
return 0;
}
//calc how many can be made overall
$max = $unit_max - $in_progress;
//if less can be made because of events than the resources allow
if ($max <= $unit_res) {
return $max;
}
//if events allow more than resources
if ($max > $unit_res) {
return $unit_res;
}
return $max;
}
public function list_create_mod_drop_admin()
{
//STUB
return array('0' => 'Nothing');
}
public function list_units_admin()
{
$sql = "SELECT * FROM units";
$q = $this->db->query($sql);
return $q->result_array();
}
public function get_unit_list_dropdown_admin()
{
$sql = "SELECT * FROM units";
$q = $this->db->query($sql);
$res = $q->result_array();
$data[0] = 'Nothing';
foreach ($res as $row) {
$data[$row['id']] = $row['name'];
}
return $data;
}
public function add_unit_admin($data)
{
$sql = "INSERT INTO units
VALUES(default,
'" . $data['type'] . "',
'" . $data['name'] . "',
@ -122,22 +122,22 @@ class Unit_model extends MO_Model
'" . $data['mod_rate_iron'] . "',
'" . $data['mod_rate_mana'] . "')";
$this->db->query($sql);
$this->db->query($sql);
$this->_create_sql($sql);
}
$this->_create_sql($sql);
}
function get_unit_admin($id)
{
$sql = "SELECT * FROM units WHERE id='$id'";
$q = $this->db->query($sql);
public function get_unit_admin($id)
{
$sql = "SELECT * FROM units WHERE id='$id'";
$q = $this->db->query($sql);
return $q->row_array();
}
return $q->row_array();
}
function edit_unit_admin($data)
{
$sql = "UPDATE units
public function edit_unit_admin($data)
{
$sql = "UPDATE units
SET type='" . $data['type'] . "',
name='" . $data['name'] . "',
icon='" . $data['icon'] . "',
@ -164,9 +164,9 @@ class Unit_model extends MO_Model
mod_rate_mana='" . $data['mod_rate_mana'] . "'
WHERE id='" . $data['id'] . "'";
$this->db->query($sql);
$this->db->query($sql);
$this->_create_sql($sql);
}
$this->_create_sql($sql);
}
}
//nowhitesp

View File

@ -2,71 +2,62 @@
class User_model extends MO_Model
{
function __construct()
{
parent::__construct();
}
function login_check($data)
{
$sql = "SELECT passkey FROM users WHERE username=" . $this->db->escape($data['username']);
$q = $this->db->query($sql);
if ($q->num_rows > 0)
public function __construct()
{
$row = $q->row_array();
if ($row['passkey'] == $data['password'])
{
return TRUE;
}
else
{
return FALSE;
}
parent::__construct();
}
else
public function login_check($data)
{
return FALSE;
$sql = "SELECT passkey FROM users WHERE username=" . $this->db->escape($data['username']);
$q = $this->db->query($sql);
if ($q->num_rows > 0) {
$row = $q->row_array();
if ($row['passkey'] == $data['password']) {
return true;
} else {
return false;
}
} else {
return false;
}
}
}
function get_userid($username)
{
$sql = "SELECT id FROM users WHERE username=" . $this->db->escape($username);
$q = $this->db->query($sql);
$res = $q->row_array();
return $res['id'];
}
function reg_username_check($uname)
{
$sql = "SELECT username FROM users WHERE username=" . $this->db->escape($uname);
$q = $this->db->query($sql);
if ($q->num_rows() == 0)
public function get_userid($username)
{
return TRUE;
}
else
{
return FALSE;
}
}
$sql = "SELECT id FROM users WHERE username=" . $this->db->escape($username);
$q = $this->db->query($sql);
$res = $q->row_array();
function reg_write($data)
{
$sql = "INSERT INTO users VALUES(default, "
. $this->db->escape($data['username']) . ", '"
. $data['password'] . "', '"
return $res['id'];
}
public function reg_username_check($uname)
{
$sql = "SELECT username FROM users WHERE username=" . $this->db->escape($uname);
$q = $this->db->query($sql);
if ($q->num_rows() == 0) {
return true;
} else {
return false;
}
}
public function reg_write($data)
{
$sql = "INSERT INTO users VALUES(default, "
. $this->db->escape($data['username']) . ", '"
. $data['password'] . "', '"
. $data['email'] . "',
default, default, default)";
return $this->db->query($sql);
}
return $this->db->query($sql);
}
}
//nowhitesp

View File

@ -2,99 +2,103 @@
class Village_model extends MO_Model
{
function __construct()
{
parent::__construct();
}
public function __construct()
{
parent::__construct();
}
function apply_settings($data)
{
if ($data['ai'])
$ai = 1;
else
$ai = 0;
public function apply_settings($data)
{
if ($data['ai']) {
$ai = 1;
} else {
$ai = 0;
}
$sql = "UPDATE villages
SET name='" . $data['name'] . "',
ai_on = '$ai'
WHERE id='" . $data['id'] . "'";
$sql = "UPDATE villages
SET name='" . $data['name'] . "',
ai_on = '$ai'
WHERE id='" . $data['id'] . "'";
$this->db->query($sql);
}
$this->db->query($sql);
}
function get_village($id)
{
$sql = "SELECT * FROM villages WHERE id='$id'";
public function get_village($id)
{
$sql = "SELECT * FROM villages WHERE id='$id'";
$q = $this->db->query($sql);
$q = $this->db->query($sql);
return $q->row_array();
}
return $q->row_array();
}
function select_village($id, $userid)
{
//first check if villageid belongs to user
$sql = "SELECT * FROM villages WHERE id='$id'";
public function select_village($id, $userid)
{
//first check if villageid belongs to user
$sql = "SELECT * FROM villages WHERE id='$id'";
$q = $this->db->query($sql);
$q = $this->db->query($sql);
if (!$q->num_rows())
return;
if (!$q->num_rows()) {
return;
}
$res = $q->row_array();
$res = $q->row_array();
if ($res['userid'] != $userid)
return;
if ($res['userid'] != $userid) {
return;
}
if ($res['selected'])
return;
if ($res['selected']) {
return;
}
$sql = "UPDATE villages SET selected='0' WHERE userid='$userid'";
$sql = "UPDATE villages SET selected='0' WHERE userid='$userid'";
$this->db->query($sql);
$this->db->query($sql);
$sql = "UPDATE villages SET selected='1' WHERE id='$id'";
$sql = "UPDATE villages SET selected='1' WHERE id='$id'";
$this->db->query($sql);
}
$this->db->query($sql);
}
function get_villages($userid)
{
$sql = "SELECT * FROM villages WHERE userid='$userid' ORDER BY score DESC";
public function get_villages($userid)
{
$sql = "SELECT * FROM villages WHERE userid='$userid' ORDER BY score DESC";
$q = $this->db->query($sql);
$q = $this->db->query($sql);
return $q->result_array();
}
return $q->result_array();
}
function create_village($userid, $username, $posx = -1, $posy = -1)
{
//make all village unselected
$sql = "UPDATE villages
public function create_village($userid, $username, $posx = -1, $posy = -1)
{
//make all village unselected
$sql = "UPDATE villages
SET selected='0'
WHERE userid='$userid'";
$this->db->query($sql);
$this->db->query($sql);
$villagename = $username . "\'s village";
$villagename = $username . "\'s village";
$sql = "INSERT INTO villages VALUES(default, '$userid', '$villagename',
$sql = "INSERT INTO villages VALUES(default, '$userid', '$villagename',
default, '1', default, default, default, default, default, default)";
$this->db->query($sql);
$this->db->query($sql);
//getting back id from newly created village
$sql = "SELECT id FROM villages WHERE userid='$userid' AND selected='1'";
$q = $this->db->query($sql);
$res = $q->row_array();
//getting back id from newly created village
$sql = "SELECT id FROM villages WHERE userid='$userid' AND selected='1'";
$q = $this->db->query($sql);
$res = $q->row_array();
$id = $res['id'];
$id = $res['id'];
//resources-> id, villageid, res[5], max_res[5], rate_res[5], last_updated
$time = time();
//resources-> id, villageid, res[5], max_res[5], rate_res[5], last_updated
$time = time();
//make resources entry
$sql = "INSERT INTO resources
//make resources entry
$sql = "INSERT INTO resources
VALUES(default, '$id',
default, default, default, default, default,
default, default, default, default, default,
@ -103,92 +107,80 @@ class Village_model extends MO_Model
default, default, default, default, default,
'$time')";
$this->db->query($sql);
$this->db->query($sql);
$found = FALSE;
$found = false;
while(!$found)
{
//get a map coordinates
//we should get 20x20 field
//ids start with 1, max is 240
$x_m_s = rand(1, 220);
$y_m_s = rand(1, 220);
while (!$found) {
//get a map coordinates
//we should get 20x20 field
//ids start with 1, max is 240
$x_m_s = rand(1, 220);
$y_m_s = rand(1, 220);
$sql = "SELECT * FROM map
$sql = "SELECT * FROM map
WHERE (X >= '$x_m_s' AND X <= '" . ($x_m_s + 20) . "')
AND (Y >= '$y_m_s' AND Y <= '" . ($y_m_s + 20) . "')";
$q = $this->db->query($sql);
$q = $this->db->query($sql);
$res = $q->result_array();
$res = $q->result_array();
foreach ($res as $row)
{
if ($row['type'] == 0)
{
$found = TRUE;
foreach ($res as $row) {
if ($row['type'] == 0) {
$found = true;
$sql = "UPDATE map SET type='3', villageid='$id' WHERE id='" . $row['id'] . "'";
$this->db->query($sql);
break;
}
}
$sql = "UPDATE map SET type='3', villageid='$id' WHERE id='" . $row['id'] . "'";
$this->db->query($sql);
break;
}
}
}
}
}
//slotids range from 1 to parent::TOTAL_BUILDINGS!
//slot 0 can be used for a wall or something
function get_buildings($vid)
{
//tODO Empty slots
//slotids range from 1 to parent::TOTAL_BUILDINGS!
//slot 0 can be used for a wall or something
public function get_buildings($vid)
{
//tODO Empty slots
//TODO query, get building info for empty spaces, and thats going to be pushed into empty
//speces
//TODO query, get building info for empty spaces, and thats going to be pushed into empty
//speces
$sql = "SELECT * FROM buildings WHERE id='1'";
$q = $this->db->query($sql);
$space = $q->row_array();
$sql = "SELECT * FROM buildings WHERE id='1'";
$q = $this->db->query($sql);
$space = $q->row_array();
//this needs left join
$sql = "SELECT * FROM village_buildings
//this needs left join
$sql = "SELECT * FROM village_buildings
INNER JOIN buildings ON village_buildings.buildingid=buildings.id
WHERE villageid='$vid' ORDER BY slotid ASC";
$q = $this->db->query($sql);
$res = $q->result_array();
$q = $this->db->query($sql);
$res = $q->result_array();
$new = FALSE;
$j = 0;
$new = false;
$j = 0;
for ($i = 1; $i <= parent::TOTAL_BUILDINGS;$i++)
{
if (isset($res[$j]))
{
if ($res[$j]['slotid'] == $i)
{
$data[] = $res[$j];
$j++;
}
else
{
$new = TRUE;
}
}
else
{
$new = TRUE;
}
for ($i = 1; $i <= parent::TOTAL_BUILDINGS;$i++) {
if (isset($res[$j])) {
if ($res[$j]['slotid'] == $i) {
$data[] = $res[$j];
$j++;
} else {
$new = true;
}
} else {
$new = true;
}
if ($new)
{
$data[] = $space;
$new = FALSE;
}
if ($new) {
$data[] = $space;
$new = false;
}
}
return $data;
}
return $data;
}
}
//nowhitesp
//nowhitesp

View File

@ -1,56 +1,54 @@
<?php
class Weather_model extends MO_Model
{
function __construct()
{
parent::__construct();
}
function get_weathers_drop_admin()
{
$sql = "SELECT * FROM weathers";
$q = $this->db->query($sql);
$res = $q->result_array();
$data[] = 'Nothing';
foreach ($res as $row)
public function __construct()
{
$data[] = $row['name'];
parent::__construct();
}
return $data;
}
public function get_weathers_drop_admin()
{
$sql = "SELECT * FROM weathers";
$q = $this->db->query($sql);
function get_weather_effects_drop_admin()
{
$data[0] = 'No Effect';
$data[1] = 'Fires';
$res = $q->result_array();
$data[] = 'Nothing';
foreach ($res as $row) {
$data[] = $row['name'];
}
return $data;
}
public function get_weather_effects_drop_admin()
{
$data[0] = 'No Effect';
$data[1] = 'Fires';
return $data;
}
return $data;
}
function list_weathers_admin()
{
$sql = "SELECT * FROM weathers";
$q = $this->db->query($sql);
public function list_weathers_admin()
{
$sql = "SELECT * FROM weathers";
$q = $this->db->query($sql);
return $q->result_array();
}
return $q->result_array();
}
function get_weather_admin($id)
{
$sql = "SELECT * FROM weathers WHERE id='$id'";
$q = $this->db->query($sql);
public function get_weather_admin($id)
{
$sql = "SELECT * FROM weathers WHERE id='$id'";
$q = $this->db->query($sql);
return $q->row_array();
}
return $q->row_array();
}
function edit_weather_admin($data)
{
$sql = "UPDATE weathers
public function edit_weather_admin($data)
{
$sql = "UPDATE weathers
SET name='" . $data['name'] . "',
description='" . $data['description'] . "',
art='" . $data['art'] . "',
@ -68,14 +66,14 @@ class Weather_model extends MO_Model
mod_percent_mana='" . $data['mod_percent_mana'] . "'
WHERE id='" . $data['id'] . "'";
$this->db->query($sql);
$this->db->query($sql);
$this->_create_sql($sql);
}
$this->_create_sql($sql);
}
function add_weather_admin($data)
{
$sql = "INSERT INTO weathers VALUES(default,
public function add_weather_admin($data)
{
$sql = "INSERT INTO weathers VALUES(default,
'" . $data['name'] . "',
'" . $data['description'] . "',
'" . $data['art'] . "',
@ -92,10 +90,9 @@ class Weather_model extends MO_Model
'" . $data['mod_percent_iron'] . "',
'" . $data['mod_percent_mana'] . "')";
$this->db->query($sql);
$this->_create_sql($sql);
}
$this->db->query($sql);
$this->_create_sql($sql);
}
}
//nowhitesp
//nowhitesp

View File

@ -5,41 +5,38 @@ $this->load->helper('form');
$link_back = 'admin/ai_settings_tool';
$attr_description = array(
'name' => 'description',
'rows' => '5',
'cols' => '50',
'class' => 'textarea');
'name' => 'description',
'rows' => '5',
'cols' => '50',
'class' => 'textarea');
$attr_setting = array(
'name' => 'setting',
'class' => 'input');
'name' => 'setting',
'class' => 'input');
$attr_value = array(
'name' => 'value',
'class' => 'input');
'name' => 'value',
'class' => 'input');
$attr_submit = array(
'name' => 'submit',
'value' => 'Submit',
'class' => 'submit');
'name' => 'submit',
'value' => 'Submit',
'class' => 'submit');
if ($new)
{
//set every value with set_value()
$link_form = 'admin/ai_settings';
if ($new) {
//set every value with set_value()
$link_form = 'admin/ai_settings';
$attr_setting['value'] = set_value('setting');
$attr_value['value'] = set_value('value');
$attr_description['value'] = set_value('description');
}
else
{
//set every value from data sent
$link_form = 'admin/ai_settings/' . $setting['id'];
$attr_setting['value'] = set_value('setting');
$attr_value['value'] = set_value('value');
$attr_description['value'] = set_value('description');
} else {
//set every value from data sent
$link_form = 'admin/ai_settings/' . $setting['id'];
$attr_setting['value'] = $setting['setting'];
$attr_value['value'] = $setting['value'];
$attr_description['value'] = $setting['description'];
$attr_setting['value'] = $setting['setting'];
$attr_value['value'] = $setting['value'];
$attr_description['value'] = $setting['description'];
}
?>
<div class="back">