Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option to disable cheat guard #58

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backup/moodle2/backup_xp_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected function define_structure() {
$xpconfig = new backup_nested_element('config', array('courseid'), array(
'enabled', 'enablelog', 'keeplogs', 'levels', 'lastlogpurge', 'enableladder', 'enableinfos', 'levelsdata',
'enablelevelupnotif', 'enablecustomlevelbadges', 'maxactionspertime', 'timeformaxactions', 'timebetweensameactions',
'identitymode', 'rankmode', 'neighbours'
'identitymode', 'rankmode', 'neighbours', 'enablecheatguard'
));
$xpfilters = new backup_nested_element('filters');
$xpfilter = new backup_nested_element('filter', array('courseid'), array('ruledata', 'points', 'sortorder'));
Expand Down
9 changes: 6 additions & 3 deletions classes/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class block_xp_manager {
'levels' => 10,
'enablelog' => 1,
'keeplogs' => 3,
'enablecheatguard' => true, // Enable cheat guard.
'enableladder' => true, // Enable the ladder.
'enableinfos' => true, // Enable the infos page.
'levelsdata' => '', // JSON encoded value of the levels data.
Expand Down Expand Up @@ -251,9 +252,11 @@ public function capture_event(\core\event\base $event) {
return;
}

// Check if the user can capture this event, anti cheater method.
if (!$this->can_capture_event($event)) {
return;
if ($this->get_config('enablecheatguard')) {
// Check if the user can capture this event, anti cheater method.
if (!$this->can_capture_event($event)) {
return;
}
}

$userid = $event->userid;
Expand Down
6 changes: 6 additions & 0 deletions classes/settings_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,26 @@ public function definition() {

$mform->addElement('header', 'hdrcheating', get_string('cheatguard', 'block_xp'));

$mform->setDefault('enablecheatguard', $defaultconfig->enablecheatguard);
$mform->addElement('selectyesno', 'enablecheatguard', get_string('enablecheatguard', 'block_xp'));

$mform->addElement('text', 'maxactionspertime', get_string('maxactionspertime', 'block_xp'));
$mform->setDefault('maxactionspertime', $defaultconfig->maxactionspertime);
$mform->addHelpButton('maxactionspertime', 'maxactionspertime', 'block_xp');
$mform->setType('maxactionspertime', PARAM_INT);
$mform->disabledIf('maxactionspertime','enablecheatguard', 'eq', 0);

$mform->addElement('text', 'timeformaxactions', get_string('timeformaxactions', 'block_xp'));
$mform->setDefault('timeformaxactions', $defaultconfig->timeformaxactions);
$mform->addHelpButton('timeformaxactions', 'timeformaxactions', 'block_xp');
$mform->setType('timeformaxactions', PARAM_INT);
$mform->disabledIf('timeformaxactions','enablecheatguard', 'eq', 0);

$mform->addElement('text', 'timebetweensameactions', get_string('timebetweensameactions', 'block_xp'));
$mform->setDefault('timebetweensameactions', $defaultconfig->timebetweensameactions);
$mform->addHelpButton('timebetweensameactions', 'timebetweensameactions', 'block_xp');
$mform->setType('timebetweensameactions', PARAM_INT);
$mform->disabledIf('timebetweensameactions','enablecheatguard', 'eq', 0);

$mform->addElement('header', 'hdrloggin', get_string('logging', 'block_xp'));

Expand Down
3 changes: 2 additions & 1 deletion db/install.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="blocks/xp/db" VERSION="20160224" COMMENT="XMLDB file for Moodle blocks/xp"
<XMLDB PATH="blocks/xp/db" VERSION="20170214" COMMENT="XMLDB file for Moodle blocks/xp"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you used the XMLDB Editor tool under Site administration > Development. The latter takes care of maintaining that XML file, it also providers the PHP upgrade code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I wish I had known before... I could not agree more with the XMDLB Editor page:

"It makes the editing of tables/fields/keys/indexes almost a trivial task, allowing developers to spend the time coding and improving things instead of fighting with XML files and the errors caused by manual editing (of course, developers are free to use such extra time as desired - beers, dance, books, music...) ;-)"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
Expand Down Expand Up @@ -45,6 +45,7 @@
<FIELD NAME="keeplogs" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="levels" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="lastlogpurge" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="enablecheatguard" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" SEQUENCE="false"/>
<FIELD NAME="enableladder" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" SEQUENCE="false" COMMENT="Enable the ladder"/>
<FIELD NAME="enableinfos" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" SEQUENCE="false" COMMENT="Enable the infos page"/>
<FIELD NAME="levelsdata" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="The data related to the levels"/>
Expand Down
15 changes: 15 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,21 @@ function xmldb_block_xp_upgrade($oldversion) {
upgrade_block_savepoint(true, 2016022403, 'xp');
}

if ($oldversion < 2017021401) {

// Define field enablecheatguard to be added to block_xp_config.
$table = new xmldb_table('block_xp_config');
$field = new xmldb_field('enablecheatguard', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'lastlogpurge');

// Conditionally launch add field enablecheatguard.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

// Xp savepoint reached.
upgrade_block_savepoint(true, 2017021401, 'xp');
}

return true;

}
1 change: 1 addition & 0 deletions lang/en/block_xp.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
$string['displayparticipantsidentity'] = 'Display participants identity';
$string['displayrank'] = 'Display rank';
$string['displayrelativerank'] = 'Display a relative rank';
$string['enablecheatguard'] = 'Enable cheat guard';
$string['enableinfos'] = 'Enable infos page';
$string['enableinfos_help'] = 'When set to \'No\', students will not be able to view the infos page.';
$string['enableladder'] = 'Enable the ladder';
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2016032700;
$plugin->version = 2017021401;
$plugin->requires = 2014041500;
$plugin->component = 'block_xp';
$plugin->maturity = MATURITY_STABLE;
Expand Down