Skip to content
This repository has been archived by the owner on Jun 12, 2018. It is now read-only.

Commit

Permalink
v1.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
DaPigGuy committed Oct 3, 2016
1 parent 3d4b44f commit 4871f0e
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 121 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ Safe & feature-rich auth plugin.

# Changelog

###v1.0.7
* Preparation for MySQL support!MySQL support!
* Fixed messages
* Xbox bypass (not finished)

###v1.0.6
* You can now use & for color codes

Expand Down
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: PiggyAuth
main: PiggyAuth\Main
version: 1.0.6
version: 1.0.7
api: [2.0.0]
load: POSTWORLD
author: MCPEPIG
Expand Down
9 changes: 6 additions & 3 deletions resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ blindness: true
see-messages: false
#If enabled, players joining when another player has their username is kicked
single-session: true
#If enabled, only players with xbox can login (ClearSky only!)
xbox-only: false
#If enabled, players with logged in with xbox are automatically registered/logged in. (ClearSky only!)
xbox-bypass: false
#Database (sqlite3)
database: sqlite3
#Version
version: v1.0.5
version: v1.0.7

#Messages

Expand All @@ -65,6 +67,7 @@ register: "&6Please register by typing in /register <password>"
register-popup: "&6Please register."
register-tip: "&6Please register."
register-success: "&aYou have been registered. Your pin is {pin}."
auto-register: "&aYou were automatically registered. Your password is {password}. Change it with /changepassword."
already-registered: "&cYou are already registered."
password-too-short: "&cPassword is too short."
password-not-match: "&cYour password is not the same."
Expand Down
2 changes: 1 addition & 1 deletion src/PiggyAuth/Commands/PinCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function execute(CommandSender $sender, $currentAlias, array $args) {
$sender->sendMessage("§cYou must use the command in-game.");
return false;
}
$sender->sendMessage(str_replace("{pin}", $this->plugin->getPin($sender), $this->plugin->getConfig()->get("pin")));
$sender->sendMessage(str_replace("{pin}", $this->plugin->database->getPin($sender->getName()), $this->plugin->getMessage("pin")));
return true;
}

Expand Down
16 changes: 16 additions & 0 deletions src/PiggyAuth/Databases/Database.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
namespace PiggyAuth\Databases;

interface Database {
public function getPlayer($player);

public function updatePlayer($player, $password, $pin, $uuid, $attempts);

public function getPin($player);

public function getPassword($player);

public function getUUID($player);

public function getAttempts($player);
}
92 changes: 92 additions & 0 deletions src/PiggyAuth/Databases/SQLite3.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php
namespace PiggyAuth\Databases;

use PiggyAuth\Main;

class SQLite3 implements Database {
public $plugin;
public $db;

public function __construct(Main $plugin, $outdated) {
if(!file_exists($plugin->getDataFolder() . "players.db")) {
$this->db = new \SQLite3($plugin->getDataFolder() . "players.db", SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE);
$this->db->exec("CREATE TABLE players (name TEXT PRIMARY KEY, password TEXT, pin INT, uuid INT, attempts INT);");
} else {
$this->db = new \SQLite3($plugin->getDataFolder() . "players.db", SQLITE3_OPEN_READWRITE);
//Updater
}
if($outdated) {
$this->db->exec("ALTER TABLE players ADD COLUMN pins INT"); //Just in case :P
$this->db->exec("ALTER TABLE players ADD COLUMN attempts INT");
}
}

public function getPlayer($player) {
$player = strtolower($player);
$statement = $this->db->prepare("SELECT * FROM players WHERE name = :name");
$statement->bindValue(":name", $player, SQLITE3_TEXT);
$result = $statement->execute();
if($result instanceof \SQLite3Result) {
$data = $result->fetchArray(SQLITE3_ASSOC);
$result->finalize();
if(isset($data["name"])) {
unset($data["name"]);
$statement->close();
return $data;
}
}
$statement->close();
return null;
}

public function updatePlayer($player, $password, $pin, $uuid, $attempts) {
$statement = $this->db->prepare("UPDATE players SET pin = :pin, password = :password, uuid = :uuid, attempts = :attempts WHERE name = :name");
$statement->bindValue(":name", strtolower($player), SQLITE3_TEXT);
$statement->bindValue(":password", $password, SQLITE3_TEXT);
$statement->bindValue(":pin", $pin, SQLITE3_INTEGER);
$statement->bindValue(":uuid", $uuid, SQLITE3_INTEGER);
$statement->bindValue(":attempts", $attempts, SQLITE3_INTEGER);
$statement->execute();
}

public function getPin($player) {
$data = $this->getPlayer($player);
if(!is_null($data)) {
if(!isset($data["pin"])) {
$pin = mt_rand(1000, 9999); //If you use $this->generatePin(), there will be issues!
$this->updatePlayer($player, $pin, $this->getPassword($player), $this->getUUID($player), $this->getAttempts($player));
return $pin;
}
return $data["pin"];
}
return null;
}

public function getPassword($player) { //ENCRYPTED!
$data = $this->getPlayer($player);
if(!is_null($data)) {
return $data["password"];
}
return null;
}

public function getUUID($player) {
$data = $this->getPlayer($player);
if(!is_null($data)) {
return $data["uuid"];
}
return null;
}

public function getAttempts($player) {
$data = $this->getPlayer($player);
if(!is_null($data)) {
if(!isset($data["attempts"])) {
$this->updatePlayer($player, $this->getPin($player), $this->getPassword($player), $this->getUUID($player), 0);
return 0;
}
return $data["attempts"];
}
return null;
}
}
31 changes: 16 additions & 15 deletions src/PiggyAuth/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,23 @@ public function onJoin(PlayerJoinEvent $event) {
$effect->setVisible(false);
$player->addEffect($effect);
}
if($this->plugin->getConfig()->get("auto-authentication")) {
$data = $this->plugin->getPlayer($player->getName());
if(!is_null($data)) {
if($player->getUniqueId()->toString() == $data["uuid"]) {
$this->plugin->force($player);
return true;
}
$data = $this->plugin->database->getPlayer($player->getName());
if($this->plugin->getConfig()->get("auto-authentication") && !is_null($data) && $player->getUniqueId()->toString() == $data["uuid"]) {
$this->plugin->force($player);
return true;
}
if($this->plugin->getConfig()->get("xbox-bypass") && $this->plugin->getServer()->getName() == "ClearSky" && $player->isAuthenticated()) {
$characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
$randompassword = [];
$characteramount = strlen($alphabet) - 1;
for($i = 0; $i < $this->getConfig()->get("minimum-password-length") - 1; $i++) {
$character = mt_rand(0, $alphaLength);
array_push($randompassword, $characters[$character]);
}
$randompassword = implode($randompassword);
$this->plugin->register($player, $randompassword, $randompassword);
$player->sendMessage(str_replace("{password}", $randompassword, $this->plugin->getMessage("auto-registered")));
return true;
}
$this->plugin->getServer()->getScheduler()->scheduleDelayedTask(new TimeoutTask($this->plugin, $player), $this->plugin->getConfig()->get("timeout") * 20);
}
Expand All @@ -214,14 +223,6 @@ public function onPrelogin(PlayerPreLoginEvent $event) {
$event->setCancelled();
}
}
if($this->plugin->getConfig()->get("xbox-only")) {
if($this->plugin->getServer()->getName() == "ClearSky") {
if(!$player->isXboxAuthenticated()) {
$player->close("", "You must use Xbox to login.");
$event->setCancelled();
}
}
}
}

public function onQuit(PlayerQuitEvent $event) {
Expand Down
Loading

0 comments on commit 4871f0e

Please sign in to comment.