FEAT: New proto check

This commit is contained in:
2026-03-27 20:16:59 +02:00
parent 8be842a8ac
commit 97b0fb4d46
6 changed files with 41 additions and 20 deletions

View File

@@ -87,7 +87,7 @@ void ClientSideNetworkHandler::onConnect(const RakNet::RakNetGUID& hostGuid)
serverGuid = hostGuid;
clearChunksLoaded();
LoginPacket packet(minecraft->options.getStringValue(OPTIONS_USERNAME).c_str(), SharedConstants::NetworkProtocolVersion);
LoginPacket packet(minecraft->options.getStringValue(OPTIONS_USERNAME).c_str(), SharedConstants::NetworkProtocolVersion, true);
raknetInstance->send(packet);
}

View File

@@ -194,7 +194,6 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, LoginPac
LOGI("LoginPacket\n");
printf("%d", packet->clientNetworkVersion);
int loginStatus = LoginStatus::Success;
//
// Bad/incompatible client version
@@ -204,6 +203,9 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, LoginPac
if (oldClient || oldServer)
loginStatus = oldClient? LoginStatus::Failed_ClientOld : LoginStatus::Failed_ServerOld;
if (packet->newProto) {
printf("New proto! \n");
}
RakNet::BitStream bitStream;
LoginStatusPacket(loginStatus).write(&bitStream);
rakPeer->Send(&bitStream, HIGH_PRIORITY, RELIABLE_ORDERED, 0, source, false);
@@ -214,8 +216,9 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, LoginPac
//
// Valid client version
//
Player* newPlayer = new ServerPlayer(minecraft, level);
Player* newPlayer = new ServerPlayer(minecraft, level, packet->newProto);
minecraft->gameMode->initAbilities(newPlayer->abilities);
newPlayer->owner = source;
newPlayer->name = packet->clientName.C_String();
@@ -366,7 +369,7 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, MovePlay
float vectorDist = sqrt( (packet->x - entity->x) * (packet->x - entity->x) +
(packet->y - entity->y) * (packet->y - entity->y) +
(packet->z - entity->z) * (packet->z - entity->z));
float speed = vectorDist / (minecraft->getTicks() - player->lastMoveTicks);
float speed = vectorDist / (minecraft->getTicks() - player->getLastMoveTicks());
if (speed < 2.5f) {
entity->xd = entity->yd = entity->zd = 0;
@@ -376,7 +379,7 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, MovePlay
redistributePacket(packet, source);
}
player->lastMoveTicks = minecraft->getTicks();
player->setLastMoveTicks(minecraft->getTicks());
}
}
@@ -512,7 +515,7 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, PlayerAr
if (!player) return;
if (rakPeer->GetMyGUID() == player->owner) return;
LOGI("Equip armor: %i %i %i %i\n", packet->head, packet->torso, packet->legs, packet->feet);
// LOGI("Equip armor: %i %i %i %i\n", packet->head, packet->torso, packet->legs, packet->feet);
packet->fillIn(player);
redistributePacket(packet, source);

View File

@@ -9,17 +9,20 @@ public:
RakNet::RakString clientName;
int clientNetworkVersion;
int clientNetworkLowestSupportedVersion;
bool newProto;
LoginPacket()
: clientNetworkVersion(-1),
clientNetworkLowestSupportedVersion(-1)
clientNetworkLowestSupportedVersion(-1),
newProto(false)
{
}
LoginPacket(const RakNet::RakString& clientName, int clientVersion)
LoginPacket(const RakNet::RakString& clientName, int clientVersion, bool newProto)
: clientName(clientName),
clientNetworkVersion(clientVersion),
clientNetworkLowestSupportedVersion(clientVersion)
clientNetworkLowestSupportedVersion(clientVersion),
newProto(newProto)
{
}
@@ -29,6 +32,7 @@ public:
bitStream->Write(clientName);
bitStream->Write(clientNetworkVersion);
bitStream->Write(clientNetworkLowestSupportedVersion);
bitStream->Write(newProto);
}
void read(RakNet::BitStream* bitStream)
@@ -39,6 +43,11 @@ public:
if (bitStream->GetNumberOfUnreadBits() > 0) {
bitStream->Read(clientNetworkVersion);
bitStream->Read(clientNetworkLowestSupportedVersion);
// Checking for new proto
if (bitStream->GetNumberOfUnreadBits() > 0) {
bitStream->Read(newProto);
}
}
}