Advertisement
Guest User

Untitled

a guest
Jul 11th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Kitsune\ClubPenguin;
  4.  
  5. use Kitsune\Logging\Logger;
  6. use Kitsune\DatabaseManager;
  7. use Kitsune\ClubPenguin\Packets\Packet;
  8.  
  9. final class Login extends ClubPenguin {
  10.  
  11. public $worldManager;
  12.  
  13. public $loginAttempts;
  14.  
  15. public function __construct() {
  16. parent::__construct();
  17.  
  18. Logger::Fine("Login server is online");
  19. }
  20.  
  21. public function discordwebhook($content)
  22. {
  23. $curl = curl_init("Removed for safety");
  24.  
  25. curl_setopt_array($curl, [
  26. CURLOPT_RETURNTRANSFER => true,
  27. CURLOPT_SSL_VERIFYPEER => false,
  28. CURLOPT_SSL_VERIFYHOST => false,
  29.  
  30. CURLOPT_USERAGENT => 'Mozilla/5.0 (+https://flash.moe)',
  31. CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
  32.  
  33. CURLOPT_POST => true,
  34. CURLOPT_POSTFIELDS => json_encode($content),
  35. ]);
  36.  
  37. curl_exec($curl);
  38. }
  39.  
  40. protected function handleLogin($socket) {
  41. $penguin = $this->penguins[$socket];
  42.  
  43. if($penguin->handshakeStep !== "randomKey") {
  44. return $this->removePenguin($penguin);
  45. }
  46.  
  47. $this->databaseManager->add($penguin);
  48.  
  49. $username = Packet::$Data['body']['login']['nick'];
  50. $password = Packet::$Data['body']['login']['pword'];
  51.  
  52. if($penguin->database->usernameExists($username) === false) {
  53. $penguin->send("%xt%e%-1%100%");
  54. return $this->removePenguin($penguin);
  55. }
  56.  
  57. $penguinData = $penguin->database->getColumnsByName($username, array("ID", "Username", "Password", "Banned"));
  58. $encryptedPassword = Hashing::getLoginHash($penguinData["Password"], $penguin->randomKey);
  59.  
  60. if($encryptedPassword != $password) {
  61.  
  62. if(!isset($this->loginAttempts[$penguin->ipAddress])) { // helps prevent the flooding of login attempts
  63. $this->loginAttempts[$penguin->ipAddress][$username] = array(time(), 1);
  64. } else {
  65. list($previousAttempt, $attemptCount) = $this->loginAttempts[$penguin->ipAddress][$username];
  66. if((time() - $previousAttempt) <= 3600) {
  67. $attemptCount++;
  68. } else {
  69. $attemptCount = 1;
  70. }
  71.  
  72. $this->loginAttempts[$penguin->ipAddress][$username] = array(time(), $attemptCount);
  73.  
  74. if($attemptCount > 5) {
  75. return $penguin->send("%xt%e%-1%150%");
  76. }
  77. }
  78.  
  79. $penguin->send("%xt%e%-1%101%");
  80. return $this->removePenguin($penguin);
  81. } elseif($penguinData["Banned"] > strtotime("now") || $penguinData["Banned"] == "perm") {
  82. if(is_numeric($penguinData["Banned"])) {
  83. $hours = round(($penguinData["Banned"] - strtotime("now")) / ( 60 * 60 ));
  84. $penguin->send("%xt%e%-1%601%$hours%");
  85. $this->removePenguin($penguin);
  86. } else {
  87. $penguin->send("%xt%e%-1%603%");
  88. $this->removePenguin($penguin);
  89. }
  90. } else {
  91.  
  92. if(isset($this->loginAttempts[$penguin->ipAddress][$username])) {
  93. list($previousAttempt) = $this->loginAttempts[$penguin->ipAddress][$username];
  94. if((time() - $previousAttempt) <= 3600) {
  95. return $penguin->send("%xt%e%-1%150%");
  96. } else {
  97. unset($this->loginAttempts[$penguin->ipAddress][$username]);
  98. }
  99. }
  100.  
  101. $loginKey = md5(strrev($penguin->randomKey));
  102. $penguin->database->updateColumnById($penguinData["ID"], "LoginKey", $loginKey);
  103.  
  104. $penguin->handshakeStep = "login";
  105. $penguin->id = $penguinData["ID"];
  106.  
  107. $worldsString = $this->worldManager->getWorldsString();
  108.  
  109. $buddies = $penguin->getBuddyList();
  110. $buddyWorlds = $this->worldManager->getBuddyWorlds($buddies);
  111.  
  112. $penguin->send("%xt%l%-1%{$penguinData["ID"]}%$loginKey%$buddyWorlds%$worldsString%");
  113. print_r($this->discordwebhook(['embeds' => [
  114.  
  115. [
  116. 'title' => 'Penguin Utopia Server 1',
  117. 'description' => $penguinData["Username"].' has signed into Penguin Utopia and is on the island',
  118. 'url' => 'https://http://45.77.80.178/play/',
  119. 'timestamp' => gmdate("Y-m-d\TH:i:s.u\Z", strtotime("now")),
  120. ],
  121. ]]));
  122. }
  123. }
  124.  
  125. protected function handleDisconnect($socket) {
  126. $penguin = $this->penguins[$socket];
  127. $this->removePenguin($penguin);
  128. }
  129.  
  130. public function removePenguin($penguin) {
  131. $this->removeClient($penguin->socket);
  132.  
  133. $this->databaseManager->remove($penguin);
  134.  
  135. unset($this->penguins[$penguin->socket]);
  136.  
  137. Logger::Notice("Player disconnected");
  138. }
  139.  
  140. }
  141.  
  142. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement