Example #1
0
function solving_form($tVars, WC_Warflag $flag)
{
    $form = '';
    $form .= GWF_Form::start(true, GWF_Form::ENC_DEFAULT, 'post', false);
    $form .= sprintf('<input type="hidden" name="wfid" value="%s" />', $flag->getID());
    $form .= sprintf('<input type="text" name="password_solution" value="" />');
    $form .= sprintf('<input type="submit" name="igotitnow" value="!" />');
    $form .= GWF_Form::end();
    // 	$data = array(
    // 		'flagid' => array(GWF_Form::HIDDEN, $flag->getID()),
    // 		'solution' => array(GWF_Form::STRING, ''),
    // 	);
    // 	$form = new GWF_Form($tVars['method'], $data);
    // 	return $form->templateX();
    return $form;
}
Example #2
0
 private function getData()
 {
     $table = GDO::table('WC_Warflags');
     $by = Common::getGetString('by', 'wf_order');
     $dir = Common::getGetString('dir', 'ASC');
     $orderby = $table->getMultiOrderby($by, $dir);
     return WC_Warflag::getForBoxAndUser($this->box, GWF_User::getStaticOrGuest(), $orderby);
 }
Example #3
0
 private function templateSolvers()
 {
     $box = $this->flag->getWarbox();
     $_GET['sid'] = $box->getSiteID();
     $_GET['bid'] = $box->getID();
     $fid = $this->flag->getID();
     $table = GDO::table('WC_Warflags');
     $where = "wf_id={$fid} AND wf_solved_at IS NOT NULL";
     $orderby = 'wf_solved_at ASC';
     $joins = array('flag', 'solvers', 'flagbox', 'flagsite');
     $ipp = 50;
     $nItems = $table->countRows($where, $joins);
     $nPages = GWF_PageMenu::getPagecount($ipp, $nItems);
     $page = Common::clamp(Common::getGetInt('page'), 1, $nPages);
     $from = GWF_PageMenu::getFrom($page, $ipp);
     $tVars = array('site_quickjump' => $this->module->templateSiteQuickjump('boxdetail'), 'solvers' => $table->selectAll('*', $where, $orderby, $joins, $ipp, $from, GDO::ARRAY_A), 'flag' => $this->flag, 'rank' => $from + 1, 'sort_url' => NULL, 'solvercount' => $nItems, 'pagemenu' => GWF_PageMenu::display($page, $nPages, GWF_WEB_ROOT . "index.php?mo=WeChall&me=WarflagSolvers&flag={$fid}&page=%PAGE%"));
     return $this->module->templatePHP('warflag_solvers.php', $tVars);
 }
Example #4
0
 public static function hasSolved(WC_Warflag $flag, GWF_User $user)
 {
     return self::table(__CLASS__)->selectVar('1', "wf_wfid={$flag->getID()} AND wf_uid={$user->getID()} AND wf_solved_at IS NOT NULL") !== false;
 }
Example #5
0
 private function onCSVExport()
 {
     GWF_Website::plaintext();
     $flags = WC_Warflag::getByWarbox($this->warbox, 'wf_order ASC');
     echo self::CSV_COLUMNS . PHP_EOL;
     foreach ($flags as $flag) {
         $flag instanceof WC_Warflag;
         $input = array($flag->getVar('wf_order'), $flag->getVar('wf_cat'), $flag->getVar('wf_score'), $flag->getVar('wf_title'), $flag->getVar('wf_url'), $flag->getVar('wf_authors'), $flag->getVar('wf_status'), $flag->getVar('wf_login'), '', $flag->isWarchall() ? 'SSH' : 'WEB');
         echo GWF_Array::toCSV($input) . PHP_EOL;
     }
     die(0);
 }
Example #6
0
 private function onSolved(WC_Warflag $flag)
 {
     if ($this->box->isMultisolve()) {
         if (false !== ($err = $this->onMultiSolved($flag))) {
             return $err;
         }
     } else {
         if (false !== ($err = $this->onSingleSolved($flag))) {
             return $err;
         }
     }
     if (!$this->box->recalcPlayersAndScore()) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     if (false === ($this->flags = WC_Warflag::getForBoxAndUser($this->box, $this->user, 'wf_order ASC'))) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     $this->module->includeClass('WC_RegAt');
     if ($this->site->isUserLinked($this->user->getID())) {
         $result = $this->site->onUpdateUser($this->user);
         return $result->display($this->site->displayName());
     } else {
         return '_YOU_ARE_NOT_LINKED_TO_THE_SITE,_BUT_WELL_DONE!';
     }
 }
Example #7
0
function warscore_levelup_multi($socket, WC_Warbox $box, GWF_User $user, $level)
{
    if (false === ($warchall = WC_Warflag::getWarchall($box, $level))) {
        return false;
    }
    if (false === ($warchalls = WC_Warflag::getWarchalls($box))) {
        return false;
    }
    if (0 >= ($levelnum = warscore_get_level_num($level))) {
        return warscore_levelup_single($socket, $box, $user, $level);
    }
    $changed = false;
    foreach ($warchalls as $warchall) {
        $warchall instanceof WC_Warflag;
        $other_level = $warchall->getVar('wf_title');
        if (0 >= ($olevelnum = warscore_get_level_num($other_level))) {
            continue;
        }
        if ($olevelnum > $levelnum) {
            continue;
        }
        if (warscore_levelup_single($socket, $box, $user, $other_level)) {
            $changed = true;
        }
    }
    return $changed;
}
Example #8
0
 public function parseFlagStats(GWF_User $user, &$stats)
 {
     $flags = WC_Warflag::getForBoxAndUser($this, $user);
     $ssh = 0;
     $flg = 0;
     if (count($flags) > 0) {
         $score = 0;
         $challs = 0;
         $maxscore = 0;
         foreach ($flags as $flag) {
             $flag instanceof WC_Warflag;
             if ($flag->getVar('wf_solved_at') !== NULL) {
                 $score += $flag->getVar('wf_score');
                 $challs++;
             }
             if ($flag->isWarflag()) {
                 $flg++;
             } else {
                 $ssh++;
             }
             $maxscore += $flag->getVar('wf_score');
         }
         # Remember challcount
         $this->saveVars(array('wb_challs' => count($flags), 'wb_levels' => $ssh, 'wb_flags' => $flg));
         # Save usercount?
         $site = $this->getSite();
         if ($site->isNoV1()) {
             $site->saveVar('site_usercount', WC_Warflags::getPlayercountForSite($site));
         }
         // score, rank, challssolved, maxscore, usercount, challcount
         $stats[0] += $score;
         // 			$stats[1]; RANK
         $stats[2] += $challs;
         $stats[3] += $maxscore;
         // 			$stats[4]; USERCOUNT
         $stats[5] += count($flags);
     }
 }
Example #9
0
function Upgrade_WeChall_5_06(Module_WeChall $module)
{
    GWF_Website::addDefaultOutput(GWF_HTML::message('WC5', "Database additions for speedy warboxes."));
    gdo_db()->setDieOnError(false);
    GWF_Debug::setDieOnError(false);
    $back = '';
    # Copy warchalls to warflags table
    $module->includeClass('WC_Warchall');
    $module->includeClass('WC_Warchalls');
    $module->includeClass('WC_Warflag');
    $module->includeClass('WC_Warflags');
    $flag = GDO::table('WC_Warflag');
    $flags = GDO::table('WC_Warflags');
    #
    if (!$flag->createColumn('wf_solvers')) {
        $back .= GWF_HTML::lang('ERR_DATABASE', array(__FILE__, __LINE__));
    }
    if (!$flag->createColumn('wf_options')) {
        $back .= GWF_HTML::lang('ERR_DATABASE', array(__FILE__, __LINE__));
    }
    if (!$flag->dropColumn('wf_flag')) {
        $back .= GWF_HTML::lang('ERR_DATABASE', array(__FILE__, __LINE__));
    }
    $flag->update("wf_options=1");
    $now = GWF_Time::getDate();
    $chall = GDO::table('WC_Warchall');
    $challs = GDO::table('WC_Warchalls');
    foreach ($chall->selectAll('*', '', '', NULL, -1, -1, GDO::ARRAY_O) as $c) {
        $c instanceof WC_Warchall;
        $boxid = $c->getVar('wc_boxid');
        $newflag = new WC_Warflag(array('wf_id' => '0', 'wf_wbid' => $boxid, 'wf_order' => '0', 'wf_cat' => 'exploit', 'wf_score' => '1', 'wf_solvers' => '0', 'wf_title' => $c->getVar('wc_level'), 'wf_url' => '', 'wf_authors' => 'Steven', 'wf_status' => 'up', 'wf_login' => '', 'wf_flag_enc' => NULL, 'wf_created_at' => $now, 'wf_last_solved_at' => NULL, 'wf_last_solved_by' => NULL, 'wf_options' => WC_Warflag::WARCHALL));
        $newflag->replace();
        $nfid = $newflag->getID();
        foreach ($challs->selectAll('*', "wc_wcid={$c->getID()}", '', NULL, -1, -1, GDO::ARRAY_O) as $entry) {
            $entry instanceof WC_Warchalls;
            $flags->insertAssoc(array('wf_wfid' => $nfid, 'wf_uid' => $entry->getVar('wc_uid'), 'wf_solved_at' => $entry->getVar('wc_solved_at'), 'wf_attempts' => '1', 'wf_last_attempt' => NULL));
        }
    }
    $flag->update("wf_solvers = (SELECT COUNT(*) FROM wc4_wc_warflags WHERE wf_wfid=wf_id)");
    $flag->update("wf_last_solved_at = (SELECT MAX(wf_solved_at) FROM wc4_wc_warflags WHERE wf_wfid=wf_id)");
    $flag->update("wf_last_solved_by = (SELECT wf_uid FROM wc4_wc_warflags WHERE wf_wfid=wf_id ORDER BY wf_solved_at DESC LIMIT 1)");
    $module->includeClass('WC_Warbox');
    $boxes = GDO::table('WC_Warbox');
    if (!$boxes->createColumn('wb_players')) {
        $back .= GWF_HTML::lang('ERR_DATABASE', array(__FILE__, __LINE__));
    }
    if (!$boxes->createColumn('wb_flags')) {
        $back .= GWF_HTML::lang('ERR_DATABASE', array(__FILE__, __LINE__));
    }
    if (!$boxes->createColumn('wb_challs')) {
        $back .= GWF_HTML::lang('ERR_DATABASE', array(__FILE__, __LINE__));
    }
    if (!$boxes->createColumn('wb_totalscore')) {
        $back .= GWF_HTML::lang('ERR_DATABASE', array(__FILE__, __LINE__));
    }
    foreach ($boxes->selectAll('*', "", "", NULL, -1, -1, GDO::ARRAY_O) as $box) {
        $box instanceof WC_Warbox;
        $box->recalcPlayersAndScore();
    }
    $box->update("wb_challs=(SELECT COUNT(*) FROM wc4_wc_warflag WHERE wf_wbid=wb_id)");
    $box->update("wb_levels=(SELECT COUNT(*) FROM wc4_wc_warflag WHERE wf_wbid=wb_id AND wf_options&2)");
    $box->update("wb_flags=(SELECT COUNT(*) FROM wc4_wc_warflag WHERE wf_wbid=wb_id AND wf_options&1)");
    $chall->dropTable();
    $challs->dropTable();
    return $back;
}
Example #10
0
 /**
  * Recalc the score for this site.
  * @return boolean
  */
 private function recalcScore()
 {
     if ($this->isLinear()) {
         $wc = Module_WeChall::instance();
         $wc->includeClass('WC_Warbox');
         $wc->includeClass('WC_Warflag');
         $basescore = WC_Warflag::getTotalscoreForSite($this);
         if ($this->isNoV1()) {
             // 				WC_RegAt::calcTotalscores()
         }
     } else {
         $basescore = $this->getBasescore();
         $average = $this->getAverage();
         $challcnt = $this->getChallcount();
         $spc = $this->getVar('site_spc');
         $basescore += $spc * $challcnt;
         $basescore += $basescore - $average * $basescore;
         $basescore = intval(round($basescore));
     }
     if ($basescore !== $this->getVar('site_score')) {
         require_once 'WC_HistorySite.php';
         if (false === WC_HistorySite::insertEntry($this->getID(), $this->getScore(), $this->getUsercount(), $this->getChallcount())) {
             echo GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
             return false;
         }
         return $this->saveVar('site_score', $basescore);
     }
     return true;
 }