Added TextPacket

This commit is contained in:
Kayne Ruse
2014-09-09 08:05:50 +10:00
parent f581c3238f
commit 4c882682ed
7 changed files with 111 additions and 7 deletions
+3
View File
@@ -89,6 +89,7 @@ void ClientApplication::Init(int argc, char** argv) {
std::cout << "Internal sizes:" << std::endl; std::cout << "Internal sizes:" << std::endl;
DEBUG_OUTPUT_VAR(NETWORK_VERSION);
DEBUG_OUTPUT_VAR(sizeof(Region::type_t)); DEBUG_OUTPUT_VAR(sizeof(Region::type_t));
DEBUG_OUTPUT_VAR(sizeof(Region)); DEBUG_OUTPUT_VAR(sizeof(Region));
DEBUG_OUTPUT_VAR(REGION_WIDTH); DEBUG_OUTPUT_VAR(REGION_WIDTH);
@@ -96,8 +97,10 @@ void ClientApplication::Init(int argc, char** argv) {
DEBUG_OUTPUT_VAR(REGION_DEPTH); DEBUG_OUTPUT_VAR(REGION_DEPTH);
DEBUG_OUTPUT_VAR(REGION_TILE_FOOTPRINT); DEBUG_OUTPUT_VAR(REGION_TILE_FOOTPRINT);
DEBUG_OUTPUT_VAR(REGION_SOLID_FOOTPRINT); DEBUG_OUTPUT_VAR(REGION_SOLID_FOOTPRINT);
DEBUG_OUTPUT_VAR(PACKET_STRING_SIZE);
DEBUG_OUTPUT_VAR(PACKET_BUFFER_SIZE); DEBUG_OUTPUT_VAR(PACKET_BUFFER_SIZE);
DEBUG_OUTPUT_VAR(MAX_PACKET_SIZE); DEBUG_OUTPUT_VAR(MAX_PACKET_SIZE);
DEBUG_OUTPUT_VAR(static_cast<int>(SerialPacketType::LAST));
#undef DEBUG_OUTPUT_VAR #undef DEBUG_OUTPUT_VAR
@@ -0,0 +1,40 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* 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 "text_packet.hpp"
#include "serial_utility.hpp"
void serializeText(void* buffer, TextPacket* packet) {
serialCopy(&buffer, &packet->type, sizeof(SerialPacketType));
//content
serialCopy(&buffer, packet->name, PACKET_STRING_SIZE);
serialCopy(&buffer, packet->text, PACKET_STRING_SIZE);
}
void deserializeText(void* buffer, TextPacket* packet) {
deserialCopy(&buffer, &packet->type, sizeof(SerialPacketType));
//content
deserialCopy(&buffer, packet->name, PACKET_STRING_SIZE);
deserialCopy(&buffer, packet->text, PACKET_STRING_SIZE);
}
@@ -0,0 +1,35 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* 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 TEXTPACKET_HPP_
#define TEXTPACKET_HPP_
#include "serial_packet_base.hpp"
struct TextPacket : SerialPacketBase {
char name[PACKET_STRING_SIZE];
char text[PACKET_STRING_SIZE];
};
void serializeText(void* buffer, TextPacket* packet);
void deserializeText(void* buffer, TextPacket* packet);
#endif
+3 -1
View File
@@ -27,18 +27,20 @@
#include "client_packet.hpp" #include "client_packet.hpp"
#include "region_packet.hpp" #include "region_packet.hpp"
#include "server_packet.hpp" #include "server_packet.hpp"
#include "text_packet.hpp"
//SerialPacketBase is defined in serial_packet_base.hpp //SerialPacketBase is defined in serial_packet_base.hpp
typedef SerialPacketBase SerialPacket; typedef SerialPacketBase SerialPacket;
//DOCS: NETWORK_VERSION is used to discern compatible servers and clients //DOCS: NETWORK_VERSION is used to discern compatible servers and clients
constexpr int NETWORK_VERSION = 20140831; constexpr int NETWORK_VERSION = 20140909;
union MaxPacket { union MaxPacket {
CharacterPacket a; CharacterPacket a;
ClientPacket b; ClientPacket b;
RegionPacket c; RegionPacket c;
ServerPacket d; ServerPacket d;
TextPacket e;
}; };
constexpr int MAX_PACKET_SIZE = sizeof(MaxPacket); constexpr int MAX_PACKET_SIZE = sizeof(MaxPacket);
+14 -2
View File
@@ -52,7 +52,6 @@ enum class SerialPacketType {
//Connecting to a server as a client //Connecting to a server as a client
JOIN_REQUEST, JOIN_REQUEST,
JOIN_RESPONSE, JOIN_RESPONSE,
JOIN_REJECTION,
//client requests all information from the server //client requests all information from the server
SYNCHRONIZE, SYNCHRONIZE,
@@ -88,10 +87,23 @@ enum class SerialPacketType {
CHARACTER_STATS_REQUEST, CHARACTER_STATS_REQUEST,
CHARACTER_STATS_RESPONSE, CHARACTER_STATS_RESPONSE,
//reject a character request //-------------------------
//TextPacket
// name, text
//-------------------------
//general speech
TEXT_BROADCAST,
//rejection/error messages
SHUTDOWN_REJECTION,
JOIN_REJECTION,
CHARACTER_REJECTION, CHARACTER_REJECTION,
//-------------------------
//not used //not used
//-------------------------
LAST LAST
}; };
+13 -4
View File
@@ -26,6 +26,7 @@
#include "client_packet.hpp" #include "client_packet.hpp"
#include "region_packet.hpp" #include "region_packet.hpp"
#include "server_packet.hpp" #include "server_packet.hpp"
#include "text_packet.hpp"
#include <cstring> #include <cstring>
@@ -53,7 +54,6 @@ void serializePacket(void* buffer, SerialPacketBase* packet) {
break; break;
case SerialPacketType::JOIN_REQUEST: case SerialPacketType::JOIN_REQUEST:
case SerialPacketType::JOIN_RESPONSE: case SerialPacketType::JOIN_RESPONSE:
case SerialPacketType::JOIN_REJECTION:
case SerialPacketType::SYNCHRONIZE: case SerialPacketType::SYNCHRONIZE:
case SerialPacketType::DISCONNECT: case SerialPacketType::DISCONNECT:
case SerialPacketType::SHUTDOWN: case SerialPacketType::SHUTDOWN:
@@ -68,9 +68,14 @@ void serializePacket(void* buffer, SerialPacketBase* packet) {
case SerialPacketType::CHARACTER_UPDATE: case SerialPacketType::CHARACTER_UPDATE:
case SerialPacketType::CHARACTER_STATS_REQUEST: case SerialPacketType::CHARACTER_STATS_REQUEST:
case SerialPacketType::CHARACTER_STATS_RESPONSE: case SerialPacketType::CHARACTER_STATS_RESPONSE:
case SerialPacketType::CHARACTER_REJECTION:
serializeCharacter(buffer, static_cast<CharacterPacket*>(packet)); serializeCharacter(buffer, static_cast<CharacterPacket*>(packet));
break; break;
case SerialPacketType::TEXT_BROADCAST:
case SerialPacketType::JOIN_REJECTION:
case SerialPacketType::SHUTDOWN_REJECTION:
case SerialPacketType::CHARACTER_REJECTION:
serializeText(buffer, static_cast<TextPacket*>(packet));
break;
} }
} }
@@ -88,7 +93,6 @@ void deserializePacket(void* buffer, SerialPacketBase* packet) {
break; break;
case SerialPacketType::JOIN_REQUEST: case SerialPacketType::JOIN_REQUEST:
case SerialPacketType::JOIN_RESPONSE: case SerialPacketType::JOIN_RESPONSE:
case SerialPacketType::JOIN_REJECTION:
case SerialPacketType::SYNCHRONIZE: case SerialPacketType::SYNCHRONIZE:
case SerialPacketType::DISCONNECT: case SerialPacketType::DISCONNECT:
case SerialPacketType::SHUTDOWN: case SerialPacketType::SHUTDOWN:
@@ -103,8 +107,13 @@ void deserializePacket(void* buffer, SerialPacketBase* packet) {
case SerialPacketType::CHARACTER_UPDATE: case SerialPacketType::CHARACTER_UPDATE:
case SerialPacketType::CHARACTER_STATS_REQUEST: case SerialPacketType::CHARACTER_STATS_REQUEST:
case SerialPacketType::CHARACTER_STATS_RESPONSE: case SerialPacketType::CHARACTER_STATS_RESPONSE:
case SerialPacketType::CHARACTER_REJECTION:
deserializeCharacter(buffer, static_cast<CharacterPacket*>(packet)); deserializeCharacter(buffer, static_cast<CharacterPacket*>(packet));
break; break;
case SerialPacketType::TEXT_BROADCAST:
case SerialPacketType::JOIN_REJECTION:
case SerialPacketType::SHUTDOWN_REJECTION:
case SerialPacketType::CHARACTER_REJECTION:
serializeText(buffer, static_cast<TextPacket*>(packet));
break;
} }
} }
+3
View File
@@ -110,6 +110,7 @@ void ServerApplication::Init(int argc, char** argv) {
std::cout << "Internal sizes:" << std::endl; std::cout << "Internal sizes:" << std::endl;
DEBUG_OUTPUT_VAR(NETWORK_VERSION);
DEBUG_OUTPUT_VAR(sizeof(Region::type_t)); DEBUG_OUTPUT_VAR(sizeof(Region::type_t));
DEBUG_OUTPUT_VAR(sizeof(Region)); DEBUG_OUTPUT_VAR(sizeof(Region));
DEBUG_OUTPUT_VAR(REGION_WIDTH); DEBUG_OUTPUT_VAR(REGION_WIDTH);
@@ -117,8 +118,10 @@ void ServerApplication::Init(int argc, char** argv) {
DEBUG_OUTPUT_VAR(REGION_DEPTH); DEBUG_OUTPUT_VAR(REGION_DEPTH);
DEBUG_OUTPUT_VAR(REGION_TILE_FOOTPRINT); DEBUG_OUTPUT_VAR(REGION_TILE_FOOTPRINT);
DEBUG_OUTPUT_VAR(REGION_SOLID_FOOTPRINT); DEBUG_OUTPUT_VAR(REGION_SOLID_FOOTPRINT);
DEBUG_OUTPUT_VAR(PACKET_STRING_SIZE);
DEBUG_OUTPUT_VAR(PACKET_BUFFER_SIZE); DEBUG_OUTPUT_VAR(PACKET_BUFFER_SIZE);
DEBUG_OUTPUT_VAR(MAX_PACKET_SIZE); DEBUG_OUTPUT_VAR(MAX_PACKET_SIZE);
DEBUG_OUTPUT_VAR(static_cast<int>(SerialPacketType::LAST));
#undef DEBUG_OUTPUT_VAR #undef DEBUG_OUTPUT_VAR