| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Desktop Mode — Games Heartbeat sync (PHP). | |
| 3 | + * OpenStation — Games Heartbeat sync (PHP). | |
| 4 | 4 | * |
| 5 | 5 | * Piggybacks on the WordPress Heartbeat tick — the same channel |
| 6 | 6 | * presence and folder sharing use — to deliver challenge activity |
| 7 | 7 | * to connected users live: a new pending challenge for the |
| @@ -9,9 +9,9 @@ | ||
| 9 | 9 | * |
| 10 | 10 | * Wire format. Client sends: |
| 11 | 11 | * |
| 12 | 12 | * { |
| 13 | - * desktop_mode_games_subscribe: { | |
| 13 | + * openstation_games_subscribe: { | |
| 14 | 14 | * challengesVersion: lastSeenUpdatedAtMs |
| 15 | 15 | * } |
| 16 | 16 | * } |
| 17 | 17 | * |
| @@ -16,9 +16,9 @@ | ||
| 16 | 16 | * } |
| 17 | 17 | * |
| 18 | 18 | * Server responds: |
| 19 | 19 | * |
| 20 | - * desktop_mode_games: { | |
| 20 | + * openstation_games: { | |
| 21 | 21 | * challenges: [ <ChallengeShape> ], // rows involving me, |
| 22 | 22 | * // updated_at_ms > version |
| 23 | 23 | * serverTimeMs: int, |
| 24 | 24 | * truncated: bool |
| @@ -24,12 +24,12 @@ | ||
| 24 | 24 | * truncated: bool |
| 25 | 25 | * } |
| 26 | 26 | * |
| 27 | 27 | * Version-gated: a quiet tick carries no rows. Truncation kicks in |
| 28 | - * past `desktop_mode_games_heartbeat_max_rows` (default 50) — the | |
| 28 | + * past `openstation_games_heartbeat_max_rows` (default 50) — the | |
| 29 | 29 | * client falls back to `GET /games/challenges` for a full resync. |
| 30 | 30 | * |
| 31 | - * @package WPDesktopMode | |
| 31 | + * @package OpenStation | |
| 32 | 32 | */ |
| 33 | 33 | |
| 34 | 34 | defined( 'ABSPATH' ) || exit; |
| 35 | 35 | |
| @@ -37,16 +37,16 @@ | ||
| 37 | 37 | * @param array $response Pre-filtered response. |
| 38 | 38 | * @param array $data Client-sent payload. |
| 39 | 39 | * @return array |
| 40 | 40 | */ |
| 41 | -function desktop_mode_games_heartbeat_received( $response, $data ) { | |
| 41 | +function openstation_games_heartbeat_received( $response, $data ) { | |
| 42 | 42 | if ( ! is_array( $response ) ) { |
| 43 | 43 | $response = array(); |
| 44 | 44 | } |
| 45 | - if ( empty( $data['desktop_mode_games_subscribe'] ) || ! is_array( $data['desktop_mode_games_subscribe'] ) ) { | |
| 45 | + if ( empty( $data['openstation_games_subscribe'] ) || ! is_array( $data['openstation_games_subscribe'] ) ) { | |
| 46 | 46 | return $response; |
| 47 | 47 | } |
| 48 | - if ( ! function_exists( 'desktop_mode_is_enabled' ) || ! desktop_mode_is_enabled() ) { | |
| 48 | + if ( ! function_exists( 'openstation_is_enabled' ) || ! openstation_is_enabled() ) { | |
| 49 | 49 | return $response; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | $user_id = (int) get_current_user_id(); |
| @@ -53,9 +53,9 @@ | ||
| 53 | 53 | if ( $user_id <= 0 ) { |
| 54 | 54 | return $response; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - $sub = $data['desktop_mode_games_subscribe']; | |
| 57 | + $sub = $data['openstation_games_subscribe']; | |
| 58 | 58 | $version = isset( $sub['challengesVersion'] ) ? (int) $sub['challengesVersion'] : 0; |
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | 61 | * Filter the per-tick challenge row cap. Past the cap the |
| @@ -63,20 +63,20 @@ | ||
| 63 | 63 | * REST. |
| 64 | 64 | * |
| 65 | 65 | * @param int $cap Default 50. |
| 66 | 66 | */ |
| 67 | - $cap = max( 1, (int) apply_filters( 'desktop_mode_games_heartbeat_max_rows', 50 ) ); | |
| 67 | + $cap = max( 1, (int) apply_filters( 'openstation_games_heartbeat_max_rows', 50 ) ); | |
| 68 | 68 | |
| 69 | - $rows = desktop_mode_games_get_challenges_for_user( $user_id, $version, $cap + 1 ); | |
| 69 | + $rows = openstation_games_get_challenges_for_user( $user_id, $version, $cap + 1 ); | |
| 70 | 70 | $truncated = count( $rows ) > $cap; |
| 71 | 71 | if ( $truncated ) { |
| 72 | 72 | $rows = array_slice( $rows, 0, $cap ); |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - $response['desktop_mode_games'] = array( | |
| 76 | - 'challenges' => array_map( 'desktop_mode_games_shape_challenge', $rows ), | |
| 77 | - 'serverTimeMs' => desktop_mode_games_now_ms(), | |
| 75 | + $response['openstation_games'] = array( | |
| 76 | + 'challenges' => array_map( 'openstation_games_shape_challenge', $rows ), | |
| 77 | + 'serverTimeMs' => openstation_games_now_ms(), | |
| 78 | 78 | 'truncated' => $truncated, |
| 79 | 79 | ); |
| 80 | 80 | return $response; |
| 81 | 81 | } |
| 82 | -add_filter( 'heartbeat_received', 'desktop_mode_games_heartbeat_received', 5, 2 ); | |
| 82 | +add_filter( 'heartbeat_received', 'openstation_games_heartbeat_received', 5, 2 ); | |