private function onRecalcEverything() { require_once GWF_CORE_PATH . 'module/WeChall/WC_RegAt.php'; $wc = Module_WeChall::instance(); $wc->includeClass('WC_Warflag'); $wc->includeClass('WC_Warflags'); foreach (WC_Warbox::getAllBoxes() as $box) { $box instanceof WC_Warbox; $box->recalcPlayersAndScore(); $box->recalcChallcounts(); } WC_Site::recalcAllSites(); WC_RegAt::calcTotalscores(); return $this->templateAdmin(); }
private function onFreeze() { $form = $this->formFreeze(); if (false !== ($error = $form->validate($this->module))) { return $error; } $userid = $this->user->getID(); $siteid = $this->site->getID(); if (WC_Freeze::isUserFrozenOnSite($userid, $siteid)) { return $this->module->message('msg_frozen', array($this->user->displayUsername(), $this->site->displayName())); } $old_totalscore = $this->user->getVar('user_level'); # Is linked? if (false !== ($row = WC_RegAt::getRegatRow($userid, $siteid))) { # Unlink if (false === WC_RegAt::unlink($userid, $siteid)) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } $this->site->increase('site_linkcount', -1); WC_RegAt::calcTotalscores(); #($this->user); } # Insert event. $rank = WC_RegAt::calcExactRank($this->user); $this->user = GWF_User::getByID($userid); $totalscore = $this->user->getVar('user_level'); WC_HistoryUser2::insertEntry($this->user, $this->site, 'ban', 0, $row->getOnsiteScore(), $totalscore - $old_totalscore); # Insert Freeze if (false === WC_Freeze::freezeUser($userid, $siteid)) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } # All done :) return $this->module->message('msg_frozen', array($this->user->displayUsername(), $this->site->displayName())); }
private function onUnLinkSite($array) { if (false !== ($error = GWF_Form::validateCSRF_WeakS())) { return GWF_HTML::error('WeChall', $error); } if (!is_array($array)) { return ''; } // TODO: Replace with appropiate PHP function foreach ($array as $siteid => $stub) { break; } if (false === ($site = WC_Site::getByID($siteid))) { return $this->module->error('err_site'); } $user = GWF_Session::getUser(); $userid = GWF_Session::getUserID(); $old_totalscore = $user->getVar('user_level'); if (WC_Freeze::isUserFrozen($userid)) { return $this->module->error('err_frozen'); } if (false === ($regat = WC_RegAt::getRegatRow($userid, $site->getID()))) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } if (false === WC_RegAt::unlink($userid, $site->getID())) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } $site->increase('site_linkcount', -1); WC_RegAt::calcTotalscores(); # (GWF_Session::getUser()); $user = GWF_User::getByID($userid); $new_totalscore = $user->getVar('user_level'); require_once GWF_CORE_PATH . 'module/WeChall/WC_HistoryUser2.php'; WC_HistoryUser2::insertEntry($user, $site, 'unlink', 0, $regat->getOnsiteScore(), $new_totalscore - $old_totalscore); return $this->module->message('msg_site_unlinked', array($site->displayName())); }
public function onEdit(WC_Site $site, $is_admin) { $form = $this->getForm($site, $is_admin); if (false !== ($errors = $form->validate($this->module))) { return $errors; } $basescore_changed = $language_changed = $status_changed = $spc_changed = $powarg_changed = false; if ($is_admin) { $basescore_changed = $form->getVar('site_basescore') != $site->getBasescore(); $language_changed = $form->getVar('site_language') !== $site->getLangID(); $status_changed = $form->getVar('site_status') !== $site->getStatus(); $spc_changed = $form->getVar('site_spc') !== $site->getVar('site_spc'); $powarg_changed = $form->getVar('site_powarg') !== $site->getVar('site_powarg'); $site->saveVars(array('site_classname' => $form->getVar('site_classname'), 'site_basescore' => $form->getVar('site_basescore'), 'site_usercount' => $form->getVar('site_usercount'), 'site_challcount' => $form->getVar('site_challcount'), 'site_joindate' => $form->getVar('site_joindate'), 'site_authkey' => $form->getVar('site_authkey'), 'site_status' => $form->getVar('site_status'), 'site_language' => $form->getVar('site_language'), 'site_spc' => $form->getVar('site_spc'), 'site_powarg' => $form->getVar('site_powarg'), 'site_color' => $form->getVar('site_color'))); } $site->saveVars(array('site_name' => $form->getVar('site_name'), 'site_country' => $form->getVar('site_country'), 'site_launchdate' => $form->getVar('site_launchdate'), 'site_xauthkey' => $form->getVar('site_xauthkey'), 'site_irc' => $form->getVar('site_irc'), 'site_url' => $form->getVar('site_url'), 'site_url_mail' => $form->getVar('site_url_mail'), 'site_url_score' => $form->getVar('site_url_score'), 'site_url_profile' => $form->getVar('site_url_profile'))); $site->setVar('site_country', GWF_Country::getByID($form->getVar('site_country'))); $site->setVar('site_language', GWF_Language::getByID($form->getVar('site_language'))); # Update tags if Admin if ($is_admin) { $new_tags = $form->getVar('site_tags'); if ($site->getTags() !== $new_tags) { echo GWF_HTML::message('WeChall', 'Fixing challenge site tags..'); $site->saveVar('site_tags', str_replace(' ', '', $new_tags)); require_once GWF_CORE_PATH . 'module/WeChall/WC_SiteCats.php'; WC_SiteCats::fixCatBits(); } } // $out = $this->onEditWarflag($site, isset($_POST['warenbl'])); $old_linear = $site->isLinear(); $site->saveOption(WC_Site::LINEAR, isset($_POST['linear'])); $linear_changed = $old_linear !== $site->isLinear(); $site->saveOption(WC_Site::NO_URLENCODE, isset($_POST['no_urlencode'])); $site->saveOption(WC_Site::AUTO_UPDATE, isset($_POST['auto_update'])); $site->saveOption(WC_Site::HIDE_BY_DEFAULT, isset($_POST['default_hide'])); $site->saveOption(WC_Site::ONSITE_RANK, isset($_POST['onsite_rank'])); $site->saveOption(WC_Site::NO_V1_SCRIPTS, isset($_POST['no_v1'])); # Trigger warbox config parsing. // if ($site->isWarBox()) // { // // $site->getWarIP(); // Module_WeChall::instance()->flushWarboxConfig(); // } # Recalculate in case of a change // if ($site->isScored()) // { if ($basescore_changed || $language_changed || $status_changed || $powarg_changed || $spc_changed || $linear_changed) { $site->recalcSite(); WC_RegAt::calcTotalscores(); } // } return $this->module->message('msg_site_edited', array($site->displayName())); #.$out; }
/** * Recalc and update all scores for this site. * @return void */ public function recalcSite() { require_once 'WC_RegAt.php'; if (WECHALL_DEBUG_SCORING) { echo WC_HTML::message('msg_site_recalc', array($this->displayName())); } $this->recalcAverage(); $this->recalcScore(); WC_RegAt::calcSite($this); WC_RegAt::calcTotalscores(); }