Skip to content

Commit

Permalink
fix: fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
OEOTYAN committed Oct 4, 2024
1 parent d3b9138 commit 70e9d2b
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 93 deletions.
8 changes: 4 additions & 4 deletions src/ll/api/command/Optional.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,28 @@ class Optional {

[[nodiscard]] constexpr T const& get() const& {
if (!has_value()) {
throw std::runtime_error{"bad Optional access"};
throw std::bad_optional_access{};
}
return mValue;
}

[[nodiscard]] constexpr T& get() & {
if (!has_value()) {
throw std::runtime_error{"bad Optional access"};
throw std::bad_optional_access{};
}
return mValue;
}

[[nodiscard]] constexpr T const&& get() const&& {
if (!has_value()) {
throw std::runtime_error{"bad Optional access"};
throw std::bad_optional_access{};
}
return std::move(mValue);
}

[[nodiscard]] constexpr T&& get() && {
if (!has_value()) {
throw std::runtime_error{"bad Optional access"};
throw std::bad_optional_access{};
}
return std::move(mValue);
}
Expand Down
5 changes: 4 additions & 1 deletion src/ll/api/command/runtime/ParamKind.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ enum Kind : ParamKindType {
FilePath,
WildcardInt,
WildcardActor,
// New types can only be added here, to keep the ABI stable.
Count,
};
} // namespace ParamKind
Expand Down Expand Up @@ -82,7 +83,9 @@ using ParamKindList = meta::TypeList<
CommandIntegerRange,
CommandFilePath,
CommandWildcardInt,
WildcardCommandSelector<Actor>>;
WildcardCommandSelector<Actor>
// New types can only be added here, to keep the ABI stable.
>;

class ParamStorageType : public Optional<ParamKindList::to<std::variant>> {
public:
Expand Down
4 changes: 2 additions & 2 deletions src/ll/api/reflection/TypeName.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ template <auto f>
consteval std::string_view getRawName() noexcept {
#if defined(_MSC_VER)
constexpr std::string_view n{__FUNCSIG__};
constexpr std::string_view k{"name_of_impl<"};
constexpr std::string_view k{"getRawName<"};
constexpr std::string_view l{">(void) noexcept"};
#else
constexpr std::string_view n{__PRETTY_FUNCTION__};
Expand All @@ -30,7 +30,7 @@ template <class f>
consteval std::string_view getRawName() noexcept {
#if defined(_MSC_VER)
constexpr std::string_view n{__FUNCSIG__};
constexpr std::string_view k{"name_of_impl<"};
constexpr std::string_view k{"getRawName<"};
constexpr std::string_view l{">(void) noexcept"};
#else
constexpr std::string_view n{__PRETTY_FUNCTION__};
Expand Down
18 changes: 10 additions & 8 deletions src/ll/api/utils/StacktraceUtils_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,23 +214,25 @@ SymbolLoader::~SymbolLoader() {
StackTraceEntryInfo getInfo(StacktraceEntry const& entry) {
DbgEngData data;

if (!data.tryInit()) {
return {};
}
auto res = data.getInfo(entry.native_handle());
if (res.name.contains('!')) {
return res;
}
static auto processRange = sys_utils::getImageRange();

if (&*processRange.begin() <= entry.native_handle() && entry.native_handle() < &*processRange.end()) {
size_t length{};
uint disp{};
auto str = pl::symbol_provider::pl_lookup_symbol_disp(entry.native_handle(), &length, &disp);
if (length) {
static auto processName = sys_utils::getModuleFileName(nullptr);
StackTraceEntryInfo res{disp, processName + '!' + str[0]};
static auto processName = sys_utils::getModuleFileName(nullptr);
res = {disp, processName + '!' + str[0]};
pl::symbol_provider::pl_free_lookup_result(str);
return res;
}
}
if (!data.tryInit()) {
return {};
}
return data.getInfo(entry.native_handle());
return res;
}

std::string toString(StacktraceEntry const& entry) {
Expand Down
2 changes: 1 addition & 1 deletion src/mc/common/wrapper/optional_ref.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class optional_ref {

[[nodiscard]] constexpr T& value() const {
if (!has_value()) {
throw std::runtime_error{"bad optional_ref access"};
throw std::bad_optional_access{};
}
return *mPtr;
}
Expand Down
12 changes: 4 additions & 8 deletions src/mc/server/SimulatedPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@ optional_ref<SimulatedPlayer> SimulatedPlayer::create(
DimensionType dimId,
Vec2 const& rotation
) {
if (!ll::service::getServerNetworkHandler()) {
return nullptr;
}
auto ownerPtr = ll::service::getServerNetworkHandler()->createSimulatedPlayer(
name,
std::to_string(ll::random_utils::rand<int64>(INT64_MIN, -1))
);
auto player = ownerPtr.tryUnwrap<SimulatedPlayer>();
auto ownerPtr = ll::service::getServerNetworkHandler().and_then([&](auto& handler) {
return handler.createSimulatedPlayer(name, std::to_string(ll::random_utils::rand<int64>(INT64_MIN, -1)));
});
auto player = ownerPtr.tryUnwrap<SimulatedPlayer>();
if (!player) {
return nullptr;
}
Expand Down
29 changes: 12 additions & 17 deletions src/mc/world/actor/player/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,9 @@ std::string Player::getLocaleCode() const {
}

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();
return ll::service::getNetworkSystem()
.transform([&](auto& system) { return system.getPeerForUser(getNetworkIdentifier()); })
.transform([](auto& peer) { return peer.getNetworkStatus(); });
}

std::string Player::getRealName() const {
Expand All @@ -75,15 +70,15 @@ std::string Player::getRealName() const {
}

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
);
ll::service::getServerNetworkHandler().and_then([&](auto& handler) {
handler.disconnectClient(
getNetworkIdentifier(),
Connection::DisconnectFailReason::Unknown,
std::string{reason},
false
);
return true;
});
}

void Player::sendMessage(std::string_view msg) const { TextPacket::createRawMessage(msg).sendTo(*this); }
Expand Down
Loading

0 comments on commit 70e9d2b

Please sign in to comment.