Merge branch 'fixes' into main/rendor-staging
[ryzomcore.git] / web / public_php / api / client / time.php
blob4b81db42aa3691a0f147a1011a27f65694f2d284
1 <?php
2 /* Copyright (C) 2009 Winch Gate Property Limited
4 * This file is part of ryzom_api.
5 * ryzom_api is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * ryzom_api is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with ryzom_api. If not, see <http://www.gnu.org/licenses/>.
19 $tick_cache_timeout = 60;
21 function ryzom_time_tick() {
22 $fn = RYAPI_URL.'data/cache/game_cycle.ticks';
23 $handle = fopen($fn, "r");
24 $version = fread($handle, 1);
25 $raw_tick = fread($handle, 4);
26 fclose($handle);
27 $arr = unpack("V", $raw_tick);
28 $tick = $arr[1];
29 return sprintf("%u", $tick & 0xffffffff);
33 /**
34 * Takes a computed ryzom time array and returns a SimpleXMLElement
36 function ryzom_time_xml($rytime) {
37 global $tick_cache_timeout;
38 $out = ryzom_time_xml_without_cache($rytime);
39 $filename = RYAPI_URL.'data/cache/game_cycle.ticks';
40 $cache = $out->addChild('cache');
41 $cache->addAttribute('created', filemtime($filename));
42 $cache->addAttribute('expire', (filemtime($filename)+$tick_cache_timeout));
43 return $out;