From 7981c4525d37232c03a5a32aabc441bef371e6a1 Mon Sep 17 00:00:00 2001 From: Quentin Bazin Date: Mon, 22 Jun 2020 00:59:24 +0200 Subject: [PATCH] Fixed #125. --- source/client/world/ClientWorld.hpp | 2 +- source/common/world/Player.hpp | 6 +++--- source/server/network/ChatCommandHandler.cpp | 17 +++++++++++------ source/server/world/ServerWorld.cpp | 2 +- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/source/client/world/ClientWorld.hpp b/source/client/world/ClientWorld.hpp index b51aa711..f1a23484 100644 --- a/source/client/world/ClientWorld.hpp +++ b/source/client/world/ClientWorld.hpp @@ -84,7 +84,7 @@ class ClientWorld : public World, public gk::Drawable { ClientCommandHandler *m_client = nullptr; gk::Camera *m_camera = nullptr; - mutable gk::Vector4f m_closestInitializedChunk{0, 0, 0, 1000000}; + mutable gk::Vector4d m_closestInitializedChunk{0, 0, 0, 1000000}; const Sky *m_sky = nullptr; }; diff --git a/source/common/world/Player.hpp b/source/common/world/Player.hpp index 29afbd2c..e8a6b424 100644 --- a/source/common/world/Player.hpp +++ b/source/common/world/Player.hpp @@ -74,9 +74,9 @@ class Player : public gk::ISerializable { u16 m_dimension = 0; - float m_viewAngleH; - float m_viewAngleV; - float m_viewAngleRoll; + float m_viewAngleH = 0; + float m_viewAngleV = 0; + float m_viewAngleRoll = 0; u16 m_clientID = 0; diff --git a/source/server/network/ChatCommandHandler.cpp b/source/server/network/ChatCommandHandler.cpp index dd5d2183..5df07192 100644 --- a/source/server/network/ChatCommandHandler.cpp +++ b/source/server/network/ChatCommandHandler.cpp @@ -75,15 +75,20 @@ void ChatCommandHandler::teleportationCommand(const std::vector &co m_server.sendChatMessage(0, "Usage: /tp x y z", &client); } else { - s32 x = std::stoi(command.at(1)); - s32 y = std::stoi(command.at(2)); - s32 z = std::stoi(command.at(3)); + try { + s32 x = std::stoi(command.at(1)); + s32 y = std::stoi(command.at(2)); + s32 z = std::stoi(command.at(3)); - m_server.setPlayerPosition(client.id, x, y, z); + m_server.setPlayerPosition(client.id, x, y, z); - m_server.sendPlayerPosUpdate(client.id, true); + m_server.sendPlayerPosUpdate(client.id, true); - m_server.sendChatMessage(0, "Teleported to " + std::to_string(x) + " " + std::to_string(y) + " " + std::to_string(z), &client); + m_server.sendChatMessage(0, "Teleported to " + std::to_string(x) + " " + std::to_string(y) + " " + std::to_string(z), &client); + } + catch (std::out_of_range &e) { + m_server.sendChatMessage(0, "Invalid coordinates", &client); + } } } diff --git a/source/server/world/ServerWorld.cpp b/source/server/world/ServerWorld.cpp index dee94fc2..ece04271 100644 --- a/source/server/world/ServerWorld.cpp +++ b/source/server/world/ServerWorld.cpp @@ -131,7 +131,7 @@ void ServerWorld::sendChunkData(const ClientInfo &client, ServerChunk &chunk) { chunk.setSent(true); chunk.setChanged(false); - // std::cout << "Chunk at (" << chunk->x() << ", " << chunk->y() << ", " << chunk->z() << ") sent to client" << std::endl; + // std::cout << "Chunk at (" << chunk.x() << ", " << chunk.y() << ", " << chunk.z() << ") sent to client" << std::endl; } void ServerWorld::sendRequestedData(ClientInfo &client, int cx, int cy, int cz) {