Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class main {
- public $connection;
- /**
- * Opens a connection to the DB
- */
- public function __construct() {
- $this->connection = mysql_connect(localhost, trama_vote, hudecki123) or die(mysql_connect_error());
- mysql_select_db(trama_vote,$this->connection);
- //echo("Connected");
- }
- /**
- * Clsoes the connection to the DB
- */
- public function __destruct() {
- mysql_close($this->connection);
- }
- /**
- *
- * @return time user voted if note it returns -1
- */
- public function hasVoted() {
- $ip = gethostbyname($_SERVER['REMOTE_ADDR']);
- $query = "SELECT UNIX_TIMESTAMP(time) as time FROM `votes` WHERE UNIX_TIMESTAMP(NOW()) < UNIX_TIMESTAMP(time)+86000 AND `ip` LIKE '$ip'";
- $result = mysql_query($query);
- if (mysql_num_rows($result) > 0) {
- $result = mysql_fetch_assoc($result);
- return $result["time"];
- } else {
- return -1;
- }
- }
- /**
- * checks if runetoplist has calledback saying the user has voted
- * @returns true if the user can continue
- * @returns false if the user hasnt voted
- */
- public function canFindTempId($callback_id) {
- $callback_id = mysql_real_escape_string($callback_id);
- $query = mysql_query("SELECT null FROM `verifying_votes` WHERE callbackid='".$callback_id."'");
- if (mysql_num_rows($query) > 0) {
- return true;
- } else {
- return false;
- }
- }
- /**
- *
- * @return type true if ports 80, 8080 or 3128 are open
- */
- public function isCheating() {
- if(@fsockopen($_SERVER['REMOTE_ADDR'], 80, $errno, $errstr, 1) ||
- @fsockopen($_SERVER['REMOTE_ADDR'], 8080, $errno, $errstr, 1) ||
- @fsockopen($_SERVER['REMOTE_ADDR'], 3128, $errno, $errstr, 1)) {
- return true;
- } else {
- return false;
- }
- }
- /**
- * gets the top 10 people who have voted the most
- * @returns a stack of data
- */
- public function getTop10Voters() {
- $query = mysql_query("SELECT `username` , COUNT( `username` ) AS times FROM `items` GROUP BY `username` LIMIT 10");
- if (mysql_num_rows($query) > 0) {
- $stack = array();
- while ($result = mysql_fetch_assoc($query)){
- array_push($stack, $result["username"], $result["times"]);
- }
- return $stack;
- } else {
- return null;
- }
- }
- /**
- * gets the amount of votes inbetween two time sets
- * @returns the amount of votes
- * @param1 start of the time set (unix time)
- * @param2 end of time set (unix time)
- */
- public function getTotalVotes($start, $end) {
- $start = mysql_real_escape_string($start);
- $end = mysql_real_escape_string($end);
- $query = mysql_query("SELECT COUNT(*) AS votes FROM `votes` WHERE UNIX_TIMESTAMP(time) >=$start AND UNIX_TIMESTAMP(time) < $end");
- $result = mysql_fetch_assoc($query);
- return $result['votes'];
- }
- /**
- * gets the most popular vote rewards
- * @returns stack of data
- */
- public function getPopularRewards() {
- $query = mysql_query("SELECT `item_id` , COUNT( `item_id` ) AS times FROM `items` GROUP BY `item_id`");
- $stack = array();
- while ($result = mysql_fetch_assoc($query)){
- array_push($stack, $result["item_id"], $result["times"]);
- }
- return $stack;
- }
- /**
- * deletes the temp id called back from RuneTopList
- * @returns amount of rows effected
- */
- public function deleteTempID($callback_id) {
- $callback_id = mysql_real_escape_string($callback_id);
- $query = mysql_query("DELETE FROM `verifying_votes` WHERE callbackid='".$callback_id."'");
- return mysql_affected_rows();
- }
- /**
- * adds the temp id to the database
- * @returns amount of rows effected
- */
- public function addTempID($callback_id) {
- $callback_id = mysql_real_escape_string($callback_id);
- $query = mysql_query("INSERT INTO `verifying_votes` (callbackid) VALUES ('$callback_id')");
- return true;
- }
- /**
- * adds item to the datebase to be checked/claimed/rewarded
- * @returns success
- */
- public function addReward($reward, $username, $voterewards) {
- $reward = $this->getItemId(mysql_real_escape_string($reward), $voterewards);
- $username = mysql_real_escape_string($username);
- $amount = $this->getAmount($reward, $voterewards);
- $ip = gethostbyname($_SERVER['REMOTE_ADDR']);
- mysql_query("INSERT INTO `items` (`username`, `item_id`, `item_amount`) VALUES ('$username', '$reward', '$amount');");
- mysql_query("INSERT INTO `votes` (`ip`) VALUES ('$ip');");
- return true;
- }
- public function getAmount($RewardId, $voterewards){
- for ($i = 0; $i < count($voterewards)/5; $i++) {
- if ($voterewards[($i*5+2)] == $RewardId) {
- return $voterewards[($i*5)+3];
- }
- }
- return 'item not found in array';
- }
- public function getItemId($RewardId, $voterewards){
- for ($i = 0; $i < count($voterewards)/5; $i++) {
- if ($voterewards[($i*5)] == $RewardId) {
- return $voterewards[($i*5)+2];
- }
- }
- return 'item not found in array';
- }
- function createRandomChars($length) {
- $chars = "abcdefghijkmnopqrstuvwxyz023456789";
- srand((double)microtime()*1000000);
- $i = 0;
- $pass = '' ;
- while ($i < $length) {
- $num = rand() % 33;
- $tmp = substr($chars, $num, 1);
- $pass = $pass . $tmp;
- $i++;
- }
- return $pass;
- }
- }
- ?>
Add Comment
Please, Sign In to add comment