|
Re: Online Jewel Drop + Highscore + GSTNet
[Re: ambe]
#310273
02/14/10 02:13
02/14/10 02:13
|
Joined: Feb 2009
Posts: 2,154
Damocles_
OP
Expert
|
OP
Expert
Joined: Feb 2009
Posts: 2,154
|
yes, ambe I can see you played quite a number of games maybe I should Refresh the highscore, so there is some challenge to get into that list ---- Ok, fresh highscore list. And for the old Score Holders: Here The All-Time best players list: Chris!!!!! 21550 Chris 20310 Chris 19410 EnterYourName 18980 plsbeatmes 18290 Niceflits!e 17840 flits 17630 MichaelS 17370 test_1 16300 test_1 16160
Last edited by Damocles_; 02/14/10 02:20.
|
|
|
Re: Online Jewel Drop + Highscore + GSTNet
[Re: Damocles_]
#310529
02/15/10 09:39
02/15/10 09:39
|
Joined: Feb 2009
Posts: 2,154
Damocles_
OP
Expert
|
OP
Expert
Joined: Feb 2009
Posts: 2,154
|
Here the php codes used for this, if anyone wants to use such a system for php based actions. (Highscores, or even stuff like sendign messages or players using the game currently)
<?php
//Higschore script
//parameterline: http://damocles11.byethost9.com/index2.php?name=hubert&score=12346
$name = $_GET['name'];
$score = $_GET['score']+0; //+0 makes shure it will be an number
$check = $_GET['check']+0; //checknumber
if(strcmp($name,"")==0) {$name="Player";}
if(strlen($name)>16) {$name="Player";} //shorten too long names
$name=trim($name); //remove spaces
$name=strip_tags($name); //remove tags
$name=str_replace("~","-",$name); //remove tilde
//check if score is valid
//this should be implemented with a new algorythm by the programmer
//echo "score:" . $score . " check:" . $score%77 . "<br>";
if($check != $score%77) {$score=0;die("error!");} //throw out wrong scores!
/*
echo "Player: ";
echo $name;
echo "<br>has a score of: ";
echo $score;
echo "<br>----------------<br>";
*/
$filename="scores.txt";
$maxentries=10; //maximum number of highscore entries
//check if Highscore file exists
if(file_exists($filename)==0)
{
//create new Highscore
//add new entry
$handle = fopen ($filename, 'w+');
rewind($handle);
for($i=0;$i<$maxentries;$i++)
{
fputs($handle,"Player");
fputs($handle,'~');
fputs($handle,$maxentries+1-$i); //generate dummyscores
fputs($handle,'~');
}
fclose($handle); //close file
}
//read contents
//compare if new Highscore is higher than one of the previous 10
$handle = fopen ($filename, 'r');
rewind($handle);
$content=fgets($handle,filesize($filename)); //read the entries
$elemente=explode('~',$content);
$j=0;
//retrive entries
for($i=0; $i<$maxentries*2;$i+=2) //read max 10 entries
{
$playerName[$j]=$elemente[$i];
$playerScore[$j]=$elemente[$i+1];
$j++;
}
//echo $content;
fclose($handle); //close file
//check if player is part of the highscore
$newEntry=0;
for($i=0; $i<$maxentries;$i++) //read max 10 entries
{
if($score>$playerScore[$i])
{
//push down lower entries
for($j=$maxentries-1; $j>=$i;$j--) //read max 10 entries
{
$playerName[$j+1]=$playerName[$j];
$playerScore[$j+1]=$playerScore[$j];
}
// save entry
$playerName[$i]=$name;
$playerScore[$i]=$score;
$newEntry=1;
//$i=100; //just for savety
break; //jump out of loop
}
}
//if($newEntry==1) {echo "better entry! <br>";}
//save the changed file
if($newEntry==1)
{
//overwrite old file
$handle = fopen ($filename, 'w+');
rewind($handle);
for($i=0;$i<$maxentries;$i++)
{
fputs($handle,$playerName[$i]);
fputs($handle,'~');
fputs($handle,$playerScore[$i]);
fputs($handle,'~');
}
//echo "$filename does not exist";
fclose($handle); //close file
}
//now show all entries
$handle2 = fopen ($filename, 'r');
rewind($handle2);
/*
$content2=fgets($handle2,filesize($filename)+1); //read the entries
$elemente2=explode('~',$content2);
//retrive entries
for($i=0; $i<$maxentries*2;$i+=2) //read max 10 entries
{
echo $elemente2[$i] . "~" . $elemente2[$i+1] ."~";
}
*/
echo fread($handle2,filesize($filename));
//echo $content;
fclose($handle2); //close file
?>
<?php
//Higschore script
//alternate script, showing the recent players
//parameterline: http://damocles11.byethost9.com/index2.php?name=hubert&score=12346
$name = $_GET['name'];
$score = $_GET['score']+0; //+0 makes shure it will be an number
$check = $_GET['check']+0; //checknumber
if(strcmp($name,"")==0) {$name="Player";}
if(strlen($name)>16) {$name="Player";} //shorten too long names
$name=trim($name); //remove spaces
$name=strip_tags($name); //remove tags
$name=str_replace("~","-",$name); //remove tilde
//check if score is valid
//this should be implemented with a new algorythm by the programmer
//And of course not lie in an open sktipt...
//echo "score:" . $score . " check:" . $score%77 . "<br>";
if($check != $score%77) {$score=0;die("error!");} //throw out wrong scores!
/*
echo "Player: ";
echo $name;
echo "<br>has a score of: ";
echo $score;
echo "<br>----------------<br>";
*/
$filename="recent.txt";
$maxentries=10; //maximum number of highscore entries
//check if Highscore file exists
if(file_exists($filename)==0)
{
//create new Highscore
//add new entry
$handle = fopen ($filename, 'w+');
rewind($handle);
for($i=0;$i<$maxentries;$i++)
{
fputs($handle,"Player");
fputs($handle,'~');
fputs($handle,0); //generate dummyscores
fputs($handle,'~');
}
fclose($handle); //close file
}
//read contents
//compare if new Highscore is higher than one of the previous 10
$handle = fopen ($filename, 'r');
rewind($handle);
$content=fgets($handle,filesize($filename)); //read the entries
$elemente=explode('~',$content);
$j=0;
//retrive entries
for($i=0; $i<$maxentries*2;$i+=2) //read max 10 entries
{
$playerName[$j]=$elemente[$i];
$playerScore[$j]=$elemente[$i+1];
$j++;
}
//echo $content;
fclose($handle); //close file
//save the changed file
if($score>0)
{
//overwrite old file
$handle = fopen ($filename, 'w+');
rewind($handle);
//add new player on top
fputs($handle,$name);
fputs($handle,'~');
fputs($handle,$score);
fputs($handle,'~');
//insert previous games (one less)
for($i=0;$i<$maxentries-1;$i++)
{
fputs($handle,$playerName[$i]);
fputs($handle,'~');
fputs($handle,$playerScore[$i]);
fputs($handle,'~');
}
//echo "$filename does not exist";
fclose($handle); //close file
}
//now show all entries
$handle2 = fopen ($filename, 'r');
rewind($handle2);
/*
$content2=fgets($handle2,filesize($filename)+1); //read the entries
$elemente2=explode('~',$content2);
//retrive entries
for($i=0; $i<$maxentries*2;$i+=2) //read max 10 entries
{
echo $elemente2[$i] . "~" . $elemente2[$i+1] ."~";
}
*/
echo fread($handle2,filesize($filename));
//echo $content;
fclose($handle2); //close file
?>
|
|
|
|