public function onVote(WC_Challenge $chall) { if ('0' === ($userid = GWF_Session::getUserID())) { return GWF_HTML::err('ERR_LOGIN_REQUIRED'); } if (!WC_ChallSolved::hasSolved($userid, $chall->getID())) { return $this->module->error('err_chall_vote'); } $form = $this->getFormVote($chall, false, $userid); if (false !== ($error = $form->validate($this->module))) { return $error; } if (false !== ($vs = $chall->getVotesDif())) { $vs->onUserVoteSafe($_POST['dif'], $userid); } if (false !== ($vs = $chall->getVotesEdu())) { $vs->onUserVoteSafe($_POST['edu'], $userid); } if (false !== ($vs = $chall->getVotesFun())) { $vs->onUserVoteSafe($_POST['fun'], $userid); } if (false === WC_ChallSolved::setVoted($userid, $chall->getID(), true)) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } if (false === $chall->onRecalcVotes()) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } return $this->module->message('msg_chall_voted'); }
public function templateChalls($for_userid = false, $from_userid = false, $tag = '', $by = '', $dir = '', $show_cloud = true, $show_empty = true) { require_once GWF_CORE_PATH . 'module/WeChall/WC_ChallSolved.php'; $challs = GDO::table('WC_Challenge'); $for_userid = (int) $for_userid; $from_userid = (int) $from_userid; $solved_bits = $for_userid > 0 ? WC_ChallSolved::getSolvedForUser($for_userid, true) : array(); if (count($solved_bits) === 0 && !$show_empty && $from_userid === 0) { return ''; } $solve_filter = Common::getGetString('filter', ''); if ($solve_filter === 'solved' or $solve_filter == 'open') { $filter_prefix = $solve_filter . '_'; } else { $filter_prefix = ''; } $from_query = $from_userid === 0 ? '1' : "chall_creator LIKE '%,{$from_userid},%'"; $conditions = "({$from_query})"; if (0 === ($count = $challs->countRows($conditions))) { return ''; } $orderby = $challs->getMultiOrderby($by, $dir); $tag_2 = $tag == '' ? '' : $tag . '/'; $this->setPageDescr($for_userid, $from_userid, $tag, $count); $sort_url = 'challs/' . $tag_2 . 'by/' . $by . '/' . $dir . '/page-1'; $tVars = array('filter_prefix' => $filter_prefix, 'sort_url' => GWF_WEB_ROOT . $filter_prefix . 'challs/' . $tag_2 . 'by/%BY%/%DIR%/page-1', 'challs' => $challs->selectObjects('*', $conditions, $orderby), 'tags' => $show_cloud ? $this->getTags() : '', 'solved_bits' => $solved_bits, 'table_title' => $this->getTableTitle($for_userid, $from_userid, $tag, $count), 'tag' => $tag, 'by' => $by, 'dir' => $dir, 'href_all' => GWF_WEB_ROOT . $sort_url, 'href_solved' => GWF_WEB_ROOT . 'solved_' . $sort_url, 'href_unsolved' => GWF_WEB_ROOT . 'open_' . $sort_url, 'sel_all' => $solve_filter === '', 'sel_solved' => $solve_filter === 'solved', 'sel_unsolved' => $solve_filter === 'open'); return $this->module->templatePHP('challs.php', $tVars); }
public function execute() { if (false === ($chall = WC_Challenge::getByID(Common::getGetString('cid')))) { return $this->module->error('err_chall'); } $user = GWF_User::getStaticOrGuest(); $token = Common::getGetString('token'); $length = Common::clamp(Common::getGetInt('length'), 1); require_once GWF_CORE_PATH . 'module/WeChall/WC_ChallSolved.php'; require_once GWF_CORE_PATH . 'module/WeChall/WC_MathChall.php'; if (!WC_ChallSolved::hasSolved($user->getID(), $chall->getID())) { if (!WC_MathChall::checkToken($chall, $length, $token)) { return $this->module->error('err_token'); } } return $this->templateSolutions($chall, $user, $length, $token); }
private function outputScore($username) { if (false === ($user = GWF_User::getByName($username))) { die('Unknown User'); } if (false === ($site = WC_Site::getWeChall())) { die('Unknown Site'); } require_once GWF_CORE_PATH . 'module/WeChall/WC_RegAt.php'; require_once GWF_CORE_PATH . 'module/WeChall/WC_ChallSolved.php'; $score = WC_Challenge::getScoreForUser($user); $maxscore = WC_Challenge::getMaxScore(); $challs_solved = WC_ChallSolved::getChallsSolvedForUser($user); $challcount = WC_Challenge::getChallCount(); $usercount = GDO::table('GWF_User')->countRows(); $rank = WC_RegAt::calcExactRank($user); die(sprintf('%d:%s:%s:%s:%s:%s', $rank, $score, $maxscore, $challs_solved, $challcount, $usercount)); }
} else { $c1 = '<b>Momo</b>'; } if (false !== ($jinx = GWF_User::getByName('Jinx'))) { $c2 = $jinx->displayProfileLink(); } else { $c2 = '<b>Jinx</b>'; } if (false !== ($paipai = GWF_User::getByName('paipai'))) { $c3 = $paipai->displayProfileLink(); } else { $c3 = '<b>paipai</b>'; } $c4 = '<b>Miles Kaufmann</b>'; echo GWF_Box::box($chall->lang('info', array($maxlen, $img, $c1, $c2, $c3, $c4)), $chall->lang('title')); if (WC_ChallSolved::hasSolved(GWF_Session::getUserID(), $chall->getID())) { require_once GWF_CORE_PATH . 'module/WeChall/WC_MathChall.php'; echo GWF_Box::box(WC_HTML::lang('msg_wmc_solved', array($chall->display('chall_title'), WC_MathChall::getLimitedHREF($chall, 0)))); } if ('' !== ($formula = Common::getPostString('formula'))) { math_pyramid_check($chall, $formula, $maxlen); } ?> <div class="box box_c"> <form action="index.php" method="post"> <div><?php echo $chall->lang('th_formula'); ?> : <input type="text" name="formula" value="<?php echo htmlspecialchars($formula); ?>
/** * Wechall internally bot response. * The advantage over the other method is accurate challcount. * @param string $input * @return string */ public function wechallChalls($input) { if ($input === '') { return sprintf('Try wechallchalls.php?userame=blub'); } require_once GWF_CORE_PATH . 'module/WeChall/WC_ChallSolved.php'; $wechall = WC_Site::getWeChall(); $siteid = $wechall->getID(); if (false !== ($user = GWF_User::getByName($input))) { if ($user->isOptionEnabled(0x10000000)) { die('This user is not ranked!'); } $rank = WC_RegAt::calcExactSiteRank($user, $siteid); } elseif (false !== ($user = WC_RegAt::getUserBySiteRank($siteid, $input))) { $rank = intval($input); } else { return sprintf('The user does not exist.'); } // if (false !== ($error = $this->module->isExcludedFromAPI($user))) { // return $error; // } $userid = $user->getID(); $username = $user->displayUsername(); $solvedCount = WC_ChallSolved::getSolvedCount($userid); $score = WC_Challenge::getScoreForUser($user); $challcount = WC_Challenge::getChallCount(); $maxScore = WC_Challenge::getMaxScore(); $percent = $score / $maxScore * 100; $out = sprintf('%s solved %d of %d Challenges with %d of %d possible points (%.02f%%).', $username, $solvedCount, $challcount, $score, $maxScore, $percent); if ($rank !== false) { $out .= sprintf(' Rank for the site WeChall: %d', $rank); } return $out; }
include 'stalking_solution.php'; chdir('../../../'); define('GWF_PAGE_TITLE', 'Stalking'); require_once 'challenge/html_head.php'; require_once GWF_CORE_PATH . 'module/WeChall/solutionbox.php'; if (false === ($chall = WC_Challenge::getByTitle(GWF_PAGE_TITLE))) { $chall = WC_Challenge::dummyChallenge(GWF_PAGE_TITLE, 10, 'challenge/identity/stalking/index.php', false); } $chall->showHeader(); # That would be you! $user = GWF_User::getStaticOrGuest(); # Get prerequisite challenge if (false === ($identity = WC_Challenge::getByTitle('Identity'))) { echo GWF_HTML::err('ERR_GENERAL', array(__FILE__, __LINE__)); } else { if (!WC_ChallSolved::hasSolved($user->getID(), $identity->getID())) { $ida = sprintf('<a href="%s">%s</a>', htmlspecialchars($identity->hrefChallenge()), htmlspecialchars($identity->getName())); echo GWF_HTML::error($chall->lang('title'), $chall->lang('err_identity', $ida)); } else { # Did we get an anwer at all? if ('' !== ($answer = Common::getPostString('answer', ''))) { # Bruteforcing answers? if (false !== ($error = $chall->isAnswerBlocked($user))) { echo $error; } elseif (false !== ($error = stalking_check_answer($chall, $answer))) { echo GWF_HTML::error($chall->lang('title'), $error); } else { echo GWF_HTML::message($chall->lang('title'), $chall->lang('msg_correct')); $chall->onChallengeSolved($user->getID()); } }