1<?php
2/**
3 * TFS_02, TFS_03, TFS_10 and TFS_16 (TFS_16 already runs the TFS_10 schema,
4 * normalised in engine/init.php). TFS_03's salted password scheme is the one
5 * real behavioural difference among them.
6 */
7final class TFSAdapter implements ServerAdapterInterface
8{
9 public function __construct(private string $realEngine) {
10 }
11
12 public function key(): string {
13 return $this->realEngine;
14 }
15
16 public function login(string $username, string $password): int|false {
17 if ($this->realEngine === 'TFS_03') {
18 return user_login_03($username, $password);
19 }
20 return user_login($username, $password);
21 }
22
23 public function accountIdentityColumn(): string {
24 return 'name';
25 }
26
27 public function accountDisplayColumn(): string {
28 return '`a`.`name`';
29 }
30
31 public function supportsLegacyTwoFactor(): bool {
32 // accounts.secret and the QR-code flow in twofa.php only exist from TFS 1.2.
33 return $this->realEngine === 'TFS_10';
34 }
35
36 public function onlineCount(): int {
37 return $this->realEngine === 'TFS_10'
38 ? znote_sql_count("SELECT COUNT(*) AS `c` FROM `players_online`;")
39 : znote_sql_count("SELECT COUNT(*) AS `c` FROM `players` WHERE `online` > 0;");
40 }
41
42 public function normalizedEngine(): string {
43 // TFS_16 already runs the TFS_10 schema (normalised in engine/init.php).
44 return $this->realEngine === 'TFS_16' ? 'TFS_10' : $this->realEngine;
45 }
46}
47