summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBlueRaja <BlueRaja.admin@gmail.com>2013-01-13 00:43:06 -0600
committerBlueRaja <BlueRaja.admin@gmail.com>2013-01-13 00:43:06 -0600
commitf972ce9c56f0bf2201cd302c0055c6ebd06be34b (patch)
treef157e660070c8100a07f5cbe3c5334d90241ea1d
parent38038e0a1582facb70a47ae3162db6e10ca831f5 (diff)
downloadpathery-f972ce9c56f0bf2201cd302c0055c6ebd06be34b.tar.xz
Added code for generating and using champion points, and for recalculating them from scratch in the admin panel. Now just need to add them to the scoreboard and the leadboard pages...
-rw-r--r--includes/championPoints.php180
-rw-r--r--includes/mapoftheday.php2
-rw-r--r--pages/admin.php26
3 files changed, 200 insertions, 8 deletions
diff --git a/includes/championPoints.php b/includes/championPoints.php
new file mode 100644
index 0000000..e824c0c
--- /dev/null
+++ b/includes/championPoints.php
@@ -0,0 +1,180 @@
+<?php
+define('CP_EARLIEST_DATE', '2012-01-01');
+define('CP_MIN_WORTH', 10);
+define('CP_MAX_WORTH_SIMPLE', 100);
+define('CP_MAX_WORTH_NORMAL', 150);
+define('CP_MAX_WORTH_COMPLEX', 200);
+define('CP_MAX_WORTH_SPECIAL', 200);
+define('CP_MAX_WORTH_WEEKLY', 350);
+define('CP_MIN_WORTH_WEEKLY', 50);
+define('CP_POINTS_FOR_ATTEMPTING', 5);
+define('CP_EXTRA_PERCENT_FOR_FIRST', 0.05);
+
+/**
+ * Calculates the worth of all maps' champion points from after the given date
+ * @param $fromDate The earliest date to count from. Use SQL date-string format.
+ * Pass in yesterday's date, for example, to add champion points from yesterday's maps
+ */
+function calculateMapsChampionPointWorth($fromDate)
+{
+ $fromDate = mysql_escape_string($fromDate);
+
+ //We take the worth of the map, multiply by the number of people who tied the high score, then divide by the
+ //total number of people who attempted the map (minus 1)
+ $sql = "
+ UPDATE mapOfTheDay
+ SET championPointsWorth = GREATEST(".CP_MIN_WORTH.",
+ (
+ CASE mapType
+ WHEN 1 THEN ".CP_MAX_WORTH_SIMPLE."
+ WHEN 2 THEN ".CP_MAX_WORTH_NORMAL."
+ WHEN 3 THEN ".CP_MAX_WORTH_COMPLEX."
+ WHEN 4 THEN ".CP_MAX_WORTH_SPECIAL."
+ WHEN 5 THEN ".CP_MAX_WORTH_WEEKLY."
+ ELSE 0
+ END
+ ) * (
+ SELECT COUNT(*)
+ FROM solutions
+ WHERE solutions.mapID = mapOfTheDay.mapID
+ AND solutions.moves <
+ (
+ SELECT MAX(moves)
+ FROM solutions AS s2
+ WHERE s2.mapId = mapOfTheDay.mapID
+ )
+ ) / (
+ SELECT GREATEST(COUNT(*)-1, 1)
+ FROM solutions
+ WHERE solutions.mapID = mapOfTheDay.mapID
+ ))
+ WHERE mapDate >= '$fromDate'
+ ";
+
+ mysql_query($sql);
+}
+
+/**
+ * Adds the champion points for each player for every day after the given date, but before today.
+ * Thus, if you're using this to add points from yesterday's maps, this should be done
+ * after the date has changed.
+ * @param $fromDate The earliest date to count from. SQL date-string format.
+ * Pass in yesterday's date, for example, to add champion points from yesterday's maps
+ */
+function addPlayerChampionPointsForMapsOfTheDay($fromDate)
+{
+ $fromDate = mysql_escape_string($fromDate);
+
+ //TODO: How do you know when an ultra-complex map has completed?
+
+ //Weird syntax of these queries is necessary due to a bug in MySQL with updating a table and selecting a table
+ //in the same query. See http://www.xaprb.com/blog/2006/06/23/how-to-select-from-an-update-target-in-mysql/
+ $sql1 = "
+ -- Add the points for tying the map
+ UPDATE solutions
+ INNER JOIN
+ (
+ SELECT mapID, MAX(moves) AS moves
+ FROM solutions AS s2
+ GROUP BY mapID
+ ) AS maxMoves ON maxMoves.mapID = solutions.mapID
+ INNER JOIN mapOfTheDay ON mapOfTheDay.mapID = solutions.mapID
+ SET solutions.championPointsWorth = mapOfTheDay.championPointsWorth
+ WHERE mapOfTheDay.mapDate >= '$fromDate'
+ AND mapOfTheDay.mapType <> 5
+ AND solutions.moves = maxMoves.moves
+ ";
+
+ $sql2 = "
+ -- Add the extra for being the first to tie the map
+ UPDATE solutions
+ SET solutions.championPointsWorth = solutions.championPointsWorth * (1 + ".CP_EXTRA_PERCENT_FOR_FIRST.")
+ WHERE solutions.ID IN
+ (
+ SELECT s2.ID
+ FROM (SELECT * FROM solutions) AS s2
+ INNER JOIN mapOfTheDay ON s2.mapID = mapOfTheDay.mapID
+ WHERE s2.moves =
+ (
+ SELECT MAX(moves)
+ FROM (SELECT * FROM solutions) AS s3
+ WHERE s3.mapID = mapOfTheDay.mapID
+ )
+ AND mapOfTheDay.mapDate >= '$fromDate'
+ )
+ ";
+
+ $sql3 = "
+ -- Add the points for doing the weekly maps
+ UPDATE solutions
+ SET championPointsWorth =
+ (
+ SELECT SUM(".CP_MAX_WORTH_WEEKLY." *
+ (
+ SELECT COUNT(*)
+ FROM (SELECT * FROM solutions) AS s2
+ WHERE s2.mapID = mapOfTheDay.mapID
+ AND s2.moves < usersSolutions.moves
+ ) / (
+ SELECT GREATEST(COUNT(*)-1, 1)
+ FROM (SELECT * FROM solutions) AS s2
+ WHERE s2.mapID = mapOfTheDay.mapID
+ ) + ".CP_MIN_WORTH_WEEKLY.")
+ FROM mapOfTheDay
+ INNER JOIN (SELECT * FROM solutions) AS usersSolutions ON usersSolutions.mapID = mapOfTheDay.mapID
+ WHERE usersSolutions.ID = solutions.ID
+ AND mapOfTheDay.mapType = 5
+ );
+ ";
+
+ $sql4 = "
+ -- Add the points for attempting the map
+ UPDATE solutions
+ SET championPointsWorth = ".CP_POINTS_FOR_ATTEMPTING."
+ WHERE championPointsWorth = 0
+ AND dateModified >= $fromDate
+ AND dateModified < CURDATE()
+ ";
+
+ //TODO: Points for doing challenges too
+ //TODO: Is summing the entire table every time slow? If so, we should just add the points instead
+ $sql5 = "
+ -- Simply re-sum all the points
+ UPDATE users
+ SET championPoints =
+ (
+ SELECT SUM(championPointsWorth)
+ FROM solutions
+ WHERE solutions.userID = users.ID
+ )
+ ";
+
+ mysql_query($sql1);
+ mysql_query($sql2);
+ mysql_query($sql3);
+ mysql_query($sql4);
+ mysql_query($sql5);
+}
+
+/**
+ * Calculates the worth of the maps for yesterday, and distributes points for them
+ */
+function addChampionPointsForYesterdaysMaps()
+{
+ $yesterday = strtotime('-1 day', time());
+ $yesterdayStr = date('Y-m-d', $yesterday);
+ calculateMapsChampionPointWorth($yesterdayStr);
+ addPlayerChampionPointsForMapsOfTheDay($yesterdayStr);
+}
+
+/**
+ * Recalculates all player's total champion points.
+ * Will probably be extremely slow, so should not be called often!
+ */
+function recalculateAllPlayersChampionPoints()
+{
+ calculateMapsChampionPointWorth(CP_EARLIEST_DATE);
+ addPlayerChampionPointsForMapsOfTheDay(CP_EARLIEST_DATE);
+ //TODO: Champion points for challenges!
+}
+?>
diff --git a/includes/mapoftheday.php b/includes/mapoftheday.php
index d244635..a8042c7 100644
--- a/includes/mapoftheday.php
+++ b/includes/mapoftheday.php
@@ -1 +1 @@
-<?php include_once('maps.php'); include_once('db.inc.php'); /** * Returns the Map Of The Day with the given type (index) */ function mapOfTheDay($type = 1) { ignore_user_abort(true); if ($type <= 8) $expire = 2; if ($type <= 4) $expire = 1; $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); //No map for today? if (mysql_num_rows($result) != 0) { $r['code'] = mysql_result($result, 0, 'code'); $r['map'] = GenerateMapByCode($r['code']); $r['id'] = mysql_result($result, 0, 'ID'); return $r; } return generateNewMapOfTheDay($type, $sql); } /** * Generates a new map of the day. DO NOT CALL OUTSIDE OF mapoftheday.php */ function generateNewMapOfTheDay($type, $sql) { // 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; } $lock = acquireMotdLock(); try { //Double check... $sql is already set $result = mysql_query($sql); //Are you SURE there's no map? if (mysql_num_rows($result) != 0) { releaseMotdLock($lock); return mapOfTheDay($type); } $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"); } } catch (Exception $exc) { /* Ignore... :| */ } releaseMotdLock($lock); // ---------- Track statistics for 'yesterdays' map. trackMOTDstats($type); return $r; } /** * 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('db.inc.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
diff --git a/pages/admin.php b/pages/admin.php
index 983c4bc..afac6c4 100644
--- a/pages/admin.php
+++ b/pages/admin.php
@@ -6,10 +6,11 @@ htmlHeader();
<?php
topbar($Links);
-include('./includes/datas.php');
-include('./includes/maps.php');
-include('./includes/mapoftheday.php');
-include('./includes/db.inc.php');
+include_once('./includes/datas.php');
+include_once('./includes/maps.php');
+include_once('./includes/mapoftheday.php');
+include_once('./includes/db.inc.php');
+include_once('./includes/championPoints.php');
if ($_GET['applyall'] == 'true') {
echo "Apply-All command heard. Executing...";
@@ -26,22 +27,33 @@ if ($_GET['applyall'] == 'true') {
echo "Execution complete!";
}
+else if ($_GET['recalcChamp'] == 'true') {
+ echo "Recalculating champion points...";
+
+ recalculateAllPlayersChampionPoints();
+
+ echo "Complete!";
+}
$sql = "SELECT `ID`, `displayName`, `dateJoined`, `dateLogin`, `email`, `isAdmin` FROM `users`";
$result = mysql_query($sql);
-echo "
+echo '
<center>
<h3>Administrators Page</h3>
<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\'">
+</p>
<p>Hello admins, this is our current userlist.</p>
</center>
-<table style='padding-left:20px;'>
+<table style="padding-left:20px;">
<tr>
<th>ID</th><th>Display name:</th><th>Joined On:</th><th>Last Logon</th><th>Email</th><th>Administrator</th>
</tr>
-";
+';
while (list($CUID, $CUsername, $Joined, $LastLogon, $email, $isAdmin) = mysql_fetch_row($result)) {