修复sendTextPack问题

This commit is contained in:
Qiuzhizhe 2022-10-14 11:39:17 +08:00
parent 50695e60b9
commit ca410cd29d
No known key found for this signature in database
GPG Key ID: 4EF4BF5521540263
4 changed files with 59 additions and 39 deletions

View File

@ -10,7 +10,16 @@
class NetworkHandler {
#define AFTER_EXTRA
// Add Member There
public:
enum NetworkStatisticsConfig;
class Connection
{
public:
Connection() = delete;
Connection(Connection const&) = delete;
Connection(Connection const&&) = delete;
};
#undef AFTER_EXTRA
#ifndef DISABLE_CONSTRUCTOR_PREVENTION_NETWORKHANDLER
public:

View File

@ -42,7 +42,7 @@ public:
LIAPI std::string getIP();
LIAPI string getLanguageCode();
LIAPI string getServerAddress();
LIAPI NetworkIdentifier* getNetworkIdentifier();
LIAPI NetworkIdentifier* getNetworkIdentifier() const;
LIAPI Certificate* getCertificate()const;
LIAPI std::pair<BlockPos, int> getRespawnPosition();
LIAPI float getAvgPacketLoss();
@ -168,6 +168,8 @@ public:
LIAPI bool sendRawFormPacket(unsigned formId, const string& data) const;
//LIAPI bool sendToastPacket(string title, string msg);
void sendNetworkPacket(class Packet &) const;
LIAPI static bool isValid(Player* player);
// For compatibility
@ -360,7 +362,7 @@ public:
/*418*/ virtual bool isItemInCooldown(enum CooldownType) const;
/*419*/ virtual void sendInventoryTransaction(class InventoryTransaction const &) const = 0;
/*420*/ virtual void sendComplexInventoryTransaction(std::unique_ptr<class ComplexInventoryTransaction>) const = 0;
/*421*/ virtual void sendNetworkPacket(class Packet &) const;
// /*421*/ virtual void sendNetworkPacket(class Packet &) const;
/*422*/ virtual class PlayerEventCoordinator & getPlayerEventCoordinator() = 0;
/*423*/ virtual class MoveInputHandler * getMoveInputHandler() = 0;
/*424*/ virtual enum InputMode getInputMode() const = 0;

View File

@ -13,22 +13,23 @@ class TextPacket : public Packet {
#define AFTER_EXTRA
// Add Member There
// char filler[168];
public:
TextType mType;
std::string mAuthor;
std::string mMessage;
std::vector<std::string> params;
bool mLocalize;
std::vector<std::string> params;//参数用于替换mMessage里的%
bool mLocalize = 0;//是否本地化
std::string mXuid;
std::string mPlatformId;
public:
TextPacket(){};
//TextPacket(){};
#undef AFTER_EXTRA
#ifndef DISABLE_CONSTRUCTOR_PREVENTION_TEXTPACKET
public:
class TextPacket& operator=(class TextPacket const &) = delete;
TextPacket(class TextPacket const &) = delete;
//TextPacket() = delete;
TextPacket() = delete;
#endif
public:

View File

@ -44,7 +44,7 @@
extern Logger logger;
NetworkIdentifier* Player::getNetworkIdentifier() {
NetworkIdentifier* Player::getNetworkIdentifier() const{
//ServerPlayer::isHostingPlayer
return dAccess<NetworkIdentifier*>(this, 2432);
}
@ -116,6 +116,12 @@ int Player::getPlayerLevel(){
return attr.getCurrentValue();
}
void Player::sendNetworkPacket(class Packet &pkt) const{
void (Player::*rv)(class Packet&) const;
*((void**)&rv) = dlsym("?sendNetworkPacket@ServerPlayer@@UEBAXAEAVPacket@@@Z");
return (this->*rv)(pkt);
}
string Player::getDeviceTypeName() {
switch ((int)getPlatform()) {
case -1:
@ -157,7 +163,8 @@ string Player::getDeviceTypeName() {
bool Player::kick(const std::string& msg) {
NetworkIdentifier* pNetworkIdentifier = getNetworkIdentifier();
Global<ServerNetworkHandler>->disconnectClient(*pNetworkIdentifier, 0, msg, 0);
unsigned char subID = dAccess<unsigned char>(this,3520);
Global<ServerNetworkHandler>->disconnectClient(*pNetworkIdentifier, subID, msg, 0);
return true;
}
@ -497,35 +504,36 @@ static_assert(sizeof(TextPacket) == 208);
static_assert(sizeof(TransferPacket) == 80);
bool Player::sendTextPacket(string text, TextType Type) const {
BinaryStream wp;
wp.reserve(8 + text.size());
wp.writeUnsignedChar((char)Type);
wp.writeBool(true);
switch (Type) {
case TextType::CHAT:
case TextType::WHISPER:
case TextType::ANNOUNCEMENT:
wp.writeString("Server");
case TextType::RAW:
case TextType::TIP:
case TextType::SYSTEM:
case TextType::JSON_WHISPER:
case TextType::JSON:
wp.writeString(text);
break;
case TextType::TRANSLATION:
case TextType::POPUP:
case TextType::JUKEBOX_POPUP:
wp.writeString(text);
wp.writeUnsignedVarInt(0);
break;
}
wp.writeString("");
wp.writeString("");
auto pkt = MinecraftPackets::createPacket(MinecraftPacketIds::Text);
pkt->read(wp);
sendNetworkPacket(*pkt);
// BinaryStream wp;
// wp.reserve(8 + text.size());
// wp.writeUnsignedChar((char)Type);
// wp.writeBool(true);
// switch (Type) {
// case TextType::CHAT:
// case TextType::WHISPER:
// case TextType::ANNOUNCEMENT:
// wp.writeString("Server");
// case TextType::RAW:
// case TextType::TIP:
// case TextType::SYSTEM:
// case TextType::JSON_WHISPER:
// case TextType::JSON:
// wp.writeString(text);
// break;
// case TextType::TRANSLATION:
// case TextType::POPUP:
// case TextType::JUKEBOX_POPUP:
// wp.writeString(text);
// wp.writeUnsignedVarInt(0);
// break;
// }
// wp.writeString("");
// wp.writeString("");
//
// auto pkt = MinecraftPackets::createPacket(MinecraftPacketIds::Text);
// pkt->read(wp);
auto pkt = TextPacket::createSystemMessage(text);
this->sendNetworkPacket(pkt);
return true;
}