Thread: [Pi] Vote4Cash Problem

Page 1 of 2 12 LastLast
Results 1 to 10 of 14
  1. #1 [Pi] Vote4Cash Problem 
    Banned

    Join Date
    Sep 2009
    Posts
    904
    Thanks given
    139
    Thanks received
    55
    Rep Power
    0
    When I vote and type my username. In


    it shows up here...


    AND

    It won't delete those/refresh after 24 hours. It stays there and I manually have to delete it, if I don't delete it, when people try to vote, it says you've already voted.



    Vote.php


    Code:
    <?php
    
    /* mysql database hostname
    */
    define("MYSQL_HOST", "localhost");
    /**
    * mysql username to connect to the database server
    */
    define("MYSQL_USERNAME", "harmank_vote");
    /**
    * mysql password the password to connect to the database server
    */
    define("MYSQL_PASSWORD", "harman");
    /**
    * mysql database the database name in which you have your vote table setup
    */
    define("MYSQL_DATABASE", "harmank_vote");
    /**
    * vote url this is the url which where users will be sent to on voting
    */
    define("VOTE_URL", "http://www.runelocus.com/toplist/index.php?action=vote&id=26645");
    /**
    * The number of hours between voting
    */
    define("VOTE_HOURS", 24);
    
    
    /**
    * connect() this function is used to connect to the mysql database server.
    */
    function connect()
    {
    if (!@mysql_connect(MYSQL_HOST, MYSQL_USERNAME, MYSQL_PASSWORD))
    die("Could not connect to mysql database: " . mysql_error());
    if (!@mysql_select_db(MYSQL_DATABASE))
    die("Could not select mysql database: " . mysql_error());
    $tables = @mysql_list_tables(MYSQL_DATABASE);
    while (list($temp) = mysql_fetch_array($tables)) {
    if ($temp == "votes") {
    return;
    }
    }
    query("CREATE TABLE `votes` (
    `playerName` VARCHAR( 255 ) NOT NULL ,
    `ip` VARCHAR( 255 ) NOT NULL,
    `time` BIGINT NOT NULL ,
    `recieved` INT( 1 ) NOT NULL DEFAULT '0')");
    }
    /**
    * query(string query) this function is used to query the mysql database server.
    */
    function query($s)
    {
    $query = @mysql_query($s);
    if (!$query)
    die("Error running query('" . $s . "'): " . mysql_error());
    return $query;
    }
    /**
    * anti_inject(string text) this function is used to make sure no injections can be made.
    */
    function anti_inject($sql)
    {
    @$sql = preg_replace(sql_regcase("/(from|select|insert|delete|where|drop table|show tables|#|\*|--|\\\\)/"),
    "", $sql);
    $sql = trim($sql);
    $sql = strip_tags($sql);
    $sql = addslashes($sql);
    $sql = strtolower($sql);
    return $sql;
    }
    /**
    * clean_request(int timestamp, string username) this function is used to delete any entries if they have already expired.
    */
    function clean_request($time, $username)
    {
    $query = query("SELECT * FROM `votes` WHERE `playerName`='" . $username . "'");
    if (mysql_num_rows($query) > 0) {
    $row = mysql_fetch_array($query);
    $timerequested = $row['time'];
    if ($time - $timerequested > VOTE_HOURS * 3600)
    query("DELETE FROM `votes` WHERE time='" . $timerequested . "'");
    }
    }
    /**
    * vote_entries(string ip) this function is used return the number of rows within the table
    */
    function vote_entries($ip)
    {
    $query = query("SELECT * FROM `votes` WHERE ip='" . $ip . "'");
    return mysql_num_rows($query);
    }
    
    
    /**
    * This is the actual working of the script, do not change anything below unless you're fully aware of what it is you're doing.
    */
    if (isset($_POST['submit']) || isset($_GET['username']) && isset($_GET['type'])) {
    connect();
    if (@$_POST['submit']) {
    if(@fsockopen($_SERVER['REMOTE_ADDR'], 85, $errno, $errstr, 1))
    die("Sorry but you have port 85 open, this is to stop voting by proxy address.");
    if(isset($_COOKIE['voted']))
    die("Sorry but it looks like you have already voted...");
    $username = anti_inject($_POST['username']);
    $ip = gethostbyaddr($_SERVER['REMOTE_ADDR']);
    clean_request(time(), $username);
    if (vote_entries($ip) == 0) {
    setcookie ("voted", "yes", VOTE_HOURS * 3600);
    query("INSERT INTO `votes` (`playerName`, `ip`, `time`) VALUES ('" . $username .
    "', '" . $ip . "', '" . time() . "')");
    header("Location: " . VOTE_URL . "");
    } else {
    die("You have already voted once today.");
    }
    } elseif ($_GET['type'] == "checkvote") {
    $username = anti_inject($_GET['username']);
    $query = query("SELECT * FROM `votes` WHERE `playerName`='" . $username . "'");
    if (mysql_num_rows($query) == 1) {
    $results = mysql_fetch_array($query);
    if ($results['recieved'] == 0) {
    query("UPDATE `votes` SET `recieved`='1' WHERE `playerName`='" . $username . "'");
    die("user needs reward...");
    } else {
    die("user been given reward...");
    }
    } else {
    die("Vote not found... ". $username .".");
    }
    }
    }
    
    ?>
    
    ?>

    Vote.class.php


    Code:
    <?php
    /*======================================================================*\
    || #################################################################### ||
    || # ---------------------------VOTE FOR ITEM------------------------ # ||
    || #                        Class by Joshua F                         # ||
    || #           Thanks to Snwspeckle(Anthony) and NoXIp(Justin)        # ||
    || #################################################################### ||
    \*======================================================================*/
    
    class Vote {
    	public $con;
    	private $VOTE_TIME;
    
    	/**
    	 * Connecting to the database and sets vote time
    	 */
    	function __construct($host, $dbuser, $dbpass, $db, $VOTE_TIME) {
    		$this->con = mysqli_connect($host, $dbuser, $dbpass, $db) or die(mysqli_error());
    		$this->VOTE_TIME = $VOTE_TIME;
    	}
    
    	/**
    	 * Checks if the user has port 80 open
    	 */
    	function checkProxy() {
    		if(@fsockopen($_SERVER['REMOTE_ADDR'], 80, $errno, $errstr, 1)) {
    			return true;
    		} else {
    			return false;
    		}
    	}
    
    	/**
    	 * Return the total times $ip is in the database
    	 */
    	function checkIP() {
    		$query = $this->con->query('SELECT * FROM `votes` WHERE `ip` = "' . gethostbyaddr($_SERVER['REMOTE_ADDR']) . '"');
    		return $query->num_rows;
    	}
    	
    	
    	/**
    	 * Cleans up the playerName so they can submit and vote again
    	 */
    	function clean_request($time, $username) {
    		$query = $this->con->query('SELECT * FROM `votes` WHERE `playerName` = "' . $this->con->real_escape_string($username) . '"');
    		if ($query->num_rows > 0) {
    			$result = $query->fetch_assoc();
    			if ($time - $result['time'] > $this->VOTE_TIME * 3600) {
    				$this->con->query('DELETE FROM `votes` WHERE `time` = "' . $result['time'] . '"');
    			}
    		}
    	}
    }
    ?>
    Reply With Quote  
     

  2. #2  
    Are you really awesome?
    Aaron's Avatar
    Join Date
    May 2011
    Age
    30
    Posts
    663
    Thanks given
    14
    Thanks received
    110
    Rep Power
    0
    First thing wrong section?
    Reply With Quote  
     

  3. #3  
    Banned

    Join Date
    Sep 2009
    Posts
    904
    Thanks given
    139
    Thanks received
    55
    Rep Power
    0
    Oh, crap!
    Reply With Quote  
     

  4. #4  
    Donator


    Join Date
    Mar 2011
    Posts
    574
    Thanks given
    2
    Thanks received
    64
    Rep Power
    235
    I don't know how the vote4cash thing works, never used it. But it'll only remove after 24 hours if someone visits the page where the (probably php) script is. If this is the way it'll remove the SQL queries...? Or does it via the server?


    Reply With Quote  
     

  5. #5  
    Are you really awesome?
    Aaron's Avatar
    Join Date
    May 2011
    Age
    30
    Posts
    663
    Thanks given
    14
    Thanks received
    110
    Rep Power
    0
    second if you showed the code would be more useful.
    Reply With Quote  
     

  6. #6  
    Banned

    Join Date
    Sep 2009
    Posts
    904
    Thanks given
    139
    Thanks received
    55
    Rep Power
    0
    Quote Originally Posted by Aaron View Post
    second if you showed the code would be more useful.


    Posted it.
    Reply With Quote  
     

  7. #7  
    Banned

    Join Date
    Sep 2009
    Posts
    904
    Thanks given
    139
    Thanks received
    55
    Rep Power
    0
    Quote Originally Posted by Can't Help View Post
    It removes the vote only if teh user claims it server sided. To add that in your votemanager.java(or wherever add this method):
    Code:
    public static void deleteVotes(Client c){
    		try {
    			query("DELETE FROM `vote` WHERE playerName = '"+c.playerName+"';");
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    And in the vote command add deletevotes(c);
    Mysqlmanager.java?
    Reply With Quote  
     

  8. #8  
    Banned

    Join Date
    Sep 2009
    Posts
    904
    Thanks given
    139
    Thanks received
    55
    Rep Power
    0
    Quote Originally Posted by Can't Help View Post
    If that is where you are connecting to the vote database yes.

    Hmm, I'm not sure.. all i got is..

    Client.java

    Code:
    			 public boolean checkVotes(String playerName) {
                    try {
                            String urlString = "http://www.stonedpkers.pcriot.com/vote.php?type=checkvote&username="+playerName;
                            urlString = urlString.replaceAll(" ", "%20");
                            URL url = new URL(urlString);
                            BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
                            String results = reader.readLine();
                            if(results.length() > 0) {
                                    if(results.equals("user needs reward..."))
                                            return true;
                                    else
                                            return false;
                            }
                    } catch (MalformedURLException e) {
                            System.out.println("Malformed URL Exception in checkVotes(String playerName)");
                    } catch (IOException e) {
                            System.out.println("IO Exception in checkVotes(String playerName)");
                    }
                    return false;
            }

    Commands.java


    Code:
    			if (playerCommand.startsWith("reward")) {
                                    if(c.checkVotes(c.playerName)) {
                                    c.getItems().addItem(995, 7000000);
    				c.getItems().addItem(989, 1);
                                    c.sendMessage("Thanks for voting.");
                                    } else {
                                    c.sendMessage("You have not yet voted, Go to www.stonedpkers.pcriot.com/ and click the VOTE button");
                                    }
                            }
    Nothing else related to voting.

    I'm not sure where to add that...
    Reply With Quote  
     

  9. #9  
    Banned

    Join Date
    Sep 2009
    Posts
    904
    Thanks given
    139
    Thanks received
    55
    Rep Power
    0
    Quote Originally Posted by Can't Help View Post
    Ok make a new class called vote in server.util:
    Code:
    package server.util;
    
    import java.sql.*;
    import server.model.players.Client;
    
    public class vote extends Thread {
    
    	public static Connection con = null;
    	public static Statement stm;
    
    	public static void createConnection() {
    		try {
    			Class.forName("com.mysql.jdbc.Driver").newInstance();
    			con = DriverManager.getConnection("jdbc:mysql://HOST/DB NAME", "DB USER", "DB USER PASS");
    			stm = con.createStatement();
    		} catch (Exception e) {
    			e.printStackTrace();
    			con = null;
    			stm = null;
    		}
    	}
    	
    	public vote(){
    		
    	}
    	
    	public void run() {
    		while(true) {		
    			try {
    				if(con == null)
    					createConnection(); 
    				else
    				Thread.sleep(10000);//10 seconds
    			} catch (Exception e) {
    				e.printStackTrace();
    			}
    		}
    	}
    	
    	
    	
    	public static void deletevote(final Client c,final String name){
    		if(con == null){
    			if(stm != null){
    				try {
    					stm = con.createStatement();
    				} catch(Exception e){
    					con = null;
    					stm = null;
    					return;
    				}
    			} else {
    				return;
    			}
    		}
    		new Thread(){
    			@Override
    			public void run()
    			{
    				try {
    					
    					query("DELETE FROM `vote` WHERE playerName = '"+c.playerName+"';");							c.sendMessage("You have received your donation set.");
    							c.sendMessage("Thank-you for voting!!");
    							c.SaveGame();
    							c.saveCharacter = true;
    					
    				} catch (Exception e) {
    					e.printStackTrace();
    					con = null;
    					stm = null;
    				}
    			}
    		}.start();
    	}
    	
    	public static ResultSet query(String s) throws SQLException {
    		try {
    			if (s.toLowerCase().startsWith("select")) {
    				ResultSet rs = stm.executeQuery(s);
    				return rs;
    			} else {
    				stm.executeUpdate(s);
    			}
    			return null;
    		} catch (Exception e) {
    			e.printStackTrace();
    			con = null;
    			stm = null;
    		}
    		return null;
    	}
    }
    And change vote commands to:

    Code:
    			if (playerCommand.startsWith("reward")) {
                                    if(c.checkVotes(c.playerName)) {
                                    c.getItems().addItem(995, 7000000);
    				c.getItems().addItem(989, 1);
                                    c.sendMessage("Thanks for voting.");
                                    vote.createConnection();
                                    vote.deleteVote(c, c.playerName);
                                    } else {
                                    c.sendMessage("You have not yet voted, Go to www.stonedpkers.pcriot.com/ and click the VOTE button");
                                    }
                            }
    and import server.util.vote (in commands.jaba)

    This will require remote mysql btw.

    Thanks,
    Saad
    My host does not allow remote mysql..
    Reply With Quote  
     

  10. #10  
    Registered Member
    Kobra's Avatar
    Join Date
    Dec 2009
    Posts
    652
    Thanks given
    215
    Thanks received
    84
    Rep Power
    88
    Quote Originally Posted by Harman View Post
    My host does not allow remote mysql..
    Get one if you want to continue with Mysql to your server.
    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. MYSQL Help Please Vote4cash Problem
    By jackd019 in forum Help
    Replies: 6
    Last Post: 06-05-2012, 12:07 AM
  2. PI vote4Cash Problem
    By LiilCraZy in forum Help
    Replies: 0
    Last Post: 12-10-2011, 12:00 AM
  3. PI fix , Vote4Cash Problem
    By jackd019 in forum Help
    Replies: 6
    Last Post: 11-25-2011, 03:25 AM
  4. vote4cash problem
    By Humbler in forum Help
    Replies: 15
    Last Post: 12-16-2010, 05:22 PM
  5. Vote4cash problem [REP]
    By The Situationist in forum Help
    Replies: 6
    Last Post: 11-25-2010, 03:54 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •