forked from xxyz/BMS-Web-Clearlamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
beatoraja_driver.php
51 lines (48 loc) · 1.53 KB
/
beatoraja_driver.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
<?php
class BeatorajaDriver implements ScoreDriver
{
private $hash;
private $pdo;
public function __construct($hash)
{
$this->hash = $hash;
$this->pdo = new PDO('sqlite:' . 'dbs/' . $hash);
}
public function fetch_score(&$song)
{
$matched = $this->pdo->query('SELECT * FROM score WHERE sha256 == "' . $song->sha256 . '"', PDO::FETCH_ASSOC)->fetch(); // No need to prepare, we trust ourselves (I hope)
if($matched) {
$matched = (object)$matched;
$matched->score = ((int)($matched->epg) + (int)($matched->lpg)) * 2 + ((int)($matched->egr) + (int)($matched->lgr));
switch ($matched->clear) {
case 8:
$matched->clear = 5;
break;
case 7:
$matched->clear = 8;
break;
case 6:
case 5:
case 4:
$matched->clear -= 2;
break;
case 3:
$matched->clear = 7;
break;
case 2:
$matched->clear = 6;
default:
break;
}
}
return $matched;
}
public function get_playername()
{
return $this->hash; // Beatoraja DB doesn't include the player name...
}
public function get_playerstring($playername)
{
return "<h2 id='playername'>Player hash: " . $this->hash . " <i>(beatoraja DB)</i></h2>";
}
}