Some query optimisations

This commit is contained in:
Stefan Brannfjell 2014-03-08 15:31:47 +01:00
parent 470bf6caa6
commit 7861292449
11 changed files with 48 additions and 46 deletions

View File

@ -44,17 +44,16 @@ This will show you the rest of the instructions as well as the mysql schema.
### This is the developement repository for the Znote AAC project. ### This is the developement repository for the Znote AAC project.
# TODO 1.5: # TODO 1.5:
* TFS 1.0 House system
* TFS 1.0 Guilds
* TFS 1.0 LUA scripts (Shop system, first items) * TFS 1.0 LUA scripts (Shop system, first items)
# TODO 1.6: # TODO 1.6:
* Recovery key * Recovery key
* Email system * Email system
* Character auction house for shop points * Character auction for shop points
* Database shop offers * Database shop offers
* Manage shop offers without touching code * Manage shop offers without touching code
* Live TFS 1.0 integration * Live TFS 1.0 integration
# Removed from TODO: # Removed from TODO:
* TFS 1.0 Livestream (Since Hani rejected to release sources for this I have no intention of adding support for it). * TFS 1.0 Livestream
Reason: Not open source, not legally available on any official free TFS distributions.

View File

@ -4,9 +4,8 @@ if ($config['log_ip']) {
} }
if (isset($_GET['name']) === true && empty($_GET['name']) === false) { if (isset($_GET['name']) === true && empty($_GET['name']) === false) {
$name = $_GET['name']; $name = $_GET['name'];
$user_id = user_character_exist($name);
if (user_character_exist($name)) { if ($user_id !== false) {
$user_id = user_character_id($name);
if ($config['TFSVersion'] == 'TFS_10') { if ($config['TFSVersion'] == 'TFS_10') {
$profile_data = user_character_data($user_id, 'name', 'level', 'vocation', 'lastlogin'); $profile_data = user_character_data($user_id, 'name', 'level', 'vocation', 'lastlogin');
$profile_data['online'] = user_is_online_10($user_id); $profile_data['online'] = user_is_online_10($user_id);
@ -22,7 +21,6 @@ if (isset($_GET['name']) === true && empty($_GET['name']) === false) {
?> ?>
<!-- PROFILE MARKUP HERE--> <!-- PROFILE MARKUP HERE-->
<?php ?>
<h1><font class="profile_font" name="profile_font_header">Profile: <?php echo $profile_data['name']; ?></font></h1> <h1><font class="profile_font" name="profile_font_header">Profile: <?php echo $profile_data['name']; ?></font></h1>
<ul class="unstyled"> <ul class="unstyled">
<li><font class="profile_font" name="profile_font_level">Level: <?php echo $profile_data['level']; ?></font></li> <li><font class="profile_font" name="profile_font_level">Level: <?php echo $profile_data['level']; ?></font></li>
@ -92,6 +90,7 @@ if (isset($_GET['name']) === true && empty($_GET['name']) === false) {
} }
//Done. //Done.
} else if ($config['TFSVersion'] == 'TFS_03') { } else if ($config['TFSVersion'] == 'TFS_03') {
//mysql_select_single("SELECT * FROM players WHERE name='TEST DEBUG';");
$array = user_fetch_deathlist03($user_id); $array = user_fetch_deathlist03($user_id);
if ($array) { if ($array) {
?> ?>

View File

@ -14,13 +14,13 @@
// ------------------------ \\ // ------------------------ \\
// phpmyadmin username for OT server: (DONT USE "root" if ur hosting to public.). // phpmyadmin username for OT server: (DONT USE "root" if ur hosting to public.).
$config['sqlUser'] = 'dev'; $config['sqlUser'] = 'daler';
// phpmyadmin password for OT server: // phpmyadmin password for OT server:
$config['sqlPassword'] = 'dev'; $config['sqlPassword'] = 'daler';
// The database name to connect to. (This is usually same as username). // The database name to connect to. (This is usually same as username).
$config['sqlDatabase'] = 'dev'; $config['sqlDatabase'] = 'daler';
// Hostname is usually localhost or 127.0.0.1. // Hostname is usually localhost or 127.0.0.1.
$config['sqlHost'] = 'localhost'; $config['sqlHost'] = 'localhost';
@ -192,7 +192,7 @@
$config['port'] = 7171; // Port number to connect to your OT. $config['port'] = 7171; // Port number to connect to your OT.
// How often do you want highscores to update? // How often do you want highscores to update?
$config['cache_lifespan'] = 1;//60 * 15; // 15 minutes. $config['cache_lifespan'] = 5;//60 * 15; // 15 minutes.
// WARNING! Account names written here will have admin access to web page! // WARNING! Account names written here will have admin access to web page!
$config['page_admin_access'] = array( $config['page_admin_access'] = array(
@ -338,7 +338,7 @@
to configure flush_ip_logs if IPs are logged. to configure flush_ip_logs if IPs are logged.
*/ */
$config['log_ip'] = true; $config['log_ip'] = false;
// Flush IP logs each configured seconds, 60 * 15 = 15 minutes. // Flush IP logs each configured seconds, 60 * 15 = 15 minutes.
// Set to false to entirely disable ip log flush. // Set to false to entirely disable ip log flush.
@ -415,7 +415,7 @@
'enableShopConfirmation' => true, // Verify that user wants to buy with popup 'enableShopConfirmation' => true, // Verify that user wants to buy with popup
'useDB' => false, // Fetch offers from database, or the below config array 'useDB' => false, // Fetch offers from database, or the below config array
'showImage' => true, 'showImage' => true,
'imageServer' => 'items.znote.eu', 'imageServer' => 'items.halfaway.net',
'imageType' => 'gif', 'imageType' => 'gif',
); );

View File

@ -4,15 +4,17 @@
<p>This website is powered by the Znote AAC engine.</p> <p>This website is powered by the Znote AAC engine.</p>
<h2>Developers:</h2> <h2>Developers:</h2>
<p>Main developer: <a href="http://otland.net/members/znote/">Znote</a>.</p> <p>Main developer: <a href="http://otland.net/members/znote.5993/">Znote</a>.</p>
<h3>Thanks to: (in no particular order)</h3> <h3>Thanks to: (in no particular order)</h3>
<p> <p>
<a href="http://otland.net/members/chris/">Chris</a> - PHP OOP file samples, testing, bugfixing. <a href="http://otland.net/members/chris.13882/">Chris</a> - PHP OOP file samples, testing, bugfixing.
<br><a href="http://otland.net/members/kiwi+dan/">Kiwi Dan</a> - Researching TFS 0.2 for me, participation in developement. <br><a href="http://otland.net/members/kiwi-dan.152/">Kiwi Dan</a> - Researching TFS 0.2 for me, participation in developement.
<br><a href="http://otland.net/members/amoaz/">Amoaz</a> - Pentesting and security tips. <br><a href="http://otland.net/members/amoaz.26626/">Amoaz</a> - Pentesting and security tips.
<br><a href="http://otland.net/members/evan/">Evan</a> - Researching TFS 0.3, constructive feedback, suggestion and participation. <br><a href="http://otland.net/members/evan.40401/">Evan</a>, <a href="http://otland.net/members/gremlee.12075/">Gremlee</a> - Researching TFS 0.3, constructive feedback, suggestion and participation.
<br><a href="http://otland.net/members/talaturen/">Talaturen</a> - Repository for this AAC. <br><a href="http://otland.net/members/att3.98289/">ATT3</a> - Reporting and fixing bugs, TFS 1.0 research.
<br><a href="http://otland.net/members/mark.1/">Mark</a> - Old repository, TFS distributions which this AAC works against.
<br><a href="https://github.com/tedbro">Tedbro</a>, <a href="https://github.com/exura">Exura</a>, <a href="https://github.com/PrinterLUA">PrinterLUA</a> - Reporting bugs
</p> </p>
<?php include 'layout/overall/footer.php'; ?> <?php include 'layout/overall/footer.php'; ?>

View File

@ -206,6 +206,11 @@ function mysql_znote_escape_string($escapestr) {
// Select single row from database // Select single row from database
function mysql_select_single($query) { function mysql_select_single($query) {
global $connect; global $connect;
global $aacQueries;
$aacQueries++;
global $accQueriesData;
$accQueriesData[] = $query;
$result = mysqli_query($connect,$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>".mysqli_error($connect)); $result = mysqli_query($connect,$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>".mysqli_error($connect));
$row = mysqli_fetch_assoc($result); $row = mysqli_fetch_assoc($result);
return !empty($row) ? $row : false; return !empty($row) ? $row : false;
@ -214,6 +219,10 @@ function mysql_select_single($query) {
// Selecting multiple rows from database. // Selecting multiple rows from database.
function mysql_select_multi($query){ function mysql_select_multi($query){
global $connect; global $connect;
global $aacQueries;
$aacQueries++;
global $accQueriesData;
$accQueriesData[] = $query;
$array = array(); $array = array();
$results = mysqli_query($connect,$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>".mysqli_error($connect)); $results = mysqli_query($connect,$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>".mysqli_error($connect));
while($row = mysqli_fetch_assoc($results)) { while($row = mysqli_fetch_assoc($results)) {
@ -234,6 +243,10 @@ function mysql_delete($query){ voidQuery($query); }
// Send a void query // Send a void query
function voidQuery($query) { function voidQuery($query) {
global $connect; global $connect;
global $aacQueries;
$aacQueries++;
global $accQueriesData;
$accQueriesData[] = $query;
mysqli_query($connect,$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>".mysqli_error($connect)); mysqli_query($connect,$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>".mysqli_error($connect));
} }
?> ?>

View File

@ -43,15 +43,7 @@ function fetchLoosers() {
// Fetch latest deaths // Fetch latest deaths
function fetchLatestDeaths($from = 0, $to = 30) { function fetchLatestDeaths($from = 0, $to = 30) {
$array = mysql_select_multi("SELECT * FROM `player_deaths` ORDER BY `time` DESC LIMIT $from, $to;"); return mysql_select_multi("SELECT `d`.`level`, `p`.`name` AS `victim`, `d`.`time`, `d`.`is_player`, `d`.`killed_by` FROM `player_deaths` AS `d` INNER JOIN `players` AS `p` ON `d`.`player_id` = `p`.`id` ORDER BY `time` DESC LIMIT $from, $to;");
if ($array !== false) {
for ($i = 0; $i < count($array); $i++) {
$data = user_character_data($array[$i]['player_id'], 'name');
$array[$i]['victim'] = $data['name'];
unset($array[$i]['player_id']);
}
}
return $array;
} }
// latest deaths .3 (Based on code from Hauni@otland.net). // latest deaths .3 (Based on code from Hauni@otland.net).
@ -149,17 +141,7 @@ function support_list() {
// NEWS // NEWS
function fetchAllNews() { function fetchAllNews() {
$data = mysql_select_multi("SELECT * FROM `znote_news` ORDER BY `id` DESC;"); return mysql_select_multi("SELECT `n`.`id`, `n`.`title`, `n`.`text`, `n`.`date`, `p`.`name` FROM `znote_news` AS `n` INNER JOIN `players` AS `p` ON `n`.`pid` = `p`.`id` ORDER BY `n`.`id` DESC;");
if ($data !== false) {
for ($i = 0; $i < count($data); $i++) {
$player = mysql_select_single("SELECT `name` FROM `players` WHERE `id`='".$data[$i]['pid']."' LIMIT 1;");
if ($player !== false) $data[$i]['name'] = $player['name'];
else $data[$i]['name'] = "Player not found.";
unset($data[$i]['pid']);
}
}
return $data;
} }
// HOUSES // HOUSES
@ -1290,8 +1272,8 @@ function user_name($id) { //USERNAME FROM PLAYER ID
// Checks that character name exist // Checks that character name exist
function user_character_exist($username) { function user_character_exist($username) {
$username = sanitize($username); $username = sanitize($username);
$data = mysql_select_single("SELECT `id` FROM `players` WHERE `name`='$username';"); $player = mysql_select_single("SELECT `id` FROM `players` WHERE `name`='$username';");
return ($data !== false) ? true : false; return ($player !== false) ? $player['id'] : false;
} }
// Checks that this email exist. // Checks that this email exist.

View File

@ -5,6 +5,9 @@ if (version_compare(phpversion(), '5.3.3', '<')) die('PHP 5.3.3 is required<br><
$time = time(); $time = time();
$version = '1.5_SVN'; $version = '1.5_SVN';
$aacQueries = 0;
$accQueriesData = array();
session_start(); session_start();
ob_start(); ob_start();
require 'config.php'; require 'config.php';

View File

@ -9,7 +9,7 @@
$time = $time[1] + $time[0]; $time = $time[1] + $time[0];
$finish = $time; $finish = $time;
$total_time = round(($finish - $start), 4); $total_time = round(($finish - $start), 4);
echo 'Server date and clock is: '. getClock(false, true) .' Page generated in '. $total_time .' seconds.'; echo 'Server date and clock is: '. getClock(false, true) .' Page generated in '. $total_time .' seconds. Q: '.$aacQueries;
?> ?>
<a href="http://www.css3templates.co.uk">Design: css3templates.co.uk</a>. Engine: <a href="credits.php">Znote AAC</a></p> <a href="http://www.css3templates.co.uk">Design: css3templates.co.uk</a>. Engine: <a href="credits.php">Znote AAC</a></p>
</footer> </footer>

View File

@ -1,3 +1,6 @@
<?php
//data_dump($accQueriesData, false, "Done Queries");
?>
</div> </div>
</div> </div>
<?php include 'layout/footer.php'; ?> <?php include 'layout/footer.php'; ?>

View File

@ -21,7 +21,8 @@
} }
if ($status) { if ($status) {
?> ?>
<li><a href="onlinelist.php">Players online: <?php echo user_count_online();?></a></li> <li><a href="onlinelist.php">Players online:
<?php echo user_count_online(); ?></a></li>
<?php <?php
} }
?> ?>

View File

@ -9,7 +9,7 @@ if (empty($_POST) === false) {
} }
$username = $_POST['username']; $username = $_POST['username'];
$password = $_POST['password']; $password = $_POST['password'];
data_dump($_POST, false, "POST"); //data_dump($_POST, false, "POST");
if (empty($username) || empty($password)) { if (empty($username) || empty($password)) {
$errors[] = 'You need to enter a username and password.'; $errors[] = 'You need to enter a username and password.';
} else if (strlen($username) > 32 || strlen($password) > 64) { } else if (strlen($username) > 32 || strlen($password) > 64) {