Beispiel #1
0
 /**
  * Legg til e-post i køen
  * @param object email $email
  * @param array receivers
  * @param string subject
  * @param bool sende e-posten med en gang
  */
 public static function add_emails(email $email, $receivers, $subject, $send_now = false)
 {
     global $_base;
     if (!is_array($receivers)) {
         $receivers = array($receivers);
     }
     if (!isset($email->data) || !$email->data) {
         throw new HSException("Email must be formatted before input.");
     }
     // sett opp tag
     $id = uniqid("", true);
     $add = array();
     foreach ($receivers as $item) {
         $more = $send_now ? ", " . (time() + self::$timeout) . ", " . \Kofradia\DB::quote($id) : "";
         $add[] = "(" . \Kofradia\DB::quote($item) . "," . \Kofradia\DB::quote($subject) . "," . \Kofradia\DB::quote($email->data[0]) . "," . \Kofradia\DB::quote($email->data[1]) . "," . \Kofradia\DB::quote($email->params) . "{$more})";
     }
     // noen vi skal legge til?
     if (count($add) > 0) {
         $more = $send_now ? ", m_active_end, m_active_id" : "";
         \Kofradia\DB::get()->exec("INSERT INTO mailer (m_receiver, m_subject, m_headers, m_body, m_params{$more}) VALUES " . implode(", ", $add));
     }
     // skal e-postene sendes med en gang?
     if ($send_now) {
         return array($add, self::send_tag($id));
     }
     return count($add);
 }
Beispiel #2
0
 /**
  * Hent beste ranker siste 24 timer
  */
 public static function getBestRankers($limit = null)
 {
     $limit = (int) ($limit ?: 1);
     // tidsperiode
     $d = \ess::$b->date->get();
     $a = $d->format("H") < 21 ? 2 : 1;
     $d->modify("-{$a} day");
     $d->setTime(21, 0, 0);
     $date_from = $d->format("U");
     $d->modify("+1 day");
     $date_to = $d->format("U");
     // hent spiller
     $result = \Kofradia\DB::get()->query("\n\t\t\tSELECT up_id, up_name, up_access_level, sum_uhi_points, up_points, up_last_online, up_profile_image_url, upr_rank_pos\n\t\t\tFROM\n\t\t\t\t(\n\t\t\t\t\tSELECT uhi_up_id, SUM(uhi_points) sum_uhi_points\n\t\t\t\t\tFROM users_hits\n\t\t\t\t\tWHERE uhi_secs_hour >= {$date_from} AND uhi_secs_hour < {$date_to}\n\t\t\t\t\tGROUP BY uhi_up_id\n\t\t\t\t\tHAVING sum_uhi_points > 0\n\t\t\t\t\tORDER BY sum_uhi_points DESC\n\t\t\t\t\tLIMIT {$limit}\n\t\t\t\t) ref,\n\t\t\t\tusers_players\n\t\t\t\tLEFT JOIN users_players_rank ON upr_up_id = up_id\n\t\t\tWHERE uhi_up_id = up_id");
     if ($result->rowCount() == 0) {
         return array();
     }
     $players = array();
     $up_id = array();
     while ($row = $result->fetch()) {
         $row['ff_links'] = array();
         $players[$row['up_id']] = $row;
         $up_id[] = $row['up_id'];
     }
     // hent familier hvor spilleren er medlem
     $ff = \ff::get_ff_list($up_id, \ff::TYPE_FAMILIE);
     foreach ($ff as $row) {
         $players[$row['ffm_up_id']]['ff'][] = $row;
         $players[$row['ffm_up_id']]['ff_links'][] = $row['link'];
     }
     return $players;
 }
Beispiel #3
0
 /**
  * Get specific donation
  *
  * @param int Donation ID
  * @return \Kofradia\Donation
  */
 public static function get($d_id)
 {
     $d_id = (int) $d_id;
     $result = DB::get()->query("\n\t\t\tSELECT d_id, d_up_id, d_time, d_amount\n\t\t\tFROM donations\n\t\t\tWHERE d_id = {$d_id}");
     if ($row = $result->fetch()) {
         return static::load($row);
     }
 }
Beispiel #4
0
 /**
  * Load settings and save to cache
  */
 public static function reload()
 {
     $result = \Kofradia\DB::get()->query("SELECT id, name, value FROM settings");
     \game::$settings = array();
     while ($row = $result->fetch()) {
         \game::$settings[$row['name']] = array("id" => $row['id'], "value" => $row['value']);
     }
     // keep for 1 hour
     \cache::store("settings", \game::$settings, 3600);
 }
Beispiel #5
0
 /**
  * Sett telleren til bestemt verdi
  * @param string $name
  * @param integer $count
  */
 public static function set($name, $value)
 {
     global $_base;
     $value = (int) $value;
     // forsøk å sett telleren til bestemt verdi
     $affected = \Kofradia\DB::get()->exec("UPDATE tasks SET t_ant = {$value} WHERE t_name = " . \Kofradia\DB::quote($name));
     // oppdater cache
     self::load(true);
     return $affected;
 }
Beispiel #6
0
 /**
  * Vote on this
  *
  * @param \user User voting
  * @return bool
  */
 public function vote(\user $user)
 {
     $a = \Kofradia\DB::get()->exec("\n\t\t\tINSERT IGNORE INTO polls_votes\n\t\t\tSET pv_p_id = {$this->poll->id}, pv_po_id = {$this->id}, pv_up_id = {$user->player->id}, pv_time = " . time());
     if ($a > 0) {
         \Kofradia\DB::get()->exec("UPDATE polls_options SET po_votes = po_votes + 1 WHERE po_id = {$this->id}");
         \Kofradia\DB::get()->exec("UPDATE polls SET p_votes = p_votes + 1 WHERE p_id = {$this->poll->id}");
         // delete vote cache
         \cache::delete("polls_options_list");
     }
     return $ok;
 }
Beispiel #7
0
 /**
  * Hent siste oppføringene
  */
 public static function get_latest($limit = 20)
 {
     $limit = (int) $limit;
     if ($limit <= 0) {
         $limit = 1;
     }
     $result = \Kofradia\DB::get()->query("SELECT lf_time, lf_html FROM livefeed ORDER BY lf_time DESC, lf_id DESC LIMIT {$limit}");
     $data = array();
     while ($row = $result->fetch()) {
         $data[] = $row;
     }
     return $data;
 }
Beispiel #8
0
 /**
  * Show betingelser
  */
 public function action_betingelser()
 {
     \ess::$b->page->add_title("Betingelser");
     $user = \login::$logged_in ? \login::$user : null;
     // markere betingelsene som sett?
     $updated = false;
     if ($user && ($user->data['u_tos_version'] != intval(Settings::get('tos_version')) || empty($user->data['u_tos_accepted_time']))) {
         $updated = true;
         $user->data['u_tos_version'] = intval(Settings::get("tos_version"));
         $user->data['u_tos_accepted_time'] = time();
         \Kofradia\DB::get()->exec("\n\t\t\t\tUPDATE users\n\t\t\t\tSET u_tos_version = " . $user->data['u_tos_version'] . ",\n\t\t\t\t\tu_tos_accepted_time = " . time() . "\n\t\t\t\tWHERE u_id = " . $user->id);
     }
     return View::forge("misc/betingelser", array("tos_version" => Settings::get("tos_version"), "tos_update" => Settings::get("tos_update"), "tos" => Settings::get("tos"), "user" => $user, "updated" => $updated));
 }
Beispiel #9
0
 /**
  * Add to database
  */
 public function addToDb()
 {
     // already in db?
     if ($this->id) {
         return;
     }
     Hendelser::incSetting("count_events");
     foreach ($this->getDescriptionHTML() as $text) {
         if ($this->event_name == "push") {
             Hendelser::incSetting("count_code", $this->getLogCount());
         } else {
             Hendelser::incSetting("count_other", $this->getLogCount());
         }
     }
     \Kofradia\DB::get()->exec("\n\t\t\tINSERT INTO github_log\n\t\t\tSET gl_time = " . $this->event_time->getTimestamp() . ", gl_event_type = " . \Kofradia\DB::quote($this->event_name) . ",\n\t\t\t    gl_contents = " . \Kofradia\DB::quote(serialize($this)) . ", gl_log_count = " . $this->getLogCount());
 }
 /**
  * Oppdater data
  */
 public static function update_data()
 {
     global $_base;
     // hent data
     $data = self::get_changes();
     if (!$data) {
         return false;
     }
     // lagre ny data
     $data_sql = \Kofradia\DB::quote(serialize($data));
     \Kofradia\DB::get()->exec("INSERT INTO settings SET name = 'wordpress_data', value = {$data_sql} ON DUPLICATE KEY UPDATE value = {$data_sql}");
     // sjekk for ny data
     self::check_new($data);
     // last inn settings på nytt
     require PATH_APP . "/scripts/update_db_settings.php";
 }
Beispiel #11
0
 /** Sett headers */
 public static function set_headers()
 {
     // kan ikke sende headers hvis headers allerede er sendt
     if (headers_sent()) {
         return;
     }
     // sett riktig retur
     self::type_header(self::$type);
     // sett script tid
     if (defined("SCRIPT_START")) {
         header("X-HSW-Time: " . round(microtime(true) - SCRIPT_START, 4));
     }
     // sett database info
     if ($profiler = \Kofradia\DB::getProfiler()) {
         header("X-HSW-Queries: " . $profiler->num);
         header("X-HSW-Queries-Time: " . round($profiler->time, 4));
     }
 }
 /** Kontroller alle artikler */
 public function __construct()
 {
     // hent alle artikkelene
     $result = \Kofradia\DB::get()->query("\n\t\t\tSELECT ffna_id, ffna_ffn_id, ffna_created_time, ffna_updated_time, ffna_title, ffna_text, ffna_published, ffna_published_time, ffna_price, ff_id, ff_name, up_name, u_email, up_access_level\n\t\t\tFROM ff_newspapers_articles\n\t\t\t\tLEFT JOIN ff_members ON ffm_ff_id = ffna_ff_id AND ffm_up_id = ffna_up_id AND ffm_status != 2, users, users_players, ff\n\t\t\tWHERE ffna_ffn_id = 0 AND ffm_up_id IS NULL AND ff_id = ffna_ff_id AND up_id = ffna_up_id AND u_id = up_u_id");
     // ingen artikler?
     if ($result->rowCount() == 0) {
         $this->deleted = 0;
         return;
     }
     $this->email = new email();
     $this->headers['Bcc'] = "*****@*****.**";
     // send hver artikkel på e-post og slett artikkelen
     while ($row = $result->fetch()) {
         // send e-post
         $this->send_email($row);
         // slett artikkelen
         \Kofradia\DB::get()->exec("DELETE FROM ff_newspapers_articles WHERE ffna_id = {$row['ffna_id']}");
     }
     $this->deleted = $result->rowCount();
 }
Beispiel #13
0
 /**
  * Hent nyeste tråder og svar i forumet
  */
 public static function getForumNew($limit = null)
 {
     $limit = (int) ($limit ?: 5);
     // hent forumdata
     $topics = \Kofradia\DB::get()->query("\n\t\t\tSELECT ft_id, ft_title, ft_time, ft_up_id, ft_fse_id, fse_name\n\t\t\tFROM forum_topics\n\t\t\t\tLEFT JOIN forum_sections ON ft_fse_id = fse_id\n\t\t\tWHERE fse_id IN (1,2,3) AND ft_deleted = 0\n\t\t\tORDER BY ft_time DESC\n\t\t\tLIMIT {$limit}");
     $replies = \Kofradia\DB::get()->query("\n\t\t\tSELECT fr_id, fr_ft_id, fr_time, fr_up_id, ft_title, fse_name\n\t\t\tFROM forum_replies\n\t\t\t\tLEFT JOIN forum_topics ON fr_ft_id = ft_id AND ft_deleted = 0\n\t\t\t\tLEFT JOIN forum_sections ON ft_fse_id = fse_id\n\t\t\tWHERE fse_id IN (1,2,3) AND fr_deleted = 0\n\t\t\tORDER BY fr_time DESC\n\t\t\tLIMIT {$limit}");
     $data = array();
     $times = array();
     while ($row = $topics->fetch()) {
         $data[] = array('topic_id' => $row['ft_id'], 'time' => $row['ft_time'], 'user' => $row['ft_up_id'], 'title' => $row['ft_title'], 'section' => $row['fse_name'], 'reply' => false);
         $times[] = $row['ft_time'];
     }
     while ($row = $replies->fetch()) {
         $data[] = array('topic_id' => $row['fr_ft_id'], 'reply_id' => $row['fr_id'], 'time' => $row['fr_time'], 'user' => $row['fr_up_id'], 'title' => $row['ft_title'], 'section' => $row['fse_name'], 'reply' => true);
         $times[] = $row['fr_time'];
     }
     // sorter data
     array_multisort($times, SORT_DESC, SORT_NUMERIC, $data);
     return array_slice($data, 0, $limit);
 }
Beispiel #14
0
 /**
  * Shows a recordlist of online users within each hour
  */
 public function action_online_top()
 {
     \ess::$b->page->add_title("Antall pålogget rekorder");
     // hent stats
     $result = \Kofradia\DB::get()->query("SELECT name, extra, value, time FROM sitestats");
     $sitestats = array();
     $sitestats_max = array();
     while ($row = $result->fetch()) {
         $sitestats[$row['name']][$row['extra']] = $row;
         $sitestats[$row['name']][$row['extra']] = $row;
         if (!array_key_exists($row['name'], $sitestats_max)) {
             $sitestats_max[$row['name']] = $row;
         } else {
             if ($row['value'] > $sitestats_max[$row['name']]['value']) {
                 $sitestats_max[$row['name']] = $row;
             }
         }
     }
     return View::forge("stats/online_top", array("sitestats" => $sitestats, "sitestats_max" => $sitestats_max));
 }
Beispiel #15
0
function visliste($name, $where)
{
    global $_base;
    $result = \Kofradia\DB::get()->query("SELECT up_id, up_name, up_access_level, up_last_online FROM users_players WHERE {$where} ORDER BY up_name");
    // hopp over hvis det ikke finnes noen
    if ($result->rowCount() == 0) {
        return;
    }
    echo '
		<h2 class="bg1">' . $name . '<span class="left2"></span><span class="right2"></span></h2>
		<div class="bg1">
			<dl class="dd_right">';
    while ($row = $result->fetch()) {
        echo '
				<dt>' . game::profile_link($row['up_id'], $row['up_name'], $row['up_access_level']) . '</dt>
				<dd>' . game::timespan($row['up_last_online'], game::TIME_ABS | game::TIME_NOBOLD) . '</dd>';
    }
    echo '
			</dl>
		</div>';
}
function save_user_backup()
{
    global $_base;
    static $i = 0;
    $i++;
    $date = date("Ymd_His");
    $url = GAMELOG_DIR . "/info_db_" . $date . "_" . $i . ".txt";
    $result = \Kofradia\DB::get()->query("SELECT up_id, up_name, up_points, up_bank, up_cash, up_last_online, up_hits, up_interest_last FROM users_players");
    if ($fh = fopen($url, "w")) {
        $row = $result->fetch();
        $fields = array_keys($row);
        fwrite($fh, "column information:\n" . implode(",", $fields));
        do {
            fwrite($fh, "\n" . implode(",", $row));
        } while ($row = $result->fetch());
        fclose($fh);
    } else {
        echo "error writing to {$url}\r\n";
    }
    return $url;
}
Beispiel #17
0
 /**
  * Handle notify URLs from PayPal
  */
 public function action_notify()
 {
     file_put_contents(PATH_ROOT . "/paypal.log", print_r($_POST, true), FILE_APPEND);
     // TODO: remove this when tested on production
     if (!isset($_POST['receiver_email']) || $_POST['receiver_email'] != '*****@*****.**') {
         die;
     }
     // should really check for duplicates, but we don't
     // but it must be "completed"
     if (!isset($_POST['payment_status']) || $_POST['payment_status'] != 'Completed') {
         die;
     }
     // verify it
     $verify = Donation::verifyPayPalData($_POST);
     if (!$verify) {
         die;
     }
     // check for user etc
     $custom = postval("custom");
     if (!preg_match('~^(.*):(.*);public=(0|1)$~', $custom, $matches)) {
         die;
     }
     trigger_error("should add");
     $player = null;
     if ($matches[1] != "gjest") {
         // find this player
         $result = DB::get()->query("\n\t\t\t\tSELECT up_id\n\t\t\t\tFROM users_players\n\t\t\t\t\tLEFT JOIN users ON up_u_id = u_id\n\t\t\t\t\tLEFT JOIN sessions ON u_id = ses_u_id\n\t\t\t\tWHERE ses_id = " . DB::quote($matches[1]) . " AND up_id = " . DB::quote($matches[2]) . " LIMIT 1");
         if ($up_id = $result->fetchColumn(0)) {
             $player = \player::get($up_id);
         }
     }
     $time = \ess::$b->date->parse(postval("payment_date"));
     // add it
     $d = Donation::create(postval("mc_gross"), $time, $matches[3] ? $player->id : null);
     putlog("CREWCHAN", sprintf("%%uDONASJON:%%u %s %s ble donert av %s", postval("mc_currency"), postval("mc_gross"), $player ? $player->data['up_name'] . ($matches[3] ? ' (synlig)' : ' (som anonym)') : 'anonym gjest'));
     // no output
     die;
 }
Beispiel #18
0
    // hindre scriptet i å kjøre to ganger
    if (defined("SCHEDULER")) {
        die;
    }
}
set_time_limit(0);
define("SCHEDULER", true);
define("SCHEDULER_REPEATING", true);
sess_start();
echo "Utfører rutine regelmessig.\n";
// kjør rutiner (autoload klassen)
ess::$b->scheduler = new scheduler();
// utfør rutiner regelmessig
while (true) {
    // finn ut når neste rutine skal utføres
    $result = \Kofradia\DB::get()->query("\n\t\tSELECT GREATEST(s_next, s_expire) next\n\t\tFROM scheduler\n\t\tWHERE s_active = 1\n\t\tORDER BY next\n\t\tLIMIT 1");
    $row = $result->fetch();
    $next = false;
    if ($row) {
        $next = $row['next'];
    }
    $t = time();
    $s = ess::$b->date->get($t)->format("s");
    $max = $t + 60 - $s;
    if (!$next || $next > $max) {
        $next = $max;
    }
    printf("Neste: %s\n", ess::$b->date->get($next)->format(date::FORMAT_SEC));
    // sov
    $sleep = max(0.1, $next - microtime(true));
    putlog("LOG", sprintf("Venter %.2f sekunder til neste.\n", $sleep));
Beispiel #19
0
 /** Hent ut data for brukeren og sørg for at den er oppdatert */
 public function update($data = NULL, $force_update = NULL)
 {
     global $_base;
     // hente data lokalt?
     if ($data === NULL && $this->data) {
         $data = $this->data['sw_xml'];
     }
     // forsøk å lese data
     $xml = $this->read_xml($data);
     $update = $force_update !== false;
     // sjekk om data ikke skal oppdateres
     if ($xml && $force_update === NULL) {
         $last_real_update = $_base->date->parse($xml->GeneratedTime)->format("U");
         // gått mindre enn en time?
         if ($last_real_update > time() - 3600) {
             // ikke oppdater data
             $update = false;
         }
     }
     // oppdatere data?
     if ($update) {
         $data = $this->get_xml();
         $xml_update = $this->read_xml($data);
         // gyldig?
         if ($xml_update) {
             $xml = $xml_update;
             // lagre data
             \Kofradia\DB::get()->exec("UPDATE stats_whatpulse SET sw_time_update = " . time() . ", sw_xml = " . \Kofradia\DB::quote($data) . " WHERE sw_userid = {$this->user_id}");
         }
     }
     $this->xml = $xml;
     return (bool) $xml;
 }
Beispiel #20
0
 /**
  * Get the players that are in a same FF as us
  *
  * We don't want to attack a allied
  *
  * TODO: Move this to player-class for reuse
  *
  * @return array(int up_id, ..)
  */
 protected function getFFPlayers()
 {
     $result = \Kofradia\DB::get()->prepare("\n\t\t\tSELECT DISTINCT f2.ffm_up_id\n\t\t\tFROM ff_members f1\n\t\t\t\tJOIN ff ON ff_id = f1.ffm_ff_id AND ff_is_crew = 0\n\t\t\t\tJOIN ff_members f2 ON f1.ffm_ff_id = f2.ffm_ff_id AND f2.ffm_status = 1 AND f2.ffm_up_id != f1.ffm_up_id\n\t\t\tWHERE f1.ffm_up_id = ? AND f1.ffm_status = 1");
     $result->execute(array($this->ut->up->id));
     $up_ids = array();
     while ($row = $result->fetch()) {
         $up_ids[] = $row['ffm_up_id'];
     }
     return $up_ids;
 }
Beispiel #21
0
					<option value="3600">Siste timen</option>
					<option value="today">I dag</option>
					<option value="d1">Siden i går</option>
					<option value="d2">Siden i forigårs</option>
					<option value="d3">Siden 3 dager</option>
					<option value="24t">Siste 24 timer</option>
					<option value="1u">Siste uken</option>
				</select>
				<noscript>
					<input type="submit" value="Go" />
				</noscript>
			</div>
			<p>Denne listen viser hvem som har vært aktive i løpet av siste ' . game::timespan($time, game::TIME_FULL) . '</p>
		</form>';
// hent brukerne
$result = \Kofradia\DB::get()->query("SELECT up_id, up_name, up_access_level FROM users_players WHERE up_last_online >= " . (time() - $time) . " ORDER BY up_name");
// sett opp alfabetisk liste
$liste = array();
while ($row = $result->fetch()) {
    $liste[mb_strtolower(mb_substr($row['up_name'], 0, 1))][] = game::profile_link($row['up_id'], $row['up_name'], $row['up_access_level']);
}
echo '
		<table class="table tablemb">
			<thead>
				<tr>
					<th colspan="2">Spillere pålogget - ' . game::format_number($result->rowCount()) . ' spiller' . ($result->rowCount() == 1 ? '' : 'e') . '</th>
				</tr>
			</thead>
			<tbody>';
foreach ($liste as $char => $rows) {
    echo '
Beispiel #22
0
<?php

require "../base.php";
global $_base;
$_base->page->add_title("IP Ban");
if (isset($_GET['active'])) {
    \Kofradia\DB::get()->query("SELECT bi_id, INET_NTOA(bi_ip_start) AS ip_range_start, IF(bi_ip_end=bi_ip_start,NULL,INET_NTOA(bi_ip_end)) AS ip_range_end, FROM_UNIXTIME(bi_time_start) AS time_start, FROM_UNIXTIME(bi_time_end) AS time_end, bi_reason, bi_info FROM ban_ip WHERE ISNULL(bi_time_end) OR bi_time_end >= UNIX_TIMESTAMP() ORDER BY bi_time_end = 0, bi_time_end DESC")->debug();
    die;
} elseif (isset($_GET['inactive'])) {
    \Kofradia\DB::get()->query("SELECT bi_id, INET_NTOA(bi_ip_start) AS ip_range_start, IF(bi_ip_end=bi_ip_start,NULL,INET_NTOA(bi_ip_end)) AS ip_range_end, FROM_UNIXTIME(bi_time_start) AS time_start, FROM_UNIXTIME(bi_time_end) AS time_end, bi_reason, bi_info FROM ban_ip WHERE bi_time_end != 0 AND bi_time_end < UNIX_TIMESTAMP() ORDER BY bi_time_end DESC")->debug();
    die;
} else {
    echo '
<h1>IP ban</h1>
<ul>
	<li><a href="ip_ban?active">Vis aktive IP-ban oppføringer</a></li>
	<li><a href="ip_ban?inactive">Vis gamle IP-ban oppføringer</a></li>
</ul>';
}
$_base->page->load();
Beispiel #23
0
 /**
  * Legg til kulene i databasen
  */
 protected function add()
 {
     $v = array();
     foreach ($this->ff_list as $f) {
         // sett opp antall som skal fordeles i hver gruppe
         $groups = array();
         $each = floor($f['ant'] / $f['grupper']);
         $rest = $f['ant'] % $f['grupper'];
         for ($i = 0; $i < $f['grupper']; $i++) {
             $groups[] = $each;
         }
         if ($rest > 0) {
             $extra_rand = (array) array_rand($groups, $rest);
             foreach ($extra_rand as $k) {
                 $groups[$k]++;
             }
         }
         // sett opp data for databasen
         foreach ($groups as $ant) {
             // velg tilfeldig tidspunkt
             $time = rand($this->time_start, $this->time_end);
             // sett opp for databasen
             for ($i = 0; $i < $ant; $i++) {
                 $v[] = "({$f['ff_id']}, {$time})";
             }
         }
     }
     // legg til i databasen
     if (count($v) > 0) {
         \Kofradia\DB::get()->exec("INSERT INTO bullets (bullet_ff_id, bullet_time) VALUES " . implode(",", $v));
     }
 }
Beispiel #24
0
 /**
  * Hent data for å generere lenker
  * @param array $rows data fra databasen
  */
 public static function generate_prerequisite($rows)
 {
     $pm = array();
     $fr = array();
     $up_id = array();
     foreach ($rows as $row) {
         switch ($row['r_type']) {
             case rapportering::TYPE_PM:
                 $pm[] = $row['r_type_id'];
                 break;
             case rapportering::TYPE_FORUM_REPLY:
                 $fr[] = $row['r_type_id'];
                 break;
             case rapportering::TYPE_PROFILE:
             case rapportering::TYPE_SIGNATURE:
                 $up_id[] = $row['r_up_id'];
                 break;
         }
     }
     // hent data
     if (count($pm) > 0) {
         $result = \Kofradia\DB::get()->query("SELECT im_id, im_it_id FROM inbox_messages WHERE im_id IN (" . implode(",", $pm) . ")");
         while ($row = $result->fetch()) {
             self::$data_prerequisite['pm'][$row['im_id']] = $row['im_it_id'];
         }
     }
     if (count($fr) > 0) {
         $result = \Kofradia\DB::get()->query("SELECT fr_id, fr_ft_id FROM forum_replies WHERE fr_id IN (" . implode(",", $fr) . ")");
         while ($row = $result->fetch()) {
             self::$data_prerequisite['fr'][$row['fr_id']] = $row['fr_ft_id'];
         }
     }
     if (count($up_id) > 0) {
         $up_id = array_unique($up_id);
         $result = \Kofradia\DB::get()->query("SELECT up_id, up_name FROM users_players WHERE up_id IN (" . implode(",", $up_id) . ")");
         while ($row = $result->fetch()) {
             self::$data_prerequisite['up_id'][$row['up_id']] = $row['up_name'];
         }
     }
 }
Beispiel #25
0
 /**
  * Get a user's vote
  *
  * @param \user $user
  * @return \Kofradia\Polls\PollOption
  */
 public function getVote(\user $user = null)
 {
     if (is_null($user) && is_null($this->user)) {
         throw new \HSException("Unknown user.");
     }
     if (is_null($user) || $user == $this->user) {
         $option_id = $this->data['pv_po_id'];
     } else {
         $result = \Kofradia\DB::get()->query("\n\t\t\t\tSELECT pv_po_id\n\t\t\t\tFROM polls_votes\n\t\t\t\tWHERE pv_p_id = {$this->id} AND pv_up_id = " . $user->player->id);
         if ($result->rowCount() == 0) {
             return null;
         }
         $option_id = $result->fetchColumn(0);
     }
     return $this->findOption($option_id);
 }
Beispiel #26
0
    /**
     * Behandle nytt passord
     */
    protected function solve_pass()
    {
        // lagre passord
        if (isset($_POST['save_pass'])) {
            // kontroller alle feltene
            $pass_new = trim(postval("pass_new"));
            $pass_repeat = trim(postval("pass_repeat"));
            // kontroller at alle feltene er fylt ut
            if ($pass_new == "" || $pass_repeat == "") {
                ess::$b->page->add_message("Alle feltene må fylles ut.", "error");
            } elseif ($pass_new != $pass_repeat) {
                ess::$b->page->add_message("De nye passordene var ikke like.", "error");
            } elseif (mb_strlen($pass_new) < 6) {
                ess::$b->page->add_message("Det nye passordet må inneholde minimum 6 tegn.", "error");
            } elseif (password::validate($pass_new, password::LEVEL_LOGIN) != 0) {
                ess::$b->page->add_message("Du må velge et vanskeligere passord.", "error");
            } elseif (password::verify_hash($pass_new, login::$user->data['u_bank_auth'], 'bank_auth')) {
                ess::$b->page->add_message("Velg et annet passord enn du har i banken.");
            } else {
                \Kofradia\DB::get()->exec("UPDATE users SET u_pass = "******", u_pass_change = NULL WHERE u_id = " . login::$user->id);
                // melding
                ess::$b->page->add_message("Du har nå lagret et nytt passord for brukeren din.");
                putlog("NOTICE", "%bPASSORD%b: %u" . login::$user->player->data['up_name'] . "%u lagret nytt passord på sin bruker (var nullstilt). " . ess::$s['path'] . "/min_side?u_id=" . login::$user->id);
                // send ut e-post for å informere
                $email = new email();
                $email->text = 'Hei,

Det er nå blitt opprettet et nytt passord fra ' . $_SERVER['REMOTE_ADDR'] . ' (' . $_SERVER['HTTP_USER_AGENT'] . ').

Bruker ID: ' . login::$user->data['u_id'] . '
E-post: ' . login::$user->data['u_email'] . '

Vi sender selvfølgelig ikke ditt nye passord på e-post. Det skal du kunne selv!

--
www.kofradia.no';
                $email->send(login::$user->data['u_email'], "Nytt passord");
                // logg ut alle andre brukere
                \Kofradia\DB::get()->exec("UPDATE sessions SET ses_active = 0, ses_logout_time = " . time() . " WHERE ses_active = 1 AND ses_u_id = " . login::$user->id . " AND ses_id != " . login::$info['ses_id']);
                redirect::handle();
            }
        }
        ess::$b->page->add_js_domready('$("lockpass").focus();');
        echo '
<div class="bg1_c small">
	<h1 class="bg1">Lagre nytt passord<span class="left"></span><span class="right"></span></h1>
	<p class="h_left"><a href="' . htmlspecialchars($this->url) . '">Tilbake</a></p>
	<div class="bg1">
		<p>Ditt passord har blitt nullstilt. Du vil ikke kunne logge inn uten å måtte benytte <i>glemt passord</i> funksjonen før du har opprettet et nytt passord.</p>
		<form action="" method="post" autocomplete="off">
			<dl class="dd_right dl_2x center" style="width: 80%">
				<dt>Nytt passord</dt>
				<dd><input type="password" class="styled w100" name="pass_new" id="lockpass" /></dd>
				<dt>Gjenta nytt passord</dt>
				<dd><input type="password" class="styled w100" name="pass_repeat" /></dd>
			</dl>
			<p class="c">' . show_sbutton("Lagre passordet", 'name="save_pass"') . '</p>
		</form>
	</div>
</div>';
    }
Beispiel #27
0
    /**
     * Våpentrening
     */
    protected function page_training_show()
    {
        // sett opp og test for anti-bot
        $this->training_antibot = new antibot(login::$user->id, "training", 7);
        if (MAIN_SERVER) {
            $this->training_antibot->check_required();
        }
        // sett opp skjema
        $this->training_form = \Kofradia\Form::getByDomain("training", login::$user);
        // ventetid?
        $wait = max(0, login::$user->player->data['up_weapon_training_next'] - time());
        // skal vi trene våpenet?
        if (isset($_POST['wt']) && $this->training_form->validateHashOrAlert(null, "Våpentrening")) {
            // kan vi ikke trene nå?
            if ($wait > 0) {
                redirect::handle();
            }
            // finnes ikke valget?
            $id = (int) postval("training_id");
            if (!isset(self::$trainings[$id])) {
                ess::$b->page->add_message("Du må velge et alternativ.", "error");
                redirect::handle();
            }
            $opt = self::$trainings[$id];
            // lagre valget for neste gang
            ess::session_put("training_id", $id);
            // har ikke nok cash?
            if ($opt['price'] > login::$user->player->data['up_cash']) {
                ess::$b->page->add_message("Du har ikke nok penger til å utføre våpentreningen.");
                redirect::handle();
            }
            $f = self::TRAINING_MAX * $opt['percent'];
            $next_old = login::$user->player->data['up_weapon_training_next'] ? ' = ' . login::$user->player->data['up_weapon_training_next'] : ' IS NULL';
            // utfør våpentrening
            $a = \Kofradia\DB::get()->exec("\n\t\t\t\tUPDATE users_players\n\t\t\t\tSET up_weapon_training = up_weapon_training + (1 - up_weapon_training) * {$f}, up_weapon_training_next = " . (time() + $opt['wait']) . ", up_cash = up_cash - {$opt['price']}\n\t\t\t\tWHERE up_id = " . login::$user->player->id . " AND up_cash >= {$opt['price']} AND up_weapon_training_next{$next_old}");
            // ikke oppdatert?
            if ($a == 0) {
                ess::$b->page->add_message("Kunne ikke utføre våpentrening.", "error");
            } else {
                $this->training_antibot->increase_counter();
                ess::$b->page->add_message("Du trente opp våpenet ditt og våpentreningen økte med " . game::format_num((1 - login::$user->player->data['up_weapon_training']) * $f * 100, 2) . " %.");
            }
            redirect::handle();
        }
        $training = login::$user->player->data['up_weapon_training'] * 100;
        echo '
<div class="bg1_c xsmall">
	<h1 class="bg1">Våpentrening<span class="left2"></span><span class="right2"></span></h1>
	<div class="bg1">';
        if ($wait > 0) {
            echo '
		<p class="c">Du må vente ' . game::counter($wait, true) . ' før du kan trene våpenet på nytt.</p>';
        } else {
            // vis alternativene
            echo '
		<form action="" method="post">
			' . $this->training_form->getHTMLInput() . '
			<table class="table tablemt center">
				<thead>
					<tr>
						<th>Pris</th>
						<th>Ventetid</th>
					</tr>
				</thead>
				<tbody>';
            $i = 0;
            $match = ess::session_get("training_id") ?: 0;
            foreach (self::$trainings as $id => $row) {
                echo '
					<tr class="box_handle' . (++$i % 2 == 0 ? ' color' : '') . '">
						<td class="r"><input type="radio" name="training_id"' . ($match == $id ? ' checked="checked"' : '') . ' value="' . $id . '" />' . game::format_cash($row['price']) . '</td>
						<td class="r">' . game::timespan($row['wait']) . '</td>
					</tr>';
            }
            echo '
				</tbody>
			</table>
			<p class="c">' . show_sbutton("Utfør", 'name="wt"') . '</p>
		</form>';
        }
        echo '
		<div class="progressbar p' . ($training < 28 ? ' levelcrit' : ($training < 35 ? ' levelwarn' : '')) . '">
			<div class="progress" style="width: ' . round(min(100, $training)) . '%">
				<p>Våpentrening: ' . ($training == 100 ? '100' : game::format_num($training, 2)) . ' %</p>
			</div>
		</div>
		<p>Du har en <b>' . htmlspecialchars(login::$user->player->weapon->data['name']) . '</b> med <b>' . game::format_num(login::$user->player->data['up_weapon_bullets']) . '</b> ' . fword('kule', 'kuler', login::$user->player->data['up_weapon_bullets']) . '.</p>
		<p>Våpentreningen din synker jevnlig i løpet av dagen, og du er nødt til å trene for å holde oppe våpentreningen din. Hvis våpentreningen din faller under 25 %, risikerer du å miste våpenet ditt.</p>
		<p>Bedre våpentrening fører til:</p>
		<ul class="spacer">
			<li>Du forbedrer treffsikkerheten din</li>
			<li>Du øker skuddtakten samtidig som treffsikkerheten forblir den samme</li>
		</ul>
	</div>
</div>';
    }
Beispiel #28
0
} else {
    $BrukerID = intval($_GET['BrukerID']);
    if ($BrukerID != $_SESSION['userinfo']['info']['id'] && !in_array("mod", $_SESSION['userinfo']['accesses'])) {
        die("Du må være moderator eller høyere for å vise andre brukere!");
    }
}
$result = \Kofradia\DB::get()->query("SELECT id, user, ip, hits, last_online FROM users WHERE id = {$BrukerID}");
if (!($user = $result->fetch())) {
    die("Fant ikke brukeren!");
}
$stats = array();
for ($i = 0; $i <= 23; $i++) {
    $stats[$i] = 0;
}
// hent timestatistikk
$result = \Kofradia\DB::get()->query("SELECT HOUR(FROM_UNIXTIME(secs_hour)) AS hour, SUM(hits) AS hits FROM users_hits WHERE userid = {$BrukerID} GROUP BY HOUR(FROM_UNIXTIME(secs_hour))");
while ($row = $result->fetch()) {
    $stats[$row['hour']] = $row['hits'];
}
$peak = max($stats);
$max_height = 150;
if (isset($_GET['Height'])) {
    $height = intval($_GET['Height']);
    if ($height >= 10 && $height <= 1000) {
        $max_height = $height;
    }
}
$width = 20 + 13 * 24;
$height = 80 + $max_height;
$result = imagecreatetruecolor($width, $height);
// bakgrunn
Beispiel #29
0
 /** Rediger revisjonsinformasjon */
 public function edit($title, $description, $mime)
 {
     global $_base;
     // sørg for at tittelen (filename) ikke inneholder noen ugyldige tegn
     $title = crewfiles::filter_filename($title);
     // lagre endringer
     \Kofradia\DB::get()->exec("UPDATE crewfiles_revisions SET cfr_title = " . \Kofradia\DB::quote($title) . ", cfr_description = " . \Kofradia\DB::quote($description) . ", cfr_mime = " . \Kofradia\DB::quote($mime) . " WHERE cfr_id = {$this->id}");
     $this->info['cfr_title'] = $title;
     $this->info['cfr_description'] = $description;
     $this->info['cfr_mime'] = $mime;
 }
Beispiel #30
0
<?php

\Kofradia\DB::get()->exec("\n\tUPDATE kriminalitet\n\tSET k_strength = k_strength * 0.8");
\Kofradia\DB::get()->exec("\n\tUPDATE kriminalitet_status\n\tSET ks_strength = ks_strength * 0.9\n\tWHERE ks_strength > 5");