mirror of
https://github.com/smartcmd/MinecraftConsoles.git
synced 2026-05-21 16:13:51 +00:00
Add PlayerPreLoginEvent (#8)
* PlayerPreLoginEvent, comments for more events * basic plugin events * plugin failed to load event * add docs --------- Co-authored-by: sylvessa <225480449+sylvessa@users.noreply.github.com>
This commit is contained in:
parent
33e0ecac56
commit
da2aaf1247
12 changed files with 241 additions and 4 deletions
|
|
@ -18,7 +18,10 @@
|
|||
#include "..\Minecraft.Server\ServerLogManager.h"
|
||||
#include "..\Minecraft.Server\Access\Access.h"
|
||||
#include "..\Minecraft.World\Socket.h"
|
||||
#include <FourKitBridge.h>
|
||||
#include <Windows64/Network/WinsockNetLayer.h>
|
||||
#endif
|
||||
|
||||
// #ifdef __PS3__
|
||||
// #include "PS3\Network\NetworkPlayerSony.h"
|
||||
// #endif
|
||||
|
|
@ -111,6 +114,58 @@ void PendingConnection::handlePreLogin(shared_ptr<PreLoginPacket> packet)
|
|||
}
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(_WINDOWS64) && defined(MINECRAFT_SERVER_BUILD)
|
||||
std::string connectionIp = "";
|
||||
int connectionPort = 0;
|
||||
|
||||
if (!connection || !connection->getSocket()) {
|
||||
goto handlePreLoginEND;
|
||||
}
|
||||
|
||||
unsigned char smallId = connection->getSocket()->getSmallId();
|
||||
if (smallId == 0) {
|
||||
goto handlePreLoginEND;
|
||||
}
|
||||
|
||||
if (!ServerRuntime::ServerLogManager::TryGetConnectionRemoteIp(smallId, &connectionIp))
|
||||
{
|
||||
SOCKET sock = WinsockNetLayer::GetSocketForSmallId(smallId);
|
||||
if (sock != INVALID_SOCKET)
|
||||
{
|
||||
sockaddr_in addr;
|
||||
int addrLen = sizeof(addr);
|
||||
if (getpeername(sock, (sockaddr*)&addr, &addrLen) == 0)
|
||||
{
|
||||
char ipBuf[64] = {};
|
||||
if (inet_ntop(AF_INET, &addr.sin_addr, ipBuf, sizeof(ipBuf)))
|
||||
{
|
||||
connectionIp = ipBuf;
|
||||
connectionPort = (int)ntohs(addr.sin_port);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (connectionIp.empty()) {
|
||||
goto handlePreLoginEND;
|
||||
}
|
||||
} else {
|
||||
SOCKET sock = WinsockNetLayer::GetSocketForSmallId(smallId);
|
||||
if (sock != INVALID_SOCKET)
|
||||
{
|
||||
sockaddr_in addr;
|
||||
int addrLen = sizeof(addr);
|
||||
if (getpeername(sock, (sockaddr*)&addr, &addrLen) == 0)
|
||||
connectionPort = (int)ntohs(addr.sin_port);
|
||||
}
|
||||
}
|
||||
|
||||
if (FourKitBridge::FirePlayerPreLogin(packet->loginKey, connectionIp, connectionPort)) {
|
||||
disconnect(DisconnectPacket::eDisconnect_EndOfStream); //idk what to use here, eventually it should be set by the event
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
handlePreLoginEND:
|
||||
// printf("Server: handlePreLogin\n");
|
||||
name = packet->loginKey; // 4J Stu - Change from the login packet as we know better on client end during the pre-login packet
|
||||
sendPreLoginResponse();
|
||||
|
|
|
|||
|
|
@ -1437,10 +1437,12 @@ void PlayerConnection::handleClientCommand(shared_ptr<ClientCommandPacket> packe
|
|||
|
||||
void PlayerConnection::handleRespawn(shared_ptr<RespawnPacket> packet)
|
||||
{
|
||||
//todo: fire respawn event
|
||||
}
|
||||
|
||||
void PlayerConnection::handleContainerClose(shared_ptr<ContainerClosePacket> packet)
|
||||
{
|
||||
//todo: fire container close event
|
||||
player->doCloseContainer();
|
||||
}
|
||||
|
||||
|
|
@ -1819,6 +1821,7 @@ bool PlayerConnection::isServerPacketListener()
|
|||
|
||||
void PlayerConnection::handlePlayerAbilities(shared_ptr<PlayerAbilitiesPacket> playerAbilitiesPacket)
|
||||
{
|
||||
//todo: fire abilities change event
|
||||
player->abilities.flying = playerAbilitiesPacket->isFlying() && player->abilities.mayfly;
|
||||
}
|
||||
|
||||
|
|
@ -1937,6 +1940,7 @@ void PlayerConnection::handleCustomPayload(shared_ptr<CustomPayloadPacket> custo
|
|||
Slot *slot = beaconMenu->getSlot(0);
|
||||
if (slot->hasItem())
|
||||
{
|
||||
//todo: beacon powered event?
|
||||
slot->remove(1);
|
||||
shared_ptr<BeaconTileEntity> beacon = beaconMenu->getBeacon();
|
||||
beacon->setPrimaryPower(primary);
|
||||
|
|
@ -1950,6 +1954,7 @@ void PlayerConnection::handleCustomPayload(shared_ptr<CustomPayloadPacket> custo
|
|||
AnvilMenu *menu = dynamic_cast<AnvilMenu *>( player->containerMenu);
|
||||
if (menu)
|
||||
{
|
||||
//todo: anvel item rename event?
|
||||
if (customPayloadPacket->data.data == nullptr || customPayloadPacket->data.length < 1)
|
||||
{
|
||||
menu->setItemName(L"");
|
||||
|
|
@ -1977,6 +1982,7 @@ bool PlayerConnection::isDisconnected()
|
|||
|
||||
void PlayerConnection::handleDebugOptions(shared_ptr<DebugOptionsPacket> packet)
|
||||
{
|
||||
//todo: debug options event?
|
||||
#ifdef _DEBUG
|
||||
// Player player = dynamic_pointer_cast<Player>( player->shared_from_this() );
|
||||
player->SetDebugOptions(packet->m_uiVal);
|
||||
|
|
@ -2063,6 +2069,8 @@ void PlayerConnection::handleCraftItem(shared_ptr<CraftItemPacket> packet)
|
|||
}
|
||||
}
|
||||
|
||||
//todo: fire item crafted event?
|
||||
|
||||
// 4J Stu - Fix for #13119 - We should add the item after we remove the ingredients
|
||||
if(player->inventory->add(pTempItemInst)==false )
|
||||
{
|
||||
|
|
@ -2137,6 +2145,7 @@ void PlayerConnection::handleTradeItem(shared_ptr<TradeItemPacket> packet)
|
|||
int buyBMatches = player->inventory->countMatches(buyBItem);
|
||||
if( (buyAItem != nullptr && buyAMatches >= buyAItem->count) && (buyBItem == nullptr || buyBMatches >= buyBItem->count) )
|
||||
{
|
||||
//todo: fire trade event?
|
||||
menu->getMerchant()->notifyTrade(activeRecipe);
|
||||
|
||||
// Remove the items we are purchasing with
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue