This repository has been archived by the owner on Jun 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
177 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.