Hello everyone. I am currently working on a plugin called "Clans" (as some of you already know), but I'm getting some help on it, and am waiting for some people to get back to me. In the mean time, I've decided that I'm going to make an auth plugin that makes you register at the servers website before playing. The plugin will be called "SAM". In case you're wondering SAM stands for "Simple Authorization Mechanism". Anyway I need help getting some code to connect SAM with the Pocketmine server and the website. Could anyone please help?
The way I connect the code with the website is sort of complex. Create a scheduled repeating task that will connect to the specified domain and attempt to find a file (I use something like connect.txt). If the server doesn't find the file, then do nothing. It will repeatedly check that file in the domain. Then, when a player registers on the website, make the file on the domain side (connect.txt), and set it to a value. The PocketMine server should detect this file, with the value, and react. You should then create a file (perhaps something.json) that the PocketMine server will check for on the domain. Once the PocketMine server finds this file (something.json), it should get the contents of the JSON file and get the encoded login information you put inside it. Finally, delete the connect.txt and the something.json files. It's sort of complex, but that's one solution I use to connect the PocketMine server to a website.
Okay, thank you. So what about this for the config.yml? PHP: #SAM plugin default configuration---#Keep logged in by IPIPLogin: true#Force single authenticationforce-single-auth: true#Allow not authenticated users to moveallow-move: true#Block chat for not authenticated usersblock-chat: true#Block commands for not authenticated usersblock-commands: true#Block all eventsblock-all-events: true#Login/Register timeouttimeout: 120#Minimum password lengthminPasswordLength: 6#Maximum password lengthmaxPasswordLength: 16#Login settingsregister:#Enable register for serverenabled: true#Website domain namedomain: website.comlogin: #Enable login on your server enabled: true\
Okay, cool. So how's this for the plugin.yml? PHP: name: SAMmain: SAM\SAMversion: "1.0.0"api: [1.11.0]author: Edwardthedog2description: Pocketmine auth plugin for signing up at the servers website.commands:login: description: Logs in to an existing account. permission: sam.login
If you're using latest PocketMine, api is 1.13.0 or 2.0.0. Also, don't use "" for version. Just type version number in.
Okay, so I fixed that. Also, when someone logs in for the first time I want this message to appear in chat: "This server uses SAM by Edwardthedog2. You must register at http://serverssite.com to play." How do I do that?
Add the following into your code: - implement Listener to your main class. - make sure to use pocketmine\event\Listener and pocketmine\event\player\PlayerJoinEvent. - on PlayerJoinEvent, detect if a player file (playername.txt?) is in your DataFolder. (is_file()) - on registration, in that function I provided, make a text file (playername.txt?) in the DataFolder. (fopen()) - on PlayerJoinEvent, if the file (playername.txt?) is found, let player in, else, kick the player with a message. (kick())
Okay, I think I can do that. Also, I'm having trouble making the login command. I've got the following so far. PHP: <?phpnamespace SAM;use pocketmine\command\Command;use pocketmine\command\ComamndSender;class LoginCommand public function onCommand(CommandSender $sender, Command $command, $label, array $args){ $commandName = $command->getName(); if($commandName === "login"){ return true; } return false;
Oh okay, I see, thank you for pointing that out. But now I need a lot of help. Whenever I test the plugin, on my Pocketmine server I have specifically for testing plugins, the server always crashes.
Okay then. plugin.yml PHP: name: SAMmain: SAM\SAMversion: 1.0.0api: [1.13.0]author: Edwardthedog2description: Pocketmine auth plugin for signing up at the servers website.commands:login: description: "This is a test command" usage: "/login <password>" permission: sam.login Web.php PHP: <?php// this is the plugin file.namespace sam;use pocketmine\plugin\PluginBase;use pocketmine\scheduler\PluginTask;class sam extends PluginBase { public function onEnable(){ $this->getServer()->getScheduler()->scheduleRepeatingTask(new Task($this), 20); } public function action($array){ $username = $array["username"]; // username $password = $array["password"]; // password // whatever script below. }}class Task extends PluginTask { public $plugin; public function __construct($plugin){ $this->plugin = $plugin; $this->start = false; parent::__construct($plugin); } public function onRun($ticks){ if ($this->start){ $requesturl = "yourdomain.com/the/core/directory/to/your/file/example.txt"; $file_headers = @get_headers($requesturl); if($file_headers[0] == 'HTTP/1.1 404 Not Found'){ $file_exists = false; } else { $file_exists = true; } if ($file_exists === true){ $data = json_decode(file_get_contents("yourdomain.com/the/core/directory/to/your/file/data.json"), true); if (isset($data["username"])){ $this->plugin->action($data); } } } else{ $this->start = true; } }}?><?php// this is what can go onto the webserver.// if you are putting this directly, please pass information as post.$username = $_POST["username"];$password = $_POST["password"];if (is_file("example.txt")){ unlink("example.txt");}$data = fopen("example.txt", "w+");fwrite($data, "open"); // whatever value works ;)fclose($data);$login = fopen("data.json", "w+");fwrite($login, json_encode(array("username" => $username, "pswd" => $password)));fclose($login);// make sure to delete those files after.?> LoginCommand.php PHP: <?phpnamespace SAM;use pocketmine\command\Command;use pocketmine\command\ComamndSender;class LoginCommand public function onCommand(CommandSender $sender, Command $command, $label, array $args){ $commandName = $command->getName(); if($commandName === "login"){ return true; } return false; } And SAM.php PHP: <?phpnamespace SAM;use pocketmine\plugin\PluginBase;class MyPlugin extends PluginBase{}
PHP: <?phpnamespace SAM;use pocketmine\command\Command;use pocketmine\command\ComamndSender;class LoginCommand{//herepublic function onCommand(CommandSender $sender, Command $command, $label, array $args){$commandName = $command->getName(); if($commandName === "login"){ return true; } return false; }}//and here