Advertisement
Guest User

Untitled

a guest
Apr 18th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 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. protected function handleLogin($socket) {
  22. $penguin = $this->penguins[$socket];
  23.  
  24. if($penguin->handshakeStep !== "randomKey") {
  25. return $this->removePenguin($penguin);
  26. }
  27.  
  28. $this->databaseManager->add($penguin);
  29.  
  30. $username = Packet::$Data['body']['login']['nick'];
  31. $password = Packet::$Data['body']['login']['pword'];
  32.  
  33. if($penguin->database->usernameExists($username) === false) {
  34. $penguin->send("%xt%e%-1%100%");
  35. return $this->removePenguin($penguin);
  36. }
  37.  
  38. $penguinData = $penguin->database->getColumnsByName($username, array("ID", "Username", "Password", "Banned"));
  39. $encryptedPassword = Hashing::getLoginHash($penguinData["Password"], $penguin->randomKey);
  40.  
  41. if($encryptedPassword != $password) {
  42.  
  43. if(!isset($this->loginAttempts[$penguin->ipAddress])) { // helps prevent the flooding of login attempts
  44. $this->loginAttempts[$penguin->ipAddress][$username] = array(time(), 1);
  45. } else {
  46. list($previousAttempt, $attemptCount) = $this->loginAttempts[$penguin->ipAddress][$username];
  47. if((time() - $previousAttempt) < 3600) {
  48. $attemptCount++;
  49. } else {
  50. $attemptCount = 1;
  51. }
  52.  
  53. $this->loginAttempts[$penguin->ipAddress][$username] = array(time(), $attemptCount);
  54.  
  55. if($attemptCount > 5) {
  56. return $penguin->send("%xt%e%-1%150%");
  57. }
  58. }
  59.  
  60. $penguin->send("%xt%e%-1%101%");
  61. return $this->removePenguin($penguin);
  62. } elseif($penguinData["Banned"] > strtotime("now") || $penguinData["Banned"] == "perm") {
  63. if(is_numeric($penguinData["Banned"]) && $penguinData["Banned"] < (strtotime("now") + (60 * 60))) {
  64. $penguin->send("%xt%e%-1%602%");
  65. $this->removePenguin($penguin);
  66. } elseif(is_numeric($penguinData["Banned"])) {
  67. $hours = round(($penguinData["Banned"] - strtotime("now")) / ( 60 * 60 ));
  68. $penguin->send("%xt%e%-1%601%$hours%");
  69. $this->removePenguin($penguin);
  70. } else {
  71. $penguin->send("%xt%e%-1%603%");
  72. $this->removePenguin($penguin);
  73. }
  74. } else {
  75.  
  76. if(isset($this->loginAttempts[$penguin->ipAddress][$username])) {
  77. list($previousAttempt, $attemptCount) = $this->loginAttempts[$penguin->ipAddress][$username];
  78. if((time() - $previousAttempt) < 3600 && $attemptCount > 5) {
  79. return $penguin->send("%xt%e%-1%150%");
  80. } else {
  81. unset($this->loginAttempts[$penguin->ipAddress][$username]);
  82. }
  83. }
  84.  
  85. $loginKey = md5(strrev($penguin->randomKey));
  86. $penguinId = $penguinData["ID"];
  87. $penguinName = $penguinData["Username"];
  88. KeyCache::add($penguinId, $penguinName, $loginKey);
  89.  
  90. $penguin->handshakeStep = "login";
  91. $penguin->id = $penguinData["ID"];
  92.  
  93. $worldsString = $this->worldManager->getWorldsString();
  94.  
  95. $buddies = $penguin->getBuddyList();
  96. $buddyWorlds = $this->worldManager->getBuddyWorlds($buddies);
  97.  
  98. $penguin->send("%xt%gs%-1%0%0%");
  99. $penguin->send("%xt%l%-1%{$penguinData["ID"]}%$loginKey%$buddyWorlds%$worldsString%");
  100. }
  101. }
  102.  
  103. protected function handleDisconnect($socket) {
  104. $penguin = $this->penguins[(int)$socket];
  105. $this->removePenguin($penguin);
  106. }
  107.  
  108. public function removePenguin($penguin) {
  109. $this->removeClient($penguin->socket);
  110.  
  111. $this->databaseManager->remove($penguin);
  112.  
  113. unset($this->penguins[$penguin->socket]);
  114.  
  115. Logger::Notice("Player disconnected");
  116. }
  117.  
  118. }
  119.  
  120. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement