예제 #1
0
 public function onPacketReceive(CustomPacketReceiveEvent $event)
 {
     $event->getPacket()->printDump();
     $data = json_decode($event->getPacket()->data);
     if (!is_array($data)) {
         echo "[테스트] 배열이 아닌 정보 전달됨\n";
         $event->getPacket()->printDump();
         return;
     }
     if ($data["password"] != $this->password) {
         echo "[테스트] 패스워드가 다른 정보 전달됨\n";
         var_dump($data["password"]);
         return;
     }
     $ip = $event->getPacket()->address;
     $port = $event->getPacket()->port;
     $address = $ip . ":" . $port;
     switch ($data["type"]) {
         case "update":
             $this->updateList[$address]["LastContact"] = time();
             CPAPI::sendPacket(new DataPacket($ip, $port, json_encode(["password" => $this->password, "type" => "inside", "state" => "succeed"])));
             break;
         case "disconnect":
             if (isset($this->updateList[$address]["LastContact"])) {
                 unset($this->updateList[$address]["LastContact"]);
             }
             CPAPI::sendPacket(new DataPacket($ip, $port, json_encode(["password" => $this->password, "type" => "inside", "state" => "disconnected"])));
             break;
     }
 }
예제 #2
0
 public function onPacketReceive(CustomPacketReceiveEvent $ev)
 {
     $this->getServer()->getLogger()->notice("[CustomPacket Example] Received custom packet. Printing dump...");
     $ev->getPacket()->printDump();
     $this->getServer()->getLogger()->notice("[CustomPacket Example] Sending example packet...");
     $pk = new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, "You sent me " . $ev->getPacket()->data . " and this example plugin is returning packet");
     CPAPI::sendPacket($pk);
 }
예제 #3
0
 public function sendMessage($message, $ip, $port)
 {
     if (!$this->canActivate) {
         return false;
     }
     $packet = new DataPacket($ip, $port, $message);
     CPAPI::sendPacket($packet);
     return true;
 }
 public function sendRedistribution(Event $event, $message)
 {
     if ($this->customPacketAvailable and $this->plugin->getConfig()->get("echo-enabled", false)) {
         if ($event instanceof PlayerCommandPreprocessEvent) {
             if ($event->getPlayer()->closed) {
                 return;
             }
         }
         $passcode = $this->plugin->getConfig()->get("echo-passcode", null);
         if ($passcode === null) {
             return;
         }
         $myName = $this->plugin->getConfig()->get("echo-my-name", "MAIN");
         $data = json_encode([$passcode, $myName, $message]);
         foreach ($this->plugin->getConfig()->get("echo-recipients", []) as $recipient) {
             $address = explode(":", $recipient);
             CPAPI::sendPacket(new DataPacket($address[0], $address[1], $data));
         }
     }
 }
예제 #5
0
 /**
  * Custom Packet event processing, server connection work
  *
  * @param CustomPacketReceiveEvent $ev        	
  */
 public function onPacketReceive(CustomPacketReceiveEvent $ev)
 {
     $data = json_decode($ev->getPacket()->data);
     if (!isset($data[3]) or $data[0] != $this->db["passcode"]) {
         return;
     }
     if ($this->db["mode"] == "master") {
         $this->updateList[$ev->getPacket()->address . ":" . $ev->getPacket()->port]["list"] = $data[1];
         $this->updateList[$ev->getPacket()->address . ":" . $ev->getPacket()->port]["max"] = $data[2];
         $this->updateList[$ev->getPacket()->address . ":" . $ev->getPacket()->port]["port"] = $data[3];
         $this->updateList[$ev->getPacket()->address . ":" . $ev->getPacket()->port]["lastcontact"] = $this->makeTimestamp(date("Y-m-d H:i:s"));
         if (!isset($this->checkFistConnect[$ev->getPacket()->address . ":" . $ev->getPacket()->port])) {
             $this->checkFistConnect[$ev->getPacket()->address . ":" . $ev->getPacket()->port] = 1;
             $this->getLogger()->info(TextFormat::DARK_AQUA . $ev->getPacket()->address . ":" . $ev->getPacket()->port . " " . $this->get("mastermode-first-connected"));
             CPAPI::sendPacket(new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, json_encode([$this->db["passcode"], "hello", "0", "0"])));
         } else {
             CPAPI::sendPacket(new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, json_encode([$this->db["passcode"], "online", count($this->getServer()->getOnlinePlayers()), $this->getServer()->getMaxPlayers()])));
         }
     } else {
         if ($this->db["mode"] == "slave") {
             switch ($data[1]) {
                 case "hello":
                     if (!isset($this->checkFistConnect[$ev->getPacket()->address . ":" . $ev->getPacket()->port])) {
                         $this->checkFistConnect[$ev->getPacket()->address . ":" . $ev->getPacket()->port] = 1;
                         $this->getLogger()->info(TextFormat::DARK_AQUA . $ev->getPacket()->address . ":" . $ev->getPacket()->port . " " . $this->get("slavemode-first-connected"));
                     }
                     break;
                 case "online":
                     $this->slaveData["online"] = $data[2];
                     $this->slaveData["max"] = $data[3];
             }
         }
     }
 }
 public static function sendPacket($ip, $port, array $data)
 {
     CPAPI::sendPacket(new DataPacket($ip, $port, json_encode($data)));
 }
 public function onPacketReceive(CustomPacketReceiveEvent $ev)
 {
     $data = json_decode($ev->getPacket()->data);
     if (!is_array($data) or $data[0] != $this->plugin->getConfig()->get("passcode", false)) {
         return;
     }
     if ($this->plugin->getConfig()->get("servermode", null) == "master") {
         switch ($data[1]) {
             case "online":
                 // online
                 // slave->master = [passcode, online]
                 $this->updateList[$ev->getPacket()->address . ":" . $ev->getPacket()->port]["lastcontact"] = $this->makeTimestamp(date("Y-m-d H:i:s"));
                 if (!isset($this->checkFistConnect[$ev->getPacket()->address . ":" . $ev->getPacket()->port])) {
                     $this->checkFistConnect[$ev->getPacket()->address . ":" . $ev->getPacket()->port] = 1;
                     $this->plugin->getLogger()->info(TextFormat::DARK_AQUA . $ev->getPacket()->address . ":" . $ev->getPacket()->port . " " . $this->plugin->get("mastermode-first-connected"));
                     CPAPI::sendPacket(new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, json_encode([$this->plugin->getConfig()->get("passcode"), "hello", "0", "0"])));
                 }
                 break;
             case "checkisRegistered":
                 /* checkisRegistered */
                 /* slave->master = [passcode, checkisRegistered, username, email] */
                 /* master->slave = [passcode, checkisRegistered, username, email, isRegistered[true||false] */
                 $username = strtolower($data[2]);
                 $email = strtolower($data[3]);
                 if ($this->plugin->db->getUserData($email) !== false) {
                     $isRegistered = true;
                 } else {
                     if ($this->plugin->db->getEmailToName($username) !== false) {
                         $isRegistered = true;
                     } else {
                         $isRegistered = false;
                     }
                 }
                 $data = [$this->plugin->getConfig()->get("passcode"), "checkisRegistered", $username, $email, $isRegistered];
                 CPAPI::sendPacket(new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, json_encode($data)));
                 break;
             case "sendAuthCode":
                 /* sendAuthCode */
                 /* slave->master = [passcode, sendAuthCode, username, email] */
                 /* master->slave = [passcode, sendAuthCode, username, email, authcodeSented */
                 $username = strtolower($data[2]);
                 $email = strtolower($data[3]);
                 $verifyNotWrong = true;
                 $verifyNotRegistered = false;
                 $check = explode("@", $email);
                 if (isset($check[1])) {
                     $lockDomain = $this->plugin->db->getLockDomain();
                     if ($lockDomain !== null and $check[1] !== $lockDomain) {
                         $verifyNotWrong = false;
                     }
                 }
                 if (!$this->plugin->db->checkUserData($email)) {
                     $verifyNotRegistered = true;
                 }
                 if ($verifyNotWrong != false and $verifyNotRegistered != false) {
                     $nowTime = date("Y-m-d H:i:s");
                     $serverName = $this->plugin->getConfig()->get("serverName", "");
                     $authCode = $this->plugin->authCodeGenerator(6);
                     $this->plugin->authcode[$username] = ["authcode" => $authCode, "email" => $email];
                     $task = new EmailSendTask($email, $username, $nowTime, $serverName, $authCode, $this->plugin->getConfig()->getAll(), $this->plugin->getDataFolder() . "signform.html");
                     $this->plugin->getServer()->getScheduler()->scheduleAsyncTask($task);
                     $data = [$this->plugin->getConfig()->get("passcode"), "sendAuthCode", $username, $email, true];
                     CPAPI::sendPacket(new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, json_encode($data)));
                 } else {
                     $data = [$this->plugin->getConfig()->get("passcode"), "sendAuthCode", $username, $email, false];
                     CPAPI::sendPacket(new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, json_encode($data)));
                 }
                 break;
             case "checkAuthCode":
                 /* checkAuthCode */
                 /* slave->master = [passcode, checkAuthCode, username, authCode, passcode_hash] */
                 /* master->slave = [passcode, checkAuthCode, username, email, isSuccess, orAuthCodeNotExist, passcode_hash] */
                 $username = strtolower($data[2]);
                 $authCode = $data[3];
                 $passcode_hash = $data[4];
                 $isSuccess = false;
                 $orAuthCodeNotExist = false;
                 if (isset($this->plugin->authcode[$username])) {
                     if ($this->plugin->authcode[$username]["authcode"] == $authCode) {
                         $isSuccess = true;
                     } else {
                         $isSuccess = false;
                     }
                     $email = $this->plugin->authcode[$username]["email"];
                 } else {
                     $email = null;
                     $orAuthCodeNotExist = true;
                 }
                 $data = [$this->plugin->getConfig()->get("passcode"), "checkAuthCode", $username, $email, $isSuccess, $orAuthCodeNotExist, $passcode_hash];
                 CPAPI::sendPacket(new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, json_encode($data)));
                 break;
             case "deleteAuthCode":
                 /* deleteAuthCode */
                 /* slave->master = [passcode, deleteAuthCode, username, email] */
                 $username = strtolower($data[2]);
                 $email = strtolower($data[3]);
                 if (isset($this->plugin->authcode[$username])) {
                     if ($this->plugin->authcode[$username]["email"] == $email) {
                         unset($this->plugin->authcode[$username]);
                     }
                 }
                 break;
             case "requestCreateOTP":
                 /* requestCreateOTP */
                 /* slave->master = [passcode, requestCreateOTP, username, IP] */
                 /* master->slave = [passcode, requestCreateOTP, username, IP, isGenerated[true|false] */
                 $username = strtolower($data[2]);
                 $address = $data[3];
                 $isGenerated = false;
                 $isTimeout = true;
                 if (isset($this->otpDb[$username])) {
                     $progress = $this->makeTimestamp(date("Y-m-d H:i:s")) - $this->makeTimestamp($this->otpDb[$username]["date"]);
                     if ($progress < 3600) {
                         $isTimeout = false;
                     }
                 }
                 if ($isTimeout) {
                     $email = $this->plugin->db->getEmailToName($username);
                     if ($email !== false) {
                         $isGenerated = true;
                         $nowTime = date("Y-m-d H:i:s");
                         $serverName = $this->plugin->getConfig()->get("serverName", "");
                         $this->otpDb[$username] = ["passkey" => $this->plugin->authCodeGenerator(6), "requestedIp" => $address, "date" => $nowTime];
                         $task = new EmailSendTask($email, $username, $nowTime, $serverName, $this->otpDb[$username]["passkey"], $this->plugin->getConfig()->getAll(), $this->plugin->getDataFolder() . "otpform.html");
                         $this->plugin->getServer()->getScheduler()->scheduleAsyncTask($task);
                     }
                 }
                 $data = [$this->plugin->getConfig()->get("passcode"), "requestCreateOTP", $username, $address, $isGenerated];
                 CPAPI::sendPacket(new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, json_encode($data)));
                 break;
             case "requestUseOTP":
                 /* requestUseOTP */
                 /* slave->master = [passcode, requestUseOTP, username, IP, otp] */
                 /* master->slave = [passcode, requestUseOTP, username, IP, isSuccess[true|false] */
                 $username = strtolower($data[2]);
                 $address = $data[3];
                 $otp = $data[4];
                 $isSuccess = false;
                 if (isset($this->otpDb[$username])) {
                     $progress = $this->makeTimestamp(date("Y-m-d H:i:s")) - $this->makeTimestamp($this->otpDb[$username]["date"]);
                     if ($progress < 3600) {
                         if ($this->otpDb[$username]["passkey"] === $otp) {
                             $email = $this->plugin->db->getEmailToName($username);
                             if ($email !== false) {
                                 $isSuccess = true;
                                 $this->onlineUserList[$username] = $ev->getPacket()->address . ":" . $ev->getPacket()->port;
                                 $this->plugin->db->updateIPAddress($email, $address);
                                 unset($this->otpDb[$username]);
                             }
                         }
                     }
                 }
                 $data = [$this->plugin->getConfig()->get("passcode"), "requestUseOTP", $username, $address, $isSuccess];
                 CPAPI::sendPacket(new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, json_encode($data)));
                 break;
             case "defaultInfoRequest":
                 /* defaultInfoRequest */
                 /* slave->master = [passcode, defaultInfoRequest, username, IP] */
                 /* master->slave = [passcode, defaultInfoRequest, username, isConnected[true|false], isRegistered[true||false], isAutoLogin[true||false], NBT, isCheckAuthReady, lockDomain] */
                 $requestedUserName = strtolower($data[2]);
                 $requestedUserIp = $data[3];
                 // IPCHECK
                 $email = $this->plugin->db->getEmailToIp($requestedUserIp);
                 $userdata = $this->plugin->db->getUserData($email);
                 if ($email === false or $userdata === false) {
                     // did not join
                     $isConnect = false;
                     $isRegistered = false;
                     $isAutoLogin = false;
                     $NBT = null;
                 } else {
                     if (isset($this->onlineUserList[$requestedUserName])) {
                         $isConnect = true;
                     } else {
                         $isConnect = false;
                     }
                     if ($userdata["name"] == $requestedUserName) {
                         $isAutoLogin = true;
                         $isRegistered = true;
                         $this->onlineUserList[$requestedUserName] = $ev->getPacket()->address . ":" . $ev->getPacket()->port;
                         $this->plugin->db->updateIPAddress($email, $requestedUserIp);
                     } else {
                         $isAutoLogin = false;
                         if ($this->plugin->db->getEmailToName($requestedUserName) !== false) {
                             $isRegistered = true;
                         } else {
                             $isRegistered = false;
                         }
                     }
                     $NBT = $this->getPlayerDataFile($requestedUserName);
                 }
                 // EMAIL-CHECK
                 if ($email === false or $userdata === false) {
                     $email = $this->plugin->db->getEmailToName($requestedUserName);
                     $userdata = $this->plugin->db->getUserData($email);
                     if ($email === false or $userdata === false) {
                         // did not join
                         $isConnect = false;
                         $isRegistered = false;
                         $isAutoLogin = false;
                         $NBT = null;
                     } else {
                         if (isset($this->onlineUserList[$requestedUserName])) {
                             $isConnect = true;
                         } else {
                             $isConnect = false;
                         }
                         $isAutoLogin = false;
                         $isRegistered = true;
                         $NBT = $this->getPlayerDataFile($requestedUserName);
                     }
                 }
                 $isCheckAuthReady = $this->plugin->db->checkAuthReady($requestedUserName);
                 $lockDomain = $this->plugin->db->getLockDomain();
                 $data = [$this->plugin->getConfig()->get("passcode"), "defaultInfoRequest", $requestedUserName, $isConnect, $isRegistered, $isAutoLogin, $NBT, $isCheckAuthReady, $lockDomain];
                 CPAPI::sendPacket(new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, json_encode($data)));
                 break;
             case "loginRequest":
                 // loginRequest
                 // slave->master = [passcode, loginRequest, username, password_hash, IP]
                 // master->slave = [passcode, loginRequest, username, isSuccess[true||false]]
                 $username = strtolower($data[2]);
                 $password_hash = $data[3];
                 $address = $data[4];
                 $email = $this->plugin->db->getEmailToName($username);
                 $userdata = $this->plugin->db->getUserData($email);
                 if ($email === false or $userdata === false) {
                     $isSuccess = false;
                 } else {
                     if ($userdata["password"] == $password_hash) {
                         $isSuccess = true;
                         $this->onlineUserList[$username] = $ev->getPacket()->address . ":" . $ev->getPacket()->port;
                         $this->plugin->db->updateIPAddress($email, $address);
                     } else {
                         $isSuccess = false;
                     }
                 }
                 $data = [$this->plugin->getConfig()->get("passcode"), "loginRequest", $username, $isSuccess];
                 CPAPI::sendPacket(new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, json_encode($data)));
                 break;
             case "logoutRequest":
                 // logoutRequest
                 // slave->master = [passcode, logoutRequest, username, IP, isUserGenerate]
                 // master->slave = [passcode, logoutRequest, username, isSuccess]
                 $username = strtolower($data[2]);
                 $address = $data[3];
                 $isUserGenerate = $data[4];
                 $isSuccess = true;
                 if (isset($this->onlineUserList[$username])) {
                     unset($this->onlineUserList[$username]);
                 }
                 if ($isUserGenerate) {
                     $isSuccess = $this->plugin->db->logout($this->plugin->db->getEmailToIp($address));
                 }
                 $data = [$this->plugin->getConfig()->get("passcode"), "logoutRequest", $username, $isSuccess];
                 CPAPI::sendPacket(new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, json_encode($data)));
                 break;
             case "registerRequest":
                 // registerRequest
                 // slave->master = [passcode, registerRequest, username, password_hash, IP, email]
                 // master->slave = [passcode, registerRequest, username, isSuccess[true||false]]
                 $username = strtolower($data[2]);
                 $password_hash = $data[3];
                 $address = $data[4];
                 $email = strtolower($data[5]);
                 $isSuccess = $this->plugin->db->addUser($email, $password_hash, $address, $username);
                 $data = [$this->plugin->getConfig()->get("passcode"), "registerRequest", $username, $isSuccess];
                 if ($this->plugin->db->checkAuthReady($username)) {
                     $this->plugin->db->completeAuthReady($username);
                 }
                 CPAPI::sendPacket(new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, json_encode($data)));
                 break;
             case "unregisterRequest":
                 // unregisterRequest
                 // slave->master = [passcode, unregisterRequest, username]
                 // master->slave = [passcode, unregisterRequest, username, isSuccess]
                 $username = strtolower($data[2]);
                 $email = $this->plugin->db->getEmailToName($username);
                 $deleteCheck = $this->plugin->db->deleteUser($email);
                 ($email === false or $deleteCheck === false) ? $isSuccess = false : ($isSuccess = true);
                 $data = [$this->plugin->getConfig()->get("passcode"), "unregisterRequest", $username, $isSuccess];
                 CPAPI::sendPacket(new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, json_encode($data)));
                 break;
             case "itemSyncro":
                 // itemSyncro
                 // slave->master = [passcode, itemSyncro, username, itemData]
                 // master->slave = [passcode, itemSyncro, username, itemData]
                 $username = strtolower($data[2]);
                 $itemData = $data[3];
                 $playerdata = $this->getPlayerData($username, $itemData);
                 $this->applyItemData($username, $playerdata);
                 break;
             case "itemSyncroRequest":
                 // itemSyncroRequest
                 // slave->master = [passcode, itemSyncro, username]
                 // master->slave = [passcode, itemSyncro, username, itemData]
                 $username = strtolower($data[2]);
                 // itemSyncro
                 // slave->master = [passcode, itemSyncro, username, itemData]
                 $data = [$this->plugin->getConfig()->get("passcode"), "itemSyncro", $username, $this->getPlayerDataFile($username)];
                 CPAPI::sendPacket(new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, json_encode($data)));
                 break;
             case "economyRequest":
                 // economyRequest
                 // slave->master = [passcode, economySyncro, username]
                 // master->slave = [passcode, economySyncro, username, money]
                 // TODO
                 break;
             case "economySyncro":
                 // economySyncro
                 // slave->master = [passcode, economySyncro, username, money]
                 // master->slave = [passcode, economySyncro, username, money]
                 $username = strtolower($data[2]);
                 $money = $data[3];
                 $this->applyEconomyData($username, $money);
                 $data = [$this->plugin->getConfig()->get("passcode"), "economySyncro", $username, $money];
                 $target_addr = $ev->getPacket()->address . ":" . $ev->getPacket()->port;
                 foreach ($this->updateList as $ipport => $data) {
                     if ($target_addr == $ipport) {
                         continue;
                     }
                     $addr = explode(":", $ipport);
                     CPAPI::sendPacket(new DataPacket($addr[0], $addr[1], json_encode($data)));
                 }
                 break;
         }
     } else {
         if ($this->plugin->getConfig()->get("servermode", null) == "slave") {
             switch ($data[1]) {
                 case "hello":
                     if (!isset($this->checkFistConnect[$ev->getPacket()->address . ":" . $ev->getPacket()->port])) {
                         $this->checkFistConnect[$ev->getPacket()->address . ":" . $ev->getPacket()->port] = 1;
                         $this->plugin->getLogger()->info(TextFormat::DARK_AQUA . $ev->getPacket()->address . ":" . $ev->getPacket()->port . " " . $this->plugin->get("slavemode-first-connected"));
                     }
                     break;
                 case "checkisRegistered":
                     /* checkisRegistered */
                     /* slave->master = [passcode, checkisRegistered, username, email] */
                     /* master->slave = [passcode, checkisRegistered, username, email, isRegistered[true||false] */
                     $username = strtolower($data[2]);
                     $email = strtolower($data[3]);
                     $isRegistered = $data[4];
                     $player = $this->plugin->getServer()->getPlayer($username);
                     if (!$player instanceof Player) {
                         return;
                     }
                     if ($isRegistered) {
                         // ALREADY REGISTERED
                         $this->plugin->message($player, $this->plugin->get("that-email-is-already-registered"));
                         return;
                     } else {
                         // NOT REGISTERED
                         $this->plugin->message($player, $this->plugin->get("issuing-an-authorization-code"));
                         /* sendAuthCode */
                         /* slave->master = [passcode, sendAuthCode, username, email] */
                         $data = [$this->plugin->getConfig()->get("passcode"), "sendAuthCode", $username, $email];
                         CPAPI::sendPacket(new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, json_encode($data)));
                     }
                     break;
                 case "requestCreateOTP":
                     /* requestCreateOTP */
                     /* slave->master = [passcode, requestCreateOTP, username, IP] */
                     /* master->slave = [passcode, requestCreateOTP, username, IP, isGenerated[true|false] */
                     $username = $data[2];
                     $address = $data[3];
                     $isGenerated = $data[4];
                     $player = $this->plugin->getServer()->getPlayer($username);
                     if (!$player instanceof Player) {
                         return;
                     }
                     if ($isGenerated) {
                         $this->plugin->message($player, $this->plugin->get("otp-is-generated"));
                     } else {
                         $this->plugin->message($player, $this->plugin->get("otp-is-not-generated"));
                         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;
                         }
                     }
                     break;
                 case "requestUseOTP":
                     /* requestUseOTP */
                     /* slave->master = [passcode, requestUseOTP, username, IP, otp] */
                     /* master->slave = [passcode, requestUseOTP, username, IP, isSuccess[true|false] */
                     $username = $data[2];
                     $address = $data[3];
                     $isSuccess = $data[4];
                     $player = $this->plugin->getServer()->getPlayer($username);
                     if (!$player instanceof Player) {
                         return;
                     }
                     if ($isSuccess) {
                         $this->plugin->message($player, $this->plugin->get("otp-logined"));
                         $this->authenticatePlayer($player);
                     } else {
                         $this->plugin->message($player, $this->plugin->get("otp-access-denied"));
                         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;
                         }
                     }
                     break;
                 case "sendAuthCode":
                     /* sendAuthCode */
                     /* slave->master = [passcode, sendAuthCode, username, email] */
                     /* master->slave = [passcode, sendAuthCode, username, email, authcodeSented */
                     $username = strtolower($data[2]);
                     $player = $this->plugin->getServer()->getPlayer($username);
                     $email = strtolower($data[3]);
                     $authcodeSented = $data[4];
                     if (!$player instanceof Player) {
                         return;
                     }
                     if ($authcodeSented) {
                         $this->plugin->message($player, $this->plugin->get("mail-has-been-sent"));
                     } else {
                         $this->plugin->message($player, $this->plugin->get("rejected-an-authorization-code"));
                     }
                     break;
                 case "checkAuthCode":
                     /* checkAuthCode */
                     /* slave->master = [passcode, checkAuthCode, username, authCode, passcode_hash] */
                     /* master->slave = [passcode, checkAuthCode, username, email, isSuccess, orAuthCodeNotExist, passcode_hash] */
                     $username = strtolower($data[2]);
                     $email = strtolower($data[3]);
                     $isSuccess = $data[4];
                     $orAuthCodeNotExist = $data[5];
                     $passcode_hash = $data[6];
                     $player = $this->plugin->getServer()->getPlayer($username);
                     if (!$player instanceof Player) {
                         return;
                     }
                     if ($orAuthCodeNotExist) {
                         $this->plugin->message($player, $this->plugin->get("authcode-resetted"));
                         $this->deauthenticatePlayer($player);
                         return;
                     }
                     if ($isSuccess) {
                         /* registerRequest */
                         /* slave->master = [passcode, registerRequest, username, password_hash, IP, email] */
                         $data = [$this->plugin->getConfig()->get("passcode"), "registerRequest", $player->getName(), $passcode_hash, $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()]++;
                                 $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;
                             }
                         }
                         $this->deauthenticatePlayer($player);
                     }
                     /* deleteAuthCode */
                     /* slave->master = [passcode, deleteAuthCode, username, email] */
                     $data = [$this->plugin->getConfig()->get("passcode"), "deleteAuthCode", $player->getName(), $email];
                     CPAPI::sendPacket(new DataPacket($this->plugin->getConfig()->get("masterip"), $this->plugin->getConfig()->get("masterport"), json_encode($data)));
                     break;
                 case "defaultInfoRequest":
                     /* defaultInfoRequest */
                     /* slave->master = [passcode, defaultInfoRequest, username, IP] */
                     /* master->slave = [passcode, defaultInfoRequest, username, isConnected[true|false], isRegistered[true||false], isConnected[true||false], NBT, isCheckAuthReady, lockDomain] */
                     $username = strtolower($data[2]);
                     $isConnect = $data[3];
                     $isRegistered = $data[4];
                     $isAutoLogin = $data[5];
                     $NBT = $data[6];
                     $isCheckAuthReady = $data[7];
                     $lockDomain = strtolower($data[8]);
                     $this->tmpDb[$username] = ["isConnect" => $isConnect, "isRegistered" => $isRegistered, "isAutoLogin" => $isAutoLogin, "isCheckAuthReady" => $isCheckAuthReady, "lockDomain" => $lockDomain];
                     $player = $this->plugin->getServer()->getPlayer($username);
                     if (!$player instanceof Player) {
                         return;
                     }
                     if ($isConnect) {
                         $this->alreadyLogined($player);
                         return;
                     }
                     $this->applyItemData($username, $this->getPlayerData($username, $NBT));
                     if ($isAutoLogin) {
                         $this->plugin->message($player, $this->plugin->get("automatic-ip-logined"));
                         $this->authenticatePlayer($player);
                         return;
                     }
                     $this->cueAuthenticatePlayer($player);
                     break;
                 case "loginRequest":
                     // loginRequest
                     // slave->master = [passcode, loginRequest, username, password_hash, IP]
                     // master->slave = [passcode, loginRequest, username, isSuccess[true||false]]
                     $username = strtolower($data[2]);
                     $isSuccess = $data[3];
                     $player = $this->plugin->getServer()->getPlayer($username);
                     if (!$player instanceof Player) {
                         return;
                     }
                     if ($isSuccess) {
                         $this->plugin->message($player, $this->plugin->get("login-is-success"));
                         $this->authenticatePlayer($player);
                     } else {
                         $this->plugin->message($player, $this->plugin->get("login-is-failed"));
                         $this->deauthenticatePlayer($player);
                     }
                     break;
                 case "logoutRequest":
                     // logoutRequest
                     // slave->master = [passcode, logoutRequest, username, IP, isUserGenerate]
                     // master->slave = [passcode, logoutRequest, username, isSuccess]
                     $username = strtolower($data[2]);
                     $isSuccess = $data[3];
                     $player = $this->plugin->getServer()->getPlayer($username);
                     if (!$player instanceof Player) {
                         return;
                     }
                     if ($isSuccess) {
                         $this->plugin->message($player, $this->plugin->get("logout-complete"));
                         $player->kick("logout");
                     } else {
                         $this->plugin->message($player, $this->plugin->get("logout-failed"));
                     }
                     break;
                 case "registerRequest":
                     // registerRequest
                     // slave->master = [passcode, registerRequest, username, password, IP, email]
                     // master->slave = [passcode, registerRequest, username, isSuccess[true||false]]
                     $username = strtolower($data[2]);
                     $isSuccess = $data[3];
                     $player = $this->plugin->getServer()->getPlayer($username);
                     if (!$player instanceof Player) {
                         return;
                     }
                     if ($isSuccess) {
                         $this->plugin->message($player, $this->plugin->get("register-complete"));
                         $this->authenticatePlayer($player);
                     } else {
                         $this->plugin->message($player, $this->plugin->get("register-failed"));
                         $this->deauthenticatePlayer($player);
                     }
                     break;
                 case "unregisterRequest":
                     // unregisterRequest
                     // slave->master = [passcode, unregisterRequest, username]
                     // master->slave = [passcode, unregisterRequest, username, isSuccess]
                     $username = strtolower($data[2]);
                     $isSuccess = $data[3];
                     $player = $this->plugin->getServer()->getPlayer($username);
                     if (!$player instanceof Player) {
                         return;
                     }
                     if ($isSuccess) {
                         $player->kick($this->plugin->get("complete-unregister"));
                     } else {
                         $this->plugin->message($player, $this->plugin->get("unregister-is-fail"));
                     }
                     break;
                 case "itemSyncro":
                     // itemSyncro
                     // slave->master = [passcode, itemSyncro, username, itemData]
                     // master->slave = [passcode, itemSyncro, username, itemData]
                     $username = $data[2];
                     $itemData = $data[3];
                     $this->applyItemData($username, $this->getPlayerData($username, $itemData));
                     break;
                 case "economyRequest":
                     // slave
                     // economyRequest
                     // slave->master = [passcode, economySyncro, username]
                     // master->slave = [passcode, economySyncro, username, money]
                     $username = $data[2];
                     $money = $data[3];
                     $this->applyEconomyData($username, $money);
                     break;
                 case "economySyncro":
                     // slave
                     // economySyncro
                     // slave->master = [passcode, economySyncro, username, money]
                     // master->slave = [passcode, economySyncro, username, money]
                     $username = $data[2];
                     $money = $data[3];
                     $this->applyEconomyData($username, $money);
                     break;
             }
         }
     }
 }
예제 #8
0
파일: Waypoint.php 프로젝트: EmreTr1/rtr
 public function onPacketReceive(CustomPacketReceiveEvent $ev)
 {
     // $ev->getPacket ()->printDump ();
     if ($this->configData["enable"] == false) {
         return;
     }
     if (count($this->configData["waypoints"]) == 0) {
         return;
     }
     if (!isset(explode("#Waypoint ", $ev->getPacket()->data)[1])) {
         return;
     }
     $data = explode("#Waypoint ", $ev->getPacket()->data)[1];
     switch ($data) {
         case "get":
             $pk = new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, json_encode($this->configData["waypoints"]));
             CPAPI::sendPacket($pk);
             break;
         default:
             $pk = new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, "parametor wrong! XI");
             CPAPI::sendPacket($pk);
             break;
     }
 }
예제 #9
0
 public function onCommand(CommandSender $sender, Command $command, $label, array $args)
 {
     if (!isset($args[0])) {
         return false;
     }
     switch ($args[0]) {
         case '이동':
             if (!isset($args[1])) {
                 $sender->sendMessage("사용법: /돈이동 이동 <서버명> <액수>");
                 $sender->sendMessage("서버목록 보는법: /돈이동 서버목록");
                 break;
             }
             if (!isset($args[2])) {
                 $sender->sendMessage("사용법: /돈이동 이동 <서버명> <액수>");
                 break;
             }
             if (!isset($this->serverlist[$args[1]])) {
                 $sender->sendMessage("해당 서버를 찾을 수 없습니다.");
                 $sender->sendMessage("서버목록 보는법: /돈이동 서버목록");
                 break;
             }
             if (!is_numeric($amount = $args[2])) {
                 $sender->sendMessage(TextFormat::RED . '금액은 숫자만 입력 가능합니다.');
                 break;
             }
             if ($this->economy->reduceMoney($sender, $amount) !== EconomyAPI::RET_SUCCESS) {
                 $lackmoney = $amount - $this->economy->myMoney($sender);
                 $sender->sendMessage(TextFormat::RED . "당신의 돈이 {$lackmoney}원 부족합니다.");
                 break;
             }
             $data = json_encode(["MoneyTransfer", $sender->getName(), $amount]);
             $packet = new DataPacket($this->serverlist[$args[1]]['ip'], $this->serverlist[$args[1]]['port'], $data);
             CPAPI::sendPacket($packet);
             $sender->sendMessage("돈을 {$args[1]} 서버로 이동하였습니다.");
             break;
         case '서버추가':
             if (!$sender->hasPermission("moneytransfer.cmd.addserver")) {
                 $sender->sendMessage(TextFormat::RED . "당신은 이 명령어를 실행할 권한이 없습니다.");
                 break;
             }
             if (!isset($args[1]) || !isset($args[2])) {
                 $sender->sendMessage("사용법: /돈이동 서버추가 <서버명> <아이피[:포트]>");
                 break;
             }
             $iport = explode(":", $args[2]);
             $ip = $iport[0];
             isset($iport[1]) ? $port = $iport[1] : ($port = 19132);
             $this->serverlist[$args[1]]['ip'] = $ip;
             $this->serverlist[$args[1]]['port'] = $port;
             $sender->sendMessage("{$args[1]} 서버를 추가하였습니다.");
             break;
         case '서버목록':
             $count = 1;
             if (!is_array($this->serverlist)) {
                 $sender->sendMessage("설정된 서버 목록이 없습니다. 관리자에게 문의하세요.");
                 break;
             }
             $serverlist = "";
             foreach ($this->serverlist as $servername => $v1) {
                 $serverlist .= $servername . '    ';
                 if (++$count % 7 == 0) {
                     $serverlist .= "\n";
                 }
             }
             $sender->sendMessage("서버목록: ");
             $sender->sendMessage($serverlist);
             break;
         case '서버제거':
             if (!$sender->hasPermission("moneytransfer.cmd.deleteserver")) {
                 $sender->sendMessage(TextFormat::RED . "당신은 이 명령어를 실행할 권한이 없습니다.");
                 break;
             }
             if (!isset($args[1])) {
                 $sender->sendMessage("사용법: /돈이동 서버제거 <서버명>");
                 return true;
             }
             if (!isset($this->serverlist[$args[1]])) {
                 $sender->sendMessage("해당 서버가 목록에 존재하지 않습니다.");
                 return true;
             }
             unset($this->serverlist[$args[1]]);
             $sender->sendMessage("{$args[1]} 서버를 서버목록에서 제거했습니다.");
             break;
         default:
             return false;
     }
     return true;
 }
예제 #10
0
 public function onPacketReceive(CustomPacketReceiveEvent $ev)
 {
     $data = $ev->getPacket()->data;
     // json 화 필요할 수도 있음
     if (!is_array($data)) {
         echo "[테스트] 어레이가 아닌 정보 전달됨";
         return;
     }
     if ($data[0] != $this->db["passcode"]) {
         echo "[테스트] 패스코드가 다른 정보 전달됨";
         return;
     }
     if ($this->db["mode"] == "master") {
         // 마스터 서버 코딩
         switch ($data[1]) {
             case "createBank":
                 // slave->master = [0패스코드, 1createBank, 2계좌명, 3username, 4비용]
                 // master->slave = [0패스코드, 1createBank, 2계좌명, 3username, 4true:success|false:failed]
                 if (isset($this->db["bank"][$data[2]])) {
                     $data[4] = false;
                     CPAPI::sendPacket(new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, $data));
                     break;
                 }
                 $this->db["bank"][$data[2]]["price"] = $data[4];
                 $this->db["bank"][$data[2]]["username"] = $data[3];
                 $data[4] = true;
                 CPAPI::sendPacket(new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, $data));
                 break;
             case "useBank":
                 // slave->master = [0패스코드, 1useBank, 2계좌명, 3username]
                 // master->slave = [0패스코드, 1useBank, 2계좌명, 3username, 4true:success|false:failed]
                 if (!isset($this->db["bank"][$data[2]])) {
                     $data[4] = false;
                     CPAPI::sendPacket(new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, $data));
                     break;
                 }
                 $price = $this->db["bank"][$data[2]]["price"];
                 $playerMoney = $this->economyAPI->myMoney($this->db["bank"][$data[2]]["username"]);
                 if ($playerMoney >= $price) {
                     // 해당계좌 돈뺏기
                     $this->economyAPI->reduceMoney($this->db["bank"][$data[2]]["username"], $price);
                     // 해당 돈 유저에게 지급하기
                     $this->economyAPI->addMoney($data[3], $price);
                     $data[4] = true;
                     CPAPI::sendPacket(new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, $data));
                 } else {
                     $data[4] = false;
                     CPAPI::sendPacket(new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, $data));
                 }
                 unset($this->db["bank"][$data[2]]);
                 break;
         }
     } else {
         // 슬레이브 서버 코딩
         $player = $this->getServer()->getPlayer($data[1]);
         if (!$player instanceof Player) {
             return;
         }
         switch ($data[1]) {
             case "createBank":
                 // master->slave = [0패스코드, 1createBank, 2계좌명, 3username, 4true:success|false:failed]
                 // failed-createBank
                 if ($data[4] == false) {
                     $this->message($player, $this->get("failed-createBank"));
                     break;
                 }
                 $this->db["bank"][$data[0]]["price"] = $data[1];
                 $this->db["bank"][$data[0]]["username"] = $player->getName();
                 $this->message($player, $this->get("passcode-created"));
                 break;
             case "useBank":
                 // slave->master = [0패스코드, 1useBank, 2계좌명, 3username]
                 // master->slave = [0패스코드, 1useBank, 2계좌명, 3username, 4true:success|false:failed]
                 break;
         }
     }
 }
예제 #11
0
 public function sendPacket(PlayerChatEvent $event)
 {
     if ($event->isCancelled()) {
         return;
     }
     if (!isset($this->db["name"])) {
         return;
     }
     if (!isset($this->db["pass"])) {
         return;
     }
     $message = $this->getServer()->getLanguage()->translateString($event->getFormat(), [$event->getPlayer()->getDisplayName(), $event->getMessage()]);
     $send = [$this->db["pass"], TextFormat::GOLD . "[ " . $this->db["name"] . " ] " . TextFormat::WHITE . $message];
     // 0-pass, 1-chat
     if (isset($this->db["echoserver"])) {
         foreach ($this->db["echoserver"] as $index => $data) {
             // echo $index . "로 패킷전송을 시도합니다 (" . $send [1] . ")\n";
             $address = explode(":", $index);
             // 0-ip, 1-port
             CPAPI::sendPacket(new DataPacket($address[0], $address[1], json_encode($send)));
         }
     }
 }
예제 #12
0
 public function onDisable()
 {
     foreach (CPAPI::getHaltTasks() as $task) {
         $task[0]($task[1]);
     }
 }
 public function onPacketReceive(CustomPacketReceiveEvent $ev)
 {
     $data = json_decode($ev->getPacket()->data);
     if (!is_array($data) or $data[0] != $this->plugin->getConfig()->get("passcode", false)) {
         return;
     }
     if ($this->plugin->getConfig()->get("servermode", null) == "master") {
         switch ($data[1]) {
             case "online":
                 // online
                 // slave->master = [passcode, online]
                 $this->updateList[$ev->getPacket()->address . ":" . $ev->getPacket()->port]["lastcontact"] = $this->makeTimestamp(date("Y-m-d H:i:s"));
                 if (!isset($this->checkFistConnect[$ev->getPacket()->address . ":" . $ev->getPacket()->port])) {
                     $this->checkFistConnect[$ev->getPacket()->address . ":" . $ev->getPacket()->port] = 1;
                     $this->plugin->getLogger()->info(TextFormat::DARK_AQUA . $ev->getPacket()->address . ":" . $ev->getPacket()->port . " " . $this->plugin->get("mastermode-first-connected"));
                     CPAPI::sendPacket(new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, json_encode([$this->plugin->getConfig()->get("passcode"), "hello", "0", "0"])));
                 }
                 break;
             case "defaultInfoRequest":
                 /* defaultInfoRequest */
                 /* slave->master = [passcode, defaultInfoRequest, username, IP] */
                 /* master->slave = [passcode, defaultInfoRequest, username, isConnected[true|false], isRegistered[true||false], isAutoLogin[true||false], NBT, isCheckAuthReady, lockDomain] */
                 $requestedUserName = $data[2];
                 $requestedUserIp = $data[3];
                 // getUserData
                 $email = $this->plugin->db->getEmailToName($requestedUserName);
                 $userdata = $this->plugin->db->getUserData($email);
                 if ($email === false or $userdata === false) {
                     // did not join
                     $isConnect = false;
                     $isRegistered = false;
                     $isAutoLogin = false;
                     $NBT = null;
                 } else {
                     if (isset($this->onlineUserList[$requestedUserName])) {
                         $isConnect = true;
                     } else {
                         $isConnect = false;
                     }
                     if ($userdata["ip"] == $requestedUserIp and $userdata["name"] == $requestedUserName) {
                         $isAutoLogin = true;
                     } else {
                         $isAutoLogin = false;
                     }
                     $isRegistered = true;
                     $NBT = $this->getPlayerDataFile($requestedUserName);
                 }
                 $isCheckAuthReady = $this->plugin->db->checkAuthReady($requestedUserName);
                 $lockDomain = $this->plugin->db->getLockDomain();
                 $data = [$this->plugin->getConfig()->get("passcode"), "defaultInfoRequest", $requestedUserName, $isConnect, $isRegistered, $isAutoLogin, $NBT, $isCheckAuthReady, $lockDomain];
                 CPAPI::sendPacket(new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, json_encode($data)));
                 break;
             case "loginRequest":
                 // loginRequest
                 // slave->master = [passcode, loginRequest, username, password_hash, IP]
                 // master->slave = [passcode, loginRequest, username, isSuccess[true||false]]
                 $username = $data[2];
                 $password_hash = $data[3];
                 $address = $data[4];
                 $email = $this->plugin->db->getEmailToName($username);
                 $userdata = $this->plugin->db->getUserData($email);
                 if ($email === false or $userdata === false) {
                     $isSuccess = false;
                 } else {
                     if ($userdata["password"] == $password_hash) {
                         $isSuccess = true;
                         $this->onlineUserList[$username] = $ev->getPacket()->address . ":" . $ev->getPacket()->port;
                         $this->plugin->db->updateIPAddress($email, $address);
                     } else {
                         $isSuccess = false;
                     }
                 }
                 $data = [$this->plugin->getConfig()->get("passcode"), "loginRequest", $username, $isSuccess];
                 CPAPI::sendPacket(new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, json_encode($data)));
                 break;
             case "logoutRequest":
                 // logoutRequest
                 // slave->master = [passcode, logoutRequest, username, IP, isUserGenerate]
                 // master->slave = [passcode, logoutRequest, username, isSuccess]
                 $username = $data[2];
                 $address = $data[3];
                 $isUserGenerate = $data[4];
                 if ($isUserGenerate) {
                     $this->plugin->db->logout($this->plugin->db->getEmail($player));
                 }
                 if (isset($this->onlineUserList[$username])) {
                     $isSuccess = true;
                     unset($this->onlineUserList[$username]);
                 } else {
                     $isSuccess = false;
                 }
                 $data = [$this->plugin->getConfig()->get("passcode"), "logoutRequest", $username, $isSuccess];
                 CPAPI::sendPacket(new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, json_encode($data)));
                 break;
             case "registerRequest":
                 // registerRequest
                 // slave->master = [passcode, registerRequest, username, password, IP, email]
                 // master->slave = [passcode, registerRequest, username, isSuccess[true||false]]
                 $username = $data[2];
                 $password = $data[3];
                 $address = $data[4];
                 $email = $data[5];
                 $isSuccess = $this->plugin->db->addUser($email, $password, $address, false, $username);
                 $data = [$this->plugin->getConfig()->get("passcode"), "registerRequest", $username, $isSuccess];
                 if ($this->plugin->db->checkAuthReady($username)) {
                     $this->plugin->db->completeAuthReady($username);
                 }
                 CPAPI::sendPacket(new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, json_encode($data)));
                 break;
             case "unregisterRequest":
                 // unregisterRequest
                 // slave->master = [passcode, unregisterRequest, username]
                 // master->slave = [passcode, unregisterRequest, username, isSuccess]
                 $username = $data[2];
                 if (isset($this->onlineUserList[$username])) {
                     $email = $this->plugin->db->getEmailToName($username);
                     $deleteCheck = $this->plugin->db->deleteUser($email);
                     ($email === false or $deleteCheck === false) ? $isSuccess = false : ($isSuccess = true);
                 } else {
                     $isSuccess = false;
                 }
                 $data = [$this->plugin->getConfig()->get("passcode"), "unregisterRequest", $username, $isSuccess];
                 CPAPI::sendPacket(new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, json_encode($data)));
                 break;
             case "itemSyncro":
                 // itemSyncro
                 // slave->master = [passcode, itemSyncro, username, itemData]
                 // master->slave = [passcode, itemSyncro, username, itemData]
                 $username = $data[2];
                 $itemData = $data[3];
                 $playerdata = $this->getPlayerData($username, $itemData);
                 $this->applyItemData($username, $playerdata);
                 break;
             case "itemSyncroRequest":
                 // itemSyncroRequest
                 // slave->master = [passcode, itemSyncro, username]
                 // master->slave = [passcode, itemSyncro, username, itemData]
                 $username = $data[2];
                 // itemSyncro
                 // slave->master = [passcode, itemSyncro, username, itemData]
                 $data = [$this->plugin->getConfig()->get("passcode"), "itemSyncro", $username, $this->getPlayerDataFile($username)];
                 CPAPI::sendPacket(new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, json_encode($data)));
                 break;
             case "economySyncro":
                 // economySyncro
                 // slave->master = [passcode, economySyncro, username, money]
                 // master->slave = [passcode, economySyncro, username, money]
                 $username = $data[2];
                 $money = $data[3];
                 $this->applyEconomyData($username, $money);
                 $data = [$this->plugin->getConfig()->get("passcode"), "economySyncro", $username, $money];
                 $target_addr = $ev->getPacket()->address . ":" . $ev->getPacket()->port;
                 foreach ($this->updateList as $ipport => $data) {
                     if ($target_addr == $ipport) {
                         continue;
                     }
                     CPAPI::sendPacket(new DataPacket($ev->getPacket()->address, $ev->getPacket()->port, json_encode($data)));
                 }
                 break;
         }
     } else {
         if ($this->plugin->getConfig()->get("servermode", null) == "slave") {
             switch ($data[1]) {
                 case "hello":
                     if (!isset($this->checkFistConnect[$ev->getPacket()->address . ":" . $ev->getPacket()->port])) {
                         $this->checkFistConnect[$ev->getPacket()->address . ":" . $ev->getPacket()->port] = 1;
                         $this->plugin->getLogger()->info(TextFormat::DARK_AQUA . $ev->getPacket()->address . ":" . $ev->getPacket()->port . " " . $this->plugin->get("slavemode-first-connected"));
                     }
                     break;
                 case "defaultInfoRequest":
                     /* defaultInfoRequest */
                     /* slave->master = [passcode, defaultInfoRequest, username, IP] */
                     /* master->slave = [passcode, defaultInfoRequest, username, isConnected[true|false], isRegistered[true||false], isConnected[true||false], NBT, isCheckAuthReady, lockDomain] */
                     $username = $data[2];
                     $isConnect = $data[3];
                     $isRegistered = $data[4];
                     $isAutoLogin = $data[5];
                     $NBT = $data[6];
                     $isCheckAuthReady = $data[7];
                     $lockDomain = $data[8];
                     $this->tmpDb[$username] = ["isConnect" => $isConnect, "isRegistered" => $isRegistered, "isAutoLogin" => $isAutoLogin, "isCheckAuthReady" => $isCheckAuthReady, "lockDomain" => $lockDomain];
                     $player = $this->plugin->getServer()->getPlayer($username);
                     if (!$player instanceof Player) {
                         return;
                     }
                     if ($isConnect) {
                         $this->alreadyLogined($player);
                         return;
                     }
                     $this->applyItemData($username, $this->getPlayerData($username, $NBT));
                     if ($isAutoLogin) {
                         $this->plugin->message($player, $this->plugin->get("automatic-ip-logined"));
                         $this->authenticatePlayer($player);
                         return;
                     }
                     $this->cueAuthenticatePlayer($player);
                     break;
                 case "loginRequest":
                     // loginRequest
                     // slave->master = [passcode, loginRequest, username, password_hash, IP]
                     // master->slave = [passcode, loginRequest, username, isSuccess[true||false]]
                     $username = $data[2];
                     $isSuccess = $data[3];
                     $player = $this->plugin->getServer()->getPlayer($username);
                     if (!$player instanceof Player) {
                         return;
                     }
                     if ($isSuccess) {
                         $this->plugin->message($player, $this->plugin->get("login-is-success"));
                         $this->authenticatePlayer($player);
                     } else {
                         $this->plugin->message($player, $this->plugin->get("login-is-failed"));
                         $this->deauthenticatePlayer($player);
                     }
                     break;
                 case "logoutRequest":
                     // logoutRequest
                     // slave->master = [passcode, logoutRequest, username, IP, isUserGenerate]
                     // master->slave = [passcode, logoutRequest, username, isSuccess]
                     $username = $data[2];
                     $isSuccess = $data[3];
                     $player = $this->plugin->getServer()->getPlayer($username);
                     if (!$player instanceof Player) {
                         return;
                     }
                     if ($isSuccess) {
                         $this->plugin->message($player, $this->plugin->get("logout-complete"));
                         $player->kick("logout");
                     } else {
                         $this->plugin->message($player, $this->plugin->get("logout-failed"));
                     }
                     break;
                 case "registerRequest":
                     // registerRequest
                     // slave->master = [passcode, registerRequest, username, password, IP, email]
                     // master->slave = [passcode, registerRequest, username, isSuccess[true||false]]
                     $username = $data[2];
                     $isSuccess = $data[3];
                     $player = $this->plugin->getServer()->getPlayer($username);
                     if (!$player instanceof Player) {
                         return;
                     }
                     if ($isSuccess) {
                         $this->plugin->message($player, $this->plugin->get("register-complete"));
                         $this->authenticatePlayer($player);
                     } else {
                         $this->plugin->message($player, $this->plugin->get("register-failed"));
                         $this->deauthenticatePlayer($player);
                     }
                     break;
                 case "itemSyncro":
                     // itemSyncro
                     // slave->master = [passcode, itemSyncro, username, itemData]
                     // master->slave = [passcode, itemSyncro, username, itemData]
                     $username = $data[2];
                     $itemData = $data[3];
                     $this->applyItemData($username, $this->getPlayerData($username, $itemData));
                     break;
                 case "economySyncro":
                     // slave
                     // economySyncro
                     // slave->master = [passcode, economySyncro, username, money]
                     // master->slave = [passcode, economySyncro, username, money]
                     $username = $data[2];
                     $money = $data[3];
                     $this->applyEconomyData($username, $money);
                     break;
             }
         }
     }
 }