public function savePlayer(IPlayer $player, array $config) { $name = trim(strtolower($player->getName())); $data = new Config($this->plugin->getDataFolder() . "players/" . $name[0] . "/{$name}.yml", Config::YAML); $data->setAll($config); $data->save(); }
public function onEnable() { $this->getServer()->getPluginManager()->registerEvents(new Listener(), $this); $this->simpleAuth = $this->getServer()->getPluginManager()->getPlugin("SimpleAuth"); if ($this->simpleAuth) { $this->getLogger()->info("Enabling support with SimpleAuth " . $this->simpleAuth->getDescription()->getVersion() . "!"); } $this->saveDefaultConfig(); }
public function __construct(EmailAuth $plugin) { $this->plugin = $plugin; if (!file_exists($this->plugin->getDataFolder() . "players.db")) { $this->database = new \SQLite3($this->plugin->getDataFolder() . "players.db", SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE); $resource = $this->plugin->getResource("sqlite3.sql"); $this->database->exec(stream_get_contents($resource)); fclose($resource); } else { $this->database = new \SQLite3($this->plugin->getDataFolder() . "players.db", SQLITE3_OPEN_READWRITE); } }
/** * @param InventoryPickupItemEvent $event * * @priority LOWEST */ public function onPickupItem(InventoryPickupItemEvent $event) { $player = $event->getInventory()->getHolder(); if ($player instanceof Player and !$this->auth->isPlayerAuthenticated($player)) { $event->setCancelled(true); } }
/** * @param PlayerChatEvent $event */ public function onChat(PlayerChatEvent $event) { if ($this->getServer()->getPluginManager()->getPlugin("SimpleAuth")) { if (!$this->simpleauth->isPlayerAuthenticated($event->getPlayer())) { return false; } } $player = $event->getPlayer(); $message = $event->getMessage(); $strlen = strlen($message); $asciiA = ord("A"); $asciiZ = ord("Z"); $count = 0; for ($i = 0; $i < $strlen; $i++) { $char = $message[$i]; $ascii = ord($char); if ($asciiA <= $ascii and $ascii <= $asciiZ) { $count++; } } if (!$player->hasPermission("capslimit.exception")) { if ($count > $this->getMaxCaps() and $this->getConfig()->get("mode") == "block") { $event->setCancelled(true); $player->sendMessage($this->getPrefix() . TextFormat::RED . "You used too much caps!"); } elseif ($count > $this->getMaxCaps() and $this->getConfig()->get("mode") === "lowercase") { $event->setMessage(strtolower($message)); } elseif ($count > $this->getMaxCaps() and $this->getConfig()->get("mode") === "kick") { $event->setCancelled(true); $player->kick("You have been kicked for overused caps!"); } if ($count > $this->getMaxCaps() and $this->getConfig()->getNested("broadcast.enable") === true) { foreach ($this->getServer()->getOnlinePlayers() as $p) { $subject = $this->getConfig()->getNested("broadcast.message"); $p->sendMessage($this->getPrefix() . TextFormat::RED . str_replace("{PLAYER}", $player->getName(), $subject)); } } else { return false; } } }
ini_set('display_errors', true);*/ // adminsetup is within the admin directory - this will load the main setup.php as well require_once "adminsetup.php"; // message is used to provide feedback to the user //eg. if we get here from an expired session $message = ''; // Authentication class required for admin functions require_once $include_dir . "SimpleAuth.php"; // add this here as not required for some pages (which use Quiz.php instead) require_once $include_dir . "Quizzes.php"; // must add this before we require the menu $admin_menu = 'home'; /*** Authentication ***/ // user must be logged in for any admin functions // this needs to be before we output anything as it uses sessions (cookies) $auth = new SimpleAuth($settings->getSetting('admin_login_username'), $settings->getSetting('admin_login_password'), $settings->getSetting('admin_login_expirytime')); // if not logged in redirect to login page $status = $auth->checkLogin(); if ($status != 1) { // no from as use default which goes back to this page header("Location: " . ADMIN_LOGIN_FILE . "?status={$status}&location=aupgrade"); // header will redirect to a new page so we just close this script exit(0); //Important to stop script here } // If we reach here then login was successful $sessionUsername = $auth->getUser(); // Have we get the filename of the old version in the post if (isset($_POST['oldfile']) && $_POST['oldfile'] != "") { $oldfile = $_POST['oldfile']; // check that the file exists
$settings->loadSettings($qdb); // Does the password setting have an entry if ($settings->getSetting('admin_login_password') != '') { displayComplete($status_msg); exit(0); } // If not then are we saving existing post if (isset($_POST['action']) && $_POST['action'] == 'savesettings') { // do passwords match if ($_POST['password'] != $_POST['passwordrepeat']) { displaySettingsForm("Passwords don't match"); exit(0); } // we use the SimpleAuth class, but note we are creating with dummy username & password require_once $app_dir . "/includes/SimpleAuth.php"; $auth = new SimpleAuth('', '', 3600); // run username & password through security / valid char checks if ($auth->securityCheck('username', $_POST['username']) && $auth->securityCheck('password', $_POST['username'])) { // add details // add login / password to the settings array $quiz_settings['admin_login_username'] = $_POST['username']; $quiz_settings['admin_login_password'] = md5($_POST['password']); foreach ($quiz_settings as $key => $value) { if (!$qdb->insertSetting($key, $value)) { displayDbError("Error adding setting {$key}"); exit(0); } } $status_msg .= "\nSettings added to database<br />\n\n"; } else { displaySettingsForm("Invalid characters used in the username or password");
$min_password_chars = 6; // message is used to provide feedback to the user //eg. if we get here from an expired session $message = ''; // must add this before we require the menu $admin_menu = 'home'; // have we successfully changed (if so don't show password change option $password_changed = false; // adminsetup is within the admin directory - this will load the main setup.php as well require_once "adminsetup.php"; // Authentication class required for admin functions require_once $include_dir . "SimpleAuth.php"; /*** Authentication ***/ // user must be logged in for any admin functions // this needs to be before we output anything as it uses sessions (cookies) $auth = new SimpleAuth($settings->getSetting('admin_login_username'), $settings->getSetting('admin_login_password'), $settings->getSetting('admin_login_expirytime')); // if not logged in redirect to login page $status = $auth->checkLogin(); if ($status != 1) { // no from as use default which goes back to this page header("Location: " . ADMIN_LOGIN_FILE . "?status={$status}"); // header will redirect to a new page so we just close this script exit(0); //Important to stop script here } // If we reach here then login was successful $sessionUsername = $auth->getUser(); // header template $templates->includeTemplate('header', 'admin'); require_once $include_dir . "adminmenu.php"; print "<div id=\"" . CSS_ID_ADMIN_MAIN . "\">\n";
// Enable debugging error_reporting(E_ALL); ini_set('display_errors', true); // message is used to provide feedback to the user //eg. if we get here from an expired session $message = ''; require_once "adminsetup.php"; // Authentication class required for admin functions require_once $include_dir . "SimpleAuth.php"; // Array of valid goto / location entries // prefixed with a in case we want to use authentication in main quiz in future // uses the #define entries - so put after setup $locations = array('aindex' => ADMIN_FILE, 'aquestions' => ADMIN_Q_FILE, 'aupgrade' => ADMIN_UPGRADE_FILE); // create authentication object // this needs to be before we output anything as it uses sessions (cookies) $auth = new SimpleAuth($settings->getSetting('admin_login_username'), $settings->getSetting('admin_login_password'), $settings->getSetting('admin_login_expirytime')); /*** Authentication - Is this a login attempt (ie. with username & password) ***/ // note we only exit if we successfully login - otherwise we continue with showing login form if (isset($_POST['username']) && isset($_POST['password'])) { // check that they are only using valid characters if ($auth->securityCheck('username', $_POST['username']) && $auth->securityCheck('password', $_POST['password'])) { //check login is correct if ($auth->loginNow($_POST['username'], $_POST['password'])) { // do we have a valid return location - if so go there, otherwise back to admin index page if (isset($_POST['location']) && $auth->securityCheck('location', $_POST['location'], $locations)) { $goto = $_POST['location']; // goto new location header("Location: " . $locations[$goto]); exit(0); // need to stop script after redirected } else {
**/ // Enable debugging error_reporting(E_ALL); ini_set('display_errors', true); //$debug = true; // message is used to provide feedback to the user //eg. if we get here from an expired session $message = ''; // adminsetup is within the admin directory - this will load the main setup.php as well require_once "adminsetup.php"; // Authentication class required for admin functions require_once $include_dir . "SimpleAuth.php"; /*** Are we logged in? ***/ // user must be logged in for any admin functions // this needs to be before we output anything as it uses sessions (cookies) $auth = new SimpleAuth($settings->getSetting('admin_login_username'), $settings->getSetting('admin_login_password'), $settings->getSetting('admin_login_expirytime')); $status = $auth->checkLogin(); if ($status != 1) { // if not logged in just go to index page header("Location: " . ADMIN_FILE . "?status={$status}"); // header will redirect to a new page so we just close this script exit(0); //Important to stop script here } // If we reach here then login was successful $sessionUsername = $auth->logout(); // redirect to the first page header("Location: " . ADMIN_FILE . "?status={$status}"); // header will redirect to a new page so we just close this script exit(0); //Important to stop script here