Advertisement
Guest User

Untitled

a guest
Aug 18th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.27 KB | None | 0 0
  1. #main
  2.  
  3. <?php
  4.  
  5. namespace Fenek912\scSecurity;
  6.  
  7. use pocketmine\command\ConsoleCommandSender;
  8. use pocketmine\event\block\BlockBreakEvent;
  9. use pocketmine\event\block\BlockPlaceEvent;
  10. use pocketmine\event\Listener;
  11. use pocketmine\plugin\PluginBase;
  12. use pocketmine\command\Command;
  13. use pocketmine\command\CommandSender;
  14. use pocketmine\event\player\PlayerMoveEvent;
  15. use pocketmine\event\player\PlayerJoinEvent;
  16. use pocketmine\event\player\PlayerPreLoginEvent;
  17. use pocketmine\event\player\PlayerInteractEvent;
  18. use pocketmine\event\player\PlayerItemConsumeEvent;
  19. use pocketmine\event\player\PlayerCommandPreprocessEvent;
  20. use pocketmine\event\entity\EntityDamageEvent;
  21. use pocketmine\event\inventory\InventoryPickupItemEvent;
  22.  
  23.  
  24. class Main extends PluginBase implements Listener {
  25.  
  26. public function onEnable() {
  27. $this->getLogger()->notice("Loading...");
  28. $this->saveDefaultConfig();
  29. $this->getServer()->getPluginManager()->registerEvents($this, $this);
  30. $credentials = $this->getConfig()->getAll()["mysql"];
  31. $this->db = @new \mysqli($credentials["host"], $credentials["username"], $credentials["passwd"], $credentials["dbname"]);
  32. if($this->db->connect_errno == 0) {
  33. $this->getLogger()->info("Successfully connected to database! (" . $credentials["host"] . ")");
  34. $this->getLogger()->warning("Loading complete!");
  35. } else {
  36. $this->getLogger()->critical("Error while connecting to MySQL database! (" . $this->db->connect_errno . ")");
  37. $this->getLogger()->critical("Stopping server...");
  38. $this->getServer()->dispatchCommand(new ConsoleCommandSender(), "stop");
  39. }
  40. }
  41.  
  42. public function getDatabase() {
  43. return $this->db;
  44. }
  45.  
  46. public function getMessage($name) {
  47. return $this->getConfig()->getAll()["messages"][$name];
  48. }
  49.  
  50. public function getPlayerCode($nameLower) {
  51. return mysqli_fetch_assoc($this->getDatabase()->query("SELECT code FROM scSecurity WHERE player='$nameLower';"))["code"];
  52. }
  53.  
  54. public function getPlayerAddress($nameLower) {
  55. return mysqli_fetch_assoc($this->getDatabase()->query("SELECT address FROM scSecurity WHERE player='$nameLower';"))["address"];
  56. }
  57.  
  58. public function isInMCPE($nameUpper) {
  59. return $this->getDatabase()->query("SELECT id FROM MCPE WHERE nick='$nameUpper';")->num_rows;
  60. }
  61.  
  62. public function isInSecurity($nameLower) {
  63. return $this->getDatabase()->query("SELECT id FROM scSecurity WHERE player='$nameLower';")->num_rows;
  64. }
  65.  
  66. public function getPlayerPass($nameUpper) {
  67. return mysqli_fetch_assoc($this->getDatabase()->query("SELECT haslo FROM MCPE WHERE nick='$nameUpper';"))["haslo"];
  68. }
  69.  
  70. public function onCommand(CommandSender $sender, Command $command, $label, array $args) {
  71. $playerNameUpper = $sender->getName();
  72. $playerNameLower = strtolower($playerNameUpper);
  73. $playerIP__a = $this->getServer()->getPlayer($playerNameUpper)->getAddress();
  74. switch($command->getName()) {
  75. case "z":
  76. if($this->isInMCPE($playerNameUpper) == 1) {
  77. $sender->sendMessage($this->getMessage("alreadyRegistered"));
  78. return true;
  79. }
  80. if(!isset($args[2])) {
  81. $sender->sendMessage($this->getMessage("registerUsage"));
  82. return true;
  83. }
  84. if($args[0] !== $args[1]) {
  85. $sender->sendMessage($this->getMessage("passwordNotMatch"));
  86. return true;
  87. }
  88. if(strlen($args[2]) !== 8) {
  89. $sender->sendMessage($this->getMessage("badCode"));
  90. return true;
  91. }
  92. if(strlen($args[1]) > 20) {
  93. $sender->sendMessage($this->getMessage("tooLong"));
  94. return true;
  95. }
  96. if(strlen($args[1]) < 5) {
  97. $sender->sendMessage($this->getMessage("tooShort"));
  98. return true;
  99. }
  100. if(strtolower($args[2]) !== strtolower($this->getPlayerCode($playerNameLower))) {
  101. $sender->sendMessage($this->getMessage("badCode"));
  102. return true;
  103. }
  104. $this->getDatabase()->query("INSERT INTO MCPE VALUES (NULL, '$playerNameUpper', '" . $args[1] . "', '300', '0', '0', '0', '0', '0', '0', '0', '1', '5');");
  105. $this->getDatabase()->query("UPDATE scSecurity SET `address` = '$playerIP__a' WHERE `player` = '$playerNameLower';");
  106. $sender->sendMessage($this->getMessage("registerSuccess"));
  107. return true;
  108. case "l":
  109. if($this->getPlayerAddress($playerNameLower) == $playerIP__a) {
  110. $sender->sendMessage($this->getMessage("alreadyLogged"));
  111. return true;
  112. }
  113. if($this->isInMCPE($playerNameUpper) == 0) {
  114. $sender->sendMessage($this->getMessage("notRegistered"));
  115. return true;
  116. }
  117. if(!isset($args[0])) {
  118. $sender->sendMessage($this->getMessage("loginUsage"));
  119. return true;
  120. }
  121. if($args[0] !== $this->getPlayerPass($playerNameUpper)) {
  122. $sender->sendMessage($this->getMessage("badPass"));
  123. return true;
  124. }
  125. $this->getDatabase()->query("UPDATE scSecurity SET `address` = '$playerIP__a' WHERE `player` = '$playerNameLower';");
  126. $sender->sendMessage($this->getMessage("loginSuccess"));
  127. return true;
  128. case "przypomnij":
  129. if(!isset($args[0])) {
  130. $sender->sendMessage($this->getMessage("helpUsage"));
  131. return true;
  132. }
  133. if(strlen($args[0]) !== 8) {
  134. $sender->sendMessage($this->getMessage("badCode"));
  135. return true;
  136. }
  137. if($this->isInMCPE($playerNameUpper) == 0) {
  138. $sender->sendMessage($this->getMessage("notRegistered"));
  139. return true;
  140. }
  141. if(strtolower($args[0]) !== strtolower($this->getPlayerCode($playerNameLower))) {
  142. $sender->sendMessage($this->getMessage("badCode"));
  143. return true;
  144. }
  145. $sender->sendMessage(str_replace("%h%", $this->getPlayerPass($playerNameUpper), $this->getMessage("passHelpSuccess")));
  146. return true;
  147. }
  148. }
  149.  
  150. public function newRow(PlayerJoinEvent $e) {
  151. $playerName = $e->getPlayer()->getName();
  152. $length = 8;
  153. $keys = array_merge(range(0,9), range('a', 'z'));
  154. for($i=0; $i < $length; $i++) {
  155. @$key .= $keys[mt_rand(0, count($keys) - 1)];
  156. }
  157. $e->getPlayer()->sendMessage($this->getMessage("welcomeLine1"));
  158. $e->getPlayer()->sendMessage(str_replace("%n%", $playerName, $this->getMessage("welcomeLine2")));
  159. $e->getPlayer()->sendMessage(str_replace("%l%", $this->getDatabase()->query("SELECT id FROM MCPE")->num_rows, $this->getMessage("welcomeLine3")));
  160. $e->getPlayer()->sendMessage($this->getMessage("welcomeLine4"));
  161. $e->getPlayer()->sendMessage($this->getMessage("welcomeLine5"));
  162. if($this->isInMCPE($e->getPlayer()->getName()) == 0) {
  163. if($this->isInSecurity(strtolower($e->getPlayer()->getName())) == 0) {
  164. $this->getDatabase()->query("INSERT INTO scSecurity VALUES (NULL, '$playerName', 'firstQuery', '" . strtolower($key) . "');");
  165. }
  166. $e->getPlayer()->sendMessage(str_replace("%c%", strtoupper($this->getPlayerCode(strtolower($playerName))), $this->getMessage("codeInfo1")));
  167. $e->getPlayer()->sendMessage($this->getMessage("codeInfo2"));
  168. $e->getPlayer()->sendMessage($this->getMessage("needToRegister"));
  169. } else {
  170. if($this->getPlayerAddress(strtolower($playerName)) == $e->getPlayer()->getAddress()) {
  171. $e->getPlayer()->sendMessage($this->getMessage("autoLogin"));
  172. } else {
  173. $e->getPlayer()->sendMessage($this->getMessage("needToLogin"));
  174. }
  175. }
  176. }
  177.  
  178. /* ---------- REPAIR PLAYER KICKS IF ANOTHER ONE IS ONLINE ---------- */
  179.  
  180. public function fixKicks(PlayerPreLoginEvent $e) {
  181. if($this->getServer()->getPlayer($e->getPlayer()->getName())) {
  182. $e->setCancelled(true);
  183. $this->getServer()->getPlayer($e->getPlayer()->getName())->sendMessage($this->getMessage("anotherTry"));
  184. }
  185. }
  186.  
  187. /* ---------- BLOCK EVENTS IF PLAYER IS NOT AUTHENTICATED ---------- */
  188.  
  189. public function blockDefaults(PlayerCommandPreprocessEvent $e) {
  190. if($this->getPlayerAddress(strtolower($e->getPlayer()->getName())) !== $e->getPlayer()->getAddress()) {
  191. $text = explode(" ", $e->getMessage());
  192. if($text[0] !== "/zarejestruj" && $text[0] !== "/zaloguj" && $text[0] !== "/przypomnij") {
  193. $e->setCancelled(true);
  194. if($this->isInMCPE($e->getPlayer()->getName())) {
  195. $e->getPlayer()->sendMessage(str_replace("%k%", $this->getPlayerCode(strtolower($e->getPlayer()->getName())), $this->getMessage("notAuthedNotRegistered")));
  196. } else {
  197. $e->getPlayer()->sendMessage($this->getMessage("notAuthedNotLogged"));
  198. }
  199. }
  200. }
  201. }
  202.  
  203. public function blockMove(PlayerMoveEvent $e) {
  204. if($this->getPlayerAddress(strtolower($e->getPlayer()->getName())) !== $e->getPlayer()->getAddress()) {
  205. $e->setCancelled(true);
  206. if($this->isInMCPE($e->getPlayer()->getName())) {
  207. $e->getPlayer()->sendMessage(str_replace("%k%", $this->getPlayerCode(strtolower($e->getPlayer()->getName())), $this->getMessage("notAuthedNotRegistered")));
  208. } else {
  209. $e->getPlayer()->sendMessage($this->getMessage("notAuthedNotLogged"));
  210. }
  211. }
  212. }
  213.  
  214. public function blockPickup(InventoryPickupItemEvent $e) {
  215. if($this->getPlayerAddress(strtolower($e->getPlayer()->getName())) !== $e->getPlayer()->getAddress()) {
  216. $e->setCancelled(true);
  217. if($this->isInMCPE($e->getPlayer()->getName())) {
  218. $e->getPlayer()->sendMessage(str_replace("%k%", $this->getPlayerCode(strtolower($e->getPlayer()->getName())), $this->getMessage("notAuthedNotRegistered")));
  219. } else {
  220. $e->getPlayer()->sendMessage($this->getMessage("notAuthedNotLogged"));
  221. }
  222. }
  223. }
  224.  
  225. public function blockInteract(PlayerInteractEvent $e) {
  226. if($this->getPlayerAddress(strtolower($e->getPlayer()->getName())) !== $e->getPlayer()->getAddress()) {
  227. $e->setCancelled(true);
  228. if($this->isInMCPE($e->getPlayer()->getName())) {
  229. $e->getPlayer()->sendMessage(str_replace("%k%", $this->getPlayerCode(strtolower($e->getPlayer()->getName())), $this->getMessage("notAuthedNotRegistered")));
  230. } else {
  231. $e->getPlayer()->sendMessage($this->getMessage("notAuthedNotLogged"));
  232. }
  233. }
  234. }
  235.  
  236. public function blockConsume(PlayerItemConsumeEvent $e) {
  237. if($this->getPlayerAddress(strtolower($e->getPlayer()->getName())) !== $e->getPlayer()->getAddress()) {
  238. $e->setCancelled(true);
  239. if($this->isInMCPE($e->getPlayer()->getName())) {
  240. $e->getPlayer()->sendMessage(str_replace("%k%", $this->getPlayerCode(strtolower($e->getPlayer()->getName())), $this->getMessage("notAuthedNotRegistered")));
  241. } else {
  242. $e->getPlayer()->sendMessage($this->getMessage("notAuthedNotLogged"));
  243. }
  244. }
  245. }
  246.  
  247. public function block1(BlockPlaceEvent $e) {
  248. if($this->getPlayerAddress(strtolower($e->getPlayer()->getName())) !== $e->getPlayer()->getAddress()) {
  249. $e->setCancelled(true);
  250. if($this->isInMCPE($e->getPlayer()->getName())) {
  251. $e->getPlayer()->sendMessage(str_replace("%k%", $this->getPlayerCode(strtolower($e->getPlayer()->getName())), $this->getMessage("notAuthedNotRegistered")));
  252. } else {
  253. $e->getPlayer()->sendMessage($this->getMessage("notAuthedNotLogged"));
  254. }
  255. }
  256. }
  257.  
  258. public function block2(BlockBreakEvent $e) {
  259. if($this->getPlayerAddress(strtolower($e->getPlayer()->getName())) !== $e->getPlayer()->getAddress()) {
  260. $e->setCancelled(true);
  261. if($this->isInMCPE($e->getPlayer()->getName())) {
  262. $e->getPlayer()->sendMessage(str_replace("%k%", $this->getPlayerCode(strtolower($e->getPlayer()->getName())), $this->getMessage("notAuthedNotRegistered")));
  263. } else {
  264. $e->getPlayer()->sendMessage($this->getMessage("notAuthedNotLogged"));
  265. }
  266.  
  267. }
  268. }
  269.  
  270.  
  271. }
  272.  
  273. #confing
  274.  
  275. ---
  276. mysql:
  277. host: "127.0.0.1"
  278. username: "root"
  279. passwd: "hrjZBN17WirGgEuy"
  280. dbname: "testowa1337"
  281.  
  282. messages:
  283. alreadyRegistered: "§c* Jestes juz zarejestrowany!"
  284. alreadyLogged: "§c* Jestes juz zalogowany!"
  285. registerUsage: "§b* Poprawne uzycie: /zarejestruj <haslo> <powtorz_haslo> <kod>"
  286. loginUsage: "§b* Poprawne uzycie: /zaloguj <haslo>"
  287. passwordNotMatch: "§e* Hasla nie zgadzaja sie!"
  288. passHelpSuccess: "§d* Twoje haslo to: §l%h%"
  289. badCode: "§c* Podany kod jest niepoprawny!"
  290. autoLogin: "§6* Zostales zalogowany automatycznie!"
  291. badPass: "§c* Niepoprawne haslo!"
  292. anotherTry: "§e* Ktos probuje zalogowac sie na twoje konto!"
  293. notAuthedNotLogged: "§7* Zaloguj sie lub zarejestruj aby wykonac ta czynnosc!"
  294. notAuthedNotRegistered: "§7* Zaloguj sie lub zarejestruj aby wykonac ta czynnosc! %c%"
  295. helpUsage: "§b* Poprawne uzycie: /przypomnij <kod>"
  296. notRegistered: "§6* Nie jestes zarejestrowany!"
  297. tooLong: "§6* Podane haslo jest zbyt dlugie!"
  298. tooShort: "§6* Podane haslo jest zbyt krotkie!"
  299. needToRegister: "§b* Zarejestruj sie komenda: /zarejestruj <haslo> <powtorz_haslo> <kod>"
  300. needToLogin: "§b* Zaloguj sie komenda: /zaloguj <haslo>"
  301. loginSuccess: "§a* Zostales zalogowany!"
  302. registerSuccess: "§a* Zostales zarejestrowany!"
  303. welcomeLine1: "§a* cos1"
  304. welcomeLine2: "§b* cos2 %n%"
  305. welcomeLine3: "§c* cos3 %l%"
  306. welcomeLine4: "§d* cos4"
  307. welcomeLine5: "§e* cos5"
  308. codeInfo1: "§a* Twoj kod to: §l%c%"
  309. codeInfo2: "§d* Zapamietaj go! Przyda ci sie do zresetowania hasla"
  310. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement