summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBlueRaja <BlueRaja.admin@gmail.com>2013-01-13 19:27:39 -0600
committerBlueRaja <BlueRaja.admin@gmail.com>2013-01-13 19:27:39 -0600
commit099e2d5ab8effe07b0e5d8c59e18c81f519fd833 (patch)
treeb23c9a4291b1391382bdf4424bb7a948a287e76d
parent35307251560e459615f2a3e5ab6572b3f80cfdd9 (diff)
downloadpathery-099e2d5ab8effe07b0e5d8c59e18c81f519fd833.tar.xz
Added totalWins and totalTies columns to the users table. Also, removed all references to the 'statistics' table - it's not needed anymore.
-rw-r--r--includes/datas.php82
-rw-r--r--includes/mapoftheday.php2
-rw-r--r--includes/playerStats.php (renamed from includes/championPoints.php)75
-rw-r--r--pages/admin.php10
-rw-r--r--pages/faq.php2
-rw-r--r--pages/memberlist.php5
6 files changed, 85 insertions, 91 deletions
diff --git a/includes/datas.php b/includes/datas.php
index 6d73230..b29f1c9 100644
--- a/includes/datas.php
+++ b/includes/datas.php
@@ -572,11 +572,9 @@ function getAchievementCurrency($userID, $aType) {
WHERE userID = '$userID'";
break;
case 3:
- $sql = "SELECT
- SUM(`value`) as t
- FROM `statistics`
- WHERE `userID` = '$userID'
- AND `type` IN (1, 2, 3, 4)";
+ $sql = "SELECT totalTies
+ FROM `users`
+ WHERE `userID` = '$userID'";
break;
case 4:
$sql = "SELECT championPoints
@@ -711,74 +709,6 @@ function getChampionPointsArray() {
return $r;
}
-//Used to track statistics on who wins or ties maps at the end of a day.
-function trackMOTDstats($mapType) {
- // Our rather massive query to get the data we need.
- $sql = "SELECT
- users.ID as userID,
- SUM(solutions.moves) as Moves,
- timediff(MAX(dateModified), maps.dateCreated) as Timetaken
- FROM `maps`
- JOIN `solutions`
- ON maps.ID = solutions.mapID
- JOIN `users`
- ON solutions.userID = users.ID
- JOIN `mapOfTheDay`
- ON maps.ID = mapOfTheDay.mapID
- WHERE
- DATE_ADD(CURDATE(), INTERVAL -1 DAY) =
- DATE_FORMAT(solutions.dateModified,'%Y-%m-%d')
- AND DATE_ADD(CURDATE(), INTERVAL -1 DAY) =
- DATE_FORMAT(maps.dateCreated,'%Y-%m-%d')
- AND `mapType` = '$mapType'
- GROUP BY solutions.userID
- ORDER BY Moves DESC, MAX(dateModified) ASC, solutions.ID DESC
- ";
-
- $mainResult = mysql_query($sql);
- if ($mainResult) {
- $first = true;
- while (list($userID, $uMoves, $uTimeTaken) = mysql_fetch_row($mainResult)) {
- //echo "$first : userID: $userID uMoves: $uMoves uTimeTaken: $uTimeTaken mapType: $mapType<br >";
- do {
- //If it's the rank #1 user, we need to repeat to also award him the tie stat.
- $repeatThis = false;
- $sType = $mapType;
- if ($first) {
- $bestMoves = $uMoves;
- $sType = 31 + $mapType;
- $repeatThis = true;
- }
- if ($uMoves == $bestMoves) {
- $sql = "SELECT `ID` FROM `statistics`
- WHERE `userID` = '$userID' AND `type` = '$sType'";
- $result = mysql_query($sql);
-
- if (mysql_num_rows($result) == 0) {
- $sql = "INSERT INTO `statistics` (`userID`, `type`, `value`)
- VALUES ('$userID', '$sType', 1)";
- $result = mysql_query($sql);
- if (!$result)
- return false;
- } else {
- $sql = "UPDATE `statistics`
- SET `value` = `value` + 1
- WHERE `userID` = '$userID' AND `type` = '$sType'";
- $result = mysql_query($sql);
- if (!$result)
- return false;
- }
-
- } else {
- break 2;
- }
- $first = false;
- } while ($repeatThis);
- }
- }
- return true;
-}
-
//Select Members
function getMembers($order, $pageNumber = 1, $pageDivide = 50) {
@@ -826,8 +756,8 @@ function getMembers($order, $pageNumber = 1, $pageDivide = 50) {
WHERE solutions.userID = users.ID AND
solutions.dateModified < CURRENT_DATE)
, 0) AS totalMazes,
- SUM(CASE WHEN statistics.type IN (32, 33, 34, 35) THEN statistics.value ELSE 0 END) as totalWins,
- SUM(CASE WHEN statistics.type IN (1, 2, 3, 4) THEN statistics.value ELSE 0 END) as totalTies,
+ users.totalWins,
+ users.totalTies,
IfNull(userData.wallColor, '#666666') as wallColor,
IfNull(userData.displayColor, '#cccccc'),
userData.wallEmblem as wallEmblem,
@@ -835,8 +765,6 @@ function getMembers($order, $pageNumber = 1, $pageDivide = 50) {
users.dateLogin as dateLogin
FROM `users`
LEFT JOIN `userData` ON users.ID = userData.userID
- LEFT JOIN `statistics` ON users.ID = statistics.userID
- GROUP BY users.ID
$order
LIMIT $limitTop, $pageDivide
";
diff --git a/includes/mapoftheday.php b/includes/mapoftheday.php
index 3a472ba..178dc64 100644
--- a/includes/mapoftheday.php
+++ b/includes/mapoftheday.php
@@ -1 +1 @@
-<?php include_once('maps.php'); include_once('sqlEmbedded.php'); include_once('championPoints.php'); define('MAP_EXPIRE_TIME_NORMAL', 1); //Days that non-weekly maps should last. Changing this won't //really work without changes to generateNewMapsOfTheDay().. define('MAP_EXPIRE_TIME_WEEKLY', 2); //Days that a weekly map should last /** * Returns the Map Of The Day with the given type (index). Generates new maps if necessary. */ function mapOfTheDay($type = 1) { $map = getMapOfTheDayInternal($type); if($map == null) { //Map doesn't exist, so we generate the maps and try again generateNewMapsOfTheDay(); $map = getMapOfTheDayInternal($type); } return $map; } /** * Returns the map of the day of the given type, or null if not found. * Do not call outside of mapoftheday.php */ function getMapOfTheDayInternal($type) { if ($type <= 4) $expire = MAP_EXPIRE_TIME_NORMAL; else if ($type <= 8) $expire = MAP_EXPIRE_TIME_WEEKLY; $sql = " SELECT maps.ID, maps.code FROM `mapOfTheDay`, `maps` WHERE `mapType` = $type AND DATEDIFF(CURDATE(), mapOfTheDay.mapDate) < $expire AND mapID = maps.ID "; $result = mysql_query($sql); if (mysql_num_rows($result) == 0) { return null; } //A map was found, so return it $r['code'] = mysql_result($result, 0, 'code'); $r['map'] = GenerateMapByCode($r['code']); $r['id'] = mysql_result($result, 0, 'ID'); return $r; } /** * Generates all the new maps for the day. Includes a critical section so maps aren't generated more * than once per day. */ function generateNewMapsOfTheDay() { ignore_user_abort(true); $lock = acquireMotdLock(); try { //Double check that there is no simple map for today. Since that was done outside of the lock, it's possible //two threads could reach this point at the same time. $map = getMapOfTheDayInternal(1); if($map != null) { releaseMotdLock($lock); return; } //The rest of the code in the try{} can be assumed to only be run once a day //Generate the maps generateMapAndAddToDB(1); generateMapAndAddToDB(2); generateMapAndAddToDB(3); generateMapAndAddToDB(4); //The weekly maps might not need to be generated tonight. Check if it does first $weeklyMap = getMapOfTheDayInternal(5); if($weeklyMap == null) { generateMapAndAddToDB(5); } //Update the player-statistics addChampionPointsForYesterdaysMaps(); } catch (Exception $exc) { /* Ignore... :| */ } //try/catch above is necessary to make sure an exception doesn't prevent us from releasing the lock! releaseMotdLock($lock); } /** * Generates a single map of the given type, and adds its info to the DB */ function generateMapAndAddToDB($type) { // If you want to modify the maps created! This is the line //GenerateMap($rows, $cols, $rockchance, $numBlocks = -1, $cp = -1, $tp = -1) switch ($type) { case 1: //Easy $map = GenerateMap(13, 7, 12, rand(7, 10), rand(0, 1), 0); break; case 2: //Normal $map = GenerateMap(15, 9, 7, rand(11, 13), rand(1, 3) + rand(0, 1), 0); break; case 3: //Hard $map = getRandomComplexMap(); break; case 4: //Full random map $map = getRandomSpecialMap(); break; case 5: $map = getRandomWeeklyMap(); break; default: $map = GenerateMap(rand(13, 18), rand(10, 14), rand(6, 9)); break; } $code = GenerateMapCode($map); $sql = "INSERT INTO `maps` (`code`) VALUES ('$code')"; $result = mysql_query($sql); if (!$result) { releaseMotdLock($lock); die("Error on inserting map"); } $mapID = mysql_insert_id(); $r['code'] = $code; $r['map'] = $map; $r['id'] = $mapID; $sql = "INSERT INTO `mapOfTheDay` (`mapID`, `mapType`, `mapDate`) VALUES ('$mapID', '$type', CURDATE()) "; $result = mysql_query($sql); if (!$result) { releaseMotdLock($lock); die("Error on insert into mapOfTheDay"); } // Track statistics for yesterday's map of this type //TODO: Tracking of statistics can be done all at once, no need to do it for each maptype trackMOTDstats($type); } /** * The file locked in order to create serialize map-creations, since our DB doesn't support transactions... */ define('FILE_MOTD_LOCK', './motdLockFile'); /** * Obtains the mutex used for creating the Map Of The Day, so that race-conditions cannot occur (like two threads * creating and inserting the maps into the database at the same time, which has happened */ function acquireMotdLock() { $fileHandle = fopen(FILE_MOTD_LOCK, 'a+'); flock($fileHandle, LOCK_EX); return $fileHandle; } /** * Releases the lock acquired from acquireMotdLock */ function releaseMotdLock($fileHandle) { if($fileHandle) flock($fileHandle, LOCK_UN); } //Select from yesterday function getYesterdaysMap() { $sql = " select `ID`, `code` from `maps` WHERE ( DAY(dateCreated) = DAY(NOW()) - 1 AND MONTH(dateCreated) = MONTH(NOW()) AND YEAR(dateCreated) = YEAR(NOW()) ) "; $result = mysql_query($sql); //No map for today? if (mysql_num_rows($result) == 0) { return -1; } $r['code'] = mysql_result($result, 0, 'code'); $r['id'] = mysql_result($result, 0, 'ID'); return $r; } function getRandomComplexMap() { $random = weight(0, 0, 0, 0, 0, 0, 0, 1); switch ($random) { case 0: $map = GenerateMap(19, 9, rand(7, 9), rand(14, 16), rand(2, 5), rand(1, 2)); break; case 1: $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath = insertPoint($reversePath, 'abc'); $reversePath = insertPoint($reversePath, 'tu'); $myparams['checkpoints'] = 3; $myparams['teleports'] = 0; $myparams['rockchance'] = 7; $myparams['walls'] = 12; $myparams['name'] = 'Reverse Order'; $map = GenerateShapedMap($reversePath, $myparams); break; } return $map; } function getRandomSpecialMap() { //This can be used to add additional weight to certain maps that we like. $random = weight(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); $shape = array(); $params = array(); switch ($random) { //===================================== case 0: //Thirty $map = GenerateMap( 18, 14, 20, //width, height, rocks weight(30), //Walls weight(1), //Checkpoints weight(1), //Teleports 'Thirty' ); break; //===================================== case 1: //Simple $map = GenerateMap( 18, 9, 7, //width, height, rocks weight(15, 16, 17), //Walls weight(0), //Checkpoints weight(0), //Teleports 'Finite' ); break; //===================================== case 2: //ABC's $map = GenerateMap( 19, 11, 12, //width, height, rocks weight(20, 21, 22, 22, 23), //Walls weight(3), //Checkpoints weight(0), //Teleports "ABC's " ); break; //===================================== case 3: //Tele Madness $map = GenerateMap( 17, 12, 10, //width, height, rocks weight(17, 18), //Walls weight(1), //Checkpoints weight(5), //Teleports 'Teleport Madness' ); break; //===================================== case 4: //Thursday //Rocky Maze $map = GenerateMap( 19, 15, 5, //width, height, rocks weight(16, 17, 18), //Walls weight(1, 2, 2, 2, 3, 3), //Checkpoints weight(0), //Teleports 'Rocky Maze' ); break; //===================================== case 5: //Friday //Side to Side $map = GenerateMap( 26, 6, 12, //width, height, rocks weight(17, 18, 19), //Walls weight(2, 2, 2, 3, 3), //Checkpoints weight(3, 3, 3, 4), //Teleports 'Side to Side' ); break; //===================================== case 6: //Ultimate's Random map: //Create shape $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; //Insert points $shape = insertPoint($shape, "sfabcr", $target = '?'); $shape = insertPoint($shape, weight("tu", "d", "tu", "", ""), $target = '?'); //Set params $params['rockchance'] = 10; $params['walls'] = weight(21, 20, 22, 20, 21); $params['name'] = 'Ultimate Random'; //Put it all together. $map = GenerateShapedMap($shape, $params); break; //===================================== //===================================== case 7: //Dual map $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "oqqqqqqqqqqqqqqqqqqqo"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapa = insertPoint($dualmapa, 'abc'); $dualmapb = insertPoint($dualmapb, 'abc'); $dualmap = array_merge($dualmapa, $dualmapb); $dualmap = insertPoint($dualmap, 'tu'); $myparams['checkpoints'] = 3; $myparams['teleports'] = 1; $myparams['rockchance'] = 9; $myparams['walls'] = weight(20, 20, 21, 21, 22, 23); $myparams['name'] = 'Seeing Double'; $map = GenerateShapedMap($dualmap, $myparams); break; //===================================== //===================================== case 8: //Centralized $myshape[] = "ooooooooooooooooooo"; $myshape[] = "o?????????????????o"; $myshape[] = "o?????????????????o"; $myshape[] = "o?????????????????o"; $myshape[] = "o???????fos???????o"; $myshape[] = "o?????????????????o"; $myshape[] = "o?????????????????o"; $myshape[] = "o?????????????????o"; $myshape[] = "ooooooooooooooooooo"; $myshape = insertPoint($myshape, "abc", $target = '?'); $myshape = insertPoint($myshape, weight("tu", "d", "tud", ""), $target = '?'); $myparams['rockchance'] = 7; $myparams['walls'] = weight(17, 18, 19, 18, 17); $myparams['name'] = 'Centralized'; $map = GenerateShapedMap($myshape, $myparams); break; //===================================== //===================================== case 9: $dualingPaths[] = 'so??????????????xf'; $dualingPaths[] = 'so??????????????xf'; $dualingPaths[] = 'so??????????????xf'; $dualingPaths[] = 'so??????????????xf'; $dualingPaths[] = 'Xo??????????????ox'; $dualingPaths[] = 'fX??????????????oS'; $dualingPaths[] = 'fX??????????????oS'; $dualingPaths[] = 'fX??????????????oS'; $dualingPaths[] = 'fX??????????????oS'; $dualingPaths = insertPoint($dualingPaths, 'abc'); $dualingPaths = insertPoint($dualingPaths, weight('xx', 'xxx', 'xxxx').weight('XX', 'XXX', 'XXXX')); $myparams['checkpoints'] = 3; $myparams['teleports'] = 0; $myparams['rockchance'] = 9; $myparams['walls'] = 13; $myparams['name'] = 'Dualing paths'; $map = GenerateShapedMap($dualingPaths, $myparams); break; //===================================== //===================================== case 10: $unlimited[] = 'so?o?o?o?o?o?o?of'; $unlimited[] = 's???????????????f'; $unlimited[] = 'so?????????????of'; $unlimited[] = 's???????????????f'; $unlimited[] = 'so?????????????of'; $unlimited[] = 's???????????????f'; $unlimited[] = 'so?????????????of'; $unlimited[] = 's???????????????f'; $unlimited[] = 'so?o?o?o?o?o?o?of'; $unlimited = insertPoint($unlimited, 'abc'); $unlimited = insertPoint($unlimited, weight('tu', 'dtu')); $myparams['checkpoints'] = 3; $myparams['teleports'] = 1; $myparams['rockchance'] = 9; $myparams['walls'] = 999; $myparams['name'] = 'Unlimited'; $map = GenerateShapedMap($unlimited, $myparams); break; //===================================== } return $map; } function getRandomWeeklyMap() { // TEST MAP... $ultraComplex[] = "sooooooooooooooooooooooor"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "sooooooooooooooooooooooor"; $ultraComplex = insertPoint($ultraComplex, 'abcde'); $ultraComplex = insertPoint($ultraComplex, weight('a', 'b', 'c', 'd', 'e')); $ultraComplex = insertPoint($ultraComplex, weight('a', 'b', 'c', 'd', 'e', 'u', 'n', 'j', 'h', 'n')); $ultraComplex = insertPoint($ultraComplex, weight('a', 'b', 'c', 'd', 'e', 'u', 'n', 'j', 'h', 'n')); $ultraComplex = insertPoint($ultraComplex, 'tumnghij'); $myparams['checkpoints'] = 5; $myparams['teleports'] = 3; $myparams['rockchance'] = 12; $myparams['walls'] = 50; $myparams['name'] = 'Ultra Complex'; $map = GenerateShapedMap($ultraComplex, $myparams); return $map; } ?> \ No newline at end of file
+<?php include_once('maps.php'); include_once('sqlEmbedded.php'); include_once('playerStats.php'); define('MAP_EXPIRE_TIME_NORMAL', 1); //Days that non-weekly maps should last. Changing this won't //really work without changes to generateNewMapsOfTheDay().. define('MAP_EXPIRE_TIME_WEEKLY', 2); //Days that a weekly map should last /** * Returns the Map Of The Day with the given type (index). Generates new maps if necessary. */ function mapOfTheDay($type = 1) { $map = getMapOfTheDayInternal($type); if($map == null) { //Map doesn't exist, so we generate the maps and try again generateNewMapsOfTheDay(); $map = getMapOfTheDayInternal($type); } return $map; } /** * Returns the map of the day of the given type, or null if not found. * Do not call outside of mapoftheday.php */ function getMapOfTheDayInternal($type) { if ($type <= 4) $expire = MAP_EXPIRE_TIME_NORMAL; else if ($type <= 8) $expire = MAP_EXPIRE_TIME_WEEKLY; $sql = " SELECT maps.ID, maps.code FROM `mapOfTheDay`, `maps` WHERE `mapType` = $type AND DATEDIFF(CURDATE(), mapOfTheDay.mapDate) < $expire AND mapID = maps.ID "; $result = mysql_query($sql); if (mysql_num_rows($result) == 0) { return null; } //A map was found, so return it $r['code'] = mysql_result($result, 0, 'code'); $r['map'] = GenerateMapByCode($r['code']); $r['id'] = mysql_result($result, 0, 'ID'); return $r; } /** * Generates all the new maps for the day. Includes a critical section so maps aren't generated more * than once per day. */ function generateNewMapsOfTheDay() { ignore_user_abort(true); $lock = acquireMotdLock(); try { //Double check that there is no simple map for today. Since that was done outside of the lock, it's possible //two threads could reach this point at the same time. $map = getMapOfTheDayInternal(1); if($map != null) { releaseMotdLock($lock); return; } //The rest of the code in the try{} can be assumed to only be run once a day //Generate the maps generateMapAndAddToDB(1); generateMapAndAddToDB(2); generateMapAndAddToDB(3); generateMapAndAddToDB(4); //The weekly maps might not need to be generated tonight. Check if it does first $weeklyMap = getMapOfTheDayInternal(5); if($weeklyMap == null) { generateMapAndAddToDB(5); } //Update the player-statistics addStatsForYesterdaysMaps(); } catch (Exception $exc) { /* Ignore... :| */ } //try/catch above is necessary to make sure an exception doesn't prevent us from releasing the lock! releaseMotdLock($lock); } /** * Generates a single map of the given type, and adds its info to the DB */ function generateMapAndAddToDB($type) { // If you want to modify the maps created! This is the line //GenerateMap($rows, $cols, $rockchance, $numBlocks = -1, $cp = -1, $tp = -1) switch ($type) { case 1: //Easy $map = GenerateMap(13, 7, 12, rand(7, 10), rand(0, 1), 0); break; case 2: //Normal $map = GenerateMap(15, 9, 7, rand(11, 13), rand(1, 3) + rand(0, 1), 0); break; case 3: //Hard $map = getRandomComplexMap(); break; case 4: //Full random map $map = getRandomSpecialMap(); break; case 5: $map = getRandomWeeklyMap(); break; default: $map = GenerateMap(rand(13, 18), rand(10, 14), rand(6, 9)); break; } $code = GenerateMapCode($map); $sql = "INSERT INTO `maps` (`code`) VALUES ('$code')"; $result = mysql_query($sql); if (!$result) { releaseMotdLock($lock); die("Error on inserting map"); } $mapID = mysql_insert_id(); $r['code'] = $code; $r['map'] = $map; $r['id'] = $mapID; $sql = "INSERT INTO `mapOfTheDay` (`mapID`, `mapType`, `mapDate`) VALUES ('$mapID', '$type', CURDATE()) "; $result = mysql_query($sql); if (!$result) { releaseMotdLock($lock); die("Error on insert into mapOfTheDay"); } } /** * The file locked in order to create serialize map-creations, since our DB doesn't support transactions... */ define('FILE_MOTD_LOCK', './motdLockFile'); /** * Obtains the mutex used for creating the Map Of The Day, so that race-conditions cannot occur (like two threads * creating and inserting the maps into the database at the same time, which has happened */ function acquireMotdLock() { $fileHandle = fopen(FILE_MOTD_LOCK, 'a+'); flock($fileHandle, LOCK_EX); return $fileHandle; } /** * Releases the lock acquired from acquireMotdLock */ function releaseMotdLock($fileHandle) { if($fileHandle) flock($fileHandle, LOCK_UN); } //Select from yesterday function getYesterdaysMap() { $sql = " select `ID`, `code` from `maps` WHERE ( DAY(dateCreated) = DAY(NOW()) - 1 AND MONTH(dateCreated) = MONTH(NOW()) AND YEAR(dateCreated) = YEAR(NOW()) ) "; $result = mysql_query($sql); //No map for today? if (mysql_num_rows($result) == 0) { return -1; } $r['code'] = mysql_result($result, 0, 'code'); $r['id'] = mysql_result($result, 0, 'ID'); return $r; } function getRandomComplexMap() { $random = weight(0, 0, 0, 0, 0, 0, 0, 1); switch ($random) { case 0: $map = GenerateMap(19, 9, rand(7, 9), rand(14, 16), rand(2, 5), rand(1, 2)); break; case 1: $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath[] = 'fo?????????????oS'; $reversePath = insertPoint($reversePath, 'abc'); $reversePath = insertPoint($reversePath, 'tu'); $myparams['checkpoints'] = 3; $myparams['teleports'] = 0; $myparams['rockchance'] = 7; $myparams['walls'] = 12; $myparams['name'] = 'Reverse Order'; $map = GenerateShapedMap($reversePath, $myparams); break; } return $map; } function getRandomSpecialMap() { //This can be used to add additional weight to certain maps that we like. $random = weight(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); $shape = array(); $params = array(); switch ($random) { //===================================== case 0: //Thirty $map = GenerateMap( 18, 14, 20, //width, height, rocks weight(30), //Walls weight(1), //Checkpoints weight(1), //Teleports 'Thirty' ); break; //===================================== case 1: //Simple $map = GenerateMap( 18, 9, 7, //width, height, rocks weight(15, 16, 17), //Walls weight(0), //Checkpoints weight(0), //Teleports 'Finite' ); break; //===================================== case 2: //ABC's $map = GenerateMap( 19, 11, 12, //width, height, rocks weight(20, 21, 22, 22, 23), //Walls weight(3), //Checkpoints weight(0), //Teleports "ABC's " ); break; //===================================== case 3: //Tele Madness $map = GenerateMap( 17, 12, 10, //width, height, rocks weight(17, 18), //Walls weight(1), //Checkpoints weight(5), //Teleports 'Teleport Madness' ); break; //===================================== case 4: //Thursday //Rocky Maze $map = GenerateMap( 19, 15, 5, //width, height, rocks weight(16, 17, 18), //Walls weight(1, 2, 2, 2, 3, 3), //Checkpoints weight(0), //Teleports 'Rocky Maze' ); break; //===================================== case 5: //Friday //Side to Side $map = GenerateMap( 26, 6, 12, //width, height, rocks weight(17, 18, 19), //Walls weight(2, 2, 2, 3, 3), //Checkpoints weight(3, 3, 3, 4), //Teleports 'Side to Side' ); break; //===================================== case 6: //Ultimate's Random map: //Create shape $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; $shape[] = "??????????????????"; //Insert points $shape = insertPoint($shape, "sfabcr", $target = '?'); $shape = insertPoint($shape, weight("tu", "d", "tu", "", ""), $target = '?'); //Set params $params['rockchance'] = 10; $params['walls'] = weight(21, 20, 22, 20, 21); $params['name'] = 'Ultimate Random'; //Put it all together. $map = GenerateShapedMap($shape, $params); break; //===================================== //===================================== case 7: //Dual map $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "s???????????????????f"; $dualmapa[] = "oqqqqqqqqqqqqqqqqqqqo"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapb[] = "s???????????????????f"; $dualmapa = insertPoint($dualmapa, 'abc'); $dualmapb = insertPoint($dualmapb, 'abc'); $dualmap = array_merge($dualmapa, $dualmapb); $dualmap = insertPoint($dualmap, 'tu'); $myparams['checkpoints'] = 3; $myparams['teleports'] = 1; $myparams['rockchance'] = 9; $myparams['walls'] = weight(20, 20, 21, 21, 22, 23); $myparams['name'] = 'Seeing Double'; $map = GenerateShapedMap($dualmap, $myparams); break; //===================================== //===================================== case 8: //Centralized $myshape[] = "ooooooooooooooooooo"; $myshape[] = "o?????????????????o"; $myshape[] = "o?????????????????o"; $myshape[] = "o?????????????????o"; $myshape[] = "o???????fos???????o"; $myshape[] = "o?????????????????o"; $myshape[] = "o?????????????????o"; $myshape[] = "o?????????????????o"; $myshape[] = "ooooooooooooooooooo"; $myshape = insertPoint($myshape, "abc", $target = '?'); $myshape = insertPoint($myshape, weight("tu", "d", "tud", ""), $target = '?'); $myparams['rockchance'] = 7; $myparams['walls'] = weight(17, 18, 19, 18, 17); $myparams['name'] = 'Centralized'; $map = GenerateShapedMap($myshape, $myparams); break; //===================================== //===================================== case 9: $dualingPaths[] = 'so??????????????xf'; $dualingPaths[] = 'so??????????????xf'; $dualingPaths[] = 'so??????????????xf'; $dualingPaths[] = 'so??????????????xf'; $dualingPaths[] = 'Xo??????????????ox'; $dualingPaths[] = 'fX??????????????oS'; $dualingPaths[] = 'fX??????????????oS'; $dualingPaths[] = 'fX??????????????oS'; $dualingPaths[] = 'fX??????????????oS'; $dualingPaths = insertPoint($dualingPaths, 'abc'); $dualingPaths = insertPoint($dualingPaths, weight('xx', 'xxx', 'xxxx').weight('XX', 'XXX', 'XXXX')); $myparams['checkpoints'] = 3; $myparams['teleports'] = 0; $myparams['rockchance'] = 9; $myparams['walls'] = 13; $myparams['name'] = 'Dualing paths'; $map = GenerateShapedMap($dualingPaths, $myparams); break; //===================================== //===================================== case 10: $unlimited[] = 'so?o?o?o?o?o?o?of'; $unlimited[] = 's???????????????f'; $unlimited[] = 'so?????????????of'; $unlimited[] = 's???????????????f'; $unlimited[] = 'so?????????????of'; $unlimited[] = 's???????????????f'; $unlimited[] = 'so?????????????of'; $unlimited[] = 's???????????????f'; $unlimited[] = 'so?o?o?o?o?o?o?of'; $unlimited = insertPoint($unlimited, 'abc'); $unlimited = insertPoint($unlimited, weight('tu', 'dtu')); $myparams['checkpoints'] = 3; $myparams['teleports'] = 1; $myparams['rockchance'] = 9; $myparams['walls'] = 999; $myparams['name'] = 'Unlimited'; $map = GenerateShapedMap($unlimited, $myparams); break; //===================================== } return $map; } function getRandomWeeklyMap() { // TEST MAP... $ultraComplex[] = "sooooooooooooooooooooooor"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "so?????????????????????or"; $ultraComplex[] = "ro?????????????????????of"; $ultraComplex[] = "sooooooooooooooooooooooor"; $ultraComplex = insertPoint($ultraComplex, 'abcde'); $ultraComplex = insertPoint($ultraComplex, weight('a', 'b', 'c', 'd', 'e')); $ultraComplex = insertPoint($ultraComplex, weight('a', 'b', 'c', 'd', 'e', 'u', 'n', 'j', 'h', 'n')); $ultraComplex = insertPoint($ultraComplex, weight('a', 'b', 'c', 'd', 'e', 'u', 'n', 'j', 'h', 'n')); $ultraComplex = insertPoint($ultraComplex, 'tumnghij'); $myparams['checkpoints'] = 5; $myparams['teleports'] = 3; $myparams['rockchance'] = 12; $myparams['walls'] = 50; $myparams['name'] = 'Ultra Complex'; $map = GenerateShapedMap($ultraComplex, $myparams); return $map; } ?> \ No newline at end of file
diff --git a/includes/championPoints.php b/includes/playerStats.php
index 28b2b78..b302812 100644
--- a/includes/championPoints.php
+++ b/includes/playerStats.php
@@ -111,6 +111,7 @@ function addPlayerChampionPointsForMapsOfTheDay($fromDate)
INNER JOIN mapOfTheDay ON mapOfTheDay.mapID = solutions.mapID
SET solutions.championPointsWorth = mapOfTheDay.championPointsWorth
WHERE mapOfTheDay.mapDate >= '$fromDate'
+ AND mapOfTheDay.mapDate < CURDATE()
AND mapOfTheDay.mapType <> 5
AND solutions.moves = maxMoves.moves
";
@@ -121,6 +122,7 @@ function addPlayerChampionPointsForMapsOfTheDay($fromDate)
SET solutions.championPointsWorth = solutions.championPointsWorth * (1 + ".CP_EXTRA_PERCENT_FOR_FIRST.")
WHERE solutions.isHighScore = 1
AND solutions.dateModified >= $fromDate
+ AND solutions.dateModified < CURDATE()
";
//TODO: This doesn't work right, weekly maps last more than a day...
@@ -145,8 +147,10 @@ function addPlayerChampionPointsForMapsOfTheDay($fromDate)
WHERE usersSolutions.ID = solutions.ID
AND mapOfTheDay.mapType = 5
AND mapOfTheDay.mapDate >= '$fromDate'
+ AND mapOfTheDay.mapDate < CURDATE()
)
WHERE solutions.dateModified >= $fromDate;
+ AND mapOfTheDay.mapDate < CURDATE()
";
$sql4 = "
@@ -179,26 +183,89 @@ function addPlayerChampionPointsForMapsOfTheDay($fromDate)
}
/**
- * Calculates the worth of the maps for yesterday, and distributes points for them
+ * Sets all players wins and draws to 0. Should be done before a total recalculation
*/
-function addChampionPointsForYesterdaysMaps()
+function clearWinsAndTies()
+{
+ $sql = "
+ UPDATE users
+ SET totalWins = 0, totalTies = 0;
+ ";
+
+ mysql_query($sql);
+}
+
+/**
+ * Calculates players' total wins and draws, adding from the given date
+ */
+function addWinsAndTies($fromDate)
+{
+ $sql1 = "
+ -- Add the players' latest wins
+ UPDATE users
+ SET totalWins = totalWins +
+ (
+ SELECT COUNT(*)
+ FROM solutions
+ INNER JOIN mapOfTheDay ON solutions.mapID = mapOfTheDay.mapID
+ WHERE solutions.isHighScore = 1
+ AND mapOfTheDay.mapDate >= '$fromDate'
+ AND mapOfTheDay.mapDate < CURDATE()
+ AND solutions.userID = users.ID
+ );
+ ";
+
+ $sql2 = "
+ -- Add the players' latest ties
+ UPDATE users
+ SET totalTies = totalTies +
+ (
+ SELECT COUNT(*)
+ FROM solutions
+ INNER JOIN mapOfTheDay ON solutions.mapID = mapOfTheDay.mapID
+ WHERE mapOfTheDay.mapDate >= '$fromDate'
+ AND mapOfTheDay.mapDate < CURDATE()
+ AND solutions.userID = users.ID
+ AND solutions.moves =
+ (
+ SELECT moves
+ FROM solutions AS s2
+ WHERE s2.mapID = mapOfTheDay.mapID
+ AND s2.isHighScore = 1
+ LIMIT 1
+ )
+ );
+ ";
+
+ mysql_query($sql1);
+ mysql_query($sql2);
+}
+
+/**
+ * Calculates the worth of the maps for yesterday, and distributes points for them. Also adds wins and ties to
+ * the correct players
+ */
+function addStatsForYesterdaysMaps()
{
$yesterday = strtotime('-1 day', time());
$yesterdayStr = date('Y-m-d', $yesterday);
setIsHighScoreFlag($yesterday);
calculateMapsChampionPointWorth($yesterdayStr);
addPlayerChampionPointsForMapsOfTheDay($yesterdayStr);
+ addWinsAndTies($yesterdayStr);
}
/**
- * Recalculates all player's total champion points.
+ * Recalculates all player's total champion points, wins, and ties.
* Will probably be extremely slow, so should not be called often!
*/
-function recalculateAllPlayersChampionPoints()
+function recalculateStatsForAllPlayers()
{
setIsHighScoreFlag(CP_EARLIEST_DATE);
calculateMapsChampionPointWorth(CP_EARLIEST_DATE);
addPlayerChampionPointsForMapsOfTheDay(CP_EARLIEST_DATE);
//TODO: Champion points for challenges!
+ clearWinsAndTies();
+ addWinsAndTies(CP_EARLIEST_DATE);
}
?>
diff --git a/pages/admin.php b/pages/admin.php
index afc6418..0f54285 100644
--- a/pages/admin.php
+++ b/pages/admin.php
@@ -10,7 +10,7 @@ include_once('./includes/datas.php');
include_once('./includes/maps.php');
include_once('./includes/mapoftheday.php');
include_once('./includes/sqlEmbedded.php');
-include_once('./includes/championPoints.php');
+include_once('./includes/playerStats.php');
if ($_GET['applyall'] == 'true') {
echo "Apply-All command heard. Executing...";
@@ -27,10 +27,10 @@ if ($_GET['applyall'] == 'true') {
echo "Execution complete!";
}
-else if ($_GET['recalcChamp'] == 'true') {
- echo "Recalculating champion points...";
+else if ($_GET['recalcStats'] == 'true') {
+ echo "Recalculating all player stats...";
- recalculateAllPlayersChampionPoints();
+ recalculateStatsForAllPlayers();
echo "Complete!";
}
@@ -45,7 +45,7 @@ echo '
<p>News:</p>
<p>Buttons:<br />
<input type="button" value="Apply all achievements" onClick="parent.location=\'admin?applyall=true\'">
- <input type="button" value="Recalculate all champion points" onClick="parent.location=\'admin?recalcChamp=true\'">
+ <input type="button" value="Recalculate all player stats" onClick="parent.location=\'admin?recalcStats=true\'">
</p>
<p>Hello admins, this is our current userlist.</p>
</center>
diff --git a/pages/faq.php b/pages/faq.php
index e9d8e5f..95b0b87 100644
--- a/pages/faq.php
+++ b/pages/faq.php
@@ -8,7 +8,7 @@ echo soundManager2();
topbar($Links);
include_once('./includes/maps.php');
-include_once('./includes/championPoints.php');
+include_once('./includes/playerStats.php');
// Demo maps:
diff --git a/pages/memberlist.php b/pages/memberlist.php
index 3baf456..2fa2cdc 100644
--- a/pages/memberlist.php
+++ b/pages/memberlist.php
@@ -115,8 +115,8 @@ $sql = "SELECT
WHERE solutions.userID = users.ID AND
solutions.dateModified BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY) AND CURRENT_DATE) AS totalMovesThisWeek,
(SELECT COUNT(*) FROM solutions WHERE solutions.userID = users.ID AND solutions.dateModified < CURRENT_DATE) AS totalMazes,
- SUM(CASE WHEN statistics.type IN (32, 33, 34, 35) THEN statistics.value ELSE 0 END) as totalWins,
- SUM(CASE WHEN statistics.type IN (1, 2, 3, 4) THEN statistics.value ELSE 0 END) as totalTies,
+ users.totalWins,
+ users.totalTies,
IfNull(userData.wallColor, '#666666') as wallColor,
IfNull(userData.displayColor, '#cccccc'),
userData.wallEmblem,
@@ -124,7 +124,6 @@ $sql = "SELECT
users.dateLogin as dateLogin
FROM `users`
LEFT JOIN `userData` ON users.ID = userData.userID
-LEFT JOIN `statistics` ON users.ID = statistics.userID
GROUP BY users.ID
$order
";