This repository was archived by the owner on May 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubmitScore.php
56 lines (44 loc) · 1.46 KB
/
submitScore.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
$file = 'AllScores.txt';
if(isset($_POST['data'])){
$data = $_POST['data'];
$data=strtr($data,'abcdefghijklmspntr#%$^&*!)(4679851@+SMLVAo2','2oAVLSM+@1589764()!*&^$%#rtnpsmlkjihgfedcba');
$data=base64_decode($data);
$data .= "|";
file_put_contents($file, $data, FILE_APPEND);
}
$data = file_get_contents($file);
$line = explode("|", $data);
for($i = 0;$i < (count($line)-1); $i++){
$ArrayLine = explode(";", $line[$i]);
$ArrayData[$i] = array('Player' => $ArrayLine[0], 'Score' => $ArrayLine[1]);
}
//Sort Scores
sort_array_of_array($ArrayData, 'Score');
//clean file
$fp = fopen($file, "r+");
ftruncate($fp, 0);
fclose($fp);
$data = null;
//put the sorted list back in the file and echo it out
echo '<div id="info"><h2><center>Scoreboard</center></h2><hr><table>';
echo '<tr><th class="user">Users</th><th>Scores</th></tr>';
$lenghtArray = (count($ArrayData) > 50 ? 50 : count($ArrayData));
for($i = 0;$i < $lenghtArray; $i++){
$data .= $ArrayData[$i]['Player'] . ";" . $ArrayData[$i]['Score'] . "|";
if($i < 10){
echo '<tr><td class="user">' . $ArrayData[$i]['Player'] . '</td><td>' . $ArrayData[$i]['Score'] . '</td></tr>';
}
}
echo '</table></div>';
file_put_contents($file, $data, FILE_APPEND);
function sort_array_of_array(&$array, $subfield)
{
$sortarray = array();
foreach ($array as $key => $row)
{
$sortarray[$key] = $row[$subfield];
}
array_multisort($sortarray, SORT_DESC, $array);
}
?>