/** * Hent Facebook-cache */ protected function get_facebook_cache() { // har vi cache? $data = cache::fetch("facebook_posts"); if ($data) { return $data; } // authentiser $app_id = KOF_FB_APP_ID; $app_secret = KOF_FB_APP_SECRET; if (!$app_id || !$app_secret) { return null; } $ret = @file_get_contents("https://graph.facebook.com/oauth/access_token?client_id={$app_id}&client_secret={$app_secret}&grant_type=client_credentials"); if ($ret === false) { // kunne ikke hente data putlog("CREWCHAN", "Henting av Facebook-data feilet."); cache::store("facebook_posts", array()); } $info = null; parse_str($ret, $info); // hent JSON $json = @file_get_contents("https://graph.facebook.com/kofradia/posts?access_token={$info['access_token']}"); $data = json_decode($json, true); cache::store("facebook_posts", $data); return $data; }
/** * Get list of ranks * * @return array(\Kofradia\Game\Rank\Base, ..) */ public static function getRanks() { if (!static::$by_number) { // check cache first, then get from DB if ($cache = \cache::fetch("ranks-" . static::$type)) { static::$by_number = $cache; return $cache; } static::fetchRanks(); \cache::store("ranks-" . static::$type, static::$by_number); } return static::$by_number; }
/** * Hent, evt. generer, cache */ public static function cache_load($reload = false) { if (!$reload) { $data = cache::fetch("hall_of_fame"); if ($data) { self::$data = $data; return; } } $data = self::get_data_structure(); // hent fra databasen $result = \Kofradia\DB::get()->query("\n\t\t\tSELECT hof_id, hof_name, hof_sub, hof_time, hof_data\n\t\t\tFROM hall_of_fame"); while ($row = $result->fetch()) { $data[$row['hof_name']][$row['hof_sub'] ?: 0] = array($row['hof_time'], unserialize($row['hof_data'])); } cache::store("hall_of_fame", $data, 900); self::$data = $data; }
/** * Hent antall likes */ public static function get_likes_num() { $d = cache::fetch("facebook_likes"); if ($d !== false) { return $d; } $ttl = 900; // 15 min cache // hent data $json = @file_get_contents("https://graph.facebook.com/kofradia"); if (!$json) { cache::store("facebook_likes", "ukjent", $ttl); return "ukjent"; } $data = json_decode($json, true); cache::store("facebook_likes", $data['likes'], $ttl); return $data['likes']; }
/** Hent oppgaver */ private static function load($skip_cache = false) { // forsøk å hent fra cache if (!$skip_cache && !self::$cache) { self::$cache = cache::fetch("tasks"); } // hent fra databasen if ($skip_cache || !self::$cache) { global $_base; $result = \Kofradia\DB::get()->query("SELECT t_name, t_ant, t_last FROM tasks"); // les data self::$cache = array(); while ($row = $result->fetch()) { self::$cache[$row['t_name']] = $row; } // lagre til cache cache::store("tasks", self::$cache); } }
function fetch($name) { if (function_exists('\\apcu_fetch')) { return \apcu_fetch($name); } else { if (function_exists('\\apc_fetch')) { return \apc_fetch($name); } else { return parent::fetch($name); } } }
/** Sjekk for IP-ban */ private function check_ip_ban() { global $_base; // sjekk for IP-ban if ($_SERVER['REQUEST_METHOD'] == "CRON") { return; } // allerede sjekket og OK? if (cache::fetch("ip_ok_" . $_SERVER['REMOTE_ADDR'])) { return; } $ip = \Kofradia\DB::quote(to_float(ip2long($_SERVER['REMOTE_ADDR']))); $time = time(); $result = \Kofradia\DB::get()->query("SELECT bi_ip_start, bi_ip_end, bi_time_start, bi_time_end, bi_reason FROM ban_ip WHERE {$ip} BETWEEN bi_ip_start AND bi_ip_end AND IF(ISNULL(bi_time_end), {$time} >= bi_time_start, {$time} BETWEEN bi_time_start AND bi_time_end) ORDER BY bi_ip_end - bi_ip_start"); // fant ingen IP-ban oppføring if ($result->rowCount() == 0) { // sjekk om vi venter en kommende IP-ban $result = \Kofradia\DB::get()->query("SELECT bi_time_start FROM ban_ip WHERE {$ip} BETWEEN bi_ip_start AND bi_ip_end AND {$time} <= bi_time_start ORDER BY bi_time_start LIMIT 1"); if ($result->rowCount() > 0) { $next = $result->fetchColumn(0); // marker som ok for tiden før IP-ban starter cache::store("ip_ok_" . $_SERVER['REMOTE_ADDR'], true, $next - $time); return; } // marker som ok cache::store("ip_ok_" . $_SERVER['REMOTE_ADDR'], true); return; } // utestengt via IP // mer enn 1 uke vil vise som ubestemt tid // sett opp grunner $ban_end = 0; $reasons = array(); while ($row = $result->fetch()) { if ($ban_end !== false && empty($row['bi_time_end'])) { $ban_end = false; } elseif ($ban_end !== false && $row['bi_time_end'] > $ban_end) { $ban_end = $row['bi_time_end']; } // sett opp IP-adresse (range?) $ip = '<b>' . long2ip($row['bi_ip_start']); if ($row['bi_ip_start'] != $row['bi_ip_end']) { // range $ip .= ' - ' . long2ip($row['bi_ip_end']); } $ip .= '</b>'; // grunn oppgitt? if (empty($row['bi_reason'])) { // nei $reason = 'Grunn ikke oppgitt.'; } else { // ja $reason = game::bb_to_html($row['bi_reason']); } #$reasons[] = '<p>'.$ip.': '.$reason.'</p>'; $reasons[] = '<fieldset><legend>' . $ip . '</legend><p>' . $reason . '</p></fieldset>'; } // "jukse" til ubestemt tid? #if ($ban_end !== false && $ban_end > time()+604800) $ban_end = false; #$timeinfo = $ban_end === false ? '<p>Din IP-adresse er utestengt på ubestemt tid.</p>' : '<p>Din IP-adresse er utestengt til <b>'.$_base->date->get($ban_end)->format(date::FORMAT_SEC).'</b>.</p>'; putlog("ABUSE", "%c8%bIP-Blokk:%b%c %u{$_SERVER['REMOTE_ADDR']}%u - {$_SERVER['HTTP_USER_AGENT']}"); // send feilmelding etc header("HTTP/1.0 403 Forbidden"); echo '<!DOCTYPE html> <html lang="no"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="author" content="Henrik Steen; http://www.henrist.net" /> <title>IP-blokkering</title> <style type="text/css"> <!-- body { font-family: tahoma; font-size: 14px; } h1 { font-size: 23px; } .hsws { color: #CCCCCC; font-size: 12px; } .subtitle { font-size: 16px; font-weight: bold; } fieldset { margin: 10px 0 } fieldset p { margin: 8px 3px 5px; padding: 0 } legend { color: #FFFFFF; background-color: #222222; padding: 3px 5px; border: 3px solid #FFFFFF; border-width: 0 3px } --> </style> </head> <body> <h1>IP-blokkering</h1> <p>Din IP-adresse er blokkert/utestengt.</p> <p>IP-adresse og eventuelle grunner:</p> ' . implode("\n", $reasons) . ' <p class="hsws"><a href="http://hsw.no/">hsw.no</a></p> </body> </html>'; die; }
/** * Hent cache over ikke-fullførte prestasjoner */ public function load_cache($reload = null) { if ($this->cache && !$reload) { return; } $cache_key = "achievements_up_" . $this->up->id; // hent fra cache if (!$reload && ($data = cache::fetch($cache_key))) { $this->achievements = $data; } // hent frisk data $result = \Kofradia\DB::get()->query("\n\t\t\tSELECT upa_id, upa_ac_id, upa_time, upa_prize, upa_apoints, upa_params, upa_up_id, upa_complete\n\t\t\tFROM up_achievements\n\t\t\tWHERE upa_up_id = {$this->up->id} AND upa_complete = 0"); $data = array(); while ($row = $result->fetch()) { $data[$row['upa_ac_id']] = $row; } $this->cache = $data; // lagre til cache cache::store($cache_key, $data, 300); }
public static function build_menu() { $ret = ''; $lock = defined("LOCK") && LOCK; $bydeler = ' <li class="bydeler_alt"><a href="' . ess::$s['relative_path'] . '/bydeler#?b" class="menu-icon menu-bydel">Bydeler<span class="icon"></span></a></li> <li class="bydeler_filter"><a href="' . ess::$s['relative_path'] . '/bydeler" class="menu-icon menu-ff" id="f_">Broderskap og firma<span class="icon"></span></a>'; if (isset(self::$data['bydeler_menu'])) { $bydeler .= ' <ul> <li><a href="#" id="f_familie" class="bydeler_vis_familie">Broderskap</a></li> <li> <a href="#" id="f_firma" class="bydeler_vis_firma">Firmaer</a> <ul> <li><a href="#" id="f_avisfirma" class="bydeler_vis_avisfirma">Avisfirmaer</a></li> <li><a href="#" id="f_bankfirma" class="bydeler_vis_bankfirma">Bankfirmaer</a></li> <li><a href="#" id="f_bomberomfirma" class="bydeler_vis_bomberomfirma">Bomberom</a></li> <li><a href="#" id="f_garasjeutleiefirma" class="bydeler_vis_garasjeutleiefirma">Utleiefirma</a></li> <li><a href="#" id="f_sykehusfirma" class="bydeler_vis_sykehusfirma">Sykehus</a></li> <li><a href="#" id="f_vapbesfirma" class="bydeler_vis_vapbesfirma" title="Våpen, kuler og beskyttelse">Våpen/besk.</a></li> </ul> </li> </ul>'; } $bydeler .= '</li>'; $min_side = ' <li><a href="' . ess::$s['relative_path'] . '/min_side" class="menu-icon menu-minside">Min side<span class="icon"></span></a></li>'; if (!$lock && login::$logged_in) { $poker_active = cache::fetch("poker_active", 0); $auksjoner_active = game::auksjoner_active_count(); $fengsel_count = game::fengsel_count(); $ret .= ' <ul> <li><a href="' . ess::$s['relative_path'] . '/kriminalitet" class="menu-icon menu-krim">Kriminalitet<span class="icon"></span></a></li> <li><a href="' . ess::$s['relative_path'] . '/utpressing" class="menu-icon menu-utpr">Utpressing<span class="icon"></span></a>' . (isset(self::$data['utpressing']) ? ' <ul> <li><a href="' . ess::$s['relative_path'] . '/utpressing/log">Siste utpressinger</a></li> </ul>' : '') . '</li> <li><a href="' . ess::$s['relative_path'] . '/gta" class="menu-icon menu-bilt">Biltyveri<span class="icon"></span></a>' . (defined("SHOW_GTA_MENU") ? ' <ul> <li><a href="' . ess::$s['relative_path'] . '/gta/garasje">Garasje</a></li> <li><a href="' . ess::$s['relative_path'] . '/gta/stats">Statistikk</a></li> </ul>' : '') . '</li> <li><a href="' . ess::$s['relative_path'] . '/oppdrag" class="menu-icon menu-oppd">Oppdrag<span class="icon"></span></a></li> <li><a href="' . ess::$s['relative_path'] . '/lotto" class="menu-icon menu-lotto">Lotto<span class="icon"></span></a>' . (isset(self::$data['lotto']) ? ' <ul> <li><a href="' . ess::$s['relative_path'] . '/lotto_trekninger">Trekninger</a></li> </ul>' : '') . '</li> <li><a href="' . ess::$s['relative_path'] . '/fengsel" class="menu-icon menu-fengsel">Fengsel <span class="ny2" id="fengsel_count">' . ($fengsel_count > 0 ? $fengsel_count : '') . '</span><span class="icon"></span></a></li> <li><a href="' . ess::$s['relative_path'] . '/angrip" class="menu-icon menu-angr">Angrip spiller<span class="icon"></span></a></li> </ul> <ul> <li><a href="' . ess::$s['relative_path'] . '/banken" class="menu-icon menu-banken">Banken<span class="icon"></span></a></li>' . $min_side . ' <li><a href="' . ess::$s['relative_path'] . '/poker" class="menu-icon menu-poker">Poker <span class="ny2" id="poker_active">' . ($poker_active > 0 ? $poker_active : '') . '</span><span class="icon"></span></a></li> <li><a href="' . ess::$s['relative_path'] . '/auksjoner" class="menu-icon menu-auks">Auksjoner <span class="ny2" id="auksjoner_active">' . ($auksjoner_active > 0 ? $auksjoner_active : '') . '</span><span class="icon"></span></a></li>' . $bydeler . ' <li><a href="' . ess::$s['relative_path'] . '/min_side?a=achievements" class="menu-icon menu-achievements">Prestasjoner<span class="icon"></span></a>' . (self::has_page_id("achievements") || self::has_page_id("hall_of_fame") ? ' <ul> <li><a href="' . ess::$s['relative_path'] . '/hall_of_fame" class="menu-icon menu-achievements">Hall of Fame</a></li> </ul>' : '') . '</li> <li><a href="' . ess::$s['relative_path'] . '/etterlyst" class="menu-icon menu-etterl">Etterlyst<span class="icon"></span></a></li> <li><a href="' . ess::$s['relative_path'] . '/drap" class="menu-icon menu-drap">Drapliste<span class="icon"></span></a></li> </ul>'; } elseif (login::$logged_in) { $ret .= ' <ul>' . $min_side . $bydeler . ' </ul>'; } else { $ret .= ' <ul> <li><a href="' . ess::$s['relative_path'] . '/?orign=' . urlencode($_SERVER['REQUEST_URI']) . '" class="menu-icon menu-logginn">Logg inn<span class="icon"></span></a></li> <li><a href="' . ess::$s['relative_path'] . '/registrer" class="menu-icon menu-register">Registrer deg<span class="icon"></span></a></li> </ul> <ul>' . $bydeler . ' <li><a href="' . ess::$s['relative_path'] . '/hall_of_fame" class="menu-icon menu-achievements">Hall of Fame<span class="icon"></span></a></li> </ul>'; } $ret .= ' <ul>'; if (!$lock) { $ret .= self::get_custom_forums(); } $ret .= ' <li><a href="' . ess::$s['relative_path'] . '/forum/forum?id=1" class="menu-icon menu-forum">Game forum<span class="icon"></span></a></li> <li><a href="' . ess::$s['relative_path'] . '/forum/forum?id=2" class="menu-icon menu-forum">Off-topic forum<span class="icon"></span></a></li> <li><a href="' . ess::$s['relative_path'] . '/forum/forum?id=3" class="menu-icon menu-forum">Salg/søknad forum<span class="icon"></span></a></li> </ul>'; $ret .= ' <ul> <li><a href="' . ess::$s['relative_path'] . '/node" class="menu-icon menu-help"><b>Hjelp</b> / Support<span class="icon"></span></a></li>' . (!$lock ? ' <li><a href="' . ess::$s['relative_path'] . '/soknader" class="menu-icon menu-sokn">Søknader<span class="icon"></span></a></li>' . (!isset(self::$data['is_avstemning']) || !self::$data['is_avstemning'] ? ' <li><a href="' . ess::$s['relative_path'] . '/polls" class="menu-icon menu-avst">Avstemninger<span class="icon"></span></a></li>' : '') . ' <li><a href="' . ess::$s['relative_path'] . '/ranklist" class="menu-icon menu-rankl">Ranklist<span class="icon"></span></a></li> <li><a href="' . ess::$s['relative_path'] . '/online_list" class="menu-icon menu-online">Spillere pålogget<span class="icon"></span></a></li>' : '') . ' <li><a href="' . ess::$s['relative_path'] . '/crewet" class="menu-icon menu-crew">Crewet<span class="icon"></span></a></li>' . (!$lock ? ' <li><a href="' . ess::$s['relative_path'] . '/statistikk" class="menu-icon menu-stats">Statistikk<span class="icon"></span></a></li>' : '') . ' <li><a href="' . ess::$s['relative_path'] . '/donasjon" class="menu-icon menu-donate">Donasjoner<span class="icon"></span></a></li> </ul>'; if (!MAIN_SERVER) { $ret .= ' <ul> <li><a href="&rpath;/dev/" class="menu-icon menu-devt">Utviklerverktøy<span class="icon"></span></a></li> </ul>'; } return $ret; }
protected static function get_revision_info() { $branch = ""; // hent informasjon fra Git $data = @file_get_contents(PATH_ROOT . "/.git/HEAD"); if (!$data) { return null; } if (mb_substr($data, 0, 3) == "ref") { $ref = trim(mb_substr($data, 5)); $commit = @file_get_contents(PATH_ROOT . "/.git/{$ref}"); $branch = basename($ref); } else { $commit = trim($data); $branch = $commit; } if (!$commit) { return null; } // hent tidspunkt og melding $last_rev = cache::fetch("gitlog_last_rev"); $last_info = cache::fetch("gitlog_last_info"); if (!$last_rev || $last_rev != $commit) { $res = shell_exec("git log -1 --format=\"%ct %s\""); $last_info = sscanf($res, "%d %[^\$]s"); cache::store("gitlog_last_info", $last_info); } $r = array("branch" => $branch, "commit" => $commit, "date" => $last_info[0], "message" => $last_info[1]); return $r; }
/** * Hent ut antall aktive auksjoner */ public static function auksjoner_active_count() { $auksjoner = cache::fetch("auksjoner_active"); if (!$auksjoner) { return 0; } $active = 0; $time = time(); foreach ($auksjoner as $row) { if ($row[0] <= $time && $row[1] >= $time) { $active++; } } return $active; }
<up_reg_time_rel>' . htmlspecialchars(game::timespan($user['up_created_time'], game::TIME_ABS)) . '</up_reg_time_rel> <up_status>' . htmlspecialchars($status) . '</up_status> <up_last_online_abs>' . htmlspecialchars($_base->date->get($user['up_last_online'])->format(date::FORMAT_SEC)) . '</up_last_online_abs> <up_last_online_rel>' . htmlspecialchars(game::timespan($user['up_last_online'], game::TIME_ABS)) . '</up_last_online_rel> <up_activated>' . htmlspecialchars($user['up_access_level'] == 0 ? 0 : 1) . '</up_activated> <up_profile_image>' . htmlspecialchars($profile_image) . '</up_profile_image> <up_log_new>' . ($user['up_log_new'] + $user['up_log_ff_new']) . '</up_log_new> <up_rank_name>' . htmlspecialchars($rank['name'] . ($rank['orig'] ? ' (' . $rank['orig'] . ')' : '')) . '</up_rank_name> <up_rank_position>' . $user['upr_rank_pos'] . '</up_rank_position> <up_hits>' . $user['up_hits'] . '</up_hits> <up_cash>' . game::format_cash($user['up_cash']) . '</up_cash> <up_bank>' . game::format_cash($user['up_bank']) . '</up_bank> <up_money>' . game::format_cash($user['money']) . '</up_money> <up_money_title>' . game::cash_name($user['money']) . '</up_money_title> <up_last_interest>' . game::format_cash($user['up_interest_last']) . '</up_last_interest> <up_bydel_latitude>' . htmlspecialchars($bydel['latitude']) . '</up_bydel_latitude> <up_bydel_longitude>' . htmlspecialchars($bydel['longitude']) . '</up_bydel_longitude> <up_bydel_id>' . htmlspecialchars($bydel['id']) . '</up_bydel_id> <up_bydel_name>' . htmlspecialchars($bydel['name']) . '</up_bydel_name> <up_health>' . ($health == 100 ? '100' : sprintf("%.2f", $health)) . '</up_health> <up_energy>' . ($energy == 100 ? '100' : sprintf("%.2f", $energy)) . '</up_energy> <up_protection>' . (!$user['up_protection_id'] ? 'null' : ($user['up_protection_state'] == 1 ? '100' : sprintf("%.2f", $user['up_protection_state'] * 100))) . '</up_protection> <up_rank>' . sprintf("%.3f", login::$user->player->rank['need_points'] == 0 ? $user['up_points'] / login::$user->player->rank['points'] * 100 : ($user['up_points'] - login::$user->player->rank['points']) / login::$user->player->rank['need_points'] * 100) . ':' . $user['up_points'] . '</up_rank> <up_wanted>' . ($user['up_wanted_level'] == 0 ? '0' : sprintf("%.1f", $user['up_wanted_level'] / 10, 1)) . '</up_wanted> </player> <game> <poker_active>' . cache::fetch("poker_active", 0) . '</poker_active> <auksjoner_active>' . game::auksjoner_active_count() . '</auksjoner_active> <fengsel_count>' . game::fengsel_count() . '</fengsel_count> </game> </userinfo>');