From dc40ee64cf287d6cb21e0353a93a8c42d4e0378d Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Tue, 13 Jan 2015 00:23:01 +1100 Subject: [PATCH] common builds cleanly --- .../network/packet_types/monster_packet.cpp | 76 +++++++++++++++++++ .../network/packet_types/monster_packet.hpp | 48 ++++++++++++ common/network/serial_packet.hpp | 8 +- common/network/serial_packet_type.hpp | 2 +- common/network/serial_utility.cpp | 31 ++++++-- 5 files changed, 155 insertions(+), 10 deletions(-) create mode 100644 common/network/packet_types/monster_packet.cpp create mode 100644 common/network/packet_types/monster_packet.hpp diff --git a/common/network/packet_types/monster_packet.cpp b/common/network/packet_types/monster_packet.cpp new file mode 100644 index 0000000..5304550 --- /dev/null +++ b/common/network/packet_types/monster_packet.cpp @@ -0,0 +1,76 @@ +/* Copyright: (c) Kayne Ruse 2013-2015 + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 3. This notice may not be removed or altered from any source + * distribution. +*/ +#include "monster_packet.hpp" + +#include "serial_utility.hpp" + +void serializeMonster(void* buffer, MonsterPacket* packet) { + serialCopy(&buffer, &packet->type, sizeof(SerialPacketType)); + + //identify the monster + serialCopy(&buffer, &packet->monsterIndex, sizeof(int)); + serialCopy(&buffer, packet->handle, PACKET_STRING_SIZE); + serialCopy(&buffer, packet->avatar, PACKET_STRING_SIZE); + + //bounds + serialCopy(&buffer, &packet->bounds.x, sizeof(int)); + serialCopy(&buffer, &packet->bounds.y, sizeof(int)); + serialCopy(&buffer, &packet->bounds.w, sizeof(int)); + serialCopy(&buffer, &packet->bounds.h, sizeof(int)); + + + //location + serialCopy(&buffer, &packet->roomIndex, sizeof(int)); + serialCopy(&buffer, &packet->origin.x, sizeof(double)); + serialCopy(&buffer, &packet->origin.y, sizeof(double)); + serialCopy(&buffer, &packet->motion.x, sizeof(double)); + serialCopy(&buffer, &packet->motion.y, sizeof(double)); + + //attack data + //TODO +} + +void deserializeMonster(void* buffer, MonsterPacket* packet) { + deserialCopy(&buffer, &packet->type, sizeof(SerialPacketType)); + + //identify the monster + deserialCopy(&buffer, &packet->monsterIndex, sizeof(int)); + deserialCopy(&buffer, packet->handle, PACKET_STRING_SIZE); + deserialCopy(&buffer, packet->avatar, PACKET_STRING_SIZE); + + //bounds + deserialCopy(&buffer, &packet->bounds.x, sizeof(int)); + deserialCopy(&buffer, &packet->bounds.y, sizeof(int)); + deserialCopy(&buffer, &packet->bounds.w, sizeof(int)); + deserialCopy(&buffer, &packet->bounds.h, sizeof(int)); + + + //location + deserialCopy(&buffer, &packet->roomIndex, sizeof(int)); + deserialCopy(&buffer, &packet->origin.x, sizeof(double)); + deserialCopy(&buffer, &packet->origin.y, sizeof(double)); + deserialCopy(&buffer, &packet->motion.x, sizeof(double)); + deserialCopy(&buffer, &packet->motion.y, sizeof(double)); + + //attack data + //TODO +} diff --git a/common/network/packet_types/monster_packet.hpp b/common/network/packet_types/monster_packet.hpp new file mode 100644 index 0000000..97ebd38 --- /dev/null +++ b/common/network/packet_types/monster_packet.hpp @@ -0,0 +1,48 @@ +/* Copyright: (c) Kayne Ruse 2013-2015 + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 3. This notice may not be removed or altered from any source + * distribution. +*/ +#ifndef MONSTERPACKET_HPP_ +#define MONSTERPACKET_HPP_ + +#include "serial_packet_base.hpp" + +#include "bounding_box.hpp" +#include "vector2.hpp" + +struct MonsterPacket : SerialPacketBase { + //identify the monster + int monsterIndex; + char handle[PACKET_STRING_SIZE]; + char avatar[PACKET_STRING_SIZE]; + BoundingBox bounds; + + //location + int roomIndex; + Vector2 origin; + Vector2 motion; + + //TODO: attack data +}; + +void serializeMonster(void* buffer, MonsterPacket* packet); +void deserializeMonster(void* buffer, MonsterPacket* packet); + +#endif \ No newline at end of file diff --git a/common/network/serial_packet.hpp b/common/network/serial_packet.hpp index b7a8412..fad3dce 100644 --- a/common/network/serial_packet.hpp +++ b/common/network/serial_packet.hpp @@ -25,6 +25,7 @@ #include "serial_packet_base.hpp" #include "character_packet.hpp" #include "client_packet.hpp" +#include "monster_packet.hpp" #include "region_packet.hpp" #include "server_packet.hpp" #include "text_packet.hpp" @@ -38,9 +39,10 @@ constexpr int NETWORK_VERSION = -1; union MaxPacket { CharacterPacket a; ClientPacket b; - RegionPacket c; - ServerPacket d; - TextPacket e; + MonsterPacket c; + RegionPacket d; + ServerPacket e; + TextPacket f; }; constexpr int MAX_PACKET_SIZE = sizeof(MaxPacket); diff --git a/common/network/serial_packet_type.hpp b/common/network/serial_packet_type.hpp index 54d6bfa..bfd808c 100644 --- a/common/network/serial_packet_type.hpp +++ b/common/network/serial_packet_type.hpp @@ -109,7 +109,7 @@ enum class SerialPacketType { //------------------------- //MonsterPacket // monster index, - // handle, avatar, hitbox? + // handle, avatar, hitbox // room index, origin, motion // TODO: attack data //------------------------- diff --git a/common/network/serial_utility.cpp b/common/network/serial_utility.cpp index a0d2c61..e258a9e 100644 --- a/common/network/serial_utility.cpp +++ b/common/network/serial_utility.cpp @@ -24,6 +24,7 @@ //packet types #include "character_packet.hpp" #include "client_packet.hpp" +#include "monster_packet.hpp" #include "region_packet.hpp" #include "server_packet.hpp" #include "text_packet.hpp" @@ -75,16 +76,25 @@ void serializePacket(void* buffer, SerialPacketBase* packet) { case SerialPacketType::QUERY_CHARACTER_EXISTS: case SerialPacketType::QUERY_CHARACTER_STATS: case SerialPacketType::QUERY_CHARACTER_LOCATION: - case SerialPacketType::CHARACTER_SET_ROOM: - case SerialPacketType::CHARACTER_SET_ORIGIN: - case SerialPacketType::CHARACTER_SET_MOTION: + case SerialPacketType::CHARACTER_MOVEMENT: + case SerialPacketType::CHARACTER_ATTACK: serializeCharacter(buffer, static_cast(packet)); break; + case SerialPacketType::MONSTER_CREATE: + case SerialPacketType::MONSTER_DELETE: + case SerialPacketType::QUERY_MONSTER_EXISTS: + case SerialPacketType::QUERY_MONSTER_STATS: + case SerialPacketType::QUERY_MONSTER_LOCATION: + case SerialPacketType::MONSTER_MOVEMENT: + case SerialPacketType::MONSTER_ATTACK: + serializeMonster(buffer, static_cast(packet)); + break; case SerialPacketType::TEXT_BROADCAST: case SerialPacketType::JOIN_REJECTION: case SerialPacketType::LOGIN_REJECTION: case SerialPacketType::REGION_REJECTION: case SerialPacketType::CHARACTER_REJECTION: + case SerialPacketType::MONSTER_REJECTION: case SerialPacketType::SHUTDOWN_REJECTION: serializeText(buffer, static_cast(packet)); break; @@ -126,16 +136,25 @@ void deserializePacket(void* buffer, SerialPacketBase* packet) { case SerialPacketType::QUERY_CHARACTER_EXISTS: case SerialPacketType::QUERY_CHARACTER_STATS: case SerialPacketType::QUERY_CHARACTER_LOCATION: - case SerialPacketType::CHARACTER_SET_ROOM: - case SerialPacketType::CHARACTER_SET_ORIGIN: - case SerialPacketType::CHARACTER_SET_MOTION: + case SerialPacketType::CHARACTER_MOVEMENT: + case SerialPacketType::CHARACTER_ATTACK: deserializeCharacter(buffer, static_cast(packet)); break; + case SerialPacketType::MONSTER_CREATE: + case SerialPacketType::MONSTER_DELETE: + case SerialPacketType::QUERY_MONSTER_EXISTS: + case SerialPacketType::QUERY_MONSTER_STATS: + case SerialPacketType::QUERY_MONSTER_LOCATION: + case SerialPacketType::MONSTER_MOVEMENT: + case SerialPacketType::MONSTER_ATTACK: + deserializeMonster(buffer, static_cast(packet)); + break; case SerialPacketType::TEXT_BROADCAST: case SerialPacketType::JOIN_REJECTION: case SerialPacketType::LOGIN_REJECTION: case SerialPacketType::REGION_REJECTION: case SerialPacketType::CHARACTER_REJECTION: + case SerialPacketType::MONSTER_REJECTION: case SerialPacketType::SHUTDOWN_REJECTION: deserializeText(buffer, static_cast(packet)); break;