1<?php
2/**
3 * Server Adapter.
4 *
5 * Every place that used to branch on $config['ServerEngine'] directly is a
6 * place that has to be found and re-checked whenever a new engine shows up.
7 * This interface collects the differences that actually matter to the
8 * website - how an account logs in, how it is identified, whether the legacy
9 * in-game 2FA exists, how "online" is counted - behind one call:
10 * znote_server_adapter().
11 *
12 * This does not replace every scattered ServerEngine check in one pass - that
13 * would be the highest-risk change in the codebase, done all at once, with no
14 * way to review it in reviewable pieces. It gives new code, and code being
15 * touched anyway, somewhere better to live. login.php and the admin
16 * dashboard/analytics modules are wired to it as the first, carefully tested
17 * examples; the rest can move over one file at a time.
18 */
19
20/** COUNT(*) helper shared by the adapters - 0 for a table this engine does not have. */
21function znote_sql_count(string $sql, array $params = array()): int {
22 $row = db()->fetchOne($sql, $params);
23 return is_array($row) && $row ? (int)reset($row) : 0;
24}
25
26interface ServerAdapterInterface
27{
28 /** The ServerEngineReal value this adapter was built for. */
29 public function key(): string;
30
31 /**
32 * Authenticates a username/password pair against `accounts`.
33 * Returns the account id, or false.
34 */
35 public function login(string $username, string $password): int|false;
36
37 /** The `accounts` column identity is checked against - 'name' everywhere except otHire. */
38 public function accountIdentityColumn(): string;
39
40 /** SQL fragment for a human-readable account label in a query - `a`.`name` or `a`.`id`. */
41 public function accountDisplayColumn(): string;
42
43 /** Whether the legacy, engine-tied 2FA (accounts.secret, twofa.php) can work here. */
44 public function supportsLegacyTwoFactor(): bool;
45
46 /** How many characters are online right now. */
47 public function onlineCount(): int;
48
49 /**
50 * The engine value the rest of the codebase should dispatch on for schema
51 * differences: one of 'TFS_02', 'TFS_03', 'TFS_10' or 'OTHIRE'. Canary,
52 * TFS_16 and BlackTek all report 'TFS_10' here - they already run that
53 * schema, which is exactly what $config['ServerEngine'] was normalised to
54 * in engine/init.php. This is the single place that mapping lives now,
55 * instead of every file re-deriving it.
56 */
57 public function normalizedEngine(): string;
58}
59