Thread: [PI]Complete vote shop, vote points, and vote for vote points.

Page 1 of 3 123 LastLast
Results 1 to 10 of 25
  1. #1 [PI]Complete vote shop, vote points, and vote for vote points. 
    Cometarum - Round 3, RSPS.
    Comets's Avatar
    Join Date
    Jan 2011
    Posts
    278
    Thanks
    64
    Thanked 30 Times in 19 Posts
    Rep Power
    0
    This will be my first ever legit tutorial, so correct me if I'm wrong. ^.^

    This tutorial will spoon feed you on how to, add a working vote shop (accepting Vote Points), Vote Points to a character, and a complete vote4cash with ::claim giving your vote points.

    Rate/ hate, I don't care.

    Credits : 99.9% to me, i'm sure someone else came in with that .1%.


    Purpose: Complete vote shop, vote points, and vote for vote points.
    Difficulty: As hard as you make it. (Spoon fed)
    Assumed Knowledge: How to open files, Copy & Paste.
    Classes Modified: Client.java, commands.java, playersave.java, shopassistant.java.
    Tested On(if it applies): PI

    I'm not going to fill your heads will alot of useless stuff, so here goes nothing.

    Go to Playersave.java (server.model.players)

    Add
    Code:
                      	} else if (token.equals("votingPoints")) {
    						p.votingPoints = Integer.parseInt(token2);
    under
    Code:
    					} else if (token.equals("fightMode")) {
    						p.fightMode = Integer.parseInt(token2);
    Still in Playersave.java;
    Add
    Code:
    			characterfile.write("votingPoints = ", 0, 15);
    			characterfile.write(Integer.toString(p.votingPoints), 0, Integer.toString(p.votingPoints).length());
    			characterfile.newLine();
    Under
    Code:
    			characterfile.write("fightMode = ", 0, 12);
    			characterfile.write(Integer.toString(p.fightMode), 0, Integer.toString(p.fightMode).length());
    			characterfile.newLine();
    Now your players, will have vote points. Moving onto the vote Point shop.

    Open ShopAssistant.java

    Add
    Code:
    if (c.myShopId == 7) {
    			c.sendMessage(c.getItems().getItemName(removeId)+": currently costs "+ gvp(removeId) + " voting points.");
    		}
    Under
    Code:
    String ShopAdd = "";
    Add
    Code:
    public int gvp(int i)
    		{
    			switch(i)
    			{
    under the boolean
    Code:
    	public boolean buyItem
    Ok. At this point, you have barely anything with the shop. Just the return of the item being purchased, so now

    add
    Code:
    case 962: return 250;
    			}
    			return 0;
    		}
    under
    Code:
    public int gvp(int i)
    		{
    			switch(i)
    			{
    Ok. To clarify the numbers, you've just input. The case will be the item in the shop. So, 962 will be christmas crackers, and the return is the price of the item, so 250 vote points. Add as many as you'd like to, just be sure to add the return.


    Moving on.

    Under
    Code:
    public void handleOtherShop(int itemID) {

    Add
    Code:
    			if (c.myShopId == 7) {
    				if (c.votingPoints >= gvp(itemID)) {
    					if (c.getItems().freeSlots() > 0){
    						c.votingPoints -= gvp(itemID);
    						c.getItems().addItem(itemID,1);
    						c.getItems().resetItems(3823);
    						return;
    					}
    				} else {
    					c.sendMessage("You dont have enough voting points to buy this item!");
    					return;
    				}
    			}

    Replace your shop ID, to whatever your vote shop is.

    Ok. Now that the shop's done, time to add a vote4votepoints.


    Open client.java, (server.model.players)

    add
    Code:
    	    public boolean checkVotes(String playerName) {
                    try {
                            String urlString = ""+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;
            }
    Remember to fill in the URL slot, to your URL.

    Directly above
    Code:
    public void initialize() {

    Last but not least, move to your commands.java . (server.model.players.packets)

    Add
    Code:
    			if (playerCommand.equalsIgnoreCase("claim")) {
                            if(c.checkVotes(c.playerName)) {
                                    c.getItems().addItem(995, 15000000);
    				c.votingPoints += 3;
                                    c.sendMessage("Thanks for voting! You know have "+c.votingPoints+" Voting Points!");
                            }
    			}

    EDIT : FORGOT THIS PART.
    Make a mySQL database on your webhosting. Then, Go to your webhosting ftp client, and upload it. (Fill in the mysql information aswell.)

    Code:
    <?php
    
    /**
     * SQL database hostname
     */
    define("MYSQL_HOST", "localhost");
    /**
     *  SQL username to connect to the database server
     */
    define("MYSQL_USERNAME", "zuthura");
    /**
     *  SQL password the password to connect to the database server
     */
    define("MYSQL_PASSWORD", "static");
    /**
     *  SQL database the database name in which you have your vote table setup
     */
    define("MYSQL_DATABASE", "zuthura");
    /**
     *  vote url this is the url which where users will be sent to on voting
     */
    define("VOTE_URL", "http://www.mmorpgtoplist.com/in.php?site=36021");
    /**
     * The number of hours between voting
     */
    define("VOTE_HOURS", 12);
    
    
    /**
     *  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 please do not touch anything below if you do not know what you are doing...
     */
    if (isset($_POST['submit']) || isset($_GET['username']) && isset($_GET['type'])) {
        connect();
        if ($_POST['submit']) {
            if(@fsockopen($_SERVER['REMOTE_ADDR'], 80, $errno, $errstr, 1))
                die("Sorry but you have port 80 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 .".");
            }
        }
    }
    
    ?>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Vote for a reward!</title>
    </head>
    <body>
    <div align="center" style="color:#ff0000"><h2>Vote for Zuthura!</h3></div>
    <table align="center">
    
    <form action="vote.php" method="post">
      <tr>
        <td align="right">Username: </td>
        <td><input name="username" type="text" /></td>
      </tr>
      <tr>
      	<td>&nbsp;</td>
        <td align="center"><input type="submit" name="submit" value="Make your vote." /></td>
      </tr>
    
    </form>
    </table>
    </body>
    </html>
    Anywhere.
    You can, of course, modify the claim or 'vote' rewards.



    Post any errors, thanks, regrets, or complaints.


    Regards,
    Slid.
     

  2. Thankful users:


  3. #2  
    Registered Member
    Join Date
    Oct 2009
    Posts
    182
    Thanks
    1
    Thanked 5 Times in 5 Posts
    Rep Power
    6
    Nice
     

  4. #3  
    The Game, You just lost

    Sillhouette's Avatar
    Join Date
    Mar 2011
    Age
    18
    Posts
    1,653
    Thanks
    290
    Thanked 208 Times in 150 Posts
    Rep Power
    345
    Spoiler for Nice Job :):
    Quote Originally Posted by The Night Life View Post
    This will be my first ever legit tutorial, so correct me if I'm wrong. ^.^

    This tutorial will spoon feed you on how to, add a working vote shop (accepting Vote Points), Vote Points to a character, and a complete vote4cash with ::claim giving your vote points.

    Rate/ hate, I don't care.


    Purpose: Complete vote shop, vote points, and vote for vote points.
    Difficulty: As hard as you make it. (Spoon fed)
    Assumed Knowledge: How to open files, Copy & Paste.
    Classes Modified: Client.java, commands.java, playersave.java, shopassistant.java.
    Tested On(if it applies): PI

    I'm not going to fill your heads will alot of useless stuff, so here goes nothing.

    Go to Playersave.java (server.model.players)

    Add
    Code:
                      	} else if (token.equals("votingPoints")) {
    						p.votingPoints = Integer.parseInt(token2);
    under
    Code:
    					} else if (token.equals("fightMode")) {
    						p.fightMode = Integer.parseInt(token2);
    Still in Playersave.java;
    Add
    Code:
    			characterfile.write("votingPoints = ", 0, 15);
    			characterfile.write(Integer.toString(p.votingPoints), 0, Integer.toString(p.votingPoints).length());
    			characterfile.newLine();
    Under
    Code:
    			characterfile.write("fightMode = ", 0, 12);
    			characterfile.write(Integer.toString(p.fightMode), 0, Integer.toString(p.fightMode).length());
    			characterfile.newLine();
    Now your players, will have vote points. Moving onto the vote Point shop.

    Open ShopAssistant.java

    Add
    Code:
    if (c.myShopId == 7) {
    			c.sendMessage(c.getItems().getItemName(removeId)+": currently costs "+ gvp(removeId) + " voting points.");
    		}
    Under
    Code:
    String ShopAdd = "";
    Add
    Code:
    public int gvp(int i)
    		{
    			switch(i)
    			{
    under the boolean
    Code:
    	public boolean buyItem
    Ok. At this point, you have barely anything with the shop. Just the return of the item being purchased, so now

    add
    Code:
    case 962: return 250;
    			}
    			return 0;
    		}
    under
    Code:
    public int gvp(int i)
    		{
    			switch(i)
    			{
    Ok. To clarify the numbers, you've just input. The case will be the item in the shop. So, 962 will be christmas crackers, and the return is the price of the item, so 250 vote points. Add as many as you'd like to, just be sure to add the return.


    Moving on.

    Under
    Code:
    public void handleOtherShop(int itemID) {

    Add
    Code:
    			if (c.myShopId == 7) {
    				if (c.votingPoints >= gvp(itemID)) {
    					if (c.getItems().freeSlots() > 0){
    						c.votingPoints -= gvp(itemID);
    						c.getItems().addItem(itemID,1);
    						c.getItems().resetItems(3823);
    						return;
    					}
    				} else {
    					c.sendMessage("You dont have enough voting points to buy this item!");
    					return;
    				}
    			}

    Replace your shop ID, to whatever your vote shop is.

    Ok. Now that the shop's done, time to add a vote4votepoints.


    Open client.java, (server.model.players)

    add
    Code:
    	    public boolean checkVotes(String playerName) {
                    try {
                            String urlString = ""+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;
            }
    Remember to fill in the URL slot, to your URL.

    Directly above
    Code:
    public void initialize() {

    Last but not least, move to your commands.java . (server.model.players.packets)

    Add
    Code:
    			if (playerCommand.equalsIgnoreCase("claim")) {
                            if(c.checkVotes(c.playerName)) {
                                    c.getItems().addItem(995, 15000000);
    				c.votingPoints += 3;
                                    c.sendMessage("Thanks for voting! You know have "+c.votingPoints+" Voting Points!");
                            }
    			}
    Anywhere.
    You can, of course, modify the claim or 'vote' rewards.



    Post any errors, thanks, regrets, or complaints.


    Regards,
    Slid.


    Does this check if they voted? or if they did the command?

    How does it check if they voted, would be a better question.
    "Fashion savvy people probably look at my outfit the same way I look at a person who opens their laptop and has the ask toolbar installed." - Brett Druck






    Spoiler for Motivational Penguin:
     

  5. #4  
    Donator

    MetalGear's Avatar
    Join Date
    Sep 2008
    Posts
    782
    Thanks
    10
    Thanked 6 Times in 6 Posts
    Rep Power
    82
    Yeah, can't players just do 'Vote' then close the page.. ?
    New transport?
     

  6. #5  
    The Game, You just lost

    Sillhouette's Avatar
    Join Date
    Mar 2011
    Age
    18
    Posts
    1,653
    Thanks
    290
    Thanked 208 Times in 150 Posts
    Rep Power
    345
    Quote Originally Posted by Ironik View Post
    Yeah, can't players just do 'Vote' then close the page.. ?
    He has not ::vote command and I looked at the client sided code and it wants a website URL so I assume you are supposed to have a vote page to check if they voted and then it'll send it to the server, he doesn't explain how to do that part though
    "Fashion savvy people probably look at my outfit the same way I look at a person who opens their laptop and has the ask toolbar installed." - Brett Druck






    Spoiler for Motivational Penguin:
     

  7. #6  
    MainScape.
    Silverdice's Avatar
    Join Date
    Sep 2010
    Age
    16
    Posts
    779
    Thanks
    0
    Thanked 66 Times in 34 Posts
    Rep Power
    19
    Naice (:

    Selling the cheapest client services here.
     

  8. #7  
    Cometarum - Round 3, RSPS.
    Comets's Avatar
    Join Date
    Jan 2011
    Posts
    278
    Thanks
    64
    Thanked 30 Times in 19 Posts
    Rep Power
    0
    Ha. True regards, It seems i've left out a major role in the system. I assumed everyone had the php script to it, and you didn't. I will add it into the thread, explaining what to do.

    Again, sorry. This is not a complete tutorial.
     

  9. #8  
    Cometarum - Round 3, RSPS.
    Comets's Avatar
    Join Date
    Jan 2011
    Posts
    278
    Thanks
    64
    Thanked 30 Times in 19 Posts
    Rep Power
    0
    Quote Originally Posted by Ironik View Post
    Yeah, can't players just do 'Vote' then close the page.. ?
    No. The website sided page, reads the cookies, so you can set the paremeters for 12 hours, 6 hours, 24 hours, etc. This is completely cheat-proof.
     

  10. #9  
    ☻☻☻☻☻☻
    Jack Daniels's Avatar
    Join Date
    Oct 2010
    Posts
    891
    Thanks
    98
    Thanked 151 Times in 81 Posts
    Rep Power
    47
    checkVotes() shouldnt be dumped in the client class

    also according to OOP standards the variable votingpoints should be private and accessed using setters and getters
     

  11. #10  
    The Game, You just lost

    Sillhouette's Avatar
    Join Date
    Mar 2011
    Age
    18
    Posts
    1,653
    Thanks
    290
    Thanked 208 Times in 150 Posts
    Rep Power
    345
    Quote Originally Posted by The Night Life View Post
    Ha. True regards, It seems i've left out a major role in the system. I assumed everyone had the php script to it, and you didn't. I will add it into the thread, explaining what to do.

    Again, sorry. This is not a complete tutorial.
    Sounds awesome, thanks

    Let me know here when its updated
    "Fashion savvy people probably look at my outfit the same way I look at a person who opens their laptop and has the ask toolbar installed." - Brett Druck






    Spoiler for Motivational Penguin:
     


Page 1 of 3 123 LastLast
Thread Information
Users Browsing this Thread

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

Similar Threads

  1. [525]::vote open vote page.
    By oh hi broski in forum Help
    Replies: 6
    Last Post: 05-31-2011, 08:33 PM
  2. [pi]::vote command or vote for cash
    By jessie thompson in forum Help
    Replies: 0
    Last Post: 12-30-2010, 06:53 AM
  3. Replies: 4
    Last Post: 10-13-2009, 09:39 AM
  4. Replies: 1
    Last Post: 10-13-2009, 03:19 AM
  5. Whats the Best Band VOTE VOTE VOTE!
    By C.T in forum Voting
    Replies: 1
    Last Post: 12-02-2008, 10:30 PM
Tags for this Thread

View Tag Cloud

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •