IPB

Welcome Guest ( Log In | Register )



6 Pages V   1 2 3 > »   
Reply to this topicStart new topic
Flux CP vote 4 points with validation
HarmonicRO
post Mar 17 2009, 07:13 AM
Post #1


eA NOOB.


Group: eA Level 1 (None)
Posts: 5
Joined: 16-March 09
Member No.: 283,746



Hey guys, I just wrote this script for for my RO server, and i have decided to share it with the rest.

This is mainly a proof-of-concept build, furthure editing is required for production use.
Hence knowledge of basic html/php/sql is required.

Vote 4 point addon for flux cp.

Version: v0.1

Feature:
-validate wheather the user have actually voted before giving out point.
(not 100% fool proof but much easier to just vote instead of cheating the system)
-12 hour per vote for each vote site.

Voting process:
1.Make sure cookie is enabled.
2.Click on link to vote.
3.Enter in any validation, and click vote on the top sites.
4.Complete the voting procoess by finding the your site's url and click to redirect back to your site.


Please read through the code/comments to understand how the code works, to make furthure modifications from there.


Instructions:

Step1: import these mysql tables into the same database as your flux cp.
CODE

CREATE TABLE IF NOT EXISTS `votepoints` (
`id` int(11) NOT NULL,
`account_id` int(11) NOT NULL,
`site` varchar(100) NOT NULL,
`lastvote` timestamp NOT NULL default CURRENT_TIMESTAMP,
`votestatus` int(11) NOT NULL default '0',
`votecount` int(11) NOT NULL default '0',
KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

CREATE TABLE IF NOT EXISTS `totalvotepoints` (
`id` int(11) NOT NULL auto_increment,
`account_id` int(11) NOT NULL,
`point` int(11) NOT NULL,
KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;


Step 2.In modules folder of your flux directory create folder vote and create the following files.

config.php
replace the placeholders with your vote site address
CODE

<?php

$vote_sites = array(
'Game Sites 200' => 'http://www.gamesites200.com/ragnarok/in.php?id=19458',
'RO Top 100' => 'http://www.rotop100.com/vote/5827/'
//add more vote sites here
);

?>


index.php
CODE
<?php

if (!defined('FLUX_ROOT')) exit;
$this->loginRequired();
$title = 'Vote 4 Points';
include("config.php");


?>


vote.php
CODE

<?php

if (!defined('FLUX_ROOT')) exit;
$this->loginRequired();
$title = 'Vote 4 Points';
include("config.php");


?>



vote2.php
replace all harmonicro.com with you sites domain.
CODE
<?php
if (!defined('FLUX_ROOT')) exit;
$this->loginRequired();

// simple security check
if(!$_SERVER['REQUEST_METHOD'] == "post" || !isset($_POST['site'])){
die("ERROR");
}
if(!eregi("www.harmonicro.com", $_SERVER['HTTP_REFERER'])){
die("ERROR");
}



if ( $session->isLoggedIn() ){
$account_id = $session->account->account_id;
}

// insert into database if user have never voted on the the top site
$qString = "insert into {$server->charMapDatabase}.votepoints (account_id, site, lastvote, votestatus) ";
$qString .= "select ?, ?, now(), 1 from dual where ";
$qString .= "not exists(";
$qString .= "select id from {$server->charMapDatabase}.votepoints ";
$qString .= "where account_id = ? and site like ?)";
$sth = $server->connection->getStatement($qString);
$sth->execute(array($account_id, $_POST['site'], $account_id, $_POST['site']));

// test wheather they have voted in the last 12 hours
if($sth->rowcount() == 0){
$qString = "select * from {$server->charMapDatabase}.votepoints where account_id = ? and site like ? and lastvote+ interval 12 hour < now()";
$sth = $server->connection->getStatement($qString);
$sth->execute(array($account_id, $_POST['site']));
$result = $sth->fetchAll();

// update current vote time, and votestatus flag
if(sizeof($result) > 0){
$qString = "update {$server->charMapDatabase}.votepoints set votestatus = 1 where site like ? and account_id = ? and lastvote = now()";
$sth = $server->connection->getStatement($qString);
$sth->execute(array($_POST['site'], $account_id));

// set cookie for vote return redirection
setcookie("voting", "true", time()+3600, '/');
setcookie("voteSite", $_POST['site'], time()+3600, '/');
}

}
else{
// set cookie for vote return redirection
setcookie("voting", "true", time()+3600, '/', '.harmonicro.com');
setcookie("voteSite", $_POST['site'], time()+3600, '/', '.harmonicro.com');
}

?>


vote3.php
again replace .harmonicro.com with your domain
CODE

<?php
if (!defined('FLUX_ROOT')) exit;
$this->loginRequired();
if ( $session->isLoggedIn() ){
$account_id = $session->account->account_id;
}
// check cookie exist from step 1 of voting
if(isset($_COOKIE['voting']) && !empty($_COOKIE['voting']) && $_COOKIE['voting'] == 'true'){
// check user have completed voting
$qString = "select id from {$server->charMapDatabase}.votepoints where votestatus = 1 and site like ? and account_id = ?";
$sth = $server->connection->getStatement($qString);
$sth->execute(array($_COOKIE['voteSite'], $account_id));
$result = $sth->fetchAll();
if(sizeof($result) > 0){
// update their vote count for the paticular vote site
$qString = "update {$server->charMapDatabase}.votepoints set votestatus = 0, votecount=votecount+1 where site like ? and account_id = ?";
$sth = $server->connection->getStatement($qString);
$sth->execute(array($_COOKIE['voteSite'], $account_id));
if($sth->rowcount() > 0){
// update their total accumulated points
$qString = "insert into {$server->charMapDatabase}.totalvotepoints (account_id, point) select ?, 1 from dual where not exists(select id from {$server->charMapDatabase}.totalvotepoints where account_id = ? )";

$sth = $server->connection->getStatement($qString);
$sth->execute(array($account_id, $account_id));
if($sth->rowcount() == 0){
$qString = "update {$server->charMapDatabase}.totalvotepoints set point = point+1 where account_id = ?";
$sth = $server->connection->getStatement($qString);
$sth->execute(array($account_id));
}
}
}
}
// get total points
$qString = "select * from totalvotepoints where account_id = ?";
$sth = $server->connection->getStatement($qString);
$sth->execute(array($account_id));
$result = $sth->fetchAll();

// delete vote flag cookie
setcookie("voting", "", time()-3600, '/', '.harmonicro.com');
setcookie("voteSite", "", time()-3600, '/', '.harmonicro.com');
?>


Step 3. In themes/default folder of your flux directory create folder vote create the following files.

index.php
CODE
<?php if (!defined('FLUX_ROOT')) exit; ?>
<?php
// displaying the top sites availiable
// probably a good idea to block off vote url if user have voted with in the last 12 hour (not implemented)
foreach($vote_sites as $site => $url){
echo "<a target='_blank' href='".$this->url."vote?site=".rawurlencode($site)."'>".$site."</a><br />";
}

?>


vote.php
replace www.harmonicro.com with your domain
CODE
<?php
if (!defined('FLUX_ROOT')) exit;
echo <<<EOT
<script>
$(document).ready(function() {


var oldHistLength = history.length;
var flag = false;


var checkHistory = function (){
if (oldHistLength != history.length && !flag){

oldHistLength = history.length;
flag = true;
$.post("http://www.harmonicro.com/cp/vote/vote2", { site: "$site"});
}
}
setInterval ( checkHistory, 1000 );
});

</script>
EOT;

echo "<iframe src='".$vote_sites[$site]."' width='100%' height='768'></iframe>";



?>


vote2.php
only a place holder, since flux requires a view model
CODE

<?php

if (!defined('FLUX_ROOT')) exit;
echo "<h1></h1>";

?>


vote3.php
CODE

<?php
if (!defined('FLUX_ROOT')) exit;
$this->loginRequired();
echo "Congratulations, you have earned 1 Vote point! You currently have ".$result[0]->point." point(s)!";
?>


Step 4. Place the following peice of code on the page where the top site redirects to (normally index.php/index.html).
Change harmonicro.com to your domain.
CODE

if(isset($_COOKIE['voting']) && !empty($_COOKIE['voting']) && $_COOKIE['voting'] == 'true'){

header("location:http://www.harmonicro.com/cp/vote/vote3");

}


Attached File  vote.rar ( 3.23K ) Number of downloads: 1078


This post has been edited by HarmonicRO: Mar 17 2009, 07:15 AM
Go to the top of the page
 
+Quote Post
ophiel
post Mar 18 2009, 06:09 PM
Post #2


eA Newbie
*

Group: eA Level 3 (Normal)
Posts: 24
Joined: 9-January 07
Member No.: 210,144



I only change your url for localhost

Missing Action!
Module: votevote?site=RO Top 100, Action: index

The action file corresponding to your request /flux/?module=votevote?site=RO%20Top%20100 was not found!

It should be in C:/xampi/htdocs/flux/modules/votevote?site=RO Top 100/index.php
Go to the top of the page
 
+Quote Post
aerolite
post Mar 20 2009, 04:39 PM
Post #3


poweroverwhelming
*****

Group: eA Level 5 (Super)
Posts: 566
Joined: 10-October 07
From: Canada de Laguna
Member No.: 246,601



this error apearing to mine.


QUOTE
Missing Action!
Module: vote, Action: view

Request URI: /Control%20Panel/?module=vote&action=view
File system location: /home/aerolite/public_html/Control Panel/modules/vote/view.php


is this working to you? help plx
Go to the top of the page
 
+Quote Post
HarmonicRO
post Mar 20 2009, 11:38 PM
Post #4


eA NOOB.


Group: eA Level 1 (None)
Posts: 5
Joined: 16-March 09
Member No.: 283,746



hmm i believe its becuase this is written for clean url on....i will post a solution in the next few days.
Go to the top of the page
 
+Quote Post
Mercurial
post Mar 20 2009, 11:52 PM
Post #5


UPDATE `char` SET char_id=1337 WHERE name="Mercurial"
Group Icon

Group: eAthena Donators
Posts: 1,050
Joined: 23-January 08
From: Ew ( Philippines Sucks )
Member No.: 254,346



hey I have a question.(I havent tested it yet dont get angry lol) so what happens if this player votes his main account and gets points, then log into another account to get an illegal point. does the check the IP has already vote for today? (IMG:http://www.eathena.ws/board/style_emoticons/default/tongue.gif) does the script prevent that from happening?

though I think it does with the cookies part.

but yea just wanna clarify it (IMG:http://www.eathena.ws/board/style_emoticons/default/smile.gif)

Anyway... Thank you very much for releasing it for free (IMG:http://www.eathena.ws/board/style_emoticons/default/smile.gif)

most voting scripts out there are for sale XD
Go to the top of the page
 
+Quote Post
HarmonicRO
post Mar 24 2009, 01:37 PM
Post #6


eA NOOB.


Group: eA Level 1 (None)
Posts: 5
Joined: 16-March 09
Member No.: 283,746



QUOTE (0Mercurial0 @ Mar 21 2009, 04:52 AM) *
hey I have a question.(I havent tested it yet dont get angry lol) so what happens if this player votes his main account and gets points, then log into another account to get an illegal point. does the check the IP has already vote for today? (IMG:http://www.eathena.ws/board/style_emoticons/default/tongue.gif) does the script prevent that from happening?

though I think it does with the cookies part.

but yea just wanna clarify it (IMG:http://www.eathena.ws/board/style_emoticons/default/smile.gif)

Anyway... Thank you very much for releasing it for free (IMG:http://www.eathena.ws/board/style_emoticons/default/smile.gif)

most voting scripts out there are for sale XD


Good point, cannot believe i have left that out....

But however, the code checks for change in iframe...if page does not change since they have voted in the past 12 hour it will not start the voting process..but i agree an ip check should be implemented.

The current script will only check based on account...so that means they will be able to vote again on their other account. I will implement ip check when i have sometime(final exams are coming up)....

Thanks.

This post has been edited by HarmonicRO: Mar 24 2009, 01:41 PM
Go to the top of the page
 
+Quote Post
EliteBlack
post Mar 27 2009, 05:48 PM
Post #7


EliteGroup
****

Group: eA Level 5 (Super)
Posts: 296
Joined: 6-February 09
From: Taguig Philippines
Member No.: 279,976



i got these error below. what should be the reason why im getting this?


CODE
Notice: Undefined variable: site in /home/kots22/public_html/themes/default/vote/vote.php on line 23

Notice: Undefined variable: site in /home/kots22/public_html/themes/default/vote/vote.php on line 26

Notice: Undefined index: in /home/kots22/public_html/themes/default/vote/vote.php on line 26
Go to the top of the page
 
+Quote Post
aerolite
post Mar 28 2009, 11:50 PM
Post #8


poweroverwhelming
*****

Group: eA Level 5 (Super)
Posts: 566
Joined: 10-October 07
From: Canada de Laguna
Member No.: 246,601



QUOTE
Missing Action!

Module: vote, Action: view

Request URI: /Control%20Panel/?module=vote&action=view

File system location: /home/qun/public_html/Control Panel/modules/vote/view.php


Thanks for sharing~

This post has been edited by aerolite: Mar 28 2009, 11:53 PM
Go to the top of the page
 
+Quote Post
Vengence
post Mar 29 2009, 12:47 PM
Post #9


Whats the meaning of eathena Developer :P
*****

Group: eA Level 5 (Super)
Posts: 547
Joined: 7-December 06
From: Freaksol
Member No.: 203,922



can i get this vote panel simply without implementing it to any control panel????
Go to the top of the page
 
+Quote Post
vanz201
post Mar 29 2009, 11:32 PM
Post #10


Leaning eA
**

Group: eA Level 3 (Normal)
Posts: 42
Joined: 25-June 07
From: Somewhere Out There.
Member No.: 234,092



QUOTE
But however, the code checks for change in iframe...if page does not change since they have voted in the past 12 hour it will not start the voting process..but i agree an ip check should be implemented.


I know this one's for free releases, but, when you want such flexibility and assurance, for this kind of voting system.
I suggest you spend 20$ for Byteflux's Vote4Credits / points addon. It can easily be configured, whether to check IP or not, it also checks if you really voted (ie: typed the confirmation code upon voting, or not)
A totally organized system, worth the price.

Flux Customization - By Byteflux

-A satisfied customer
Go to the top of the page
 
+Quote Post
ophiel
post Apr 27 2009, 12:18 PM
Post #11


eA Newbie
*

Group: eA Level 3 (Normal)
Posts: 24
Joined: 9-January 07
Member No.: 210,144



Notice: Undefined variable: vote_sites in /home/lxxxx/public_html/cp66/themes/default/vote/index.php on line 4

Warning: Invalid argument supplied for foreach() in /home/xxx/public_html/cp66/themes/default/vote/index.php on line 4

This post has been edited by ophiel: Apr 27 2009, 12:19 PM
Go to the top of the page
 
+Quote Post
Dant3
post May 2 2009, 12:09 PM
Post #12


eA Regular
*****

Group: eA Level 5 (Super)
Posts: 522
Joined: 28-December 06
From: Germany, NRW, Dsseldorf
Member No.: 207,855



Can someone fix this problems? -.-
Go to the top of the page
 
+Quote Post
fourxhackd
post May 3 2009, 04:15 AM
Post #13


Confused beyond all reason
****

Group: eA Level 5 (Super)
Posts: 361
Joined: 18-June 05
From: Philippines
Member No.: 115,101



Or, can someone explain how the script would work so at least I could try to make something similar?

HELP!

the $.post does not redirect me when the frame history changes! :(

From the research i did today, I learned that this uses a Javascript library called Jquery. It's a very useful and famous library that has connections with Ajax and other stuff.

I DL'd their .js and tested it out on a seperate file but the $.post does not request a different page! When i test it with variables, the variables change, but when it comes to the $.post part, it's like it ignores it!

What am I doing wrong? Is there no other way?

This post has been edited by fourxhackd: May 3 2009, 07:35 AM
Go to the top of the page
 
+Quote Post
HarmonicRO
post May 5 2009, 02:18 PM
Post #14


eA NOOB.


Group: eA Level 1 (None)
Posts: 5
Joined: 16-March 09
Member No.: 283,746



QUOTE (fourxhackd @ May 3 2009, 09:15 AM) *
Or, can someone explain how the script would work so at least I could try to make something similar?

HELP!

the $.post does not redirect me when the frame history changes! :(

From the research i did today, I learned that this uses a Javascript library called Jquery. It's a very useful and famous library that has connections with Ajax and other stuff.

I DL'd their .js and tested it out on a seperate file but the $.post does not request a different page! When i test it with variables, the variables change, but when it comes to the $.post part, it's like it ignores it!

What am I doing wrong? Is there no other way?


$.post is a ajax request so it does not redirect in anyway that can be seen.

I just finished all my exams, I will be working on this again in the next few days.
Go to the top of the page
 
+Quote Post
Dant3
post May 29 2009, 07:39 AM
Post #15


eA Regular
*****

Group: eA Level 5 (Super)
Posts: 522
Joined: 28-December 06
From: Germany, NRW, Dsseldorf
Member No.: 207,855



Whats about the update?
Go to the top of the page
 
+Quote Post

6 Pages V   1 2 3 > » 
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



Lo-Fi Version Time is now: 27th November 2014 - 03:26 PM
Bridged By IpbWiki: Integration Of Invision Power Board and MediaWiki © GlobalSoft