Znote AAC rev 168 from subversion.

This commit is contained in:
Stefan Brannfjell
2013-08-28 23:46:32 +02:00
parent ba07284044
commit 21dea78379
160 changed files with 24752 additions and 0 deletions

1
engine/cache/deaths.cache.php vendored Normal file
View File

@@ -0,0 +1 @@
[{"time":"0","level":"8","killed_by":"Testing","is_player":"1","mostdamage_by":"Testing","mostdamage_is_player":"1","unjustified":"1","mostdamage_unjustified":"1","victim":"Znote"},{"time":"0","level":"8","killed_by":"Rat","is_player":"0","mostdamage_by":"Cave Rat","mostdamage_is_player":"0","unjustified":"0","mostdamage_unjustified":"0","victim":"Testing"}]

1
engine/cache/gallery.cache.php vendored Normal file
View File

@@ -0,0 +1 @@
[{"title":"Quest Done!","desc":"Yaay! Finally!","date":"1370715254","image":"4!47qyHg!jpg"},{"title":"Testing stuff.","desc":"I am testing if this system still works.","date":"1370561230","image":"1!hqxwUn!png"}]

1
engine/cache/highscores.cache.php vendored Normal file
View File

@@ -0,0 +1 @@
[false,false,false,false,false,false,false,false,false]

1
engine/cache/houses.cache.php vendored Normal file

File diff suppressed because one or more lines are too long

1
engine/cache/houses/sqldata.cache.php vendored Normal file
View File

@@ -0,0 +1 @@
[{"name":"Znote","id":"3"},{"name":"Mister Dude","id":"4"}]

1
engine/cache/killers.cache.php vendored Normal file
View File

@@ -0,0 +1 @@
[{"killed_by":"Testing","kills":"1"}]

1
engine/cache/lastkillers.cache.php vendored Normal file
View File

@@ -0,0 +1 @@
[{"victim":"Znote","killed_by":"Testing","time":"0"}]

1
engine/cache/news.cache.php vendored Normal file
View File

@@ -0,0 +1 @@
[{"id":"7","title":"BBcode test","text":"[size=6][b]Big size 6 bold text[\/b][\/size]\r\n[img]http:\/\/media.npr.org\/assets\/img\/2013\/01\/29\/cat-bird_wide-85ce4b8383b9440d3ff03413cdd913513e9737bf-s6-c30.jpg[\/img]\r\n[center]Centered text[\/center]\r\n\r\n[b]Bold text[\/b]\r\n[color=red]Red Text[\/color]\r\n[color=green]green Text[\/color]\r\n\r\n[*]element 1[\/*]\r\n[*]element 2[\/*]\r\n[*]element 3[\/*]\r\n\r\nLink without text assigned:\r\n[link]http:\/\/otland.net\/f118\/znote-aac-1-3-forgotten-server-0-2-13-forgotten-server-0-3-6-0-4-a-166722\/[\/link]\r\n\r\nLink with text assigned:\r\n[link=http:\/\/otland.net\/f118\/znote-aac-1-3-forgotten-server-0-2-13-forgotten-server-0-3-6-0-4-a-166722\/]CLICK HERE TO VIEW ZNOTE AAC[\/link]","date":"1370778017","name":"Znote"}]

1
engine/cache/support.cache.php vendored Normal file
View File

@@ -0,0 +1 @@
{"God":[{"group_id":"6","name":"Znote","online":1}]}

1
engine/cache/topPlayer.cache.php vendored Normal file
View File

@@ -0,0 +1 @@
[{"name":"Znote","level":"8","experience":"4200"},{"name":"Testing","level":"8","experience":"4200"},{"name":"Brannfjell","level":"8","experience":"4200"}]

1
engine/cache/victims.cache.php vendored Normal file
View File

@@ -0,0 +1 @@
[{"name":"Znote","Deaths":"1"},{"name":"Testing","Deaths":"1"}]

230
engine/database/connect.php Normal file
View File

@@ -0,0 +1,230 @@
<?php
$time = time();
if (!isset($version)) $version = '1.5_SVN';
$install = "
<h2>Install:</h2>
<ol>
<li>
<p>
Make sure you have imported TFS database. (OTdir/forgottenserver.sql OR OTdir/schemas/mysql.sql)
</p>
</li>
<li>
Import the below schema to a <b>TFS database in phpmyadmin</b>:<br>
<textarea cols=\"65\" rows=\"10\">
CREATE TABLE IF NOT EXISTS `znote` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`version` varchar(30) NOT NULL COMMENT 'Znote AAC version',
`installed` int(10) NOT NULL,
`cached` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
INSERT INTO `znote` (`version`, `installed`) VALUES
('$version', '$time');
CREATE TABLE IF NOT EXISTS `znote_accounts` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`account_id` int(11) NOT NULL,
`ip` int(10) NOT NULL,
`created` int(10) NOT NULL,
`points` int(10) DEFAULT 0,
`cooldown` int(10) DEFAULT 0,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
INSERT INTO `znote_accounts` (`account_id`, `ip`, `created`) VALUES
('1', '0', '$time');
CREATE TABLE IF NOT EXISTS `znote_news` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(30) NOT NULL,
`text` text NOT NULL,
`date` int(11) NOT NULL,
`pid` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `znote_images` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(30) NOT NULL,
`desc` text NOT NULL,
`date` int(11) NOT NULL,
`status` int(11) NOT NULL,
`image` varchar(30) NOT NULL,
`account_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `znote_paypal` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`txn_id` varchar(30) NOT NULL,
`email` varchar(255) NOT NULL,
`accid` int(11) NOT NULL,
`price` int(11) NOT NULL,
`points` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `znote_paygol` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`account_id` int(11) NOT NULL,
`price` int(11) NOT NULL,
`points` int(11) NOT NULL,
`message_id` varchar(255) NOT NULL,
`service_id` varchar(255) NOT NULL,
`shortcode` varchar(255) NOT NULL,
`keyword` varchar(255) NOT NULL,
`message` varchar(255) NOT NULL,
`sender` varchar(255) NOT NULL,
`operator` varchar(255) NOT NULL,
`country` varchar(255) NOT NULL,
`currency` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `znote_players` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`player_id` int(11) NOT NULL,
`created` int(11) NOT NULL,
`hide_char` tinyint(4) NOT NULL,
`comment` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
INSERT INTO `znote_players` (`player_id`, `created`, `hide_char`, `comment`) VALUES
('1', '$time', '0', '. . .');
CREATE TABLE IF NOT EXISTS `znote_shop` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`type` int(11) NOT NULL,
`itemid` int(11) DEFAULT NULL,
`count` int(11) NOT NULL DEFAULT '1',
`describtion` varchar(255) NOT NULL,
`points` int(11) NOT NULL DEFAULT '10',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `znote_shop_logs` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`account_id` int(11) NOT NULL,
`player_id` int(11) NOT NULL,
`type` int(11) NOT NULL,
`itemid` int(11) NOT NULL,
`count` int(11) NOT NULL,
`points` int(11) NOT NULL,
`time` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `znote_shop_orders` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`account_id` int(11) NOT NULL,
`type` int(11) NOT NULL,
`itemid` int(11) NOT NULL,
`count` int(11) NOT NULL,
`time` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `znote_visitors` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`ip` int(11) NOT NULL,
`value` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `znote_visitors_details` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`ip` int(11) NOT NULL,
`time` int(11) NOT NULL,
`type` tinyint(4) NOT NULL,
`account_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `znote_forum` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`access` tinyint(4) NOT NULL,
`closed` tinyint(4) NOT NULL,
`hidden` tinyint(4) NOT NULL,
`guild_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
INSERT INTO `znote_forum` (`name`, `access`, `closed`, `hidden`, `guild_id`) VALUES
('Staff Board', '4', '0', '0', '0'),
('Tutors Board', '2', '0', '0', '0'),
('Discussion', '1', '0', '0', '0'),
('Feedback', '1', '0', '1', '0');
CREATE TABLE IF NOT EXISTS `znote_forum_threads` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`forum_id` int(11) NOT NULL,
`player_id` int(11) NOT NULL,
`player_name` varchar(50) NOT NULL,
`title` varchar(50) NOT NULL,
`text` text NOT NULL,
`created` int(11) NOT NULL,
`updated` int(11) NOT NULL,
`sticky` tinyint(4) NOT NULL,
`hidden` tinyint(4) NOT NULL,
`closed` tinyint(4) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `znote_forum_posts` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`thread_id` int(11) NOT NULL,
`player_id` int(11) NOT NULL,
`player_name` varchar(50) NOT NULL,
`text` text NOT NULL,
`created` int(11) NOT NULL,
`updated` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
</textarea>
</li>
<li>
<p>
Edit config.php with correct mysql connection details.
</p>
</li>
</ol>
";
mysql_connect($config['sqlHost'], $config['sqlUser'], $config['sqlPassword']) or die('<h1>Failed to connect to database.</h1>'. $install);
mysql_select_db($config['sqlDatabase']) or die('<h1>Connection accepted but failed to find configured database name.</h1>'. $install);
// Select single row from database
function mysql_select_single($query) {
$result = mysql_query($query) or die(var_dump($query)."<br>(query - <font color='red'>SQL error</font>) <br>Type: <b>select_single</b> (select single row from database)<br><br>".mysql_error());
$row = mysql_fetch_assoc($result);
return !empty($row) ? $row : false;
}
// Selecting multiple rows from database.
function mysql_select_multi($query){
$array = array();
$results = mysql_query($query) or die(var_dump($query)."<br>(query - <font color='red'>SQL error</font>) <br>Type: <b>select_multi</b> (select multiple rows from database)<br><br>".mysql_error());
while($row = mysql_fetch_assoc($results)) {
$array[] = $row;
}
return !empty($array) ? $array : false;
}
//////
// Query database without expecting returned results
// - mysql update
function mysql_update($query){ voidQuery($query); }
// mysql insert
function mysql_insert($query){ voidQuery($query); }
// mysql delete
function mysql_delete($query){ voidQuery($query); }
// Send a void query
function voidQuery($query) {
mysql_query($query) or die(var_dump($query)."<br>(query - <font color='red'>SQL error</font>) <br>Type: <b>voidQuery</b> (voidQuery is used for update, insert or delete from database)<br><br>".mysql_error());
}
?>

11
engine/footer.php Normal file
View File

@@ -0,0 +1,11 @@
<footer>
&copy; Znote AAC.
<?php
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$finish = $time;
$total_time = round(($finish - $start), 4);
echo 'Server date and clock is: '. getClock(false, true) .' Page generated in '. $total_time .' seconds. ';
?>
</footer>

122
engine/function/cache.php Normal file
View File

@@ -0,0 +1,122 @@
<?php
class Cache
{
protected $_file = false;
protected $_lifespan = 0;
protected $_content;
const EXT = '.cache.php';
/**
* @param string $file
* @access public
* @return void
**/
public function __construct($file) {
$this->_file = $file . self::EXT;
$this->setExpiration(config('cache_lifespan'));
}
/**
* Sets the cache expiration limit (IMPORTANT NOTE: seconds, NOT ms!).
*
* @param integer $span
* @access public
* @return void
**/
public function setExpiration($span) {
$this->_lifespan = $span;
}
/**
* Set the content you'd like to cache.
*
* @param mixed $content
* @access public
* @return void
**/
public function setContent($content) {
switch (strtolower(gettype($content))) {
case 'array':
$this->_content = json_encode($content);
break;
default:
$this->_content = $content;
break;
}
}
/**
* Validates whether it is time to refresh the cache data or not.
*
* @access public
* @return boolean
**/
public function hasExpired() {
if (is_file($this->_file) && time() < filemtime($this->_file) + $this->_lifespan) {
return false;
}
return true;
}
/**
* Returns remaining time before scoreboard will update itself.
*
* @access public
* @return integer
**/
public function remainingTime() {
$remaining = 0;
if (!$this->hasExpired()) {
$remaining = (filemtime($this->_file) + $this->_lifespan) - time();
}
return $remaining;
}
/**
* Saves the content into its appropriate cache file.
*
* @access public
* @return void
**/
public function save() {
$handle = fopen($this->_file, 'w');
fwrite($handle, $this->_content);
fclose($handle);
}
/**
* Loads the content from a specified cache file.
*
* @access public
* @return mixed
**/
public function load() {
if (!is_file($this->_file)) {
return false;
}
ob_start();
include_once($this->_file);
$content = ob_get_clean();
if (!isset($content) && strlen($content) == 0) {
return false;
}
if ($content = json_decode($content, true)) {
return (array) $content;
} else {
return $content;
}
}
}

425
engine/function/general.php Normal file
View File

@@ -0,0 +1,425 @@
<?php
// Fetch and sanitize POST and GET values
function getValue($post) {
return (!empty($post)) ? sanitize($post) : false;
}
function SendGet($getArray, $location = 'error.php') {
$string = "";
$count = 0;
foreach ($getArray as $getKey => $getValue) {
if ($count > 0) $string .= '&';
$string .= "{$getKey}={$getValue}";
}
header("Location: {$location}?{$string}");
exit();
}
// Sweet error reporting
function data_dump($print = false, $var = false, $title = false) {
if ($title !== false) echo "<pre><font color='red' size='5'>$title</font><br>";
else echo '<pre>';
if ($print !== false) {
echo 'Print: - ';
print_r($print);
echo "<br>";
}
if ($var !== false) {
echo 'Var_dump: - ';
var_dump($var);
}
echo '</pre><br>';
}
function accountAccess($accountId, $TFS) {
$accountId = (int)$accountId;
$access = 0;
// TFS 0.3/4
$yourChars = mysql_select_multi("SELECT `name`, `group_id`, `account_id` FROM `players` WHERE `account_id`='$accountId';");
if ($yourChars !== false) {
foreach ($yourChars as $char) {
if ($TFS === 'TFS_03') {
if ($char['group_id'] > $access) $access = $char['group_id'];
} else {
if ($char['group_id'] > 1) {
if ($access == 0) {
$acc = mysql_select_single("SELECT `type` FROM `accounts` WHERE `id`='". $char['account_id'] ."' LIMIT 1;");
$access = $acc['type'];
}
}
}
}
if ($access == 0) $access++;
return $access;
} else return false;
//
}
// Generate recovery key
function generate_recovery_key($lenght) {
$lenght = (int)$lenght;
$tmp = rand(1000, 9000);
$tmp += time();
$tmp = sha1($tmp);
$results = '';
for ($i = 0; $i < $lenght; $i++) $results = $results.''.$tmp[$i];
return $results;
}
// Calculate discount
function calculate_discount($orig, $new) {
$orig = (int)$orig;
$new = (int)$new;
$tmp = '';
if ($new >= $orig) {
if ($new != $orig) {
$calc = ($new/$orig) - 1;
$calc *= 100;
$tmp = '+'. $calc .'%';
} else $tmp = '0%';
} else {
$calc = 1 - ($new/$orig);
$calc *= 100;
$tmp = '-'. $calc .'%';
}
return $tmp;
}
// Proper URLs
function url($path = false) {
$protocol = (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://';
$domain = $_SERVER['SERVER_NAME'] . ($_SERVER['SERVER_PORT'] != 80 ? ':' . $_SERVER['SERVER_PORT'] : null);
$folder = dirname($_SERVER['SCRIPT_NAME']);
return $protocol . $domain . $folder . '/' . $path;
}
// Get last cached
function getCache() {
return mysql_result(mysql_query("SELECT `cached` FROM `znote`;"), 0, 'cached');
}
function setCache($time) {
$time = (int)$time;
mysql_query("UPDATE `znote` set `cached`='$time'");
}
// Get visitor basic data
function znote_visitors_get_data() {
// select
$result = mysql_query("SELECT `ip`, `value` FROM `znote_visitors`");
while ($row = mysql_fetch_assoc($result)) {
$data[] = $row;
}
if (isset($data)) return $data;
else return false;
}
// Set visitor basic data
function znote_visitor_set_data($visitor_data) {
$exist = false;
$ip = ip2long(getIP());
foreach ((array)$visitor_data as $row) {
if ($ip == $row['ip']) {
$exist = true;
$value = $row['value'];
}
}
if ($exist && isset($value)) {
// Update the value
$value++;
mysql_query("UPDATE `znote_visitors` SET `value` = '$value' WHERE `ip` = '$ip'") or die(mysql_error());
} else {
// Insert new row
mysql_query("INSERT INTO `znote_visitors` (`ip`, `value`) VALUES ('$ip', '1')") or die(mysql_error());
}
}
// Get visitor basic data
function znote_visitors_get_detailed_data($cache_time) {
$period = (int)time() - (int)$cache_time;
// select
$result = mysql_query("SELECT `ip`, `time`, `type`, `account_id` FROM `znote_visitors_details` WHERE `time` >= '$period' LIMIT 0, 50");
while ($row = mysql_fetch_assoc($result)) {
$data[] = $row;
}
if (isset($data)) return $data;
else return false;
}
function znote_visitor_insert_detailed_data($type) {
$type = (int)$type;
/*
type 0 = normal visits
type 1 = register form
type 2 = character creation
type 3 = fetch highscores
type 4 = search character
*/
$time = time();
$ip = ip2long(getIP());
if (user_logged_in() === true) {
$acc = $_SESSION['user_id'];
mysql_query("INSERT INTO `znote_visitors_details` (`ip`, `time`, `type`, `account_id`) VALUES ('$ip', '$time', '$type', '$acc')") or die(mysql_error());
} else mysql_query("INSERT INTO `znote_visitors_details` (`ip`, `time`, `type`, `account_id`) VALUES ('$ip', '$time', '$type', '0')") or die(mysql_error());
}
function something () {
// Make acc data compatible:
$ip = ip2long(getIP());
}
// Secret token
function create_token() {
echo 'Checking whether to create token or not<br />';
#if (empty($_SESSION['token'])) {
echo 'Creating token<br />';
$token = sha1(uniqid(time(), true));
$token2 = $token;
var_dump($token, $token2);
$_SESSION['token'] = $token2;
#}
echo "<input type=\"hidden\" name=\"token\" value=\"". $_SESSION['token'] ."\" />";
}
function reset_token() {
echo 'Reseting token<br />';
unset($_SESSION['token']);
}
// Time based functions
// 60 seconds to 1 minute
function second_to_minute($seconds) {
return ($seconds / 60);
}
// 1 minute to 60 seconds
function minute_to_seconds($minutes) {
return ($minutes * 60);
}
// 60 minutes to 1 hour
function minute_to_hour($minutes) {
return ($minutes / 60);
}
// 1 hour to 60 minutes
function hour_to_minute($hours) {
return ($hour * 60);
}
// seconds / 60 / 60 = hours.
function seconds_to_hours($seconds) {
$minutes = second_to_minute($seconds);
$hours = minute_to_hour($minutes);
return $hours;
}
function remaining_seconds_to_clock($seconds) {
return date("(H:i)",time() + $seconds);
}
// Returns false if name contains more than configured max words, returns name otherwise.
function validate_name($string) {
//edit: make sure only one space separates words:
//(found this regex through a search and havent tested it)
$string = preg_replace("/\\s+/", " ", $string);
//trim off beginning and end spaces;
$string = trim($string);
//get an array of the words
$wordArray = explode(" ", $string);
//get the word count
$wordCount = sizeof($wordArray);
//see if its too big
if($wordCount > config('maxW')) {
return false;
} else {
return $string;
}
}
// Checks if an IPv4 address is valid
function validate_ip($ip) {
$ipL = ip2long($ip);
$ipR = long2ip($ipL);
if ($ip === $ipR) {
return true;
} else {
return false;
}
}
// Fetch a config value. Etc config('vocations') will return vocation array from config.php.
function config($value) {
global $config;
return $config[$value];
}
// Some functions uses several configurations from config.php, so it sounds
// smarter to give them the whole array instead of calling the function all the time.
function fullConfig() {
global $config;
return $config;
}
// Capitalize Every Word In String.
function format_character_name($name) {
return ucwords(strtolower($name));
}
// Returns a list of players online
function online_list() {
if (config('TFSVersion') == 'TFS_10') return mysql_select_multi("SELECT `o`.`player_id` AS `id`, `p`.`name` as `name`, `p`.`level` as `level`, `p`.`vocation` as `vocation` FROM `players_online` as `o` INNER JOIN `players` as `p` ON o.player_id = p.id");
else return mysql_select_multi("SELECT `name`, `level`, `vocation` FROM `players` WHERE `online`='1' ORDER BY `name` DESC;");
}
// Gets you the actual IP address even from users behind ISP proxies and so on.
function getIP() {
/*
$IP = '';
if (getenv('HTTP_CLIENT_IP')) {
$IP =getenv('HTTP_CLIENT_IP');
} elseif (getenv('HTTP_X_FORWARDED_FOR')) {
$IP =getenv('HTTP_X_FORWARDED_FOR');
} elseif (getenv('HTTP_X_FORWARDED')) {
$IP =getenv('HTTP_X_FORWARDED');
} elseif (getenv('HTTP_FORWARDED_FOR')) {
$IP =getenv('HTTP_FORWARDED_FOR');
} elseif (getenv('HTTP_FORWARDED')) {
$IP = getenv('HTTP_FORWARDED');
} else {
$IP = $_SERVER['REMOTE_ADDR'];
} */
return $_SERVER['REMOTE_ADDR'];
}
function array_length($ar) {
$r = 1;
foreach($ar as $a) {
$r++;
}
return $r;
}
// Parameter: level, returns experience for that level from an experience table.
function level_to_experience($level) {
// Generated experience table. Currently up to level 200.
$experience = array (1 => 0, 2 => 100, 3 => 200, 4 => 400, 5 => 800, 6 => 1500, 7 => 2600, 8 => 4200, 9 => 6400, 10 => 9300, 11 => 13000, 12 => 17600, 13 => 23200, 14 => 29900, 15 => 37800, 16 => 47000, 17 => 57600, 18 => 69700, 19 => 83400, 20 => 98800, 21 => 116000, 22 => 135100, 23 => 156200, 24 => 179400, 25 => 204800, 26 => 232500, 27 => 262600, 28 => 295200, 29 => 330400, 30 => 368300, 31 => 409000, 32 => 452600, 33 => 499200, 34 => 548900, 35 => 601800, 36 => 658000, 37 => 717600, 38 => 780700, 39 => 847400, 40 => 917800, 41 => 992000, 42 => 1070100, 43 => 1152200, 44 => 1238400, 45 => 1328800, 46 => 1423500, 47 => 1522600, 48 => 1626200, 49 => 1734400, 50 => 1847300, 51 => 1965000, 52 => 2087600, 53 => 2215200, 54 => 2347900, 55 => 2485800, 56 => 2629000, 57 => 2777600, 58 => 2931700, 59 => 3091400, 60 => 3256800, 61 => 3428000, 62 => 3605100, 63 => 3788200, 64 => 3977400, 65 => 4172800, 66 => 4374500, 67 => 4582600, 68 => 4797200, 69 => 5018400, 70 => 5246300, 71 => 5481000, 72 => 5722600, 73 => 5971200, 74 => 6226900, 75 => 6489800, 76 => 6760000, 77 => 7037600, 78 => 7322700, 79 => 7615400, 80 => 7915800, 81 => 8224000, 82 => 8540100, 83 => 8864200, 84 => 9196400, 85 => 9536800, 86 => 9885500, 87 => 10242600, 88 => 10608200, 89 => 10982400, 90 => 11365300, 91 => 11757000, 92 => 12157600, 93 => 12567200, 94 => 12985900, 95 => 13413800, 96 => 13851000, 97 => 14297600, 98 => 14753700, 99 => 15219400, 100 => 15694800, 101 => 16180000, 102 => 16675100, 103 => 17180200, 104 => 17695400, 105 => 18220800, 106 => 18756500, 107 => 19302600, 108 => 19859200, 109 => 20426400, 110 => 21004300, 111 => 21593000, 112 => 22192600, 113 => 22803200, 114 => 23424900, 115 => 24057800, 116 => 24702000, 117 => 25357600, 118 => 26024700, 119 => 26703400, 120 => 27393800, 121 => 28096000, 122 => 28810100, 123 => 29536200, 124 => 30274400, 125 => 31024800, 126 => 31787500, 127 => 32562600, 128 => 33350200, 129 => 34150400, 130 => 34963300, 131 => 35789000, 132 => 36627600, 133 => 37479200, 134 => 38343900, 135 => 39221800, 136 => 40113000, 137 => 41017600, 138 => 41935700, 139 => 42867400, 140 => 43812800, 141 => 44772000, 142 => 45745100, 143 => 46732200, 144 => 47733400, 145 => 48748800, 146 => 49778500, 147 => 50822600, 148 => 51881200, 149 => 52954400, 150 => 54042300, 151 => 55145000, 152 => 56262600, 153 => 57395200, 154 => 58542900, 155 => 59705800, 156 => 60884000, 157 => 62077600, 158 => 63286700, 159 => 64511400, 160 => 65751800, 161 => 67008000, 162 => 68280100, 163 => 69568200, 164 => 70872400, 165 => 72192800, 166 => 73529500, 167 => 74882600, 168 => 76252200, 169 => 77638400, 170 => 79041300, 171 => 80461000, 172 => 81897600, 173 => 83351200, 174 => 84821900, 175 => 86309800, 176 => 87815000, 177 => 89337600, 178 => 90877700, 179 => 92435400, 180 => 94010800, 181 => 95604000, 182 => 97215100, 183 => 98844200, 184 => 100491400, 185 => 102156800, 186 => 103840500, 187 => 105542600, 188 => 107263200, 189 => 109002400, 190 => 110760300, 191 => 112537000, 192 => 114332600, 193 => 116147200, 194 => 117980900, 195 => 119833800, 196 => 121706000, 197 => 123597600, 198 => 125508700, 199 => 127439400, 200 => 129389800);
return ($level > 0 && $level <= 200) ? $experience[$level] : false;
}
// Parameter: players.hide_char returns: Status word inside a font with class identifier so it can be designed later on by CSS.
function hide_char_to_name($id) {
$id = (int)$id;
if ($id == 1) {
return 'hidden';
} else {
return 'visible';
}
}
// Parameter: players.online returns: Status word inside a font with class identifier so it can be designed later on by CSS.
function online_id_to_name($id) {
$id = (int)$id;
if ($id == 1) {
return '<font class="status_online">ONLINE</font>';
} else {
return '<font class="status_offline">offline</font>';
}
}
// Parameter: players.vocation_id. Returns: Configured vocation name.
function vocation_id_to_name($id) {
$vocations = config('vocations');
return ($vocations[$id] >= 0) ? $vocations[$id] : false;
}
function gender_exist($gender) {
// Range of allowed gender ids, fromid toid
if ($gender >= 0 && $gender <= 1) {
return true;
} else {
return false;
}
}
function skillid_to_name($skillid) {
$skillname = array(
0 => 'fist fighting',
1 => 'club fighting',
2 => 'sword fighting',
3 => 'axe fighting',
4 => 'distance fighting',
5 => 'shielding',
6 => 'fishing',
7 => 'experience', // Hardcoded, does not actually exist in database as a skillid.
8 => 'magic level' // Hardcoded, does not actually exist in database as a skillid.
);
return ($skillname[$skillid] >= 0) ? $skillname[$skillid] : false;
}
// Parameter: players.town_id. Returns: Configured town name.
function town_id_to_name($id) {
$towns = config('towns');
return (array_key_exists($id, $towns)) ? $towns[$id] : 'Missing Town';
}
// Unless you have an internal mail server then mail sending will not be supported in this version.
function email($to, $subject, $body) {
mail($to, $subject, $body, 'From: TEST');
}
function logged_in_redirect() {
if (user_logged_in() === true) {
header('Location: myaccount.php');
}
}
function protect_page() {
if (user_logged_in() === false) {
header('Location: protected.php');
exit();
}
}
// When function is called, you will be redirected to protect_page and deny access to rest of page, as long as you are not admin.
function admin_only($user_data) {
// Chris way
$gotAccess = is_admin($user_data);
if ($gotAccess == false) {
logged_in_redirect();
exit();
}
}
function is_admin($user_data) {
return in_array($user_data['name'], config('page_admin_access')) ? true : false;
}
function array_sanitize(&$item) {
$item = htmlentities(strip_tags(mysql_real_escape_string($item)));
}
function sanitize($data) {
return htmlentities(strip_tags(mysql_real_escape_string($data)));
}
function output_errors($errors) {
return '<ul><li>'. implode('</li><li>', $errors) .'</li></ul>';
}
?>

89
engine/function/token.php Normal file
View File

@@ -0,0 +1,89 @@
<?php
// List of characters: $, {}, []
class Token {
public static function generate() {
$token = sha1(uniqid(time(), true));
$_SESSION['token'] = $token;
}
/**
* Displays a random token to prevent CSRF attacks.
*
* @access public
* @static true
* @return void
**/
public static function create() {
echo '<input type="hidden" name="token" value="' . self::get() . '" />';
}
/**
* Returns the active token, if there is one.
*
* @access public
* @static true
* @return mixed
**/
public static function get() {
return isset($_SESSION['token']) ? $_SESSION['token'] : false;
}
/**
* Validates whether the active token is valid or not.
*
* @param string $post
* @access public
* @static true
* @return boolean
**/
public static function isValid($post) {
if (config('use_token')) {
// Token doesn't exist yet, return false.
if (!self::get()) {
return false;
}
// Token was invalid, return false.
if ($post == $_SESSION['old_token'] || $post == $_SESSION['token']) {
//self::_reset();
return true;
} else {
return false;
}
} else {
return true;
}
}
/**
* Destroys the active token.
*
* @access protected
* @static true
* @return void
**/
protected static function _reset() {
unset($_SESSION['token']);
}
/**
* Displays information on both the post token and the session token.
*
* @param string $post
* @access public
* @static true
* @return void
**/
public static function debug($post) {
echo '<pre>', var_dump(array(
'post' => $post,
'old_token' => $_SESSION['old_token'],
'token' => self::get()
)), '</pre>';
}
}
?>

1513
engine/function/users.php Normal file

File diff suppressed because it is too large Load Diff

105
engine/init.php Normal file
View File

@@ -0,0 +1,105 @@
<?php
// Verify the PHP version, gives tutorial if fail.
if (version_compare(phpversion(), '5.3.3', '<')) die('PHP 5.3.3 is required<br><br>WINDOWS:<br>Download and use the latest Uniform Server.<br><a href="http://www.uniformserver.com/">CLICK ME</a> to get to their website. <br> XAMPP sucks and is insecure. Kthxbye.<br><br>LINUX DEBIAN:<br>Edit /etc/apt/sources.list<br>etc if you use nano text editor, make sure you are root and do<br>nano /etc/apt/sources.list<br><br>At the bottom, add this:<br><br>deb http://packages.dotdeb.org stable all<br>deb-src http://packages.dotdeb.org stable all<br><br>save file. <br><br>Then in terminal, do these 2 commands:<br>gpg --keyserver keys.gnupg.net --recv-key 89DF5277<br><br>gpg -a --export 89DF5277 | sudo apt-key add -<br><br>And then do these 2 commands:<br><br>apt-get update<br>apt-get upgrade<br><br>You now have the latest stable PHP version.<br>');
$time = time();
$version = '1.5_SVN';
session_start();
ob_start();
require 'config.php';
require 'database/connect.php';
require 'function/general.php';
require 'function/users.php';
require 'function/cache.php';
require 'function/token.php';
if (isset($_SESSION['token'])) {
$_SESSION['old_token'] = $_SESSION['token'];
//var_dump($_SESSION['old_token'], $_SESSION['token']);
}
Token::generate();
if (user_logged_in() === true) {
$session_user_id = $_SESSION['user_id'];
$user_data = user_data($session_user_id, 'id', 'name', 'password', 'email');
$user_znote_data = user_znote_account_data($session_user_id, 'ip', 'created', 'points', 'cooldown');
}
$errors = array();
// Log IP
if ($config['log_ip']) {
$visitor_config = $config['ip_security'];
$flush = $config['flush_ip_logs'];
if ($flush != false) {
$timef = $time - $flush;
if (getCache() < $timef) {
$timef = $time - $visitor_config['time_period'];
mysql_query("DELETE FROM znote_visitors_details WHERE time <= '$timef'") or die(mysql_error());
setCache($time);
}
}
$visitor_data = znote_visitors_get_data();
znote_visitor_set_data($visitor_data); // update or insert data
znote_visitor_insert_detailed_data(0); // detailed data
$visitor_detailed = znote_visitors_get_detailed_data($visitor_config['time_period']);
// max activity
$v_activity = 0;
$v_register = 0;
$v_highscore = 0;
$v_c_char = 0;
$v_s_char = 0;
$v_form = 0;
foreach ((array)$visitor_detailed as $v_d) {
// Activity
if ($v_d['ip'] == ip2long(getIP())) {
// count each type of visit
switch ($v_d['type']) {
case 0: // max activity
$v_activity++;
break;
case 1: // account registered
$v_register++;
$v_form++;
break;
case 2: // character creations
$v_c_char++;
$v_form++;
break;
case 3: // Highscore fetched
$v_highscore++;
$v_form++;
break;
case 4: // character searched
$v_s_char++;
$v_form++;
break;
case 5: // Other forms (login.?)
$v_form++;
break;
}
}
}
// Deny access if activity is too high
if ($v_activity > $visitor_config['max_activity']) die("Chill down. Your web activity is too big. max_activity");
if ($v_register > $visitor_config['max_account']) die("Chill down. You can't create multiple accounts that fast. max_account");
if ($v_c_char > $visitor_config['max_character']) die("Chill down. Your web activity is too big. max_character");
if ($v_form > $visitor_config['max_post']) die("Chill down. Your web activity is too big. max_post");
//var_dump($v_activity, $v_register, $v_highscore, $v_c_char, $v_s_char, $v_form);
//echo ' <--- IP logging activity past 10 seconds.';
}
?>

6
engine/js/jquery-1.10.2.min.js vendored Normal file

File diff suppressed because one or more lines are too long