From ee2ac0b7a9ae854c072ab0c6fc417131d02ea98f Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 8 Jun 2014 00:36:05 +1000 Subject: [PATCH] Created MAX_PACKET_SIZE --- common/network/packet/serial_packet.hpp | 10 ++++++++++ server/server_application.cpp | 21 ++++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/common/network/packet/serial_packet.hpp b/common/network/packet/serial_packet.hpp index 7b7137f..44198aa 100644 --- a/common/network/packet/serial_packet.hpp +++ b/common/network/packet/serial_packet.hpp @@ -31,4 +31,14 @@ //NOTE: SerialPacket is defined in serial_packet_base.hpp +union MaxPacket { + CharacterPacket a; + ClientPacket b; + CombatPacket c; + EnemyPacket d; + RegionPacket e; + ServerPacket f; +}; +constexpr int MAX_PACKET_SIZE = sizeof(MaxPacket); + #endif diff --git a/server/server_application.cpp b/server/server_application.cpp index 836af2b..f4dd348 100644 --- a/server/server_application.cpp +++ b/server/server_application.cpp @@ -115,14 +115,29 @@ void ServerApplication::Init(int argc, char** argv) { //------------------------- std::cout << "Startup completed successfully" << std::endl; + + //------------------------- + //debugging + //------------------------- + + std::cout << "Debugging dump:" << std::endl; + std::cout << "\tMAX_PACKET_SIZE:\t\t" << MAX_PACKET_SIZE << std::endl; + std::cout << "\tsizeof(SerialPacket):\t\t" << sizeof(SerialPacket) << std::endl; + std::cout << "\tsizeof(CharacterPacket):\t" << sizeof(CharacterPacket) << std::endl; + std::cout << "\t\tsizeof(Statistics):\t" << sizeof(Statistics) << std::endl; + std::cout << "\tsizeof(ClientPacket):\t\t" << sizeof(ClientPacket) << std::endl; + std::cout << "\tsizeof(CombatPacket):\t\t" << sizeof(CombatPacket) << std::endl; + std::cout << "\tsizeof(EnemyPacket):\t\t" << sizeof(EnemyPacket) << std::endl; + std::cout << "\tsizeof(RegionPacket):\t\t" << sizeof(RegionPacket) << std::endl; + std::cout << "\tsizeof(ServerPacket):\t\t" << sizeof(ServerPacket) << std::endl; } void ServerApplication::Proc() { - SerialPacket packet; + char packetBuffer[MAX_PACKET_SIZE]; while(running) { //suck in the waiting packets & process them - while(network.Receive(&packet)) { - HandlePacket(&packet); + while(network.Receive(reinterpret_cast(packetBuffer))) { + HandlePacket(reinterpret_cast(packetBuffer)); } //update the internals //TODO: update the internals i.e. player positions