Skip to content

Commit

Permalink
fix: fix IP bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
OEOTYAN committed Nov 30, 2023
1 parent ef5c1dd commit d94ffa7
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 27 deletions.
1 change: 0 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ cert-str34-c,
cppcoreguidelines-interfaces-global-init,
cppcoreguidelines-narrowing-conversions,
cppcoreguidelines-pro-type-member-init,
cppcoreguidelines-pro-type-static-cast-downcast,
cppcoreguidelines-slicing,
google-default-arguments,
google-explicit-constructor,
Expand Down
9 changes: 5 additions & 4 deletions src/ll/api/event/command/ExecuteCommandEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
#include "ll/api/event/Cancellable.h"
#include "ll/api/event/Event.h"

#include "mc/codebuilder/MCRESULT.h"
#include "mc/server/commands/CommandContext.h"
#include "mc/server/commands/MinecraftCommands.h"

struct MCRESULT;
class MinecraftCommands;

namespace ll::event::command {
class ExecutingCommandEvent : public Cancellable<Event> {
Expand All @@ -31,13 +32,13 @@ class ExecutedCommandEvent : public Event {
MCRESULT& result;
MinecraftCommands& minecraftCommands;
CommandContext const& commandContext;
bool suppressOutput;
bool const& suppressOutput;

constexpr explicit ExecutedCommandEvent(
MCRESULT& result,
MinecraftCommands& minecraftCommands,
CommandContext& commandContext,
bool suppressOutput
bool const& suppressOutput
)
: result(result),
minecraftCommands(minecraftCommands),
Expand Down
14 changes: 8 additions & 6 deletions src/ll/api/event/player/PlayerConnectEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#include "ll/api/event/Emitter.h"
#include "ll/api/memory/Hook.h"

#include "mc/network/ConnectionRequest.h"
#include "mc/network/NetworkIdentifier.h"

#include "mc/network/ServerNetworkHandler.h"


Expand All @@ -11,14 +14,13 @@ LL_TYPED_INSTANCE_HOOK(
PlayerConnectEventHook,
HookPriority::Normal,
ServerNetworkHandler,
"?sendLoginMessageLocal@ServerNetworkHandler@@QEAAXAEBVNetworkIdentifier@@AEBVConnectionRequest@@AEAVServerPlayer@@"
"@Z",
&ServerNetworkHandler::sendLoginMessageLocal,
void,
const NetworkIdentifier& ni,
const ConnectionRequest& cr,
const ServerPlayer& sp
NetworkIdentifier const& ni,
ConnectionRequest const& cr,
ServerPlayer& sp
) {
auto event = PlayerConnectEvent(sp);
auto event = PlayerConnectEvent{ni, cr, sp};
EventBus::getInstance().publish(event);
if (event.isCancelled()) {
return;
Expand Down
16 changes: 14 additions & 2 deletions src/ll/api/event/player/PlayerConnectEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,24 @@

#include "mc/server/ServerPlayer.h"

class ConnectionRequest;
class NetworkIdentifier;

namespace ll::event::player {
class PlayerConnectEvent : public Cancellable<Event> {
public:
const ServerPlayer& player;
NetworkIdentifier const& networkIdentifier;
ConnectionRequest const& connectionRequest;
ServerPlayer& player;

constexpr explicit PlayerConnectEvent(const ServerPlayer& player) : player(player) {}
constexpr explicit PlayerConnectEvent(
NetworkIdentifier const& networkIdentifier,
ConnectionRequest const& connectionRequest,
ServerPlayer& player
)
: networkIdentifier(networkIdentifier),
connectionRequest(connectionRequest),
player(player) {}

LLNDAPI static std::unique_ptr<EmitterBase> emitterFactory(ListenerBase&);
};
Expand Down
3 changes: 1 addition & 2 deletions src/ll/api/event/player/PlayerLeaveEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
namespace ll::event::player {

LL_TYPED_INSTANCE_HOOK(PlayerLeaveEventHook, HookPriority::Normal, ServerPlayer, &ServerPlayer::disconnect, void) {
auto event = PlayerLeaveEvent(*this);
EventBus::getInstance().publish(event);
EventBus::getInstance().publish(PlayerLeaveEvent{*this});
origin();
}

Expand Down
12 changes: 4 additions & 8 deletions src/ll/api/service/GlobalService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,14 @@ LL_AUTO_INSTANCE_HOOK(LevelDestructor, HookPriority::High, "??1Level@@UEAA@XZ",

// RakNet::RakPeer

LL_AUTO_STATIC_HOOK(
RakNetRakPeerCreater,
HookPriority::High,
createUniqueRakPeer,
RakNet::RakPeerInterface::InstanceOwner
) {
LL_AUTO_INSTANCE_HOOK(RakNetRakPeerConstructor, HookPriority::High, "??0RakPeer@RakNet@@QEAA@XZ", RakNet::RakPeer*) {
auto self = origin();
ll::Global<RakNet::RakPeer>.init((RakNet::RakPeer*)self.get());
ll::Global<RakNet::RakPeer>.init(self);
unhook();
return self;
}
LL_AUTO_INSTANCE_HOOK(RakNetRakPeerDestructor, HookPriority::High, "??1RakPeer@RakNet@@UEAA@XZ", void) {
ll::Global<RakNet::RakPeer>.init(nullptr);
if ((void*)this == (void*)ll::Global<RakNet::RakPeer>.get()) ll::Global<RakNet::RakPeer>.init(nullptr);
origin();
}

Expand Down
3 changes: 2 additions & 1 deletion src/ll/test/EventTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "ll/api/event/player/PlayerConnectEvent.h"
#include "ll/api/event/player/PlayerJoinEvent.h"
#include "ll/api/event/player/PlayerLeaveEvent.h"
#include "mc/codebuilder/MCRESULT.h"
#include "mc/nbt/CompoundTag.h"

#include "ll/api/base/FixedString.h"
Expand Down Expand Up @@ -125,7 +126,7 @@ LL_AUTO_TYPED_INSTANCE_HOOK(
ll::logger.debug("result: {}", ev.result.getFullCode());
});
bus.emplaceListener<player::PlayerConnectEvent>([](player::PlayerConnectEvent& ev) {
ll::logger.debug("Player connect: {}", ev.player.getRealName());
ll::logger.debug("Player connect: {} {}", ev.player.getRealName(), ev.player.getIPAndPort());
});
bus.emplaceListener<player::PlayerJoinEvent>([](player::PlayerJoinEvent& ev) {
ll::logger.debug("Player join: {}", ev.player.getRealName());
Expand Down
7 changes: 4 additions & 3 deletions src/mc/network/NetworkIdentifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#include "ll/api/service/GlobalService.h"

std::string NetworkIdentifier::getIPAndPort() const {
if (!ll::Global<RakNet::RakPeer>) { return ""; }
std::string rv = ll::Global<RakNet::RakPeer>->GetSystemAddressFromGuid(mGuid).ToString(':');
return rv.substr(0, rv.find('|'));
if (!ll::Global<RakNet::RakPeer>) {
return "";
}
return ll::Global<RakNet::RakPeer>->GetSystemAddressFromGuid(mGuid).ToString(':');
}

0 comments on commit d94ffa7

Please sign in to comment.