$line) { list($t, $s) = $line; if ($t > (time() + 7)) { continue; } if ($score == $s) { $allowed = true; continue; } $file_content .= sprintf('%s:%s', $t, $s).PHP_EOL; } file_put_contents($filename, $file_content); return $allowed; } function HT_Rate () { $rank = 1; $file = file( "highscore.txt" ); foreach ($file as $line) { if ($line !== "\n") { $entry = explode( "::", $line ); if ($entry[1] < $_POST['score']) { break; } $rank++; } if ($rank > 100) { break; } } if ($rank > 100) { printf("0"); return; } else { HT_RateAllow($_POST['score']); } printf( $rank ); } function HT_Insert() { if (!HT_InsertAllowed($_POST["score"])) { return; } $_POST['name'] = str_replace( ":", ".", $_POST['name'] ); $written = false; $rank = 1; $file = file( "highscore.txt" ); $out = fopen( "highscore.txt", "w" ); foreach ($file as $line) { if ('' === ($line = trim($line))) { } if ( ($line != "\n") && ($line != "") ) { $entry = explode( "::", $line ); if ( ($entry[1] < $_POST["score"]) && ($written === false) ) { fprintf( $out, "%s::%s::%s::%s::%s::%s::%s\n", $_POST['name'], $_POST['score'], $_POST['length'], $_POST['bananas'], $_POST['cherries'], $_POST['hemps'], $_POST['multi'] ); $written = true; $rank++; } if ($rank < 101) { fprintf( $out, "%s", $line ); echo( "$rank:$line
" ); $rank++; } else { break; } } } if ( ($written === false) && ($rank < 101) ) { // echo "Hallo"; fprintf( $out, "%s::%s::%s::%s::%s::%s::%s\n", $_POST['name'], $_POST['score'], $_POST['length'], $_POST['bananas'], $_POST['cherries'], $_POST['hemps'], $_POST['multi'] ); } fclose( $out ); } if (isset( $_POST['cmd'] )) { switch ($_POST["cmd"]){ case "HT_INSERT": HT_Insert(); break; case "HT_HOTD": HT_GetHotd(); break; case "HT_RATE": HT_Rate(); break; default: // echo "LIST"; foreach ($_POST as $name => $value) { echo "

".$name."= ".$value."

"; } break; } } else { $file = file( "highscore.txt" ); $rank = 1; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; foreach ($file as $line) { if ( ($line !== "\n") && ($line != "") ) { $entry = explode( "::", $line ); echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } } echo "
RankNameScoreLengthCherriesHemps
".$rank++."".htmlspecialchars($entry[0])."".htmlspecialchars($entry[1])."".htmlspecialchars($entry[2])."".htmlspecialchars($entry[3])."".htmlspecialchars($entry[5])."
"; } ?>