Skip to content

Commit

Permalink
revert: revert some ServerPlayer functions
Browse files Browse the repository at this point in the history
  • Loading branch information
OEOTYAN committed Oct 2, 2024
1 parent 0b5728c commit 6bdf66e
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 157 deletions.
43 changes: 0 additions & 43 deletions src-server/ll/core/plugin-abi/Plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
71 changes: 0 additions & 71 deletions src/mc/server/ServerPlayer.cpp

This file was deleted.

43 changes: 0 additions & 43 deletions src/mc/server/ServerPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,56 +38,13 @@ 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
ServerPlayer& operator=(ServerPlayer const&);
ServerPlayer(ServerPlayer const&);
ServerPlayer();

LLNDAPI UserEntityIdentifierComponent const& getUserEntityIdentifier() const;

LLNDAPI UserEntityIdentifierComponent& getUserEntityIdentifier();

LLNDAPI optional_ref<ConnectionRequest const> getConnectionRequest() const;

LLNDAPI NetworkIdentifier const& getNetworkIdentifier() const;

LLNDAPI optional_ref<Certificate const> 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<NetworkPeer::NetworkStatus> getNetworkStatus() const;

/**
* @brief Disconnect player's client
*/
LLAPI void disconnect(std::string_view reason) const;


public:
// NOLINTBEGIN
// vIndex: 6
Expand Down
55 changes: 55 additions & 0 deletions src/mc/world/actor/player/Player.cpp
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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>());
}

UserEntityIdentifierComponent& Player::getUserEntityIdentifier() {
return *(getEntityContext().tryGetComponent<UserEntityIdentifierComponent>());
}

optional_ref<ConnectionRequest const> Player::getConnectionRequest() const {
if (isSimulatedPlayer()) {
return std::nullopt;
}
return ll::service::getServerNetworkHandler()->fetchConnectionRequest(getNetworkIdentifier());
}

NetworkIdentifier const& Player::getNetworkIdentifier() const { return getUserEntityIdentifier().mNetworkId; }

optional_ref<Certificate const> 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<NetworkPeer::NetworkStatus> 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()
Expand All @@ -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) {
Expand Down
41 changes: 41 additions & 0 deletions src/mc/world/actor/player/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -89,11 +92,49 @@ class Player : public ::Mob {
};

public:
LLNDAPI UserEntityIdentifierComponent const& getUserEntityIdentifier() const;

LLNDAPI UserEntityIdentifierComponent& getUserEntityIdentifier();

LLNDAPI optional_ref<ConnectionRequest const> getConnectionRequest() const;

LLNDAPI NetworkIdentifier const& getNetworkIdentifier() const;

LLNDAPI optional_ref<Certificate const> 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<NetworkPeer::NetworkStatus> getNetworkStatus() const;

/**
* @brief Disconnect player's client
*/
LLAPI void disconnect(std::string_view reason) const;
/**
* @brief Send a message to player
*/
Expand Down

0 comments on commit 6bdf66e

Please sign in to comment.