diff --git a/README.md b/README.md index 717dc5a..e0dd3de 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ The Infractions module for Nameless v2 allows you to display a list of ingame punishments on your website. ### Supported Plugins +- AdvancedBan - LiteBans If you would like to request plugin support, please open an issue on [GitHub](https://github.com/samerton/Nameless-Infractions/issues). @@ -13,4 +14,4 @@ If you would like to request plugin support, please open an issue on [GitHub](ht ### Installation - Upload the contents of the **upload** directory straight into your NamelessMC installation's directory - Activate the module in the StaffCP -> Modules tab -- Configure your Infractions plugin information in the StaffCP -> Infractions tab \ No newline at end of file +- Configure your Infractions plugin information in the StaffCP -> Infractions tab diff --git a/upload/custom/panel_templates/Default/infractions/index.tpl b/upload/custom/panel_templates/Default/infractions/index.tpl index 9e46b56..87a1203 100644 --- a/upload/custom/panel_templates/Default/infractions/index.tpl +++ b/upload/custom/panel_templates/Default/infractions/index.tpl @@ -81,10 +81,12 @@
-
+
{$DATABASE_SETTINGS}
diff --git a/upload/custom/templates/Default/infractions/infractions.tpl b/upload/custom/templates/Default/infractions/infractions.tpl index d410fcc..5a84d29 100644 --- a/upload/custom/templates/Default/infractions/infractions.tpl +++ b/upload/custom/templates/Default/infractions/infractions.tpl @@ -62,7 +62,7 @@ {$infraction.action} {/if} - {if $infraction.action_id eq 1 OR $infraction.action_id eq 3} + {if $infraction.action_id lte 4} {if $infraction.revoked == 1} {$infraction.revoked_full} {else} diff --git a/upload/custom/templates/DefaultRevamp/infractions/infractions.tpl b/upload/custom/templates/DefaultRevamp/infractions/infractions.tpl index 7a420ad..43507ea 100644 --- a/upload/custom/templates/DefaultRevamp/infractions/infractions.tpl +++ b/upload/custom/templates/DefaultRevamp/infractions/infractions.tpl @@ -46,7 +46,7 @@ {$infraction.action} {/if} - {if $infraction.action_id eq 1 OR $infraction.action_id eq 3} + {if $infraction.action_id lte 4} {if $infraction.revoked == 1} {$infraction.revoked_full} {else} diff --git a/upload/modules/Infractions/classes/AdvancedBan.php b/upload/modules/Infractions/classes/AdvancedBan.php new file mode 100644 index 0000000..4b05f4c --- /dev/null +++ b/upload/modules/Infractions/classes/AdvancedBan.php @@ -0,0 +1,136 @@ + 'Punishments', + 'punishment_history_table' => 'PunishmentHistory' + ); + } + + $this->_extra = $inf_extra['advancedban']; + } + + // Retrieve a list of all infractions, either from cache or database + public function listInfractions($page, $limit){ + // Cached? + $cache = $this->_cache; + $cache->setCache('infractions_infractions'); + if($cache->isCached('infractions' . $page)){ + $mapped_punishments = $cache->retrieve('infractions' . $page); + } else { + $this->initDB(); + + $total = $this->getTotal()->first()->total; + $infractions = $this->listAll($page, $limit)->results(); + + $mapped_punishments = array(); + $staff_usernames = array(); + + $mapped_punishments['total'] = $total; + + if(count($infractions)){ + foreach($infractions as $punishment){ + $staff_uuid = $punishment->operator; + + if(!isset($staff_usernames[$punishment->operator])){ + $staff_query = DB::getInstance()->query('SELECT uuid FROM nl2_users WHERE username = ?', array($punishment->operator)); + if($staff_query->count()){ + $staff_uuid = $staff_query->first()->uuid; + $staff_usernames[$punishment->operator] = $staff_uuid; + } + } else { + $staff_uuid = $staff_usernames[$punishment->operator]; + } + + $mapped_punishments[] = (object) array( + 'id' => $punishment->id, + 'name' => $punishment->name, + 'uuid' => $punishment->uuid, + 'reason' => $punishment->reason, + 'banned_by_uuid' => $staff_uuid, + 'banned_by_name' => $punishment->operator, + 'removed_by_uuid' => '', + 'removed_by_name' => '', + 'removed_by_date' => '', + 'time' => $punishment->start, + 'until' => $punishment->end > 0 ? $punishment->end : null, + 'ipban' => '', + 'active' => $punishment->pstart ? 1 : 0, + 'type' => $this->mapType($punishment->punishmentType) + ); + } + } + + $cache->store('infractions' . $page, $mapped_punishments, 120); + } + + return $mapped_punishments; + } + + // List all infractions + public function listAll($page, $limit){ + $start = ($page - 1) * $limit; + + return $this->_db->query( + $this->getPunishmentQuery() . ' LIMIT ?,?', + array($start, $limit) + ); + } + + // Get total rows + protected function getTotal(){ + return $this->_db->query( + 'SELECT (SELECT COUNT(*) FROM ' . $this->_extra['punishment_history_table'] . ') AS total', array() + ); + } + + // Get bans query + private function getPunishmentQuery(){ + return 'SELECT ph.id, ph.name, ph.uuid, ph.reason, ph.operator, ph.punishmentType, p.start as pstart, ph.start, ph.end' . + ' FROM ' . $this->_extra['punishments_table'] . ' AS p' . + ' RIGHT JOIN (SELECT id, name, uuid, reason, operator, punishmentType, start, end FROM ' . $this->_extra['punishment_history_table'] . ') AS ph ON p.start = ph.start' . + ' WHERE ph.punishmentType <> \'IP_BAN\' ORDER BY ph.start DESC'; + } + + // Map punishment type + private function mapType($type){ + switch($type){ + case 'BAN': + case 'IP_BAN': + return 'ban'; + + case 'KICK': + return 'kick'; + + case 'MUTE': + return 'mute'; + + case 'WARNING': + return 'warning'; + } + + return 'unknown'; + } +} diff --git a/upload/modules/Infractions/extra.php b/upload/modules/Infractions/extra.php index 984dbaf..126f51f 100644 --- a/upload/modules/Infractions/extra.php +++ b/upload/modules/Infractions/extra.php @@ -9,5 +9,9 @@ 'mutes_table' => 'litebans_mutes', 'warnings_table' => 'litebans_warnings', 'history_table' => 'litebans_history' - ) -); \ No newline at end of file + ), + 'advancedban' => array( + 'punishments_table' => 'Punishments', + 'punishment_history_table' => 'PunishmentHistory' + ) +); diff --git a/upload/modules/Infractions/module.php b/upload/modules/Infractions/module.php index 478ea01..2244aa3 100644 --- a/upload/modules/Infractions/module.php +++ b/upload/modules/Infractions/module.php @@ -2,7 +2,7 @@ /* * Made by Samerton and Partydragen * https://github.com/samerton/Nameless-Infractions - * NamelessMC version 2.0.0-pr6 + * NamelessMC version 2.0.0-pr7 * * License: MIT * @@ -19,7 +19,7 @@ public function __construct($language, $infractions_language, $pages, $cache){ $name = 'Infractions'; $author = 'Samerton'; - $module_version = '1.0.0'; + $module_version = '1.1.0'; $nameless_version = '2.0.0-pr7'; parent::__construct($this, $name, $author, $module_version, $nameless_version); diff --git a/upload/modules/Infractions/pages/infractions.php b/upload/modules/Infractions/pages/infractions.php index 72603e8..a631842 100644 --- a/upload/modules/Infractions/pages/infractions.php +++ b/upload/modules/Infractions/pages/infractions.php @@ -39,6 +39,11 @@ require_once(ROOT_PATH . '/modules/Infractions/classes/LiteBans.php'); $infractions = new LiteBans($inf_db, $infractions_language); break; + case 'advancedban': + // AdvancedBan integration + require_once(ROOT_PATH . '/modules/Infractions/classes/AdvancedBan.php'); + $infractions = new AdvancedBan($inf_db, $infractions_language); + break; default: die('Plugin not supported!'); break; diff --git a/upload/modules/Infractions/pages/panel/index.php b/upload/modules/Infractions/pages/panel/index.php index cc7f7e8..b35a83a 100644 --- a/upload/modules/Infractions/pages/panel/index.php +++ b/upload/modules/Infractions/pages/panel/index.php @@ -22,7 +22,7 @@ die(); } else { if(!$user->hasPermission('admincp.infractions.settings')){ - require_once(ROOT_PATH . '/404.php'); + require_once(ROOT_PATH . '/403.php'); die(); } } @@ -149,6 +149,18 @@ 'ERRORS_TITLE' => $language->get('general', 'error') )); +// Plugin options +$plugin_options = array( + array( + 'name' => 'LiteBans', + 'value' => 'litebans' + ), + array( + 'name' => 'AdvancedBan', + 'value' => 'advancedban' + ) +); + $smarty->assign(array( 'PARENT_PAGE' => PARENT_PAGE, 'PAGE' => PANEL_PAGE, @@ -158,6 +170,7 @@ 'DATABASE_SETTINGS' => $infractions_language->get('infractions', 'database_settings'), 'PLUGIN' => $infractions_language->get('infractions', 'plugin'), 'PLUGIN_VALUE' => (!empty($inf_config['plugin']) ? Output::getClean($inf_config['plugin']) : 'litebans'), + 'PLUGIN_OPTIONS' => $plugin_options, 'LINK_LOCATION' => $infractions_language->get('infractions', 'link_location'), 'LINK_LOCATION_VALUE' => $link_location, 'LINK_NAVBAR' => $language->get('admin', 'page_link_navbar'), @@ -173,7 +186,6 @@ 'PORT' => $infractions_language->get('infractions', 'database_port'), 'PORT_VALUE' => (!empty($inf_db['port']) ? Output::getClean($inf_db['port']) : '3306'), 'PASSWORD' => $infractions_language->get('infractions', 'database_password'), - 'INFO' => $language->get('general', 'info'), 'PASSWORD_HIDDEN' => $language->get('admin', 'email_password_hidden'), 'TOKEN' => Token::get(), 'SUBMIT' => $language->get('general', 'submit')