Guest User

Untitled

a guest
Aug 8th, 2013
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.93 KB | None | 0 0
  1. <?php
  2.  
  3. ///////////////////////////////////////////////////
  4. // HawkEye Interface Search File //
  5. // by oliverw92 //
  6. // Maintained by HawkEye Reloaded Dev Team //
  7. ///////////////////////////////////////////////////
  8.  
  9. error_reporting(E_ALL);
  10. session_start();
  11.  
  12. //Include config, lang pack and MySQL connector
  13. include("config.php");
  14. include("langs/" . $hawkConfig["langFile"]);
  15.  
  16. //Set up output array
  17. $output = array(
  18. "error" => "",
  19. "columns" => $lang["results"],
  20. "data" => array()
  21. );
  22.  
  23. //Check if required functions are here
  24. if (!function_exists("json_decode")) require('json.php');
  25.  
  26. //If not logged in, throw an error
  27. if (!isset($_SESSION["loggedIn"]) && $hawkConfig["password"] != "")
  28. return error($lang["messages"]["notLoggedIn"]);
  29.  
  30. if (!isset($_GET["data"]))
  31. return error($lang["messages"]["breakMe"]);
  32.  
  33. $data = json_decode(stripslashes($_GET["data"]), true);
  34.  
  35. // Sanitize input
  36. foreach ($data["actions"] as $key => $val)
  37. $data["actions"][$key] = intval($val);
  38. foreach ($data["loc"] as $key => $val)
  39. $data["loc"][$key] = intval($val);
  40. foreach ($data["keywords"] as $key => $val)
  41. $data["keywords"][$key] = mysql_real_escape_string($val);
  42. foreach ($data["exclude"] as $key => $val)
  43. $data["exclude"][$key] = mysql_real_escape_string($val);
  44.  
  45. $data["block"] = intval($data["block"]);
  46. $data["range"] = intval($data["range"]);
  47. $data["dateFrom"] = mysql_real_escape_string($data["dateFrom"]);
  48. $data["dateTo"] = mysql_real_escape_string($data["dateTo"]);
  49.  
  50. //Get players
  51. $players = array();
  52. $res = mysql_query("SELECT * FROM `" . $hawkConfig["dbPlayerTable"] . "`");
  53. if (!$res)
  54. return error(mysql_error());
  55. if (mysql_num_rows($res) == 0)
  56. return error($lang["messages"]["noResults"]);
  57. while ($player = mysql_fetch_object($res))
  58. $players[$player->player_id] = $player->player;
  59.  
  60. //Get worlds
  61. $worlds = array();
  62. $res = mysql_query("SELECT * FROM `" . $hawkConfig["dbWorldTable"] . "`");
  63. if (!$res)
  64. return error(mysql_error());
  65. if (mysql_num_rows($res) == 0)
  66. return error($lang["messages"]["noResults"]);
  67. while ($world = mysql_fetch_object($res))
  68. $worlds[$world->world_id] = $world->world;
  69.  
  70. $sql = "SELECT * FROM `" . $hawkConfig["dbTable"] . "` WHERE ";
  71. $args = array();
  72.  
  73. if ($data["players"][0] != "") {
  74. $pids = array();
  75. foreach ($data["players"] as $key => $val)
  76. foreach ($players as $key2 => $val2)
  77. if (stristr($val2, $val))
  78. array_push($pids, $key2);
  79. if (count($pids) > 0)
  80. array_push($args, "player_id IN (" . join(",", $pids) . ")");
  81. else
  82. return error($lang["messages"]["noResults"]);
  83. }
  84. if ($data["worlds"][0] != "") {
  85. $wids = array();
  86. foreach ($data["worlds"] as $key => $val)
  87. foreach ($worlds as $key2 => $val2)
  88. if (stristr($val2, $val))
  89. array_push($wids, $key2);
  90. if (count($wids) > 0)
  91. array_push($args, "world_id IN (" . join(",", $wids) . ")");
  92. else
  93. return error($lang["messages"]["noResults"]);
  94. }
  95. if (count($data["actions"]) == 0)
  96. return error($lang["messages"]["noActions"]);
  97. else
  98. array_push($args, "`action` IN (" . join(",", $data["actions"]) . ")");
  99.  
  100. $range = $hawkConfig["radius"];
  101. if ($data["range"] != "")
  102. $range = $data["range"];
  103. if ($data["loc"][0] != "")
  104. array_push($args, "(`x` BETWEEN " . ($data["loc"][0] - $range) . " AND " . ($data["loc"][0] + $range) . ")");
  105. if ($data["loc"][1] != "")
  106. array_push($args, "(`y` BETWEEN " . ($data["loc"][1] - $range) . " AND " . ($data["loc"][1] + $range) . ")");
  107. if ($data["loc"][2] != "")
  108. array_push($args, "(`z` BETWEEN " . ($data["loc"][2] - $range) . " AND " . ($data["loc"][2] + $range) . ")");
  109. if ($data["block"] != "00") {
  110. if ($data["keywords"][0] == "")
  111. $data["keywords"][0] = $data["block"];
  112. else
  113. array_push($data["keywords"], $data["block"]);
  114. }
  115.  
  116. if ($data["dateFrom"] != "" && $data["dateFrom"] != " ")
  117. array_push($args, "`timestamp` >= '" . $data["dateFrom"] . "'");
  118. if ($data["dateTo"] != "" && $data["dateTo"] != " ")
  119. array_push($args, "`timestamp` <= '" . $data["dateTo"] . "'");
  120. if ($data["keywords"][0] != "") {
  121. foreach ($data["keywords"] as $key => $val)
  122. $data["keywords"][$key] = "'%" . $val . "%'";
  123. array_push($args, "`data` LIKE " . join(" OR `data` LIKE ", $data["keywords"]));
  124. }
  125. if ($data["exclude"][0] != "") {
  126. foreach ($data["exclude"] as $key => $val)
  127. $data["exclude"][$key] = "'%" . $val . "%'";
  128. array_push($args, "`data` NOT LIKE " . join(" OR `data` LIKE ", $data["exclude"]));
  129. }
  130.  
  131. //Compile SQL statement
  132. $sql .= join(" AND ", $args);
  133. if ($hawkConfig["maxResults"] > 0)
  134. $sql .= " LIMIT " . $hawkConfig["maxResults"];
  135.  
  136. //Log query
  137. set_error_handler('handleError');
  138. if ($hawkConfig["logQueries"] == true) {
  139. try {
  140. if (!file_put_contents("log.txt", date("m.d.y G:i:s") . " - " . $_SERVER["REMOTE_ADDR"] . " - " . $sql . "\n", FILE_APPEND))
  141. return error("Unable to open/write to log.txt!");
  142. } catch (ErrorException $e) {
  143. if (stristr($e, "Warning:"))
  144. return error("Unable to open/write to log.txt!");
  145. }
  146. }
  147. restore_error_handler();
  148.  
  149. //Run query
  150. $res = mysql_query($sql);
  151. if (!$res)
  152. return error(mysql_error());
  153.  
  154. $items = explode("\n", file_get_contents("items.txt"));
  155. $itemhash = array();
  156. foreach($items as $i) {
  157. $item = explode(",", $i, 2);
  158. if (count($item) < 2) continue;
  159. if(isset($item[0]) && isset($item[1])) $itemhash[intval($item[0])] = $item[1];
  160. }
  161. $results = array();
  162.  
  163. //Get results from MySQL
  164. while ($entry = mysql_fetch_object($res))
  165. array_push($results, $entry);
  166.  
  167. foreach ($results as $key => $entry) {
  168. $row = array();
  169. $fdata = $entry->data;
  170. $action = $entry->action;
  171.  
  172. //Manipulate data according to action
  173. switch ($action) {
  174. case 0:
  175. case 10:
  176. case 17:
  177. case 32:
  178. case 33:
  179. $fdata = getBlockName($fdata);
  180. break;
  181. case 1:
  182. case 19:
  183. case 25:
  184. $arr = explode("-", $fdata);
  185. if (getBlockName($arr[0]) == "AIR") {
  186. $fdata = getBlockName($arr[1]);
  187. } else {
  188. $fdata = getBlockName($arr[0]) . " replaced by " . getBlockName($arr[1]);
  189. }
  190. break;
  191. case 16:
  192. $arr = explode("-", $fdata);
  193. if (count($arr) > 0)
  194. $action = array_shift($arr);
  195. $action .= $entry->plugin . " - ";
  196. $fdata = join("-", $arr);
  197. break;
  198. case 28:
  199. $changeString = "";
  200. foreach (explode("@", $fdata) as $change) {
  201. $changes = array();
  202.  
  203. if ($change == "") break;
  204. $item = explode("~", $change);
  205. $change = $item[1] . "x " . getBlockName($item[0]);
  206.  
  207. if ($change[0] == "+" $changeString .= '<span style="color: green">+(' . trim(implode(", ", $changes)) . ')</span>';
  208. if ($change[0] == "-" $changeString .= '<span style="color: red">-(' . trim(implode(", ", $changes)) . ')</span>';
  209. }
  210. $fdata = $changeString;
  211. break;
  212. case 2:
  213. case 29:
  214. if (strpos("@", $fdata)) {
  215. $fdata = str_replace("|", "<br />", $fdata);
  216. break;
  217. }
  218. $arr = explode("@", $fdata);
  219. if (count($arr) < 3) break;
  220. $lines = explode(",", $arr[2]);
  221. foreach ($lines as $key => $value)
  222. $lines[$key] = base64_decode($value);
  223. $fdata = implode("<br />", $lines);
  224. break;
  225. case 23:
  226. case 24:
  227. $arr = explode("x ", $fdata); //Separate the quantity from the item/block number
  228. $item = explode(":", $arr[1]); //Separate the damage value from the item/block
  229. $changeString = $arr[0] . "x " . getBlockName($item[0]); //String is now "quantity"x "blockname"
  230. if($item[1] != "0")
  231. $changeString = $changeString . ":" . $item[1]; //If item has a damage value other than 0, add it to changeString
  232. $fdata = $changeString;
  233. break;
  234. }
  235.  
  236. $action = str_replace(array_reverse(array_keys($lang["actions"])), array_reverse($lang["actions"]), $action);
  237.  
  238. //Add to output row
  239. array_push($row, $entry->data_id, $entry->timestamp, $players[$entry->player_id], $action, $worlds[$entry->world_id], round($entry->x, 1).",".round($entry->y, 1).",".round($entry->z, 1), $fdata);
  240. array_push($output["data"], $row);
  241. }
  242.  
  243. echo json_encode($output);
  244.  
  245. /*
  246. // FUNCTION: getBlockName($string);
  247. // Gets block name of block
  248. */
  249. function getBlockName($string) {
  250. global $itemhash;
  251.  
  252. $parts = explode(":", $string);
  253.  
  254. if (!isset($itemhash[$parts[0]])) return $string;
  255.  
  256. $i = $itemhash[$parts[0]];
  257. if ($string == "00")
  258. return "AIR";
  259. else if (count($parts) == 2)
  260. return $i . ":" . $parts[1];
  261. else
  262. return $i;
  263. }
  264.  
  265. /*
  266. // FUNCTION: error($message);
  267. // Displays an error box with the inputted text
  268. */
  269. function error($message) {
  270. global $lang;
  271. $output["error"] = '<div class="ui-widget">
  272. <div class="ui-state-highlight ui-corner-all searchError">
  273. <p><span class="ui-icon ui-icon-alert"></span>
  274. <strong>' . $lang["messages"]["error"] . '</strong> ' . $message . '</p>
  275. </div>
  276. </div>';
  277. echo json_encode($output);
  278. }
  279.  
  280. ?>
Advertisement
Add Comment
Please, Sign In to add comment