Added TextPacket
This commit is contained in:
@@ -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
|
||||
@@ -27,18 +27,20 @@
|
||||
#include "client_packet.hpp"
|
||||
#include "region_packet.hpp"
|
||||
#include "server_packet.hpp"
|
||||
#include "text_packet.hpp"
|
||||
|
||||
//SerialPacketBase is defined in serial_packet_base.hpp
|
||||
typedef SerialPacketBase SerialPacket;
|
||||
|
||||
//DOCS: NETWORK_VERSION is used to discern compatible servers and clients
|
||||
constexpr int NETWORK_VERSION = 20140831;
|
||||
constexpr int NETWORK_VERSION = 20140909;
|
||||
|
||||
union MaxPacket {
|
||||
CharacterPacket a;
|
||||
ClientPacket b;
|
||||
RegionPacket c;
|
||||
ServerPacket d;
|
||||
TextPacket e;
|
||||
};
|
||||
|
||||
constexpr int MAX_PACKET_SIZE = sizeof(MaxPacket);
|
||||
|
||||
@@ -52,7 +52,6 @@ enum class SerialPacketType {
|
||||
//Connecting to a server as a client
|
||||
JOIN_REQUEST,
|
||||
JOIN_RESPONSE,
|
||||
JOIN_REJECTION,
|
||||
|
||||
//client requests all information from the server
|
||||
SYNCHRONIZE,
|
||||
@@ -88,10 +87,23 @@ enum class SerialPacketType {
|
||||
CHARACTER_STATS_REQUEST,
|
||||
CHARACTER_STATS_RESPONSE,
|
||||
|
||||
//reject a character request
|
||||
//-------------------------
|
||||
//TextPacket
|
||||
// name, text
|
||||
//-------------------------
|
||||
|
||||
//general speech
|
||||
TEXT_BROADCAST,
|
||||
|
||||
//rejection/error messages
|
||||
SHUTDOWN_REJECTION,
|
||||
JOIN_REJECTION,
|
||||
CHARACTER_REJECTION,
|
||||
|
||||
//-------------------------
|
||||
//not used
|
||||
//-------------------------
|
||||
|
||||
LAST
|
||||
};
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "client_packet.hpp"
|
||||
#include "region_packet.hpp"
|
||||
#include "server_packet.hpp"
|
||||
#include "text_packet.hpp"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
@@ -53,7 +54,6 @@ void serializePacket(void* buffer, SerialPacketBase* packet) {
|
||||
break;
|
||||
case SerialPacketType::JOIN_REQUEST:
|
||||
case SerialPacketType::JOIN_RESPONSE:
|
||||
case SerialPacketType::JOIN_REJECTION:
|
||||
case SerialPacketType::SYNCHRONIZE:
|
||||
case SerialPacketType::DISCONNECT:
|
||||
case SerialPacketType::SHUTDOWN:
|
||||
@@ -68,9 +68,14 @@ void serializePacket(void* buffer, SerialPacketBase* packet) {
|
||||
case SerialPacketType::CHARACTER_UPDATE:
|
||||
case SerialPacketType::CHARACTER_STATS_REQUEST:
|
||||
case SerialPacketType::CHARACTER_STATS_RESPONSE:
|
||||
case SerialPacketType::CHARACTER_REJECTION:
|
||||
serializeCharacter(buffer, static_cast<CharacterPacket*>(packet));
|
||||
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;
|
||||
case SerialPacketType::JOIN_REQUEST:
|
||||
case SerialPacketType::JOIN_RESPONSE:
|
||||
case SerialPacketType::JOIN_REJECTION:
|
||||
case SerialPacketType::SYNCHRONIZE:
|
||||
case SerialPacketType::DISCONNECT:
|
||||
case SerialPacketType::SHUTDOWN:
|
||||
@@ -103,8 +107,13 @@ void deserializePacket(void* buffer, SerialPacketBase* packet) {
|
||||
case SerialPacketType::CHARACTER_UPDATE:
|
||||
case SerialPacketType::CHARACTER_STATS_REQUEST:
|
||||
case SerialPacketType::CHARACTER_STATS_RESPONSE:
|
||||
case SerialPacketType::CHARACTER_REJECTION:
|
||||
deserializeCharacter(buffer, static_cast<CharacterPacket*>(packet));
|
||||
break;
|
||||
case SerialPacketType::TEXT_BROADCAST:
|
||||
case SerialPacketType::JOIN_REJECTION:
|
||||
case SerialPacketType::SHUTDOWN_REJECTION:
|
||||
case SerialPacketType::CHARACTER_REJECTION:
|
||||
serializeText(buffer, static_cast<TextPacket*>(packet));
|
||||
break;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user