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 class Alliance extends MO_Controller
{ {
function __construct() public function __construct()
{ {
parent::__construct(); parent::__construct();
} }
function index() public function index()
{ {
} }
function alliance_menu() public function alliance_menu()
{ {
$this->headers('alliance'); $this->headers('alliance');
$this->footer();
}
$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 class Changelog extends MO_Controller
{ {
public function __construct()
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())
{ {
$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'); $data['versions'] = $this->changelog_model->get_versions();
$this->changelog_model->new_version($text); $data['commits'] = $this->changelog_model->get_commits();
$data['userlevel'] = $this->userlevel;
$data['required_userlevel'] = 4;
$this->load->helper('url'); $this->headers();
redirect('changelog/show'); $this->load->view('changelog/changelog', $data);
$this->footer();
} }
} public function add_new_version()
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'); if (!$this->userlevel > 4) {
show404();
}
$text = $this->input->post('text'); $this->load->library('form_validation');
$this->changelog_model->new_commit($text);
$this->load->helper('url'); $this->form_validation->set_rules('text', 'Text', 'required');
redirect('changelog/show');
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 //nowhitesp

View File

@ -1,23 +1,22 @@
<?php <?php
class Cron extends CI_Controller 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() public function __construct()
{ {
parent::__construct(); parent::__construct();
} }
function aiattack() public function aiattack()
{ {
//check for useragent and stuff like that //check for useragent and stuff like that
$this->load->model('ai_model'); $this->load->model('ai_model');
$a = $this->ai_model->attack(); $a = $this->ai_model->attack();
echo $a;
}
echo $a;
}
} }
//nowhitesp //nowhitesp

View File

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

View File

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

View File

@ -2,212 +2,192 @@
class Hero extends MO_Controller class Hero extends MO_Controller
{ {
function __construct() public 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')
{ {
$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') if ($page == 'stats') {
{ $data['hero'] = $this->hero;
$data['hero'] = $this->hero;
$data['hpp'] = floor(($this->hero['health'] / $this->hero['max_health']) * 100); $data['hpp'] = floor(($this->hero['health'] / $this->hero['max_health']) * 100);
$data['mpp'] = floor(($this->hero['mana'] / $this->hero['max_mana']) * 100); $data['mpp'] = floor(($this->hero['mana'] / $this->hero['max_mana']) * 100);
$data['exp'] = floor(($this->hero['experience'] /1000) * 100); $data['exp'] = floor(($this->hero['experience'] /1000) * 100);
//STUB! //STUB!
$data['experience'] = 10000; $data['experience'] = 10000;
$this->load->view('hero/stats', $data); $this->load->view('hero/stats', $data);
} } elseif ($page == 'inventory') {
elseif ($page == 'inventory') $this->load->model('item_model');
{
$this->load->model('item_model');
if ($d1 !== FALSE && $d2 !== FALSE && $d3 !== FALSE && $d4 !== FALSE) if ($d1 !== false && $d2 !== false && $d3 !== false && $d4 !== false) {
{ $this->item_model->set_hero($this->hero);
$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) if ($res['message'] === true) {
$this->hero = $this->item_model->get_hero(); $this->hero = $this->item_model->get_hero();
}
$d1 = FALSE; $d1 = false;
$d2 = FALSE; $d2 = false;
//we doesn't care about d3,d4 that isn't used in views //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['d1'] = $d1;
$data['d2'] = $d2; $data['d2'] = $d2;
$res['inventory'] = $this->load->view('hero/inventory', $data, TRUE); $res['inventory'] = $this->load->view('hero/inventory', $data, true);
$res['equipment'] = $this->load->view('hero/character', $data, TRUE); $res['equipment'] = $this->load->view('hero/character', $data, true);
$this->load->view('hero/inventory_view', $res); $this->load->view('hero/inventory_view', $res);
} } elseif ($page == 'talents') {
elseif ($page == 'talents') } elseif ($page == 'spells') {
{ } elseif ($page == 'actionbars') {
} }
elseif ($page == 'spells')
{ $this->footer();
}
elseif ($page == 'actionbars')
{
} }
$this->footer(); public function create()
}
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())
{ {
$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(); $this->footer();
} } else {
else $this->load->model('hero_model');
{
$this->load->model('hero_model');
$data['name'] = $this->input->post('name'); $data['name'] = $this->input->post('name');
$data['gender'] = $this->input->post('gender'); $data['gender'] = $this->input->post('gender');
$data['class'] = $this->input->post('class'); $data['class'] = $this->input->post('class');
$this->hero_model->create($data, $this->userid); $this->hero_model->create($data, $this->userid);
$this->load->helper('url'); $this->load->helper('url');
redirect('hero/selected'); redirect('hero/selected');
}
} }
}
function select() public 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())
{ {
$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'); $this->load->model('hero_model');
redirect('hero/selected'); $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) public function addstat()
{
$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())
{ {
$data['id'] = $id; //hero's stat view calls this with a form the hidden field's name is attrid
$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
//1 agi, 2 str, 3 stam, 4 int, 5 spirit //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) public function delete_check($chk)
{ {
if ($chk == "DELETE") if ($chk == "DELETE") {
return TRUE; return true;
}
$this->form_validation->set_message('delete_check', 'You have to spell DELETE, exactly, and uppercase.'); $this->form_validation->set_message('delete_check', 'You have to spell DELETE, exactly, and uppercase.');
return FALSE;
}
return false;
}
} }
//nowhitesp //nowhitesp

View File

@ -2,163 +2,144 @@
class Mail extends MO_Controller class Mail extends MO_Controller
{ {
function __construct() public 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))
{ {
$d['draft'] = $this->mail_model->get_draft($id, $this->userid); parent::__construct();
} }
$this->form_validation->set_rules('name', 'Username', 'required'); public function index()
$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); $this->load->helper('url');
} redirect('mail/inbox');
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(); public function inbox()
}
function del_draft($id = 0)
{
if ($id && is_numeric($id))
{ {
$this->load->model("mail_model"); $this->headers('mail');
$this->mail_model->delete_draft($id, $this->userid);
$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'); public function compose($id = 0)
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))
{ {
$this->load->helper('url'); $this->headers('mail');
redirect('mail/inbox'); $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'); public function del_draft($id = 0)
$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))
{ {
$this->load->helper('url'); if ($id && is_numeric($id)) {
redirect('mail/inbox'); $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->load->model('mail_model');
{
$this->headers('mail');
$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 //nowhitesp

View File

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

View File

@ -2,138 +2,137 @@
class User extends MO_Controller class User extends MO_Controller
{ {
public function __construct()
{
parent::__construct();
}
function __construct() public function login()
{ {
parent::__construct(); $this->load->helper(array('form', 'url'));
} $this->load->library('form_validation');
function login() //is_unique[users.username]
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
//is_unique[users.username] //xss_validation
//xss_validation
//TODO figure rules out //TODO figure rules out
$this->form_validation->set_rules('username', 'Username', $this->form_validation->set_rules(
'required'); 'username',
'Username',
'required'
);
//password callback -> $this->input->post('username'), after xss filter //password callback -> $this->input->post('username'), after xss filter
$this->form_validation->set_rules('password', 'Password', $this->form_validation->set_rules(
'required|callback_login_check'); 'password',
'Password',
'required|callback_login_check'
);
if ($this->form_validation->run() == FALSE) if ($this->form_validation->run() == false) {
{ $this->load->view('login/login');
$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'); $this->load->helper(array('form', 'url'));
redirect('news/index'); $this->load->library('form_validation');
//$this->load->view('login/success');
//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() public function logout()
{
$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'); $this->session->unset_userdata('userid');
}
else
{
if ($this->register_write())
{
$this->load->view('register/success');
}
}
}
function logout() $this->load->helper('url');
{ redirect('user/login');
$this->session->unset_userdata('userid');
$this->load->helper('url'); //TODO make it look cool
redirect('user/login');
//TODO make it look cool
//$this->load->view('redirect_to_login'); //$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!'); $this->load->model('user_model');
return FALSE;
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() public 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))
{ {
$this->session->set_userdata('userid', $data['username'] = $this->input->post('username');
$this->user_model->get_userid($data['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() public function login_check($attr)
{ {
$this->headers('settings'); $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 }//login class
//nowhitesp //nowhitesp

View File

@ -2,261 +2,246 @@
class Village extends MO_Controller class Village extends MO_Controller
{ {
function __construct() public 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')
{ {
$px = $this->input->post('x'); parent::__construct();
$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'];
}
}
} }
$this->load->model('map_model'); public function index()
if (!$x && !$y)
{ {
$coords = $this->map_model->get_village_coords($this->villageid); $this->load->helper('url');
$x = $coords['X']; redirect('village/selected');
$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; //function for testing, this will be handled when registering, and with npcs
$data['y'] = $y; public function create_village()
$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))
{ {
$action = 'list'; $this->load->model('village_model');
$id = 0;
$this->village_model->create_village($this->userid, $this->username);
} }
$this->load->model('log_model'); public function selected()
if ($action == 'list')
{ {
$this->headers('village'); $this->load->model('village_model');
$data['logs'] = $this->log_model->get_combat_logs($this->villageid); $this->headers('village');
$this->load->view('village/log/list', $data);
$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); if ($action == 'xy') {
$this->load->view('village/log/combat', $data); $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'); $data['units'] = $this->unit_model->get_village_units($this->villageid);
redirect('village/log');
}
}
function select() $this->headers('village');
{
$this->load->model('village_model');
$this->load->library('form_validation');
$this->form_validation->set_rules('id', 'ID', 'is_natural|required'); $this->load->view('village/units', $data);
if (!$this->form_validation->run()) $this->footer();
{
$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');
} }
$village = $this->village_model->get_village($id); public function log($action = 'list', $id = 0)
if ($village['userid'] != $this->userid)
{ {
$this->load->heper('url'); if ($action != 'list' && $action != 'view' && $action != 'delete') {
redirect('village/selected'); $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'); public function select()
$this->form_validation->set_rules('name', 'Name',
'required|alpha|is_unique[ai_villages.name]');
if (!$this->form_validation->run())
{ {
$this->headers('village'); $this->load->model('village_model');
$this->load->library('form_validation');
$data['id'] = $id; $this->form_validation->set_rules('id', 'ID', 'is_natural|required');
$data['village'] = $village;
$this->load->view('village/settings', $data); if (!$this->form_validation->run()) {
$this->footer(); $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; $this->headers('village');
$name = $this->input->post('name');
$data['ai'] = $this->input->post('ai');
$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'); $this->load->helper('url');
redirect('village/select'); redirect('village/select');
}
} }
}
function event_update() public function event_update()
{ {
//TODO for ajax, but maybe it will be solved with APE //TODO for ajax, but maybe it will be solved with APE
} }
function list_all()
{
}
public function list_all()
{
}
} }
//nowhitesp //nowhitesp

View File

@ -2,429 +2,384 @@
class MO_Controller extends CI_Controller class MO_Controller extends CI_Controller
{ {
public $userid; public $userid;
public $username; public $username;
public $language; public $language;
public $userlevel; public $userlevel;
public $villageid; public $villageid;
public $village_name; public $village_name;
public $resources; public $resources;
public $events; public $events;
public $building; public $building;
public $village_data; public $village_data;
public $weather; public $weather;
//hero stuff //hero stuff
public $hero; public $hero;
public $new_mail; public $new_mail;
public $new_log; public $new_log;
function __construct($page = 'village') public function __construct($page = 'village')
{ {
parent::__construct(); parent::__construct();
$this->weather = FALSE; $this->weather = false;
$this->resources = FALSE; $this->resources = false;
$this->hero = FALSE; $this->hero = false;
$this->_manage_session($page); $this->_manage_session($page);
} }
public function _manage_session($page) public function _manage_session($page)
{ {
$this->userid = 0; $this->userid = 0;
//this should be solved with db! //this should be solved with db!
// if (!$this->session->userdata('language')) // if (!$this->session->userdata('language'))
// $this->session->set_userdata('language', 'english'); // $this->session->set_userdata('language', 'english');
// $this->language = $this->session->userdata('language'); // $this->language = $this->session->userdata('language');
$this->language = 'english'; $this->language = 'english';
if ($this->session->userdata('userid')) if ($this->session->userdata('userid')) {
$this->userid = $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) if ($this->userid) {
{ $data = $this->mo_common_model->get_userdata($this->userid);
$data = $this->mo_common_model->get_userdata($this->userid);
$this->userlevel = $data['userlevel']; $this->userlevel = $data['userlevel'];
$this->username = $data['username']; $this->username = $data['username'];
$this->new_mail = $data['new_mail']; $this->new_mail = $data['new_mail'];
if ($page == 'village') if ($page == 'village') {
{ $mdata = $this->mo_common_model->get_village_data($this->userid);
$mdata = $this->mo_common_model->get_village_data($this->userid);
$this->villageid = $mdata['id']; $this->villageid = $mdata['id'];
$this->villagename = $mdata['name']; $this->villagename = $mdata['name'];
$this->new_log = $mdata['new_log']; $this->new_log = $mdata['new_log'];
$this->village_data = $mdata; $this->village_data = $mdata;
} }
if ($page == 'hero') if ($page == 'hero') {
{ $this->hero = $this->mo_common_model->get_hero_data($this->userid);
$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');
} }
return TRUE; public function check_login()
}
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')
{ {
$data['villagename'] = $this->villagename; if ($this->userid == 0) {
$data['newlog'] = $this->new_log; $this->load->helper('url');
redirect('user/login');
}
if ($page == 'building' || $page == 'village' || $page == 'build' || $page == 'build_in_progress' || return true;
$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')
public function headers($page = 'village', $slotid = 0)
{ {
if (!$this->hero && !$slotid) $data['username'] = $this->username;
{ $data['userid'] = $this->userid;
$this->load->helper('url'); $data['userlevel'] = $this->userlevel;
redirect('hero/create'); $data['newmail'] = $this->new_mail;
return; $data['page'] = $page;
}
$data['hero'] = $this->hero; if ($page != 'hero') {
$data['weather'] = FALSE; $data['villagename'] = $this->villagename;
$data['resources'] = FALSE; $data['newlog'] = $this->new_log;
$this->load->view('parts/header', $data);
$this->load->view('menu', $data); if ($page == 'building' || $page == 'village' || $page == 'build' || $page == 'build_in_progress' ||
$this->load->view('hero/menu', $data); $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) public function _get_slot_building($slotid = 0)
{ {
if (!$slotid) if (!$slotid) {
return; return;
}
if ($this->building) if ($this->building) {
return; return;
}
$this->load->model('building_model'); $this->load->model('building_model');
$this->building = $this->building_model->get_slot_building($slotid, $this->villageid); $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) // if (!$this->building)
// { // {
// $this->load->helper('url'); // $this->load->helper('url');
// redirect('village/selected'); // 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') if ($this->resources) {
{ return;
foreach ($this->events as $row) }
{
if ($row['type'] == $ev_type) $this->load->model('resource_model');
{ $this->resources = $this->resource_model->get_resources($this->villageid);
$data[] = $row;
}
}
}
else
{
foreach ($this->events as $row)
{
if ($row['type'] == $ev_type && $row['slotid'] == $slotid)
{
$data[] = $row;
}
}
}
} }
if ($type == 'next') public function _update()
{ {
if ($filter == 'all') $this->load->model('event_model');
{
$last_end = 99999999999;
$smallest = FALSE;
foreach ($this->events as $row)
{
if ($row['end'] < $last_end)
{
$last_end = $row['end'];
$smallest = $row;
}
}
return $smallest; if ($this->resources || $this->events || $this->weather) {
} return;
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; //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 public function footer()
if ($data)
{ {
$last_end = 99999999999; $this->load->view('parts/footer');
$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; /*
} 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() public function _filter_events($type, $filter, $slotid = 0, $ev_type = 0, $next = false)
{
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) //means no events
{ if (!$this->events) {
$last = $a[$i]; return false;
$index = $i; }
}
$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 public function _prep_res_js()
switch ($index)
{ {
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: case 0:
$s_index = 'food'; $s_index = 'food';
break; break;
case 1: case 1:
$s_index = 'wood'; $s_index = 'wood';
break; break;
case 2: case 2:
$s_index = 'stone'; $s_index = 'stone';
break; break;
case 3: case 3:
$s_index = 'iron'; $s_index = 'iron';
break; break;
case 4: case 4:
$s_index = 'mana'; $s_index = 'mana';
break; break;
default: default:
$s_index = 'food'; $s_index = 'food';
break; break;
} }
//calculating the rate it brings 1 resource //calculating the rate it brings 1 resource
$num_tick = 0.1; $num_tick = 0.1;
$rate = 'rate_' . $s_index; $rate = 'rate_' . $s_index;
while (TRUE) while (true) {
{ if (($res[$rate] * $num_tick) > 1) {
if (($res[$rate] * $num_tick) > 1) break;
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 }//MO_Controller
//nowhitesp //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'); <?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';
}
} }
if ( ! function_exists('class_name')) if (! function_exists('gender')) {
{ function gender($gender = '')
function class_name($id = 0)
{
switch ($id)
{ {
case 1: if ($gender == 1) {
return 'Warrior'; return 'Male';
case 2: } else {
return 'Rogue'; return 'Female';
case 3: }
return 'Archer';
default:
return 'Error';
} }
} }
}
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 //means set_selected
if (!function_exists('ss')) if (!function_exists('ss')) {
{ function ss($d1, $d2, $o1, $o2)
function ss($d1, $d2, $o1, $o2)
{
if ($o1 == $d1 && $o2 == $d2)
{ {
if ($d1 == 'eq') if ($o1 == $d1 && $o2 == $d2) {
return 'equipment_entry_selected'; if ($d1 == 'eq') {
else return 'equipment_entry_selected';
return 'inventory_entry_selected'; } else {
return 'inventory_entry_selected';
}
}
} }
}
} }
//quality_(in)inventory //quality_(in)inventory
if (!function_exists('qi')) if (!function_exists('qi')) {
{ function qi($row)
function qi($row)
{
if ($row)
{ {
switch ($row['quality']) if ($row) {
{ switch ($row['quality']) {
case (0): case (0):
return 'iv_quality_really_poor'; return 'iv_quality_really_poor';
case (1): case (1):
@ -39,19 +37,16 @@ if (!function_exists('qi'))
case (6): case (6):
return 'iv_quality_omg'; return 'iv_quality_omg';
} }
}
} }
}
} }
//quality_(in)character('s view) //quality_(in)character('s view)
if (!function_exists('qc')) if (!function_exists('qc')) {
{ function qc($equipment, $id)
function qc($equipment, $id)
{
if ($equipment[$id])
{ {
switch ($equipment[$id]['quality']) if ($equipment[$id]) {
{ switch ($equipment[$id]['quality']) {
case (0): case (0):
return 'eq_quality_really_poor'; return 'eq_quality_really_poor';
case (1): case (1):
@ -67,180 +62,163 @@ if (!function_exists('qc'))
case (6): case (6):
return 'eq_quality_omg'; return 'eq_quality_omg';
} }
}
} }
}
} }
if (!function_exists('can_be_equipped')) if (!function_exists('can_be_equipped')) {
{ function can_be_equipped($item, $hero)
function can_be_equipped($item, $hero) {
{ if (!$item) {
if (!$item) return false;
return FALSE; }
$data['can'] = FALSE; $data['can'] = false;
$data['message'] = ''; $data['message'] = '';
$data['allowed_slot1'] = FALSE; $data['allowed_slot1'] = false;
$data['allowed_slot2'] = FALSE; $data['allowed_slot2'] = false;
$data['two_handed'] = FALSE; $data['two_handed'] = false;
if ($item['type'] != 1) if ($item['type'] != 1) {
{ $data['message'] = 'That item cannot be equipped.';
$data['message'] = 'That item cannot be equipped.'; return $data;
return $data; }
}
if ($item['req_class'] != 0 && $item['req_class'] != $hero['class']) if ($item['req_class'] != 0 && $item['req_class'] != $hero['class']) {
{ $data['message'] = 'You can never use that item.';
$data['message'] = 'You can never use that item.'; return $data;
return $data; }
}
if ($item['req_level'] > $hero['level']) if ($item['req_level'] > $hero['level']) {
{ $data['message'] = 'Your level is too low to use that item.';
$data['message'] = 'Your level is too low to use that item.'; return $data;
return $data; }
}
if ($item['subtype'] == 6) if ($item['subtype'] == 6) {
{ $data['can'] = true;
$data['can'] = TRUE; $data['allowed_slot1'] = 6;
$data['allowed_slot1'] = 6; return $data;
return $data; } elseif ($item['subtype'] == 12) {
} $data['can'] = true;
elseif ($item['subtype'] == 12) $data['allowed_slot1'] = 12;
{ $data['allowed_slot2'] = 13;
$data['can'] = TRUE; return $data;
$data['allowed_slot1'] = 12; } elseif ($item['subtype'] == 14) {
$data['allowed_slot2'] = 13; $data['can'] = true;
return $data; $data['allowed_slot1'] = 14;
} $data['allowed_slot2'] = 15;
elseif ($item['subtype'] == 14) return $data;
{ } elseif ($item['subtype'] == 19) {
$data['can'] = TRUE; if ($hero['class'] == 2) {
$data['allowed_slot1'] = 14; $data['can'] = true;
$data['allowed_slot2'] = 15; $data['allowed_slot1'] = 19;
return $data; return $data;
} }
elseif ($item['subtype'] == 19) }
{
if ($hero['class'] == 2)
{
$data['can'] = TRUE;
$data['allowed_slot1'] = 19;
return $data;
}
}
$datatype = array( $datatype = array(
//warrior //warrior
'1' => array(0, 1, 2, 3, 4), '1' => array(0, 1, 2, 3, 4),
//rogue //rogue
'2' => array(0, 1, 2, FALSE, FALSE), '2' => array(0, 1, 2, false, false),
//archer //archer
'3' => array(0, 1, 2, 3, FALSE)); '3' => array(0, 1, 2, 3, false));
$dataeqslots = array( $dataeqslots = array(
//head //head
'0' => array(0, FALSE), '0' => array(0, false),
//neck //neck
'1' => array(1, FALSE), '1' => array(1, false),
//shoulder //shoulder
'2' => array(2, FALSE), '2' => array(2, false),
//back //back
'3' => array(3, FALSE), '3' => array(3, false),
//chest //chest
'4' => array(4, FALSE), '4' => array(4, false),
//shirt //shirt
'5' => array(5, FALSE), '5' => array(5, false),
//bracer //bracer
'7' => array(7, FALSE), '7' => array(7, false),
//gloves //gloves
'8' => array(8, FALSE), '8' => array(8, false),
//belt //belt
'9' => array(9, FALSE), '9' => array(9, false),
//legs //legs
'10' => array(10, FALSE), '10' => array(10, false),
//foots //foots
'11' => array(11, FALSE), '11' => array(11, false),
); );
//this means every item, whose subsubtype means the type (like cloth) //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 ($item['subtype'] >= 0 && $item['subtype'] < 6 || $item['subtype'] > 6 && $item['subtype'] < 12) {
{ if ($datatype[$hero['class']][$item['subsubtype']] !== false) {
if ($datatype[$hero['class']][$item['subsubtype']] !== FALSE) $data['can'] = true;
{ $data['allowed_slot1'] = $dataeqslots[$item['subtype']][0];
$data['can'] = TRUE; $data['allowed_slot2'] = $dataeqslots[$item['subtype']][1];
$data['allowed_slot1'] = $dataeqslots[$item['subtype']][0]; return $data;
$data['allowed_slot2'] = $dataeqslots[$item['subtype']][1]; } else {
return $data; $data['can'] = false;
} $data['message'] = "You don't have the required proficiency to use that item.";
else return $data;
{ }
$data['can'] = FALSE; }
$data['message'] = "You don't have the required proficiency to use that item.";
return $data;
}
}
$dataclasswep = array( $dataclasswep = array(
//warrior //warrior
'1' => array(FALSE, FALSE, FALSE, FALSE, 5, 6, 7, 8, 9, 10, '1' => array(false, false, false, false, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, FALSE, FALSE, FALSE, 20, FALSE), 11, 12, 13, 14, 15, 16, false, false, false, 20, false),
//rogue //rogue
'2' => array(FALSE, 2, 3, 4, 5, 6, 7, FALSE, 9, 10, '2' => array(false, 2, 3, 4, 5, 6, 7, false, 9, 10,
11, FALSE, 13, 14, 15, FALSE, FALSE, FALSE, FALSE, FALSE, 21), 11, false, 13, 14, 15, false, false, false, false, false, 21),
//archer //archer
'3' => array(FALSE, 2, 3, 4, FALSE, FALSE, FALSE, FALSE, 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) false, false, 13, 14, 15, 16, 17, 18, 19, false, false)
); );
//array(first slot, second slot, two Handed) //array(first slot, second slot, two Handed)
$datawep = array( $datawep = array(
//staff //staff
'1' => array(16, FALSE, TRUE), '1' => array(16, false, true),
//dagger one, main, off //dagger one, main, off
'2' => array(16, 17, FALSE), '2' => array(16, 17, false),
'3' => array(16, FALSE, FALSE), '3' => array(16, false, false),
'4' => array(17, FALSE, FALSE), '4' => array(17, false, false),
//mace one main, off, 2h //mace one main, off, 2h
'5' => array(16, 17, FALSE), '5' => array(16, 17, false),
'6' => array(16, FALSE, FALSE), '6' => array(16, false, false),
'7' => array(17, FALSE, FALSE), '7' => array(17, false, false),
'8' => array(16, FALSE, TRUE), '8' => array(16, false, true),
//axe one, main, off, 2h //axe one, main, off, 2h
'9' => array(16, 17, FALSE), '9' => array(16, 17, false),
'10' => array(16, FALSE, FALSE), '10' => array(16, false, false),
'11' => array(17, FALSE, FALSE), '11' => array(17, false, false),
'12' => array(16, FALSE, TRUE), '12' => array(16, false, true),
//sword one, main, off, 2h //sword one, main, off, 2h
'13' => array(16, 17, FALSE), '13' => array(16, 17, false),
'14' => array(16, FALSE, FALSE), '14' => array(16, false, false),
'15' => array(17, FALSE, FALSE), '15' => array(17, false, false),
'16' => array(16, FALSE, TRUE), '16' => array(16, false, true),
//bow, crossbow, gun //bow, crossbow, gun
'17' => array(18, 17, FALSE), '17' => array(18, 17, false),
'18' => array(18, FALSE, FALSE), '18' => array(18, false, false),
'19' => array(18, FALSE, FALSE), '19' => array(18, false, false),
//?? warri, rogue ranged //?? warri, rogue ranged
'20' => array(18, FALSE, FALSE), '20' => array(18, false, false),
'21' => array(18, FALSE, FALSE) '21' => array(18, false, false)
); );
if ($item['subtype'] == 16) if ($item['subtype'] == 16) {
{ if ($dataclasswep[$hero['class']][$item['subsubtype']] !== false) {
if ($dataclasswep[$hero['class']][$item['subsubtype']] !== FALSE) $data['can'] = true;
{ $data['allowed_slot1'] = $datawep[$item['subsubtype']][0];
$data['can'] = TRUE; $data['allowed_slot2'] = $datawep[$item['subsubtype']][1];
$data['allowed_slot1'] = $datawep[$item['subsubtype']][0]; $data['two_handed'] = $datawep[$item['subsubtype']][2];
$data['allowed_slot2'] = $datawep[$item['subsubtype']][1]; return $data;
$data['two_handed'] = $datawep[$item['subsubtype']][2]; }
return $data; }
}
}
$data['can'] = FALSE; $data['can'] = false;
$data['message'] = 'You cannot use that item.'; $data['message'] = 'You cannot use that item.';
return $data; return $data;
} }
} }

View File

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

View File

@ -1,145 +1,127 @@
<?php <?php
class Ai_model extends MO_Model class Ai_model extends MO_Model
{ {
protected $settings; protected $settings;
function __construct() public 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'])
{ {
$a = rand(0, $this->settings['attack_village_rand']); parent::__construct();
$attacking_num -= $a;
} }
$log .= $attacking_num . " villages attacking. \n"; public function attack()
$reset = FALSE;
//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; $this->parse_settings();
$reset = TRUE; if (!$this->settings['on']) {
} return 'AI is off';
}
//determining which villages are going to attack $sql = "SELECT * FROM ai_villages WHERE attacked='0'";
for ($i = 0; $i < $attacking_num; $i++)
{
$found = FALSE;
while (!$found) $q = $this->db->query($sql);
{
foreach ($ai_villages as $row)
{
$r = rand(1, 100);
if ($r > 50 && !isset($s[$row['id']])) $ai_village_not_attacked = $q->num_rows();
{
$s[$row['id']] = TRUE;
$data[] = $row;
$found = TRUE;
break;
}
}
}
}
//saving to the db that they are attacked $log = "ai_villages query returned " . $ai_village_not_attacked . " rows. \n";
if (!$reset)
{
$sql = "UPDATE ai_villages SET attacked='1' WHERE ";
$first = TRUE; $ai_villages = $q->result_array();
foreach ($data as $row)
{
if ($first)
$first = FALSE;
else
$sql .= " OR ";
$sql .= "id='" . $row['id'] . "'";
}
$this->db->query($sql); $attacking_num = $this->settings['max_attack_village_limit'];
}
else
{
$sql = "UPDATE ai_villages SET attacked='0'";
$this->db->query($sql);
$log .= "ai_villages's attacked field reseted.\n";
}
//getting ai_units //determining how much will attack
$sql = "SELECT * FROM ai_units"; if ($this->settings['attack_village_rand']) {
$q = $this->db->query($sql); $a = rand(0, $this->settings['attack_village_rand']);
$num_ai_units = $q->num_rows();
$res = $q->result_array(); $attacking_num -= $a;
}
if ($this->settings['ai_unit_max_diff'] < $num_ai_units) $log .= $attacking_num . " villages attacking. \n";
{
$num = 0; $reset = false;
$d = FALSE;
while ($num != $this->settings['ai_unit_max_diff']) //resetting ai_villages's attack field if everything will be set to attacked
{ if ($ai_village_not_attacked < $attacking_num) {
foreach ($res as $row) $attacking_num = $ai_village_not_attacked;
{
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 $reset = true;
$log .= "Attacking villages: \n"; }
foreach ($data as $row)
{
$log .= $row['name'] . "(" .$row['X'] . " " . $row['Y'] . ") \n";
}
//sending attackers //determining which villages are going to attack
foreach ($data as $row) for ($i = 0; $i < $attacking_num; $i++) {
{ $found = false;
$sql = "SELECT map.X,map.Y,villages.*
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 FROM map
LEFT JOIN villages ON (map.villageid=villages.id AND map.type='3') LEFT JOIN villages ON (map.villageid=villages.id AND map.type='3')
WHERE (map.type = 3 AND 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) . "'
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 //no villages in range
if (!$q->num_rows()) if (!$q->num_rows()) {
continue; continue;
}
$log .= $row['name'] . " is attacking: \n"; $log .= $row['name'] . " is attacking: \n";
$res = $q->result_array(); $res = $q->result_array();
//sending attackers //sending attackers
foreach ($res as $rrow) foreach ($res as $rrow) {
{ if ($rrow['ai_on'] || $rrow['ai_flagged']) {
if ($rrow['ai_on'] || $rrow['ai_flagged']) $log .= "Sending attackers to: " . $rrow['name'] . "[" . $rrow['id'] . "]";
{ $log .= " (S: " . $rrow['score'] . ")\n";
$log .= "Sending attackers to: " . $rrow['name'] . "[" . $rrow['id'] . "]"; $log .= "Sent: \n";
$log .= " (S: " . $rrow['score'] . ")\n";
$log .= "Sent: \n";
foreach ($ai_units as $unit) foreach ($ai_units as $unit) {
{ $a = ($rrow['score'] / $unit['rate']) / $unit['per_score'];
$a = ($rrow['score'] / $unit['rate']) / $unit['per_score']; $num = floor($a);
$num = floor($a);
$log .= $unit['name'] . "->" . $num . "\n"; $log .= $unit['name'] . "->" . $num . "\n";
$send[] = array('unitid' => $unit['id'], $send[] = array('unitid' => $unit['id'],
'num' => $num); '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'); public function send_attack($send, $ai_village, $village)
$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'])
{ {
$atkid = ($res['attackid'] + 1); $villageid = $village['id'];
}
else
$atkid = 1;
$first = TRUE; $sql = "SELECT max(attackid) AS attackid FROM attacks WHERE villageid='$villageid'";
$sql = "INSERT INTO attacks VALUES"; $q = $this->db->query($sql);
foreach ($send as $row)
$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) $sql = "SELECT * FROM ai_settings";
$first = FALSE;
else
$sql .= ',';
$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 .= ";"; public function get_unit_list_drop_admin()
$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)
{ {
$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; public function list_units_admin()
}
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)
{ {
$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() return $q->row_array();
{ }
$sql = "SELECT * FROM ai_units";
$q = $this->db->query($sql); public function add_unit_admin($data)
{
return $q->result_array(); $sql = "INSERT INTO ai_units
}
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
VALUES(default, VALUES(default,
'" . $data['name'] . "', '" . $data['name'] . "',
'" . $data['icon'] . "', '" . $data['icon'] . "',
@ -317,14 +292,14 @@ class Ai_model extends MO_Model
'" . $data['strong_against'] . "', '" . $data['strong_against'] . "',
'" . $data['weak_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) public function edit_unit_admin($data)
{ {
$sql = "UPDATE ai_units $sql = "UPDATE ai_units
SET name='" . $data['name'] . "', SET name='" . $data['name'] . "',
icon='" . $data['icon'] . "', icon='" . $data['icon'] . "',
ability='" . $data['ability'] . "', ability='" . $data['ability'] . "',
@ -338,52 +313,52 @@ class Ai_model extends MO_Model
weak_against='" . $data['weak_against'] . "' weak_against='" . $data['weak_against'] . "'
WHERE id='" . $data['id'] . "'"; 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() public function get_settings_list_admin()
{ {
$sql = "SELECT * FROM ai_settings"; $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) public function get_setting_admin($id)
{ {
$sql = "SELECT * FROM ai_settings WHERE id='$id'"; $sql = "SELECT * FROM ai_settings WHERE id='$id'";
$q = $this->db->query($sql); $q = $this->db->query($sql);
return $q->row_array(); return $q->row_array();
} }
function edit_setting_admin($data) public function edit_setting_admin($data)
{ {
$sql = "UPDATE ai_settings $sql = "UPDATE ai_settings
SET setting='" . $data['setting'] . "', SET setting='" . $data['setting'] . "',
value='" . $data['value'] . "', value='" . $data['value'] . "',
description='" . $data['description'] . "' description='" . $data['description'] . "'
WHERE id='" . $data['id'] . "'"; 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) public function add_setting_admin($data)
{ {
$sql = "INSERT INTO ai_settings $sql = "INSERT INTO ai_settings
VALUES(default, VALUES(default,
'" . $data['setting'] . "', '" . $data['setting'] . "',
'" . $data['value'] . "' , '" . $data['value'] . "' ,
'" . $data['description'] . "')"; '" . $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 class Assignment_model extends MO_Model
{ {
function __construct() public function __construct()
{ {
parent::__construct(); parent::__construct();
} }
function assign_unit($assid, $num, $slotid, $res, $villageid, $userid) public function assign_unit($assid, $num, $slotid, $res, $villageid, $userid)
{ {
$this->set_resources($res); $this->set_resources($res);
//check if there is building in that slot //check if there is building in that slot
$sql = "SELECT buildings.* FROM village_buildings $sql = "SELECT buildings.* FROM village_buildings
INNER JOIN buildings ON village_buildings.buildingid=buildings.id INNER JOIN buildings ON village_buildings.buildingid=buildings.id
WHERE slotid='$slotid' AND villageid='$villageid'"; WHERE slotid='$slotid' AND villageid='$villageid'";
$q = $this->db->query($sql); $q = $this->db->query($sql);
if (!$q->num_rows()) if (!$q->num_rows()) {
return 1; return 1;
}
$building = $q->row_array(); $building = $q->row_array();
//check if there is already an assignment in which case we just deassign //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, //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 //but we shouldn't care about that since the user can write 0 into the form
$sql = "SELECT * FROM building_assignments $sql = "SELECT * FROM building_assignments
WHERE assignmentid='$assid' WHERE assignmentid='$assid'
AND slotid='$slotid' AND slotid='$slotid'
AND villageid='$villageid'"; AND villageid='$villageid'";
$q = $this->db->query($sql); $q = $this->db->query($sql);
if ($q->num_rows()) if ($q->num_rows()) {
{ //the user wants to just deassign
//the user wants to just deassign $ass = $q->row_array();
$ass = $q->row_array();
//delete assignment //delete assignment
$sql = "DELETE FROM building_assignments WHERE id='" . $ass['id'] . "'"; $sql = "DELETE FROM building_assignments WHERE id='" . $ass['id'] . "'";
$this->db->query($sql); $this->db->query($sql);
//giving back units //giving back units
//getting units //getting units
$sql = "SELECT * FROM village_units $sql = "SELECT * FROM village_units
WHERE villageid='$villageid' WHERE villageid='$villageid'
AND userid='$userid'"; AND userid='$userid'";
$q = $this->db->query($sql); $q = $this->db->query($sql);
if ($q->num_rows()) if ($q->num_rows()) {
{ $units = $q->result_array();
$units = $q->result_array(); } else {
} $units = false;
else }
{
$units = FALSE;
}
$found = FALSE; $found = false;
if ($units) if ($units) {
{ foreach ($units as $row) {
foreach ($units as $row) if ($row['unitid'] == $ass['unitid']) {
{ $found = true;
if ($row['unitid'] == $ass['unitid']) $fdata = $row['id'];
{ }
$found = TRUE; }
$fdata = $row['id']; }
}
}
}
if ($found) if ($found) {
{ $sql = "UPDATE village_units
$sql = "UPDATE village_units
SET unitcount = unitcount + '". $ass['num_unit'] . "' SET unitcount = unitcount + '". $ass['num_unit'] . "'
WHERE id='$fdata'"; WHERE id='$fdata'";
} } else {
else $sql = "INSERT INTO village_units
{
$sql = "INSERT INTO village_units
VALUES(default, '$userid', '$villageid', VALUES(default, '$userid', '$villageid',
'" . $ass['unitid'] . "', '" . $ass['num_unit'] . "')"; '" . $ass['unitid'] . "', '" . $ass['num_unit'] . "')";
} }
$this->db->query($sql); $this->db->query($sql);
//substract the bonuses //substract the bonuses
$this->substract_modifiers($assid, $villageid, 'assignment', $this->substract_modifiers(
$ass['num_bonus']); $assid,
$villageid,
'assignment',
$ass['num_bonus']
);
$this->write_resources(); $this->write_resources();
//taking away spells //taking away spells
$sql = "DELETE FROM building_spells $sql = "DELETE FROM building_spells
WHERE assignmentid='$assid' WHERE assignmentid='$assid'
AND slotid='$slotid' AND slotid='$slotid'
AND villageid='$villageid'"; AND villageid='$villageid'";
$this->db->query($sql); $this->db->query($sql);
return 0; return 0;
} }
//check if assignment exists //check if assignment exists
$sql = "SELECT * FROM assignments WHERE id='$assid'"; $sql = "SELECT * FROM assignments WHERE id='$assid'";
$q = $this->db->query($sql); $q = $this->db->query($sql);
if (!$q->num_rows()) if (!$q->num_rows()) {
return 2; return 2;
}
$ass = $q->row_array(); $ass = $q->row_array();
//checking technology //checking technology
if ($ass['req_tech']) if ($ass['req_tech']) {
if (!$this->has_req_tech($ass['req_tech'], $villageid, $slotid)) if (!$this->has_req_tech($ass['req_tech'], $villageid, $slotid)) {
return 3; return 3;
}
//check if building has that assignment }
if (!($building['assignment1'] == $ass['id'] ||
$building['assignment2'] == $ass['id'] || //check if building has that assignment
$building['assignment3'] == $ass['id'] || if (!($building['assignment1'] == $ass['id'] ||
$building['assignment4'] == $ass['id'] || $building['assignment2'] == $ass['id'] ||
$building['assignment5'] == $ass['id'])) $building['assignment3'] == $ass['id'] ||
return 3; $building['assignment4'] == $ass['id'] ||
$building['assignment5'] == $ass['id'])) {
return 3;
}
//getting unit //getting unit
$sql = "SELECT * FROM village_units $sql = "SELECT * FROM village_units
WHERE unitid='" . $ass['unitid'] . "' WHERE unitid='" . $ass['unitid'] . "'
AND userid='$userid'"; AND userid='$userid'";
$q = $this->db->query($sql); $q = $this->db->query($sql);
if (!$q->num_rows()) if (!$q->num_rows()) {
return 4; return 4;
}
$unit = $q->row_array(); $unit = $q->row_array();
//it probably shouldn't happen but who knows //it probably shouldn't happen but who knows
if (!$unit['unitcount']) if (!$unit['unitcount']) {
return 5; return 5;
}
//if the user just clicks on the assign we should assign max //if the user just clicks on the assign we should assign max
if (!$num) if (!$num) {
$num = $ass['max']; $num = $ass['max'];
}
//we shouldn't assign more than allowed //we shouldn't assign more than allowed
if ($ass['max'] < $num) if ($ass['max'] < $num) {
$num = $ass['max']; $num = $ass['max'];
}
//determining how much can be assigned //determining how much can be assigned
if ($unit['unitcount'] < $num) if ($unit['unitcount'] < $num) {
$num = $unit['unitcount']; $num = $unit['unitcount'];
}
//determining number of bonuses granted //determining number of bonuses granted
$num_bonus = floor(($num / $ass['bonus_per_assigned'])); $num_bonus = floor(($num / $ass['bonus_per_assigned']));
$count = ($unit['unitcount'] - $num); $count = ($unit['unitcount'] - $num);
//updating unit field in db //updating unit field in db
if ($count <= 0) if ($count <= 0) {
{ $sql = "DELETE FROM village_units WHERE id='" . $unit['id'] . "'";
$sql = "DELETE FROM village_units WHERE id='" . $unit['id'] . "'"; } else {
} $sql = "UPDATE village_units
else
{
$sql = "UPDATE village_units
SET unitcount=unitcount - '$num' SET unitcount=unitcount - '$num'
WHERE id='" . $unit['id'] . "'"; WHERE id='" . $unit['id'] . "'";
} }
$this->db->query($sql); $this->db->query($sql);
//adding assignment //adding assignment
$sql = "INSERT INTO building_assignments $sql = "INSERT INTO building_assignments
VALUES(default, '$villageid', '$slotid', '" . $unit['unitid'] . "', VALUES(default, '$villageid', '$slotid', '" . $unit['unitid'] . "',
'$num', '" . $assid . "', '$num_bonus')"; '$num', '" . $assid . "', '$num_bonus')";
$this->db->query($sql); $this->db->query($sql);
//grant resource bonus //grant resource bonus
$this->add_modifiers($assid, $villageid, 'assignment', $num_bonus); $this->add_modifiers($assid, $villageid, 'assignment', $num_bonus);
$this->write_resources(); $this->write_resources();
//assignment has spell //assignment has spell
if (!$ass['spellid']) if (!$ass['spellid']) {
return 0; return 0;
}
/* /*
//only give spells if bonus is granted //only give spells if bonus is granted
if (!$num_bonus) if (!$num_bonus)
return 0; return 0;
*/ */
//only give spell if max unit assigned //only give spell if max unit assigned
if (!($ass['max'] == $num)) if (!($ass['max'] == $num)) {
return 0; return 0;
}
//granting spell //granting spell
$sql = "INSERT INTO building_spells $sql = "INSERT INTO building_spells
VALUES(default, '$villageid', '$slotid', '$assid', VALUES(default, '$villageid', '$slotid', '$assid',
'" . $ass['spellid'] . "')"; '" . $ass['spellid'] . "')";
$this->db->query($sql); $this->db->query($sql);
return 0; return 0;
} }
function get_assignments($slotid, $villageid, $userid) public function get_assignments($slotid, $villageid, $userid)
{ {
if ($slotid > parent::TOTAL_BUILDINGS) if ($slotid > parent::TOTAL_BUILDINGS) {
return 1; //that shouldn't happen 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 INNER JOIN buildings ON village_buildings.buildingid = buildings.id
WHERE village_buildings.slotid='$slotid' WHERE village_buildings.slotid='$slotid'
AND village_buildings.villageid='$villageid'"; AND village_buildings.villageid='$villageid'";
$q = $this->db->query($sql); $q = $this->db->query($sql);
if (!$q->num_rows()) if (!$q->num_rows()) {
return 2; //nothing in that slot return 2;
} //nothing in that slot
$res = $q->row_array(); $res = $q->row_array();
//getting assignment data //getting assignment data
$sql = "SELECT assignments.*,units.name $sql = "SELECT assignments.*,units.name
FROM assignments FROM assignments
INNER JOIN units ON assignments.unitid=units.id INNER JOIN units ON assignments.unitid=units.id
WHERE assignments.id='" . $res['assignment1'] . "' WHERE assignments.id='" . $res['assignment1'] . "'
@ -234,97 +239,87 @@ class Assignment_model extends MO_Model
OR assignments.id='" . $res['assignment4'] . "' OR assignments.id='" . $res['assignment4'] . "'
OR assignments.id='" . $res['assignment5'] . "'"; OR assignments.id='" . $res['assignment5'] . "'";
$q = $this->db->query($sql); $q = $this->db->query($sql);
if (!$q->num_rows()) if (!$q->num_rows()) {
{ $data['assigndata'] = false; //building doesn't have assignments
$data['assigndata'] = FALSE; //building doesn't have assignments return $data;
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) foreach ($adata as $row) {
{ if ($this->have_technology($tech, $row['req_tech'])) {
if ($this->have_technology($tech, $row['req_tech'])) $data['assigndata'][] = $row;
$data['assigndata'][] = $row; }
} }
if (!isset($data['assigndata'])) if (!isset($data['assigndata'])) {
{ $data['assigndata'] = false;
$data['assigndata'] = FALSE; return $data;
return $data; }
}
//getting assigned data //getting assigned data
$sql = "SELECT * FROM building_assignments $sql = "SELECT * FROM building_assignments
WHERE slotid='$slotid' WHERE slotid='$slotid'
AND villageid='$villageid'"; AND villageid='$villageid'";
$q = $this->db->query($sql); $q = $this->db->query($sql);
if (!$q->num_rows()) if (!$q->num_rows()) {
{ $data['assigned'] = false;
$data['assigned'] = FALSE; } else {
} $data['assigned'] = $q->result_array();
else }
{
$data['assigned'] = $q->result_array();
}
$data['building'] = $res; $data['building'] = $res;
//getting units //getting units
$sql = "SELECT * FROM village_units $sql = "SELECT * FROM village_units
WHERE villageid='$villageid' WHERE villageid='$villageid'
AND userid='$userid'"; AND userid='$userid'";
$q = $this->db->query($sql); $q = $this->db->query($sql);
if ($q->num_rows) if ($q->num_rows) {
{ $data['units'] = $q->result_array();
$data['units'] = $q->result_array(); } else {
} $data['units'] = false;
else }
{
$data['units'] = FALSE; return $data;
} }
return $data; public function get_assignment_list_drop_admin()
}
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)
{ {
$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() $q = $this->db->query($sql);
{
$sql = "SELECT * FROM assignments";
$q = $this->db->query($sql); return $q->result_array();
}
return $q->result_array(); public function add_assignment_admin($data)
} {
$sql = "INSERT INTO assignments
function add_assignment_admin($data)
{
$sql = "INSERT INTO assignments
VALUES (default, VALUES (default,
'" . $data['unitid'] . "', '" . $data['unitid'] . "',
'" . $data['max'] . "', '" . $data['max'] . "',
@ -348,14 +343,14 @@ class Assignment_model extends MO_Model
'" . $data['mod_percent_mana'] . "', '" . $data['mod_percent_mana'] . "',
'" . $data['description'] . "')"; '" . $data['description'] . "')";
$this->db->query($sql); $this->db->query($sql);
$this->_create_sql($sql); $this->_create_sql($sql);
} }
function edit_assignment_admin($data) public function edit_assignment_admin($data)
{ {
$sql = "UPDATE assignments $sql = "UPDATE assignments
SET unitid='" . $data['unitid'] . "', SET unitid='" . $data['unitid'] . "',
max='" . $data['max'] . "', max='" . $data['max'] . "',
bonus_per_assigned='" . $data['bonus_per_assigned'] . "', bonus_per_assigned='" . $data['bonus_per_assigned'] . "',
@ -379,18 +374,18 @@ class Assignment_model extends MO_Model
description='" . $data['description'] . "' description='" . $data['description'] . "'
WHERE id='" . $data['id'] . "'"; 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) public function get_assignment_admin($id)
{ {
$sql = "SELECT * FROM assignments WHERE id='$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 //nowhitesp

View File

@ -1,173 +1,162 @@
<?php <?php
class Building_model extends MO_Model class Building_model extends MO_Model
{ {
function __construct() public function __construct()
{ {
parent::__construct(); parent::__construct();
} }
function get_building($buildingid) public function get_building($buildingid)
{ {
$sql = "SELECT * FROM buildings WHERE id='$buildingid'"; $sql = "SELECT * FROM buildings WHERE id='$buildingid'";
$q = $this->db->query($sql); $q = $this->db->query($sql);
if ($q->num_rows()) if ($q->num_rows()) {
return $q->row_array(); return $q->row_array();
}
return FALSE; return false;
} }
function set_build_in_progress($slotid, $villageid) public function set_build_in_progress($slotid, $villageid)
{ {
$sql = "INSERT INTO village_buildings $sql = "INSERT INTO village_buildings
VALUES(default, '$villageid', '$slotid', '2')"; VALUES(default, '$villageid', '$slotid', '2')";
$this->db->query($sql); $this->db->query($sql);
} }
function building_list($villageid) public function building_list($villageid)
{ {
$sql = "SELECT * FROM buildings $sql = "SELECT * FROM buildings
WHERE rank='1'"; WHERE rank='1'";
$q = $this->db->query($sql); $q = $this->db->query($sql);
$res = $q->result_array(); $res = $q->result_array();
$sql = "SELECT * FROM village_buildings WHERE villageid='$villageid'"; $sql = "SELECT * FROM village_buildings WHERE villageid='$villageid'";
$q = $this->db->query($sql); $q = $this->db->query($sql);
$vb = $q->result_array(); $vb = $q->result_array();
//checking requirements //checking requirements
foreach ($res as $row) foreach ($res as $row) {
{ if ($this->can_build($villageid, $row, $vb, false)) {
if ($this->can_build($villageid, $row, $vb, FALSE)) $build[] = $row;
{ }
$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 //returns 0 if upgrade in progress
$tech = $this->get_village_technologies($villageid); //returns 1 if technology requirement not met
//returns 2 if not enough resources
foreach ($build as $row) //returns 3 if can be built
public function can_be_upgraded($event, $res, $building, $villageid, $query = false)
{ {
if ($row['req_tech']) if ($query) {
{ //this means we have to get building from the db,
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,
//and $building is only the id //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 public function can_build($villageid, $buildingid, $data = 0, $is_buildingid = true)
//we can just do this, since event is filtered to update events
if ($event)
{ {
return 0; //STUB requirements aren't implemented
return true;
} }
if (!$this->has_req_tech($building['req_tech'], $villageid)) public function is_valid_slot($slotid, $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; if ($slotid > parent::TOTAL_BUILDINGS) {
} return false;
}
//can be built $sql = "SELECT id FROM village_buildings
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
WHERE villageid='$villageid' AND slotid='$slotid'"; WHERE villageid='$villageid' AND slotid='$slotid'";
$q = $this->db->query($sql); $q = $this->db->query($sql);
if ($q->num_rows()) if ($q->num_rows()) {
return FALSE; return false;
}
return TRUE; 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 $data; public function get_building_ranks_admin()
} {
$sql = "SELECT * FROM buildings WHERE id > 2";
$q = $this->db->query($sql);
function list_buildings_admin() $res = $q->result_array();
{
$sql = "SELECT * FROM buildings";
$q = $this->db->query($sql);
return $q->result_array(); $data[0] = 'Nothing';
}
function get_building_admin($id) foreach ($res as $row) {
{ if (!$row['next_rank']) {
$sql = "SELECT * FROM buildings WHERE id='$id'"; $name = $row['name'] . ' R: ' . $row['rank'];
$q = $this->db->query($sql); $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'] . "', SET name='" . $data['name'] . "',
description='" . $data['description'] . "', description='" . $data['description'] . "',
icon='" . $data['icon'] . "', icon='" . $data['icon'] . "',
@ -209,14 +198,14 @@ class Building_model extends MO_Model
tech_secondary_group='" . $data['tech_secondary_group'] . "' tech_secondary_group='" . $data['tech_secondary_group'] . "'
WHERE id='" . $data['id'] . "'"; 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) public function add_building_admin($data)
{ {
$sql = "INSERT INTO buildings VALUES(default, $sql = "INSERT INTO buildings VALUES(default,
'" . $data['name'] . "', '" . $data['name'] . "',
'" . $data['description'] . "', '" . $data['description'] . "',
'" . $data['icon'] . "', '" . $data['icon'] . "',
@ -257,9 +246,9 @@ class Building_model extends MO_Model
'" . $data['tech_group'] . "', '" . $data['tech_group'] . "',
'" . $data['tech_secondary_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 class Changelog_model extends MO_Model
{ {
public function __construct()
{
parent::__construct();
}
function __construct() public function new_version($version)
{ {
parent::__construct(); $time = time();
}
function new_version($version) $sql = "INSERT INTO changelog_versions VALUES(default, '$version', '$time')";
{ $this->db->query($sql);
$time = time(); $this->_create_sql($sql);
}
$sql = "INSERT INTO changelog_versions VALUES(default, '$version', '$time')"; public function new_commit($text)
$this->db->query($sql); {
$this->_create_sql($sql); $time = time();
}
function new_commit($text) $sql = "SELECT id FROM changelog_versions ORDER BY id DESC LIMIT 1";
{ $q = $this->db->query($sql);
$time = time(); $res = $q->row_array();
$versionid = $res['id'];
$sql = "SELECT id FROM changelog_versions ORDER BY id DESC LIMIT 1"; $sql = "INSERT INTO changelog_commits VALUES(default, '$versionid', '$text', '$time')";
$q = $this->db->query($sql); $this->db->query($sql);
$res = $q->row_array(); $this->_create_sql($sql);
$versionid = $res['id']; }
$sql = "INSERT INTO changelog_commits VALUES(default, '$versionid', '$text', '$time')"; public function get_versions()
$this->db->query($sql); {
$this->_create_sql($sql); $sql = "SELECT * FROM changelog_versions ORDER BY timestamp DESC";
} $q = $this->db->query($sql);
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() public function get_commits()
{ {
$sql = "SELECT * FROM changelog_commits ORDER BY timestamp DESC"; $sql = "SELECT * FROM changelog_commits ORDER BY timestamp DESC";
$q = $this->db->query($sql); $q = $this->db->query($sql);
return $q->result_array(); return $q->result_array();
}
}
} }
//nowhitesp //nowhitesp

View File

@ -1,10 +1,9 @@
<?php <?php
class Cron_model extends MO_Model class Cron_model extends MO_Model
{ {
function __construct() public function __construct()
{ {
parent::__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 class Hero_model extends MO_Model
{ {
function __construct() public 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'])
{ {
$sql = "SELECT * FROM heroes WHERE userid = ? AND deleted = '0'"; parent::__construct();
$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='' 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 = ?"; WHERE id = ?";
$this->db->query($sql, array($id)); $this->db->query($sql, array($id));
return TRUE; 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';
} }
$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()) $this->db->query($sql, array($userid));
return FALSE;
$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, VALUES(default, '$userid', ?, default, default,
?, default, '" . $cd['max_health'] . "', '" . $cd['max_mana'] . "', '" . $cd['max_health'] . "', ?, default, '" . $cd['max_health'] . "', '" . $cd['max_mana'] . "', '" . $cd['max_health'] . "',
'" . $cd['max_mana'] . "', default, default, '" . $cd['nomod_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, ?, '" . $cd['nomod_heal_min'] . "', '" . $cd['nomod_heal_max'] . "', default, default, ?,
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 //add starter spells
//make actionbar entry //make actionbar entry
} }
function hero_name_is_unique($name) public function hero_name_is_unique($name)
{ {
$name = ucfirst(mb_strtolower($name, 'UTF-8')); $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()) if ($q->num_rows()) {
return FALSE; return false;
else } else {
return TRUE; return true;
} }
}
function all_hero_templates_admin() public function all_hero_templates_admin()
{ {
$sql = "SELECT * FROM hero_templates"; $sql = "SELECT * FROM hero_templates";
$q = $this->db->query($sql); $q = $this->db->query($sql);
if ($q->num_rows()) if ($q->num_rows()) {
return $q->result_array(); return $q->result_array();
else } else {
return FALSE; return false;
} }
}
function get_template_admin($id) public function get_template_admin($id)
{ {
$sql = "SELECT * FROM hero_templates WHERE id = '$id'"; $sql = "SELECT * FROM hero_templates WHERE id = '$id'";
$q = $this->db->query($sql); $q = $this->db->query($sql);
if ($q->num_rows()) if ($q->num_rows()) {
return $q->row_array(); return $q->row_array();
else } else {
return FALSE; return false;
} }
}
function edit_template_admin($d) public function edit_template_admin($d)
{ {
$c = $this->template_calc_stats($d, 'edit'); $c = $this->template_calc_stats($d, 'edit');
$sql = "UPDATE hero_templates $sql = "UPDATE hero_templates
SET classname = '" . $d['classname'] . "', SET classname = '" . $d['classname'] . "',
nomod_max_health = '" . $d['nomod_max_health'] . "', nomod_max_health = '" . $d['nomod_max_health'] . "',
nomod_max_mana = '" . $d['nomod_max_mana'] . "', nomod_max_mana = '" . $d['nomod_max_mana'] . "',
@ -251,21 +257,21 @@ class Hero_model extends MO_Model
heal_max = '" . $c['heal_max'] . "' heal_max = '" . $c['heal_max'] . "'
WHERE id = '" . $d['id'] . "'"; 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) public function add_template_admin($d)
{ {
//0 armor is being added, because when adding a new class, eqipments shouldn't exists in db //0 armor is being added, because when adding a new class, eqipments shouldn't exists in db
//think about this! //think about this!
//maybe this is uniform in template and normal mode! or can be made uniform //maybe this is uniform in template and normal mode! or can be made uniform
$c = $this->template_calc_stats($d, 'add'); $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'] . "', VALUES(default, '" . $d['classname'] . "', '" . $d['nomod_max_health'] . "',
'" . $d['nomod_max_mana'] . "', '" . $c['max_health'] . "', '" . $d['nomod_max_mana'] . "', '" . $c['max_health'] . "',
'" . $c['max_mana'] . "', '" . $d['agility'] . "', '" . $d['strength'] . "', '" . $c['max_mana'] . "', '" . $d['agility'] . "', '" . $d['strength'] . "',
@ -281,51 +287,50 @@ class Hero_model extends MO_Model
'" . $d['nomod_heal_min'] . "', '" . $d['nomod_heal_min'] . "',
'" . $d['nomod_heal_max'] . "', '" . $c['heal_min'] . "', '" . $c['heal_max'] . "')"; '" . $d['nomod_heal_max'] . "', '" . $c['heal_min'] . "', '" . $c['heal_max'] . "')";
$this->db->query($sql); $this->db->query($sql);
$this->_create_sql($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'];
} }
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 <?php
class Image_model extends MO_Model class Image_model extends MO_Model
{ {
function __construct() public 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'])
{ {
$data['source_image'] = $path . $data['wm_text'] . '.png'; parent::__construct();
$this->image_lib->initialize($data);
$this->image_lib->watermark();
return;
} }
//apply all is set public function apply_menu_images($data)
$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++)
{ {
$data['source_image'] = $path . $menu_file_list[$i] . '.png'; $path = './img/generated/';
$data['wm_text'] = $menu_list[$i];
$this->image_lib->initialize($data); $this->load->library('image_lib');
$this->image_lib->watermark();
$this->image_lib->clear();
}
}
function prepare_dir($for, $sourcefile, $group = 1, $filename = FALSE) if ($data['apply_all']) {
{ $this->prepare_dir('menu', $data['file'], $data['menu_group']);
$path = './img/generated/'; } else {
$source = './img/imggen/' . $sourcefile; $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') $this->image_lib->watermark();
{
$img = read_file($source);
if (!$filename) return;
{ }
$menu_list = $this->get_menu_file_list($group);
foreach ($menu_list as $row) //apply all is set
{ $menu_list = $this->get_menu_list($data['menu_group']);
$file = $path . $row . '.png'; $menu_file_list = $this->get_menu_file_list($data['menu_group']);
write_file($file, $img); for ($i = 0; $i < sizeof($menu_list); $i++) {
} $data['source_image'] = $path . $menu_file_list[$i] . '.png';
} $data['wm_text'] = $menu_list[$i];
else
{
$file = $path . $filename . '.png';
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) $this->load->helper('file');
{
if ($group == 1) delete_files($path, false);
{
//select village vill be omitted since it will need a different style button with a ˇ if ($for == 'menu') {
$data[] = 'News'; $img = read_file($source);
$data[] = 'Village';
$data[] = 'Select Village'; if (!$filename) {
$data[] = 'Forum'; $menu_list = $this->get_menu_file_list($group);
$data[] = 'Changelog';
$data[] = 'Settings'; foreach ($menu_list as $row) {
$data[] = 'Logout'; $file = $path . $row . '.png';
$data[] = 'Forum Mod Panel';
$data[] = 'GM Panel'; write_file($file, $img);
$data[] = 'Admin Panel'; }
} } else {
$file = $path . $filename . '.png';
if ($group == 2)
{ write_file($file, $img);
$data[] = 'Stats'; }
}
} }
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) return $data;
{
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; 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() return $data;
{ }
$data = array(
public function get_menu_group_list_drop()
{
$data = array(
'1' => 'main', '1' => 'main',
'2' => 'alt1'); '2' => 'alt1');
return $data; 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; public function apply_slot_images($data)
}
function get_font_list_drop()
{
$this->load->helper('directory');
$dir = directory_map('./system/fonts', 1);
foreach ($dir as $row)
{ {
$a = explode('.', $row); $path = './img/generated/';
if ($a[1] == 'ttf' || $a['1'] == 'TTF') $this->load->library('image_lib');
{
$data[$row] = $row; $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() $dir = directory_map('./img/imggen/', 1);
{
$data = array( 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', 'top' => 'top',
'middle' => 'middle', 'middle' => 'middle',
'bottom' => 'bottom'); 'bottom' => 'bottom');
return $data; return $data;
} }
function get_h_align_drop() public function get_h_align_drop()
{ {
$data = array( $data = array(
'left' => 'left', 'left' => 'left',
'center' => 'center', 'center' => 'center',
'right' => 'right'); 'right' => 'right');
return $data; return $data;
} }
function get_overlay_list_drop() public function get_overlay_list_drop()
{
$this->load->helper('directory');
$dir = directory_map('./img/imggen/overlay/', 1);
foreach ($dir as $row)
{ {
$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) $this->load->helper('file');
{
$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'); 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) $this->load->helper('file');
{
$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'); 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 <?php
class Log_model extends MO_Model class Log_model extends MO_Model
{ {
function __construct() public 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'])
{ {
$sql = "UPDATE combat_logs SET new='0' WHERE id='$id'"; parent::__construct();
$this->db->query($sql);
} }
return $res; public function delete_combat_log($id, $villageid)
}
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)
{ {
if ($row['new']) $sql = "SELECT * FROM combat_logs WHERE id='$id'";
{
$new = TRUE; $q = $this->db->query($sql);
break;
} 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 class Mail_model extends MO_Model
{ {
function __construct() public function __construct()
{ {
parent::__construct(); parent::__construct();
} }
function save_draft($data, $userid) public function save_draft($data, $userid)
{ {
//values id, userid, friend, name, X, Y, time, subject, body //values id, userid, friend, name, X, Y, time, subject, body
$sql = "INSERT INTO mail_drafts $sql = "INSERT INTO mail_drafts
VALUES(default, '$userid', ?, ?, ?, ?, '" . time() . "', ?, ?)"; VALUES(default, '$userid', ?, ?, ?, ?, '" . time() . "', ?, ?)";
//friend, name, X, Y, subject, body //friend, name, X, Y, subject, body
$this->db->query($sql, array(0, $data['name'], 0, 0, $data['subject'], $data['message'])); $this->db->query($sql, array(0, $data['name'], 0, 0, $data['subject'], $data['message']));
} }
function get_drafts($userid) public function get_drafts($userid)
{ {
$sql = "SELECT * FROM mail_drafts WHERE userid='$userid'"; $sql = "SELECT * FROM mail_drafts WHERE userid='$userid'";
$q = $this->db->query($sql); $q = $this->db->query($sql);
if (!$q->num_rows()) if (!$q->num_rows()) {
return FALSE; return false;
}
return $q->result_array(); return $q->result_array();
} }
function get_draft($id, $userid) public function get_draft($id, $userid)
{ {
$sql = "SELECT * FROM mail_drafts WHERE id = ?"; $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()) if (!$q->num_rows()) {
return FALSE; return false;
}
$res = $q->row_array(); $res = $q->row_array();
if ($res['userid'] != $userid) if ($res['userid'] != $userid) {
return FALSE; return false;
}
return $res; return $res;
} }
function delete_draft($id, $userid) public function delete_draft($id, $userid)
{ {
$sql = "DELETE FROM mail_drafts WHERE id = ? AND 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) public function get_inbox($userid, $new)
{ {
$sql = "SELECT mails.*,users.username FROM mails $sql = "SELECT mails.*,users.username FROM mails
LEFT JOIN users on mails.sender=users.id LEFT JOIN users on mails.sender=users.id
WHERE owner='$userid' WHERE owner='$userid'
ORDER BY time DESC"; ORDER BY time DESC";
$q = $this->db->query($sql); $q = $this->db->query($sql);
if (!$q->num_rows()) if (!$q->num_rows()) {
return FALSE; return false;
}
$res = $q->result_array(); $res = $q->result_array();
if (!$new) if (!$new) {
return $res; return $res;
}
$found = FALSE; $found = false;
foreach ($res as $row) foreach ($res as $row) {
{ if ($row['new']) {
if ($row['new']) $found = true;
{ break;
$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) public function send_message($data, $userid)
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)
{ {
$d = ""; $sql = "SELECT * FROM users WHERE username = ?";
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; $q = $this->db->query($sql, array($data['name']));
if (strlen($sub) == 70) if (!$q->num_rows()) {
$d .= "«"; return;
}
$d .= "\r\n"; $res = $q->row_array();
}
}
else
{
$d .= $row . "\r\n";
}
}
$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"); //determining line endings
$text = str_ireplace($breaks, "<br />", $data['message']); $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')"; '" . $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 //saving mail to sent
//id, userid, to_id, to, time, subject, body //id, userid, to_id, to, time, subject, body
$sql = "INSERT INTO mail_sent VALUES(default, ?, ?, ?, " . time(). ", ?, ?)"; $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) 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 //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 $sql = "SELECT mails.*,users.username FROM mails
LEFT JOIN users ON mails.sender=users.id LEFT JOIN users ON mails.sender=users.id
WHERE mails.id = ? AND mails.owner = ?"; 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()) if (!$q->num_rows()) {
return FALSE; return false;
}
$res = $q->row_array(); $res = $q->row_array();
if ($res['new']) if ($res['new']) {
{ //userid is correct we can query with just the id
//userid is correct we can query with just the id $sql = "UPDATE mails SET new='0' WHERE 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 //querying userid here, so if the user types a random id into the browser bar, it won't return anything
$breaks = array("<br />","<br>","<br/>"); $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'); if (!$q->num_rows()) {
$data['subject'] = htmlspecialchars_decode($data['subject'], ENT_HTML5, 'UTF-8'); return false;
}
return $q->row_array();
} }
return $res;
}
function get_sent($id, $userid) public function get_all_sent($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 userid = ?";
$sql = "SELECT * FROM mail_sent WHERE id = ? AND userid = ?";
$q = $this->db->query($sql, array($id, $userid)); $q = $this->db->query($sql, array($userid));
if (!$q->num_rows()) if (!$q->num_rows()) {
return FALSE; return false;
}
return $q->row_array(); return $q->result_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();
}
} }
//nowhitesp //nowhitesp

View File

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

View File

@ -2,72 +2,70 @@
class Mo_common_model extends MO_Model class Mo_common_model extends MO_Model
{ {
function __construct() public function __construct()
{ {
parent::__construct(); parent::__construct();
} }
function get_hero_data($userid) public function get_hero_data($userid)
{ {
$sql = "SELECT * FROM heroes WHERE userid = ? AND selected = '1'"; $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()) if (!$q->num_rows()) {
return FALSE; return false;
}
return $q->row_array(); return $q->row_array();
} }
function get_userlevel($uid) public function get_userlevel($uid)
{ {
$sql = "SELECT userlevel FROM users WHERE id=$uid"; $sql = "SELECT userlevel 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['userlevel']; return $res['userlevel'];
}
} public function get_username($uid)
{
$sql = "SELECT username FROM users WHERE id=$uid";
function get_username($uid) $q = $this->db->query($sql);
{
$sql = "SELECT username FROM users WHERE id=$uid";
$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) return $q->row_array();
{ }
$sql = "SELECT * FROM users WHERE id='$id'";
$q = $this->db->query($sql);
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();
} return $res['id'];
}
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();
}
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 class News_model extends MO_Model
{ {
public function get_news($page)
{
$p = ($page - 1) * 5;
function get_news($page) $sql = "SELECT * FROM news LIMIT $p, 5";
{
$p = ($page - 1) * 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(); public function add_news($text, $uname)
} {
$sql = "INSERT INTO news VALUES(default, '$uname', '$text')";
function add_news($text, $uname)
{ return $this->db->query($sql);
$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 del_news($id)
{
$sql = "";
return $this->db->query($sql);
}
} }
//nowhitesp //nowhitesp

View File

@ -1,64 +1,58 @@
<?php <?php
class Resource_model extends MO_Model class Resource_model extends MO_Model
{ {
function __construct() public 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++)
{ {
$res['food'] -= $unit['cost_food']; parent::__construct();
$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; //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) public function have_enough_resources_building($buildingid, $villageid)
{ {
$res = $this->get_resources($villageid); $res = $this->get_resources($villageid);
$sql = "SELECT * FROM buildings WHERE id='$buildingid'"; $sql = "SELECT * FROM buildings WHERE id='$buildingid'";
$q = $this->db->query($sql); $q = $this->db->query($sql);
$building = $q->row_array(); $building = $q->row_array();
if ($res['food'] >= $building['cost_food'] && if ($res['food'] >= $building['cost_food'] &&
$res['wood'] >= $building['cost_wood'] && $res['wood'] >= $building['cost_wood'] &&
$res['stone'] >= $building['cost_stone'] && $res['stone'] >= $building['cost_stone'] &&
$res['iron'] >= $building['cost_iron'] && $res['iron'] >= $building['cost_iron'] &&
$res['mana'] >= $building['cost_mana']) $res['mana'] >= $building['cost_mana']) {
return TRUE; return true;
}
return FALSE; return false;
}
}
} }
//nowhitesp //nowhitesp

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -1,101 +1,101 @@
<?php <?php
class Unit_model extends MO_Model class Unit_model extends MO_Model
{ {
function __construct() public function __construct()
{ {
parent::__construct(); parent::__construct();
} }
function get_village_units($villageid) public function get_village_units($villageid)
{ {
$sql = "SELECT users.username,units.*,village_units.userid,village_units.unitcount $sql = "SELECT users.username,units.*,village_units.userid,village_units.unitcount
FROM village_units FROM village_units
LEFT JOIN users ON village_units.userid=users.id LEFT JOIN users ON village_units.userid=users.id
LEFT JOIN units ON village_units.unitid=units.id LEFT JOIN units ON village_units.unitid=units.id
WHERE villageid='$villageid'"; WHERE villageid='$villageid'";
$q = $this->db->query($sql); $q = $this->db->query($sql);
//TODO order it! //TODO order it!
return $q->result_array(); 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'];
}
} }
//if more are in progress that the building can make public function get_unit($id)
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)
{ {
$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) if ($event) {
{ foreach ($event as $row) {
$sql = "INSERT INTO units $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, VALUES(default,
'" . $data['type'] . "', '" . $data['type'] . "',
'" . $data['name'] . "', '" . $data['name'] . "',
@ -122,22 +122,22 @@ class Unit_model extends MO_Model
'" . $data['mod_rate_iron'] . "', '" . $data['mod_rate_iron'] . "',
'" . $data['mod_rate_mana'] . "')"; '" . $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) public function get_unit_admin($id)
{ {
$sql = "SELECT * FROM units WHERE id='$id'"; $sql = "SELECT * FROM units WHERE id='$id'";
$q = $this->db->query($sql); $q = $this->db->query($sql);
return $q->row_array(); return $q->row_array();
} }
function edit_unit_admin($data) public function edit_unit_admin($data)
{ {
$sql = "UPDATE units $sql = "UPDATE units
SET type='" . $data['type'] . "', SET type='" . $data['type'] . "',
name='" . $data['name'] . "', name='" . $data['name'] . "',
icon='" . $data['icon'] . "', icon='" . $data['icon'] . "',
@ -164,9 +164,9 @@ class Unit_model extends MO_Model
mod_rate_mana='" . $data['mod_rate_mana'] . "' mod_rate_mana='" . $data['mod_rate_mana'] . "'
WHERE id='" . $data['id'] . "'"; WHERE id='" . $data['id'] . "'";
$this->db->query($sql); $this->db->query($sql);
$this->_create_sql($sql); $this->_create_sql($sql);
} }
} }
//nowhitesp //nowhitesp

View File

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

View File

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

View File

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

View File

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