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.5.0 uses NPv8
|
||||||
// 0.6.0 uses NPv9
|
// 0.6.0 uses NPv9
|
||||||
// TODO: Better proto check
|
const int NetworkProtocolVersion = 9;
|
||||||
const int NetworkProtocolVersion = 10;
|
const int NetworkProtocolLowestSupportedVersion = 9;
|
||||||
const int NetworkProtocolLowestSupportedVersion = 10;
|
|
||||||
const int GameProtocolVersion = 1;
|
const int GameProtocolVersion = 1;
|
||||||
const int GameProtocolLowestSupportedVersion = 1;
|
const int GameProtocolLowestSupportedVersion = 1;
|
||||||
|
|
||||||
|
|||||||
@@ -120,6 +120,8 @@ public:
|
|||||||
void optionUpdated(OptionId option, bool value);
|
void optionUpdated(OptionId option, bool value);
|
||||||
void optionUpdated(OptionId option, float value);
|
void optionUpdated(OptionId option, float value);
|
||||||
void optionUpdated(OptionId option, int value);
|
void optionUpdated(OptionId option, int value);
|
||||||
|
|
||||||
|
int getTicks() { return ticks; }
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
bool _isSuperFast;
|
bool _isSuperFast;
|
||||||
bool isSuperFast() { return _isSuperFast; }
|
bool isSuperFast() { return _isSuperFast; }
|
||||||
@@ -197,6 +199,7 @@ public:
|
|||||||
std::string externalCacheStoragePath;
|
std::string externalCacheStoragePath;
|
||||||
protected:
|
protected:
|
||||||
Timer timer;
|
Timer timer;
|
||||||
|
|
||||||
// @note @attn @warn: this is dangerous as fuck!
|
// @note @attn @warn: this is dangerous as fuck!
|
||||||
volatile bool isGeneratingLevel;
|
volatile bool isGeneratingLevel;
|
||||||
bool _hasSignaledGeneratingLevelFinished;
|
bool _hasSignaledGeneratingLevelFinished;
|
||||||
|
|||||||
@@ -77,10 +77,10 @@ void PlayerRenderer::render(Entity* mob_, float x, float y, float z, float rot,
|
|||||||
model = desired;
|
model = desired;
|
||||||
humanoidModel = 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(),
|
((Player*)mob)->name.c_str(), mob->getTexture().c_str(),
|
||||||
humanoidModel->texWidth, humanoidModel->texHeight,
|
humanoidModel->texWidth, humanoidModel->texHeight,
|
||||||
(desired == playerModel64 ? "64" : "32"));
|
(desired == playerModel64 ? "64" : "32")); */
|
||||||
HumanoidMobRenderer::render(mob_, x, y, z, rot, a);
|
HumanoidMobRenderer::render(mob_, x, y, z, rot, a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ void ClientSideNetworkHandler::onConnect(const RakNet::RakNetGUID& hostGuid)
|
|||||||
serverGuid = hostGuid;
|
serverGuid = hostGuid;
|
||||||
|
|
||||||
clearChunksLoaded();
|
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);
|
raknetInstance->send(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include "../raknet/RakPeerInterface.h"
|
#include "../raknet/RakPeerInterface.h"
|
||||||
#include "../raknet/PacketPriority.h"
|
#include "../raknet/PacketPriority.h"
|
||||||
#include "platform/log.h"
|
#include "platform/log.h"
|
||||||
|
#include "util/Mth.h"
|
||||||
#include "world/item/ItemInstance.h"
|
#include "world/item/ItemInstance.h"
|
||||||
#include "world/level/storage/LevelStorage.h"
|
#include "world/level/storage/LevelStorage.h"
|
||||||
#include "world/phys/Vec3.h"
|
#include "world/phys/Vec3.h"
|
||||||
@@ -196,7 +197,6 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, LoginPac
|
|||||||
|
|
||||||
LOGI("LoginPacket\n");
|
LOGI("LoginPacket\n");
|
||||||
|
|
||||||
printf("%d", packet->clientNetworkVersion);
|
|
||||||
int loginStatus = LoginStatus::Success;
|
int loginStatus = LoginStatus::Success;
|
||||||
//
|
//
|
||||||
// Bad/incompatible client version
|
// Bad/incompatible client version
|
||||||
@@ -216,7 +216,8 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, LoginPac
|
|||||||
//
|
//
|
||||||
// Valid client version
|
// Valid client version
|
||||||
//
|
//
|
||||||
Player* newPlayer = new ServerPlayer(minecraft, level);
|
|
||||||
|
Player* newPlayer = new ServerPlayer(minecraft, level, packet->newProto);
|
||||||
|
|
||||||
minecraft->gameMode->initAbilities(newPlayer->abilities);
|
minecraft->gameMode->initAbilities(newPlayer->abilities);
|
||||||
newPlayer->owner = source;
|
newPlayer->owner = source;
|
||||||
@@ -251,6 +252,11 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, LoginPac
|
|||||||
).write(&bitStream);
|
).write(&bitStream);
|
||||||
|
|
||||||
rakPeer->Send(&bitStream, HIGH_PRIORITY, RELIABLE_ORDERED, 0, source, false);
|
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,13 +399,23 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, MovePlay
|
|||||||
//LOGI("MovePlayerPacket\n");
|
//LOGI("MovePlayerPacket\n");
|
||||||
if (Entity* entity = level->getEntity(packet->entityId))
|
if (Entity* entity = level->getEntity(packet->entityId))
|
||||||
{
|
{
|
||||||
|
ServerPlayer* player = (ServerPlayer*) getPlayer(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->xd = entity->yd = entity->zd = 0;
|
||||||
entity->lerpTo(packet->x, packet->y, packet->z, packet->yRot, packet->xRot, 3);
|
entity->lerpTo(packet->x, packet->y, packet->z, packet->yRot, packet->xRot, 3);
|
||||||
|
|
||||||
// broadcast this packet to other clients
|
// broadcast this packet to other clients
|
||||||
redistributePacket(packet, source);
|
redistributePacket(packet, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
player->setLastMoveTicks(minecraft->getTicks());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, RemoveBlockPacket* packet){
|
void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, RemoveBlockPacket* packet){
|
||||||
@@ -534,7 +550,7 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, PlayerAr
|
|||||||
if (!player) return;
|
if (!player) return;
|
||||||
if (rakPeer->GetMyGUID() == player->owner) 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);
|
packet->fillIn(player);
|
||||||
redistributePacket(packet, source);
|
redistributePacket(packet, source);
|
||||||
|
|||||||
@@ -9,17 +9,20 @@ public:
|
|||||||
RakNet::RakString clientName;
|
RakNet::RakString clientName;
|
||||||
int clientNetworkVersion;
|
int clientNetworkVersion;
|
||||||
int clientNetworkLowestSupportedVersion;
|
int clientNetworkLowestSupportedVersion;
|
||||||
|
bool newProto;
|
||||||
|
|
||||||
LoginPacket()
|
LoginPacket()
|
||||||
: clientNetworkVersion(-1),
|
: 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),
|
: clientName(clientName),
|
||||||
clientNetworkVersion(clientVersion),
|
clientNetworkVersion(clientVersion),
|
||||||
clientNetworkLowestSupportedVersion(clientVersion)
|
clientNetworkLowestSupportedVersion(clientVersion),
|
||||||
|
newProto(newProto)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,6 +32,7 @@ public:
|
|||||||
bitStream->Write(clientName);
|
bitStream->Write(clientName);
|
||||||
bitStream->Write(clientNetworkVersion);
|
bitStream->Write(clientNetworkVersion);
|
||||||
bitStream->Write(clientNetworkLowestSupportedVersion);
|
bitStream->Write(clientNetworkLowestSupportedVersion);
|
||||||
|
bitStream->Write(newProto);
|
||||||
}
|
}
|
||||||
|
|
||||||
void read(RakNet::BitStream* bitStream)
|
void read(RakNet::BitStream* bitStream)
|
||||||
@@ -39,6 +43,11 @@ public:
|
|||||||
if (bitStream->GetNumberOfUnreadBits() > 0) {
|
if (bitStream->GetNumberOfUnreadBits() > 0) {
|
||||||
bitStream->Read(clientNetworkVersion);
|
bitStream->Read(clientNetworkVersion);
|
||||||
bitStream->Read(clientNetworkLowestSupportedVersion);
|
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() {
|
void ServerLevel::updateSleepingPlayerList() {
|
||||||
bool allPlayersWasSleeping = allPlayersAreSleeping;
|
bool allPlayersWasSleeping = allPlayersAreSleeping;
|
||||||
allPlayersAreSleeping = !players.empty();
|
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;
|
Player* player = *it;
|
||||||
if(!player->isSleeping()) {
|
|
||||||
|
if (!player->isSleeping()) {
|
||||||
allPlayersAreSleeping = false;
|
allPlayersAreSleeping = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!allPlayersWasSleeping && allPlayersAreSleeping) {
|
if (!allPlayersWasSleeping && allPlayersAreSleeping) {
|
||||||
levelEvent(NULL, LevelEvent::ALL_PLAYERS_SLEEPING, 0, 0, 0, 0);
|
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();
|
(*it)->setAllPlayersSleeping();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -29,23 +32,26 @@ void ServerLevel::updateSleepingPlayerList() {
|
|||||||
|
|
||||||
void ServerLevel::awakenAllPlayers() {
|
void ServerLevel::awakenAllPlayers() {
|
||||||
allPlayersAreSleeping = false;
|
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;
|
Player* player = *it;
|
||||||
if(player->isSleeping()) {
|
|
||||||
|
if (player->isSleeping()) {
|
||||||
player->stopSleepInBed(false, false, true);
|
player->stopSleepInBed(false, false, true);
|
||||||
player->health = Player::MAX_HEALTH;
|
player->health = Player::MAX_HEALTH;
|
||||||
player->lastHealth = Player::MAX_HEALTH;
|
player->lastHealth = Player::MAX_HEALTH;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SetHealthPacket packet(Player::MAX_HEALTH);
|
SetHealthPacket packet(Player::MAX_HEALTH);
|
||||||
raknetInstance->send(packet);
|
raknetInstance->send(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ServerLevel::allPlayersSleeping() {
|
bool ServerLevel::allPlayersSleeping() {
|
||||||
if(allPlayersAreSleeping && !isClientSide) {
|
if (allPlayersAreSleeping && !isClientSide) {
|
||||||
// all players are sleeping, but have they slept long enough?
|
// all players are sleeping, but have they slept long enough?
|
||||||
for(PlayerList::iterator it = players.begin(); it != players.end(); ++it) {
|
for (PlayerList::iterator it = players.begin(); it != players.end(); ++it) {
|
||||||
if(!(*it)->isSleepingLongEnough()) {
|
if (!(*it)->isSleepingLongEnough()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -55,13 +61,17 @@ bool ServerLevel::allPlayersSleeping() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerLevel::tick(){
|
void ServerLevel::tick() {
|
||||||
super::tick();
|
super::tick();
|
||||||
if(allPlayersSleeping()) {
|
|
||||||
|
if (allPlayersSleeping()) {
|
||||||
long newTime = levelData.getTime() + TICKS_PER_DAY;
|
long newTime = levelData.getTime() + TICKS_PER_DAY;
|
||||||
|
|
||||||
levelData.setTime(newTime - (newTime % TICKS_PER_DAY));
|
levelData.setTime(newTime - (newTime % TICKS_PER_DAY));
|
||||||
|
|
||||||
SetTimePacket packet(levelData.getTime());
|
SetTimePacket packet(levelData.getTime());
|
||||||
raknetInstance->send(packet);
|
raknetInstance->send(packet);
|
||||||
|
|
||||||
awakenAllPlayers();
|
awakenAllPlayers();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,11 +22,12 @@
|
|||||||
#include "network/packet/SendInventoryPacket.h"
|
#include "network/packet/SendInventoryPacket.h"
|
||||||
#include "world/entity/player/Inventory.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()),
|
: super(level, minecraft->isCreativeMode()),
|
||||||
_mc(minecraft),
|
_mc(minecraft),
|
||||||
_prevHealth(-999),
|
_prevHealth(-999),
|
||||||
_containerCounter(0)
|
_containerCounter(0),
|
||||||
|
isNewProto(proto)
|
||||||
{
|
{
|
||||||
// hasFakeInventory = true;
|
// hasFakeInventory = true;
|
||||||
footSize = 0;
|
footSize = 0;
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class ServerPlayer: public Player,
|
|||||||
{
|
{
|
||||||
typedef Player super;
|
typedef Player super;
|
||||||
public:
|
public:
|
||||||
ServerPlayer(Minecraft* minecraft, Level* level);
|
ServerPlayer(Minecraft* minecraft, Level* level, bool proto);
|
||||||
|
|
||||||
~ServerPlayer();
|
~ServerPlayer();
|
||||||
|
|
||||||
@@ -43,6 +43,15 @@ public:
|
|||||||
virtual void stopSleepInBed(bool forcefulWakeUp, bool updateLevelList, bool saveRespawnPoint);
|
virtual void stopSleepInBed(bool forcefulWakeUp, bool updateLevelList, bool saveRespawnPoint);
|
||||||
|
|
||||||
void completeUsingItem();
|
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:
|
private:
|
||||||
void nextContainerCounter();
|
void nextContainerCounter();
|
||||||
void setContainerMenu( BaseContainerMenu* menu );
|
void setContainerMenu( BaseContainerMenu* menu );
|
||||||
@@ -50,6 +59,11 @@ private:
|
|||||||
Minecraft* _mc;
|
Minecraft* _mc;
|
||||||
int _prevHealth;
|
int _prevHealth;
|
||||||
int _containerCounter;
|
int _containerCounter;
|
||||||
|
|
||||||
|
int lastMoveTicks = 0;
|
||||||
|
int ticksInAir = 0;
|
||||||
|
|
||||||
|
bool isNewProto = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /*ServerPlayer_H__*/
|
#endif /*ServerPlayer_H__*/
|
||||||
|
|||||||
Reference in New Issue
Block a user