public function onPacketRecieve(CustomPacketReceiveEvent $event) { echo "Incoming Packet!\n"; if ($event->getPacket()->address != $this->mainServer["ip"]) { $this->getLogger()->info(TextFormat::LIGHT_PURPLE . "Packet from " . $event->getPacket()->address . ":" . $event->getPacket()->port . " has been blocked!"); return; } $data = json_decode($event->getPacket()->data, true); if (!isset($data["TYPE"])) { return; } switch ($data["TYPE"]) { case GCFramework::PACKET_TYPE_POST_WHOLE_RANK: case GCFramework::PACKET_TYPE_POST_GAME_RANK: case GCFramework::PACKET_TYPE_POST_DESCRIPTION: if ($data["USER"] === null) { $this->getLogger()->info($data["MESSAGE"]); } else { $player = $this->getServer()->getPlayerExact($data["USER"]); if ($player !== null) { $player->sendMessage($data["MESSAGE"]); } } break; case GCFramework::PACKET_TYPE_POST_GAME_MESSAGE: $this->getServer()->broadcastMessage($data["MESSAGE"]); break; } }
public function onCustomPacketReceiveEvent(\ifteam\CustomPacket\event\CustomPacketReceiveEvent $event) { $receivedData = (array) json_decode($event->getPacket()->data, true); if (is_array($receivedData) && isset($receivedData[3]) && $receivedData[0] == $this->passcode) { $this->caster->receive($receivedData[1], $receivedData[2]); } }
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); }
public function onPacketReceive(CustomPacketReceiveEvent $event) { if (!$this->plugin->getConfig()->get("echo-enabled", false)) { return; } // $data[0] "passcode" => $passcode, // $data[1] "name" => $myName, // $data[2] "message" => $message $passcode = $this->plugin->getConfig()->get("echo-passcode", null); if ($passcode === null) { return; } $data = json_decode($event->getPacket()->data); if (!is_array($data) or !isset($data[0])) { return; } if ($passcode !== $data[0]) { return; } $this->broadcastMessage("[" . $data[1] . "] " . $data[2], $data[1], $data[1]); }
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; } }
/** * 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 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; } } } }
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; } }
public function onDataPacketRecieve(CustomPacketReceiveEvent $event) { $packet = $event->getPacket(); $array = json_decode($packet->data); if ($array[0] != "MoneyTransfer") { return; } $player = $array[1]; $amount = $array[2]; $this->economy->addMoney($player, $amount); $this->getLogger()->info("플레이어 {$player}가 {$amount}원을 다른서버에서 옮겨왔습니다."); }
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; } } }
public function onPacketReceive(CustomPacketReceiveEvent $ev) { // echo "패킷받음\n"; if (!isset($this->db["name"])) { return; } if (!isset($this->db["pass"])) { return; } $data = json_decode($ev->getPacket()->data); if (!is_array($data)) { // echo "[테스트] 어레이가 아닌 정보 전달됨\n"; $ev->getPacket()->printDump(); return; } if ($data[0] != $this->db["pass"]) { // echo "[테스트] 패스코드가 다른 정보 전달됨\n"; var_dump($data[0]); return; } $this->getServer()->broadcastMessage($data[1]); }
public function onPacketRecieve(CustomPacketReceiveEvent $event) { //echo "Incoming Packet!\n"; if (!in_array($event->getPacket()->address, $this->ipWhitelist)) { $this->getLogger()->info(TextFormat::LIGHT_PURPLE . "Packet from " . $event->getPacket()->address . ":" . $event->getPacket()->port . " has been blocked!"); return; } $data = json_decode($event->getPacket()->data, true); if (!isset($data["TYPE"])) { return; } switch ($data["TYPE"]) { case GCFramework::PACKET_TYPE_GAME_FINISH: $message = $this->onGameFinish($data["NAME"], $data["WINNER"], $data["MESSAGE"]); GCFramework::sendPacket($event->getPacket()->address, $event->getPacket()->port, ["TYPE" => GCFramework::PACKET_TYPE_POST_GAME_MESSAGE, "MESSAGE" => $message]); break; case GCFramework::PACKET_TYPE_GET_DESCRIPTION: GCFramework::sendPacket($event->getPacket()->address, $event->getPacket()->port, ["TYPE" => GCFramework::PACKET_TYPE_POST_DESCRIPTION, "USER" => $data["USER"], "MESSAGE" => $this->getGameDescription($data["NAME"])]); break; case GCFramework::PACKET_TYPE_GET_GAME_RANK: GCFramework::sendPacket($event->getPacket()->address, $event->getPacket()->port, ["TYPE" => GCFramework::PACKET_TYPE_POST_GAME_RANK, "USER" => $data["USER"], "MESSAGE" => $this->getRank($data["NAME"], $data["PAGE"], $data["USER"])]); break; case GCFramework::PACKET_TYPE_GET_WHOLE_RANK: GCFramework::sendPacket($event->getPacket()->address, $event->getPacket()->port, ["TYPE" => GCFramework::PACKET_TYPE_POST_WHOLE_RANK, "USER" => $data["USER"], "MESSAGE" => $this->getWholeRank($data["PAGE"], $data["USER"])]); break; } }
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; } } } }