From 113b1f4bbdecfab24ed9781b730a76a442adad6f Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 19 Sep 2008 11:15:14 +0200 Subject: Exceptions vereinheitlicht --- src/Net/Packets/ErrorPacket.cpp | 9 +++++++-- src/Net/Packets/ErrorPacket.h | 10 ++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'src/Net/Packets') diff --git a/src/Net/Packets/ErrorPacket.cpp b/src/Net/Packets/ErrorPacket.cpp index 2a72415..28d364a 100644 --- a/src/Net/Packets/ErrorPacket.cpp +++ b/src/Net/Packets/ErrorPacket.cpp @@ -18,6 +18,7 @@ */ #include "ErrorPacket.h" +#include namespace Mad { namespace Net { @@ -26,18 +27,22 @@ namespace Packets { ErrorPacket::ErrorPacket(Type type, uint16_t requestId, const Common::Exception &exception) : Packet(type, requestId) { - setLength(sizeof(ErrorData)); + setLength(sizeof(ErrorData) + exception.getWhere().length()); errorData = (ErrorData*)&rawData->data; errorData->errorCode = htonl(exception.getErrorCode()); errorData->subCode = htonl(exception.getSubCode()); errorData->subSubCode = htonl(exception.getSubSubCode()); + + std::memcpy(errorData->where, exception.getWhere().c_str(), exception.getWhere().length()); } ErrorPacket& ErrorPacket::operator=(const Packet &p) { Packet::operator=(p); - setLength(sizeof(ErrorData)); + if(getLength() < sizeof(ErrorData)) + setLength(sizeof(ErrorData)); + errorData = (ErrorData*)&rawData->data; return *this; diff --git a/src/Net/Packets/ErrorPacket.h b/src/Net/Packets/ErrorPacket.h index 4c6a026..01c1303 100644 --- a/src/Net/Packets/ErrorPacket.h +++ b/src/Net/Packets/ErrorPacket.h @@ -33,6 +33,7 @@ class ErrorPacket : public Packet { uint32_t errorCode; uint32_t subCode; uint32_t subSubCode; + uint8_t where[0]; }; ErrorData *errorData; @@ -41,7 +42,9 @@ class ErrorPacket : public Packet { ErrorPacket(Type type, uint16_t requestId, const Common::Exception &exception); ErrorPacket(const Packet &p) : Packet(p) { - setLength(sizeof(ErrorData)); + if(getLength() < sizeof(ErrorData)) + setLength(sizeof(ErrorData)); + errorData = (ErrorData*)&rawData->data; } @@ -56,7 +59,10 @@ class ErrorPacket : public Packet { } Common::Exception getException() const { - return Common::Exception((Common::Exception::ErrorCode)ntohl(errorData->errorCode), ntohl(errorData->subCode), ntohl(errorData->subSubCode)); + return Common::Exception( + std::string((char*)errorData->where, getLength()-sizeof(ErrorData)), (Common::Exception::ErrorCode)ntohl(errorData->errorCode), + ntohl(errorData->subCode), ntohl(errorData->subSubCode) + ); } }; -- cgit v1.2.3