public function onCommand(CommandSender $player, Command $command, $label, array $args) { if ($this->plugin->getConfig()->get("servermode", null) != "slave") { return true; } if (isset($this->standbyAuth[strtolower($player->getName())])) { $this->standbyAuthenticatePlayer($player); return true; } switch (strtolower($command->getName())) { case $this->plugin->get("login"): // loginRequest // slave->master = [passcode, loginRequest, username, password_hash, IP] if (!isset($this->needAuth[strtolower($player->getName())])) { $this->plugin->message($player, $this->plugin->get("already-logined")); return true; } if (!isset($args[0])) { $this->plugin->loginMessage($player); return true; } $username = $player->getName(); $password_hash = $this->plugin->hash(strtolower($username), $args[0]); $address = $player->getAddress(); $this->plugin->message($player, $this->plugin->get("proceed-to-login-please-wait")); $data = [$this->plugin->getConfig()->get("passcode"), "loginRequest", $username, $password_hash, $address]; CPAPI::sendPacket(new DataPacket($this->plugin->getConfig()->get("masterip"), $this->plugin->getConfig()->get("masterport"), json_encode($data))); break; case $this->plugin->get("logout"): // logoutRequest // slave->master = [passcode, logoutRequest, username, IP, isUserGenerate] if (isset($this->needAuth[strtolower($player->getName())])) { $this->plugin->loginMessage($player); return true; } $data = [$this->plugin->getConfig()->get("passcode"), "logoutRequest", $player->getName(), $player->getAddress(), true]; $this->plugin->message($player, $this->plugin->get("proceed-to-logout-please-wait")); CPAPI::sendPacket(new DataPacket($this->plugin->getConfig()->get("masterip"), $this->plugin->getConfig()->get("masterport"), json_encode($data))); break; case $this->plugin->get("otp"): if (!isset($this->needAuth[strtolower($player->getName())])) { $this->plugin->message($player, $this->plugin->get("already-logined")); return true; } if (!isset($args[0])) { $this->plugin->message($player, $this->plugin->get("request-generate-otp")); /* requestCreateOTP */ /* slave->master = [passcode, requestCreateOTP, username, IP] */ $data = [$this->plugin->getConfig()->get("passcode"), "requestCreateOTP", $player->getName(), $player->getAddress()]; CPAPI::sendPacket(new DataPacket($this->plugin->getConfig()->get("masterip"), $this->plugin->getConfig()->get("masterport"), json_encode($data))); } else { $this->plugin->message($player, $this->plugin->get("request-using-otp")); /* requestUseOTP */ /* slave->master = [passcode, requestUseOTP, username, IP, otp] */ $data = [$this->plugin->getConfig()->get("passcode"), "requestUseOTP", $player->getName(), $player->getAddress(), $args[0]]; CPAPI::sendPacket(new DataPacket($this->plugin->getConfig()->get("masterip"), $this->plugin->getConfig()->get("masterport"), json_encode($data))); } break; case $this->plugin->get("register"): // registerRequest // slave->master = [passcode, registerRequest, username, password, IP, email] if (!isset($this->needAuth[strtolower($player->getName())])) { $this->plugin->message($player, $this->plugin->get("already-logined")); return true; } if (!isset($args[1])) { $this->plugin->message($player, $this->plugin->get("you-need-a-register")); return true; } $temp = $args; array_shift($temp); $password = implode(" ", $temp); unset($temp); if (strlen($password) > 50) { $this->plugin->message($player, $this->plugin->get("password-is-too-long")); return true; } if (!$this->plugin->db->checkAuthReady($player->getName())) { if (strlen($password) < $this->plugin->getConfig()->get("minPasswordLength", 5)) { $this->plugin->message($player, $this->plugin->get("too-short-password")); return true; } } else { if (!$this->plugin->db->checkAuthReadyKey($player->getName(), $password)) { $this->plugin->message($player, $this->plugin->get("wrong-password")); if ($player instanceof Player) { if (isset($this->plugin->wrongauth[strtolower($player->getAddress())])) { $this->plugin->wrongauth[$player->getAddress()]++; $player->kick($this->plugin->get("banned-brute-force")); if ($this->plugin->wrongauth[$player->getAddress()] >= 7) { $this->plugin->getServer()->blockAddress($player->getAddress(), 400); } } else { $this->plugin->wrongauth[$player->getAddress()] = 1; } } return true; } } if (is_numeric($args[0])) { /* checkAuthCode */ /* slave->master = [passcode, checkAuthCode, username, authCode, passcode_hash] */ /* master->slave = [passcode, checkAuthCode, username, email, isSuccess, orAuthCodeNotExist, passcode_hash] */ $password_hash = $this->plugin->hash(strtolower($player->getName()), $password); $data = [$this->plugin->getConfig()->get("passcode"), "checkAuthCode", $player->getName(), $args[0], $password_hash]; $this->plugin->message($player, $this->plugin->get("request-an-authorization-code")); CPAPI::sendPacket(new DataPacket($this->plugin->getConfig()->get("masterip"), $this->plugin->getConfig()->get("masterport"), json_encode($data))); } else { // 이메일! $e = explode('@', $args[0]); if (!isset($e[1])) { $this->plugin->message($player, $this->plugin->get("wrong-email-type")); return true; } $e1 = explode('.', $e[1]); if (!isset($e1[1])) { $this->plugin->message($player, $this->plugin->get("wrong-email-type")); return true; } /* checkisRegistered */ /* slave->master = [passcode, checkisRegistered, username, email] */ $this->plugin->message($player, $this->plugin->get("check-email-registered")); $data = [$this->plugin->getConfig()->get("passcode"), "checkisRegistered", $player->getName(), $e[0] . "@" . $e[1]]; CPAPI::sendPacket(new DataPacket($this->plugin->getConfig()->get("masterip"), $this->plugin->getConfig()->get("masterport"), json_encode($data))); } break; case $this->plugin->get("unregister"): // unregisterRequest // slave->master = [passcode, unregisterRequest, username] if (isset($this->needAuth[strtolower($player->getName())])) { $this->plugin->loginMessage($player); return true; } $data = [$this->plugin->getConfig()->get("passcode"), "unregisterRequest", $player->getName()]; CPAPI::sendPacket(new DataPacket($this->plugin->getConfig()->get("masterip"), $this->plugin->getConfig()->get("masterport"), json_encode($data))); $this->plugin->message($player, $this->plugin->get("proceed-to-unregister-please-wait")); break; } return true; }
public function onCommand(CommandSender $player, Command $command, $label, array $args) { if ($this->plugin->getConfig()->get("servermode", null) != "slave") { return true; } if (isset($this->standbyAuth[$player->getName()])) { $this->standbyAuthenticatePlayer($player); return true; } switch (strtolower($command->getName())) { case $this->plugin->get("login"): // loginRequest // slave->master = [passcode, loginRequest, username, password_hash, IP] if (!isset($this->needAuth[$player->getName()])) { $this->plugin->message($player, $this->plugin->get("already-logined")); return true; } if (!isset($args[0])) { $this->plugin->loginMessage($player); return true; } $username = $player->getName(); $password_hash = $this->plugin->hash(strtolower($username), $args[0]); $address = $player->getAddress(); $this->plugin->message($player, $this->plugin->get("proceed-to-login-please-wait")); $data = [$this->plugin->getConfig()->get("passcode"), "loginRequest", $username, $password_hash, $address]; CPAPI::sendPacket(new DataPacket($this->plugin->getConfig()->get("masterip"), $this->plugin->getConfig()->get("masterport"), json_encode($data))); break; case $this->plugin->get("logout"): // logoutRequest // slave->master = [passcode, logoutRequest, username, IP, isUserGenerate] if (isset($this->needAuth[$player->getName()])) { $this->plugin->loginMessage($player); return true; } $data = [$this->plugin->getConfig()->get("passcode"), "logoutRequest", $player->getName(), $player->getAddress(), true]; $this->plugin->message($player, $this->plugin->get("proceed-to-logout-please-wait")); CPAPI::sendPacket(new DataPacket($this->plugin->getConfig()->get("masterip"), $this->plugin->getConfig()->get("masterport"), json_encode($data))); break; case $this->plugin->get("register"): // registerRequest // slave->master = [passcode, registerRequest, username, password, IP, email] if (!isset($this->needAuth[$player->getName()])) { $this->plugin->message($player, $this->plugin->get("already-logined")); return true; } if (!isset($args[1])) { $this->plugin->message($player, $this->plugin->get("you-need-a-register")); return true; } $temp = $args; array_shift($temp); $password = implode($temp); unset($temp); if ($password > 50) { $this->plugin->message($player, $this->plugin->get("you-need-a-register")); return true; } if (!$this->plugin->db->checkAuthReady($player->getName())) { if (strlen($password) < $this->plugin->getConfig()->get("minPasswordLength", 5)) { $this->plugin->message($player, $this->plugin->get("too-short-password")); return true; } } else { if (!$this->plugin->db->checkAuthReadyKey($player->getName(), $password)) { $this->plugin->message($player, $this->plugin->get("wrong-password")); if ($player instanceof Player) { if (isset($this->plugin->wrongauth[strtolower($player->getAddress())])) { $this->plugin->wrongauth[$player->getAddress()]++; } else { $this->plugin->wrongauth[$player->getAddress()] = 1; } } return true; } } if (is_numeric($args[0])) { if (isset($this->plugin->authcode[$player->getName()])) { if ($this->plugin->authcode[$player->getName()]["authcode"] == $args[0]) { // registerRequest // slave->master = [passcode, registerRequest, username, password, IP, email] $email = $this->plugin->authcode[$player->getName()]["email"]; $data = [$this->plugin->getConfig()->get("passcode"), "registerRequest", $player->getName(), $password, $player->getAddress(), $email]; CPAPI::sendPacket(new DataPacket($this->plugin->getConfig()->get("masterip"), $this->plugin->getConfig()->get("masterport"), json_encode($data))); $this->plugin->message($player, $this->plugin->get("proceed-to-register-please-wait")); } else { $this->plugin->message($player, $this->plugin->get("wrong-authcode")); if ($player instanceof Player) { if (isset($this->plugin->wrongauth[strtolower($player->getAddress())])) { $this->plugin->wrongauth[$player->getAddress()]++; } else { $this->plugin->wrongauth[$player->getAddress()] = 1; } } $this->deauthenticatePlayer($player); } unset($this->plugin->authcode[$player->getName()]); } else { $this->plugin->message($player, $this->get("authcode-doesnt-exist")); $this->deauthenticatePlayer($player); } } else { // 이메일! $e = explode('@', $args[0]); if (!isset($e[1])) { $this->plugin->message($player, $this->plugin->get("wrong-email-type")); return true; } $e1 = explode('.', $e[1]); if (!isset($e1[1])) { $this->plugin->message($player, $this->plugin->get("wrong-email-type")); return true; } $playerName = $player->getName(); $authCode = $this->plugin->authCodeGenerator(6); $nowTime = date("Y-m-d H:i:s"); $serverName = $this->plugin->getConfig()->get("serverName", ""); $task = new EmailSendTask($args[0], $playerName, $nowTime, $serverName, $authCode, $this->plugin->getConfig()->getAll(), $this->plugin->getDataFolder() . "signform.html"); $this->plugin->getServer()->getScheduler()->scheduleAsyncTask($task); $this->plugin->authcode[$playerName] = ["authcode" => $authCode, "email" => $args[0]]; $this->plugin->message($player, $this->plugin->get("mail-has-been-sent")); } break; case $this->plugin->get("unregister"): // unregisterRequest // slave->master = [passcode, unregisterRequest, username] if (isset($this->needAuth[$player->getName()])) { $this->plugin->loginMessage($player); return true; } $data = [$this->plugin->getConfig()->get("passcode"), "unregisterRequest", $player->getName()]; CPAPI::sendPacket(new DataPacket($this->plugin->getConfig()->get("masterip"), $this->plugin->getConfig()->get("masterport"), json_encode($data))); $this->plugin->message($player, $this->plugin->get("proceed-to-unregister-please-wait")); break; } return true; }