From 6bdf66e11a2b3b88c7984349caa847880c48ad54 Mon Sep 17 00:00:00 2001 From: OEOTYAN Date: Thu, 3 Oct 2024 00:49:30 +0800 Subject: [PATCH] revert: revert some ServerPlayer functions --- src-server/ll/core/plugin-abi/Plugin.cpp | 43 -------------- src/mc/server/ServerPlayer.cpp | 71 ------------------------ src/mc/server/ServerPlayer.h | 43 -------------- src/mc/world/actor/player/Player.cpp | 55 ++++++++++++++++++ src/mc/world/actor/player/Player.h | 41 ++++++++++++++ 5 files changed, 96 insertions(+), 157 deletions(-) delete mode 100644 src/mc/server/ServerPlayer.cpp diff --git a/src-server/ll/core/plugin-abi/Plugin.cpp b/src-server/ll/core/plugin-abi/Plugin.cpp index 714fe0be84..23adf48cda 100644 --- a/src-server/ll/core/plugin-abi/Plugin.cpp +++ b/src-server/ll/core/plugin-abi/Plugin.cpp @@ -110,46 +110,3 @@ Logger& Plugin::getLogger() const { linker, \ "/export:?self@PlayerEvent@player@event@ll@@QEBAAEAVServerPlayer@@XZ=?self@PlayerEvent@player@event@ll@@QEBAAEAVPlayer@@XZ" \ ) -#pragma comment( \ - linker, \ - "/export:?disconnect@Player@@QEBAXV?$basic_string_view@DU?$char_traits@D@std@@@std@@@Z=?disconnect@ServerPlayer@@QEBAXV?$basic_string_view@DU?$char_traits@D@std@@@std@@@Z" \ -) -#pragma comment( \ - linker, \ - "/export:?getCertificate@Player@@QEBA?AV?$optional_ref@$$CBVCertificate@@@@XZ=?getCertificate@ServerPlayer@@QEBA?AV?$optional_ref@$$CBVCertificate@@@@XZ" \ -) -#pragma comment( \ - linker, \ - "/export:?getClientSubId@Player@@QEBAAEBW4SubClientId@@XZ=?getClientSubId@ServerPlayer@@QEBAAEBW4SubClientId@@XZ" \ -) -#pragma comment( \ - linker, \ - "/export:?getConnectionRequest@Player@@QEBA?AV?$optional_ref@$$CBVConnectionRequest@@@@XZ=?getConnectionRequest@ServerPlayer@@QEBA?AV?$optional_ref@$$CBVConnectionRequest@@@@XZ" \ -) -#pragma comment( \ - linker, \ - "/export:?getIPAndPort@Player@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ=?getIPAndPort@ServerPlayer@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ" \ -) -#pragma comment( \ - linker, \ - "/export:?getLocaleName@Player@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ=?getLocaleCode@ServerPlayer@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ" \ -) -#pragma comment( \ - linker, \ - "/export:?getNetworkIdentifier@Player@@QEBAAEBVNetworkIdentifier@@XZ=?getNetworkIdentifier@ServerPlayer@@QEBAAEBVNetworkIdentifier@@XZ" \ -) -#pragma comment( \ - linker, \ - "/export:?getNetworkStatus@Player@@QEBA?AV?$optional@UNetworkStatus@NetworkPeer@@@std@@XZ=?getNetworkStatus@ServerPlayer@@QEBA?AV?$optional@UNetworkStatus@NetworkPeer@@@std@@XZ" \ -) -#pragma comment( \ - linker, \ - "/export:?getUserEntityIdentifier@Player@@QEAAAEAVUserEntityIdentifierComponent@@XZ=?getUserEntityIdentifier@ServerPlayer@@QEAAAEAVUserEntityIdentifierComponent@@XZ" \ -) -#pragma comment( \ - linker, \ - "/export:?getUserEntityIdentifier@Player@@QEBAAEBVUserEntityIdentifierComponent@@XZ=?getUserEntityIdentifier@ServerPlayer@@QEBAAEBVUserEntityIdentifierComponent@@XZ" \ -) -#pragma comment(linker, "/export:?getUuid@Player@@QEBAAEBVUUID@mce@@XZ=?getUuid@ServerPlayer@@QEBAAEBVUUID@mce@@XZ") - -#pragma comment(linker, "/export:?sendTo@Packet@@QEBAXAEBVPlayer@@@Z=?sendTo@Packet@@QEBAXAEBVServerPlayer@@@Z") diff --git a/src/mc/server/ServerPlayer.cpp b/src/mc/server/ServerPlayer.cpp deleted file mode 100644 index eab313fdcf..0000000000 --- a/src/mc/server/ServerPlayer.cpp +++ /dev/null @@ -1,71 +0,0 @@ - -#include "mc/certificates/ExtendedCertificate.h" - -#include "ll/api/service/Bedrock.h" - -#include "mc/certificates/WebToken.h" -#include "mc/locale/I18n.h" -#include "mc/locale/Localization.h" -#include "mc/network/ConnectionRequest.h" -#include "mc/network/MinecraftPackets.h" -#include "mc/network/NetworkIdentifier.h" -#include "mc/network/NetworkPeer.h" -#include "mc/network/NetworkSystem.h" -#include "mc/network/ServerNetworkHandler.h" -#include "mc/server/ServerLevel.h" -#include "mc/server/ServerPlayer.h" -#include "mc/world/Minecraft.h" - -UserEntityIdentifierComponent const& ServerPlayer::getUserEntityIdentifier() const { - return *(getEntityContext().tryGetComponent()); -} - -UserEntityIdentifierComponent& ServerPlayer::getUserEntityIdentifier() { - return *(getEntityContext().tryGetComponent()); -} - -optional_ref ServerPlayer::getConnectionRequest() const { - if (isSimulatedPlayer()) { - return std::nullopt; - } - return ll::service::getServerNetworkHandler().transform([&](auto& handler) { - return handler.fetchConnectionRequest(getNetworkIdentifier()); - }); -} - -NetworkIdentifier const& ServerPlayer::getNetworkIdentifier() const { return getUserEntityIdentifier().mNetworkId; } - -optional_ref ServerPlayer::getCertificate() const { - return getUserEntityIdentifier().mCertificate.get(); -} - -SubClientId const& ServerPlayer::getClientSubId() const { return getUserEntityIdentifier().mClientSubId; } - -mce::UUID const& ServerPlayer::getUuid() const { return getUserEntityIdentifier().mClientUUID; } - -std::string ServerPlayer::getIPAndPort() const { return getNetworkIdentifier().getIPAndPort(); } - -std::string ServerPlayer::getLocaleCode() const { - if (auto request = getConnectionRequest()) { - return request->mRawToken->mDataInfo["LanguageCode"].asString({}); - } - return {}; -} - -std::optional ServerPlayer::getNetworkStatus() const { - return ll::service::getNetworkSystem() - .and_then([&](auto& system) { return optional_ref{system.getPeerForUser(getNetworkIdentifier())}; }) - .and_then([&](auto& peer) { return peer.getNetworkStatus(); }); -} - -void ServerPlayer::disconnect(std::string_view reason) const { - ll::service::getServerNetworkHandler().transform([&](auto& handler) { - handler.disconnectClient( - getNetworkIdentifier(), - Connection::DisconnectFailReason::Unknown, - std::string{reason}, - false - ); - return true; - }); -} diff --git a/src/mc/server/ServerPlayer.h b/src/mc/server/ServerPlayer.h index 5b8da59e42..ef90925957 100644 --- a/src/mc/server/ServerPlayer.h +++ b/src/mc/server/ServerPlayer.h @@ -38,11 +38,6 @@ namespace mce { class Color; } namespace mce { class UUID; } // clang-format on -class NetworkIdentifier; -class Certificate; -class UserEntityIdentifierComponent; -class ConnectionRequest; - class ServerPlayer : public ::Player { public: // prevent constructor by default @@ -50,44 +45,6 @@ class ServerPlayer : public ::Player { ServerPlayer(ServerPlayer const&); ServerPlayer(); - LLNDAPI UserEntityIdentifierComponent const& getUserEntityIdentifier() const; - - LLNDAPI UserEntityIdentifierComponent& getUserEntityIdentifier(); - - LLNDAPI optional_ref getConnectionRequest() const; - - LLNDAPI NetworkIdentifier const& getNetworkIdentifier() const; - - LLNDAPI optional_ref getCertificate() const; - - LLNDAPI SubClientId const& getClientSubId() const; - - /** - * @brief Get the player's uuid - * @return Player's uuid - */ - LLNDAPI mce::UUID const& getUuid() const; - - /** - * @brief Get the player's IP and port - * @return player's IP and port - */ - LLNDAPI std::string getIPAndPort() const; - - /** - * @brief Get the player's lang code. - * @return the player's lang code. - */ - LLNDAPI std::string getLocaleCode() const; - - LLNDAPI std::optional getNetworkStatus() const; - - /** - * @brief Disconnect player's client - */ - LLAPI void disconnect(std::string_view reason) const; - - public: // NOLINTBEGIN // vIndex: 6 diff --git a/src/mc/world/actor/player/Player.cpp b/src/mc/world/actor/player/Player.cpp index 5c9e795b02..028cc91e57 100644 --- a/src/mc/world/actor/player/Player.cpp +++ b/src/mc/world/actor/player/Player.cpp @@ -1,6 +1,7 @@ #include "mc/world/actor/player/Player.h" #include "ll/api/memory/Memory.h" +#include "ll/api/service/Bedrock.h" #include "mc/certificates/ExtendedCertificate.h" #include "mc/certificates/WebToken.h" @@ -22,6 +23,48 @@ #include "mc/world/level/AdventureSettings.h" #include "mc/world/level/LayeredAbilities.h" +UserEntityIdentifierComponent const& Player::getUserEntityIdentifier() const { + return *(getEntityContext().tryGetComponent()); +} + +UserEntityIdentifierComponent& Player::getUserEntityIdentifier() { + return *(getEntityContext().tryGetComponent()); +} + +optional_ref Player::getConnectionRequest() const { + if (isSimulatedPlayer()) { + return std::nullopt; + } + return ll::service::getServerNetworkHandler()->fetchConnectionRequest(getNetworkIdentifier()); +} + +NetworkIdentifier const& Player::getNetworkIdentifier() const { return getUserEntityIdentifier().mNetworkId; } + +optional_ref Player::getCertificate() const { return getUserEntityIdentifier().mCertificate.get(); } + +SubClientId const& Player::getClientSubId() const { return getUserEntityIdentifier().mClientSubId; } + +mce::UUID const& Player::getUuid() const { return getUserEntityIdentifier().mClientUUID; } + +std::string Player::getIPAndPort() const { return getNetworkIdentifier().getIPAndPort(); } + +std::string Player::getLocaleName() const { + if (auto request = getConnectionRequest()) { + return request->mRawToken->mDataInfo["LanguageCode"].asString({}); + } + return {}; +} + +std::optional Player::getNetworkStatus() const { + if (!ll::service::getNetworkSystem()) { + return std::nullopt; + } + auto peer = ll::service::getNetworkSystem()->getPeerForUser(getNetworkIdentifier()); + if (!peer) { + return std::nullopt; + } + return peer->getNetworkStatus(); +} std::string Player::getRealName() const { return getEntityContext() @@ -31,6 +74,18 @@ std::string Player::getRealName() const { .value_or(getName()); } +void Player::disconnect(std::string_view reason) const { + if (!ll::service::getServerNetworkHandler()) { + return; + } + ll::service::getServerNetworkHandler()->disconnectClient( + getNetworkIdentifier(), + Connection::DisconnectFailReason::Unknown, + std::string{reason}, + false + ); +} + void Player::sendMessage(std::string_view msg) const { TextPacket::createRawMessage(msg).sendTo(*this); } LLAPI void Player::setAbility(::AbilitiesIndex index, bool value) { diff --git a/src/mc/world/actor/player/Player.h b/src/mc/world/actor/player/Player.h index 9b0fe00a43..35a2ceb8f5 100644 --- a/src/mc/world/actor/player/Player.h +++ b/src/mc/world/actor/player/Player.h @@ -47,6 +47,9 @@ namespace mce { class Color; } namespace mce { class UUID; } // clang-format on +class NetworkIdentifier; +class Certificate; +class ConnectionRequest; class Packet; class PlayerEventCoordinator; @@ -89,11 +92,49 @@ class Player : public ::Mob { }; public: + LLNDAPI UserEntityIdentifierComponent const& getUserEntityIdentifier() const; + + LLNDAPI UserEntityIdentifierComponent& getUserEntityIdentifier(); + + LLNDAPI optional_ref getConnectionRequest() const; + + LLNDAPI NetworkIdentifier const& getNetworkIdentifier() const; + + LLNDAPI optional_ref getCertificate() const; + + LLNDAPI SubClientId const& getClientSubId() const; + + /** + * @brief Get the player's uuid + * @return Player's uuid + */ + LLNDAPI mce::UUID const& getUuid() const; + + /** + * @brief Get the player's IP and port + * @return player's IP and port + */ + LLNDAPI std::string getIPAndPort() const; + /** * @brief Get the player's real in-game nickname * @return player's real in-game nickname */ LLNDAPI std::string getRealName() const; + + /** + * @brief Get the name of the player's langtext. + * @return The name of the player's langtext. + * @warning This is not the player's in-game nickname. + */ + LLNDAPI std::string getLocaleName() const; + + LLNDAPI std::optional getNetworkStatus() const; + + /** + * @brief Disconnect player's client + */ + LLAPI void disconnect(std::string_view reason) const; /** * @brief Send a message to player */