2019-01-09 20:44:58 +01:00
|
|
|
/*
|
|
|
|
* =====================================================================================
|
|
|
|
*
|
2020-02-08 18:34:26 +09:00
|
|
|
* OpenMiner
|
2020-02-25 01:42:10 +09:00
|
|
|
*
|
2020-02-08 18:34:26 +09:00
|
|
|
* Copyright (C) 2018-2020 Unarelith, Quentin Bazin <openminer@unarelith.net>
|
2020-02-25 01:42:10 +09:00
|
|
|
* Copyright (C) 2019-2020 the OpenMiner contributors (see CONTRIBUTORS.md)
|
|
|
|
*
|
|
|
|
* This file is part of OpenMiner.
|
2019-01-09 20:44:58 +01:00
|
|
|
*
|
2020-02-25 01:42:10 +09:00
|
|
|
* OpenMiner is free software; you can redistribute it and/or
|
2020-02-08 18:34:26 +09:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2019-01-09 20:44:58 +01:00
|
|
|
*
|
2020-02-25 01:42:10 +09:00
|
|
|
* OpenMiner is distributed in the hope that it will be useful,
|
2020-02-08 18:34:26 +09:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2019-01-09 20:44:58 +01:00
|
|
|
*
|
2020-02-08 18:34:26 +09:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2020-02-25 01:42:10 +09:00
|
|
|
* along with OpenMiner; if not, write to the Free Software Foundation, Inc.,
|
2020-02-08 18:34:26 +09:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2019-01-09 20:44:58 +01:00
|
|
|
*
|
|
|
|
* =====================================================================================
|
|
|
|
*/
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
#include <gk/core/IntTypes.hpp>
|
|
|
|
|
|
|
|
#include "Network.hpp"
|
|
|
|
|
|
|
|
std::string Network::commandToString(Network::Command command) {
|
|
|
|
std::map<Network::Command, std::string> commandNames = {
|
2020-03-08 15:28:46 +01:00
|
|
|
{Network::Command::ClientConnect, "ClientConnect"},
|
|
|
|
{Network::Command::ClientDisconnect, "ClientDisconnect"},
|
|
|
|
{Network::Command::ClientOk, "ClientOk"},
|
|
|
|
{Network::Command::ClientRefused, "ClientRefused"},
|
2019-01-18 01:59:26 +01:00
|
|
|
|
2020-03-08 15:28:46 +01:00
|
|
|
{Network::Command::KeyState, "KeyState"},
|
2019-01-18 01:59:26 +01:00
|
|
|
|
2020-03-08 15:28:46 +01:00
|
|
|
{Network::Command::ChunkData, "ChunkData"},
|
|
|
|
{Network::Command::ChunkRequest, "ChunkRequest"},
|
2019-01-18 01:59:26 +01:00
|
|
|
|
2020-03-08 15:28:46 +01:00
|
|
|
{Network::Command::PlayerPlaceBlock, "PlayerPlaceBlock"},
|
|
|
|
{Network::Command::PlayerDigBlock, "PlayerDigBlock"},
|
|
|
|
{Network::Command::PlayerInvUpdate, "PlayerInvUpdate"},
|
|
|
|
{Network::Command::PlayerPosUpdate, "PlayerPosUpdate"},
|
|
|
|
{Network::Command::PlayerSpawn, "PlayerSpawn"},
|
|
|
|
{Network::Command::PlayerInventory, "PlayerInventory"},
|
|
|
|
{Network::Command::PlayerCreativeWindow, "PlayerCreativeWindow"},
|
|
|
|
{Network::Command::PlayerChangeDimension, "PlayerChangeDimension"},
|
2019-01-18 01:59:26 +01:00
|
|
|
|
2020-03-08 15:28:46 +01:00
|
|
|
{Network::Command::BlockUpdate, "BlockUpdate"},
|
|
|
|
{Network::Command::BlockActivated, "BlockActivated"},
|
|
|
|
{Network::Command::BlockGUIData, "BlockGUIData"},
|
|
|
|
{Network::Command::BlockInvUpdate, "BlockInvUpdate"},
|
|
|
|
{Network::Command::BlockDataUpdate, "BlockDataUpdate"},
|
2019-01-23 00:04:03 +01:00
|
|
|
|
2020-03-08 15:28:46 +01:00
|
|
|
{Network::Command::RegistryData, "RegistryData"},
|
2020-02-21 17:25:56 +09:00
|
|
|
|
2020-04-05 18:58:25 +02:00
|
|
|
{Network::Command::ChatMessage, "ChatMessage"},
|
2020-04-28 18:16:40 +02:00
|
|
|
|
|
|
|
{Network::Command::EntitySpawn, "EntitySpawn"},
|
|
|
|
{Network::Command::EntityPosUpdate, "EntityPosUpdate"},
|
|
|
|
{Network::Command::EntityDrawableDef, "EntityDrawableDef"},
|
2019-01-09 20:44:58 +01:00
|
|
|
};
|
2020-04-05 18:58:25 +02:00
|
|
|
|
2019-01-09 20:44:58 +01:00
|
|
|
return commandNames[command];
|
|
|
|
}
|
|
|
|
|
|
|
|
sf::Packet &operator<<(sf::Packet &packet, Network::Command command) {
|
|
|
|
return packet << static_cast<u16>(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
sf::Packet &operator>>(sf::Packet &packet, Network::Command &command) {
|
|
|
|
u16 tmp;
|
|
|
|
packet >> tmp;
|
|
|
|
command = static_cast<Network::Command>(tmp);
|
|
|
|
return packet;
|
|
|
|
}
|
|
|
|
|