Merge remote-tracking branch 'refs/remotes/origin/dedicated-rewrite' into dedicated-rewrite
This commit is contained in:
@@ -16,9 +16,8 @@ namespace SharedConstants
|
||||
{
|
||||
// 0.5.0 uses NPv8
|
||||
// 0.6.0 uses NPv9
|
||||
// TODO: Better proto check
|
||||
const int NetworkProtocolVersion = 10;
|
||||
const int NetworkProtocolLowestSupportedVersion = 10;
|
||||
const int NetworkProtocolVersion = 9;
|
||||
const int NetworkProtocolLowestSupportedVersion = 9;
|
||||
const int GameProtocolVersion = 1;
|
||||
const int GameProtocolLowestSupportedVersion = 1;
|
||||
|
||||
|
||||
@@ -120,6 +120,8 @@ public:
|
||||
void optionUpdated(OptionId option, bool value);
|
||||
void optionUpdated(OptionId option, float value);
|
||||
void optionUpdated(OptionId option, int value);
|
||||
|
||||
int getTicks() { return ticks; }
|
||||
#ifdef __APPLE__
|
||||
bool _isSuperFast;
|
||||
bool isSuperFast() { return _isSuperFast; }
|
||||
@@ -197,7 +199,8 @@ public:
|
||||
std::string externalCacheStoragePath;
|
||||
protected:
|
||||
Timer timer;
|
||||
// @note @attn @warn: this is dangerous as fuck!
|
||||
|
||||
// @note @attn @warn: this is dangerous as fuck!
|
||||
volatile bool isGeneratingLevel;
|
||||
bool _hasSignaledGeneratingLevelFinished;
|
||||
|
||||
|
||||
@@ -77,10 +77,10 @@ void PlayerRenderer::render(Entity* mob_, float x, float y, float z, float rot,
|
||||
model = desired;
|
||||
humanoidModel = desired;
|
||||
}
|
||||
LOGI("[PlayerRenderer] %s: skin=%s, modelTex=%dx%d, desired=%s\n",
|
||||
/* LOGI("[PlayerRenderer] %s: skin=%s, modelTex=%dx%d, desired=%s\n",
|
||||
((Player*)mob)->name.c_str(), mob->getTexture().c_str(),
|
||||
humanoidModel->texWidth, humanoidModel->texHeight,
|
||||
(desired == playerModel64 ? "64" : "32"));
|
||||
(desired == playerModel64 ? "64" : "32")); */
|
||||
HumanoidMobRenderer::render(mob_, x, y, z, rot, a);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "../raknet/RakPeerInterface.h"
|
||||
#include "../raknet/PacketPriority.h"
|
||||
#include "platform/log.h"
|
||||
#include "util/Mth.h"
|
||||
#include "world/item/ItemInstance.h"
|
||||
#include "world/level/storage/LevelStorage.h"
|
||||
#include "world/phys/Vec3.h"
|
||||
@@ -196,7 +197,6 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, LoginPac
|
||||
|
||||
LOGI("LoginPacket\n");
|
||||
|
||||
printf("%d", packet->clientNetworkVersion);
|
||||
int loginStatus = LoginStatus::Success;
|
||||
//
|
||||
// Bad/incompatible client version
|
||||
@@ -216,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();
|
||||
@@ -251,6 +252,11 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, LoginPac
|
||||
).write(&bitStream);
|
||||
|
||||
rakPeer->Send(&bitStream, HIGH_PRIORITY, RELIABLE_ORDERED, 0, source, false);
|
||||
|
||||
if (!packet->newProto) {
|
||||
MessagePacket packet("You're using outdated client. Some features disabled.");
|
||||
raknetInstance->send(packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -393,12 +399,22 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, MovePlay
|
||||
//LOGI("MovePlayerPacket\n");
|
||||
if (Entity* entity = level->getEntity(packet->entityId))
|
||||
{
|
||||
|
||||
entity->xd = entity->yd = entity->zd = 0;
|
||||
entity->lerpTo(packet->x, packet->y, packet->z, packet->yRot, packet->xRot, 3);
|
||||
ServerPlayer* player = (ServerPlayer*) getPlayer(source);
|
||||
|
||||
// broadcast this packet to other clients
|
||||
redistributePacket(packet, source);
|
||||
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->getLastMoveTicks());
|
||||
|
||||
if (speed < 2.5f) {
|
||||
entity->xd = entity->yd = entity->zd = 0;
|
||||
entity->lerpTo(packet->x, packet->y, packet->z, packet->yRot, packet->xRot, 3);
|
||||
|
||||
// broadcast this packet to other clients
|
||||
redistributePacket(packet, source);
|
||||
}
|
||||
|
||||
player->setLastMoveTicks(minecraft->getTicks());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -534,7 +550,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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,16 +12,19 @@ ServerLevel::ServerLevel(LevelStorage* levelStorage, const std::string& levelNam
|
||||
void ServerLevel::updateSleepingPlayerList() {
|
||||
bool allPlayersWasSleeping = allPlayersAreSleeping;
|
||||
allPlayersAreSleeping = !players.empty();
|
||||
for(PlayerList::iterator it = players.begin(); it != players.end(); ++it) {
|
||||
|
||||
for (PlayerList::iterator it = players.begin(); it != players.end(); ++it) {
|
||||
Player* player = *it;
|
||||
if(!player->isSleeping()) {
|
||||
|
||||
if (!player->isSleeping()) {
|
||||
allPlayersAreSleeping = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!allPlayersWasSleeping && allPlayersAreSleeping) {
|
||||
if (!allPlayersWasSleeping && allPlayersAreSleeping) {
|
||||
levelEvent(NULL, LevelEvent::ALL_PLAYERS_SLEEPING, 0, 0, 0, 0);
|
||||
for(PlayerList::iterator it = players.begin(); it != players.end(); ++it) {
|
||||
|
||||
for (PlayerList::iterator it = players.begin(); it != players.end(); ++it) {
|
||||
(*it)->setAllPlayersSleeping();
|
||||
}
|
||||
}
|
||||
@@ -29,23 +32,26 @@ void ServerLevel::updateSleepingPlayerList() {
|
||||
|
||||
void ServerLevel::awakenAllPlayers() {
|
||||
allPlayersAreSleeping = false;
|
||||
for(PlayerList::iterator it = players.begin(); it != players.end(); ++it) {
|
||||
|
||||
for (PlayerList::iterator it = players.begin(); it != players.end(); ++it) {
|
||||
Player* player = *it;
|
||||
if(player->isSleeping()) {
|
||||
|
||||
if (player->isSleeping()) {
|
||||
player->stopSleepInBed(false, false, true);
|
||||
player->health = Player::MAX_HEALTH;
|
||||
player->lastHealth = Player::MAX_HEALTH;
|
||||
}
|
||||
}
|
||||
|
||||
SetHealthPacket packet(Player::MAX_HEALTH);
|
||||
raknetInstance->send(packet);
|
||||
}
|
||||
|
||||
bool ServerLevel::allPlayersSleeping() {
|
||||
if(allPlayersAreSleeping && !isClientSide) {
|
||||
if (allPlayersAreSleeping && !isClientSide) {
|
||||
// all players are sleeping, but have they slept long enough?
|
||||
for(PlayerList::iterator it = players.begin(); it != players.end(); ++it) {
|
||||
if(!(*it)->isSleepingLongEnough()) {
|
||||
for (PlayerList::iterator it = players.begin(); it != players.end(); ++it) {
|
||||
if (!(*it)->isSleepingLongEnough()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -55,13 +61,17 @@ bool ServerLevel::allPlayersSleeping() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void ServerLevel::tick(){
|
||||
void ServerLevel::tick() {
|
||||
super::tick();
|
||||
if(allPlayersSleeping()) {
|
||||
|
||||
if (allPlayersSleeping()) {
|
||||
long newTime = levelData.getTime() + TICKS_PER_DAY;
|
||||
|
||||
levelData.setTime(newTime - (newTime % TICKS_PER_DAY));
|
||||
|
||||
SetTimePacket packet(levelData.getTime());
|
||||
raknetInstance->send(packet);
|
||||
|
||||
awakenAllPlayers();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,11 +22,12 @@
|
||||
#include "network/packet/SendInventoryPacket.h"
|
||||
#include "world/entity/player/Inventory.h"
|
||||
|
||||
ServerPlayer::ServerPlayer( Minecraft* minecraft, Level* level )
|
||||
ServerPlayer::ServerPlayer( Minecraft* minecraft, Level* level, bool proto)
|
||||
: super(level, minecraft->isCreativeMode()),
|
||||
_mc(minecraft),
|
||||
_prevHealth(-999),
|
||||
_containerCounter(0)
|
||||
_containerCounter(0),
|
||||
isNewProto(proto)
|
||||
{
|
||||
// hasFakeInventory = true;
|
||||
footSize = 0;
|
||||
|
||||
@@ -15,7 +15,7 @@ class ServerPlayer: public Player,
|
||||
{
|
||||
typedef Player super;
|
||||
public:
|
||||
ServerPlayer(Minecraft* minecraft, Level* level);
|
||||
ServerPlayer(Minecraft* minecraft, Level* level, bool proto);
|
||||
|
||||
~ServerPlayer();
|
||||
|
||||
@@ -43,6 +43,15 @@ public:
|
||||
virtual void stopSleepInBed(bool forcefulWakeUp, bool updateLevelList, bool saveRespawnPoint);
|
||||
|
||||
void completeUsingItem();
|
||||
|
||||
void setLastMoveTicks(int lastMoveTicks) { this->lastMoveTicks = lastMoveTicks; }
|
||||
int getLastMoveTicks() { return lastMoveTicks; }
|
||||
|
||||
void setTicksInAir(int ticksInAir) { this->ticksInAir = ticksInAir; }
|
||||
int getTicksInAir() { return ticksInAir; }
|
||||
|
||||
void setNewProto(bool proto) { isNewProto = proto; }
|
||||
bool getProto() { return isNewProto; }
|
||||
private:
|
||||
void nextContainerCounter();
|
||||
void setContainerMenu( BaseContainerMenu* menu );
|
||||
@@ -50,6 +59,11 @@ private:
|
||||
Minecraft* _mc;
|
||||
int _prevHealth;
|
||||
int _containerCounter;
|
||||
|
||||
int lastMoveTicks = 0;
|
||||
int ticksInAir = 0;
|
||||
|
||||
bool isNewProto = false;
|
||||
};
|
||||
|
||||
#endif /*ServerPlayer_H__*/
|
||||
|
||||
Reference in New Issue
Block a user