summaryrefslogtreecommitdiffstats
path: root/src/Net/Packets
diff options
context:
space:
mode:
Diffstat (limited to 'src/Net/Packets')
-rw-r--r--src/Net/Packets/ErrorPacket.cpp48
-rw-r--r--src/Net/Packets/ErrorPacket.h67
-rw-r--r--src/Net/Packets/Makefile.am4
-rw-r--r--src/Net/Packets/Makefile.in8
4 files changed, 122 insertions, 5 deletions
diff --git a/src/Net/Packets/ErrorPacket.cpp b/src/Net/Packets/ErrorPacket.cpp
new file mode 100644
index 0000000..2a72415
--- /dev/null
+++ b/src/Net/Packets/ErrorPacket.cpp
@@ -0,0 +1,48 @@
+/*
+ * ErrorPacket.cpp
+ *
+ * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "ErrorPacket.h"
+
+namespace Mad {
+namespace Net {
+namespace Packets {
+
+ErrorPacket::ErrorPacket(Type type, uint16_t requestId, const Common::Exception &exception)
+: Packet(type, requestId)
+{
+ setLength(sizeof(ErrorData));
+ errorData = (ErrorData*)&rawData->data;
+
+ errorData->errorCode = htonl(exception.getErrorCode());
+ errorData->subCode = htonl(exception.getSubCode());
+ errorData->subSubCode = htonl(exception.getSubSubCode());
+}
+
+ErrorPacket& ErrorPacket::operator=(const Packet &p) {
+ Packet::operator=(p);
+
+ setLength(sizeof(ErrorData));
+ errorData = (ErrorData*)&rawData->data;
+
+ return *this;
+}
+
+}
+}
+}
diff --git a/src/Net/Packets/ErrorPacket.h b/src/Net/Packets/ErrorPacket.h
new file mode 100644
index 0000000..4c6a026
--- /dev/null
+++ b/src/Net/Packets/ErrorPacket.h
@@ -0,0 +1,67 @@
+/*
+ * ErrorPacket.h
+ *
+ * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_NET_PACKETS_ERRORPACKET_H_
+#define MAD_NET_PACKETS_ERRORPACKET_H_
+
+#include "../Packet.h"
+#include <Common/Exception.h>
+
+namespace Mad {
+namespace Net {
+namespace Packets {
+
+class ErrorPacket : public Packet {
+ protected:
+ struct ErrorData {
+ uint32_t errorCode;
+ uint32_t subCode;
+ uint32_t subSubCode;
+ };
+
+ ErrorData *errorData;
+
+ public:
+ ErrorPacket(Type type, uint16_t requestId, const Common::Exception &exception);
+
+ ErrorPacket(const Packet &p) : Packet(p) {
+ setLength(sizeof(ErrorData));
+ errorData = (ErrorData*)&rawData->data;
+ }
+
+ ErrorPacket(const ErrorPacket &p) : Packet(p) {
+ errorData = (ErrorData*)&rawData->data;
+ }
+
+ ErrorPacket& operator=(const Packet &p);
+
+ ErrorPacket& operator=(const ErrorPacket &p) {
+ return (*this = (Packet)p);
+ }
+
+ Common::Exception getException() const {
+ return Common::Exception((Common::Exception::ErrorCode)ntohl(errorData->errorCode), ntohl(errorData->subCode), ntohl(errorData->subSubCode));
+ }
+};
+
+}
+}
+}
+
+#endif /* MAD_NET_PACKETS_ERRORPACKET_H_ */
diff --git a/src/Net/Packets/Makefile.am b/src/Net/Packets/Makefile.am
index 9e1f589..4600c96 100644
--- a/src/Net/Packets/Makefile.am
+++ b/src/Net/Packets/Makefile.am
@@ -1,4 +1,4 @@
noinst_LTLIBRARIES = libpackets.la
-libpackets_la_SOURCES = HostStatusPacket.cpp NameListPacket.cpp
+libpackets_la_SOURCES = ErrorPacket.cpp HostStatusPacket.cpp NameListPacket.cpp
-noinst_HEADERS = HostStatusPacket.h NameListPacket.h
+noinst_HEADERS = ErrorPacket.cpp HostStatusPacket.h NameListPacket.h
diff --git a/src/Net/Packets/Makefile.in b/src/Net/Packets/Makefile.in
index 6a7e39f..abd8137 100644
--- a/src/Net/Packets/Makefile.in
+++ b/src/Net/Packets/Makefile.in
@@ -45,7 +45,8 @@ CONFIG_HEADER = $(top_builddir)/src/config.h
CONFIG_CLEAN_FILES =
LTLIBRARIES = $(noinst_LTLIBRARIES)
libpackets_la_LIBADD =
-am_libpackets_la_OBJECTS = HostStatusPacket.lo NameListPacket.lo
+am_libpackets_la_OBJECTS = ErrorPacket.lo HostStatusPacket.lo \
+ NameListPacket.lo
libpackets_la_OBJECTS = $(am_libpackets_la_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src
depcomp = $(SHELL) $(top_srcdir)/depcomp
@@ -184,8 +185,8 @@ target_alias = @target_alias@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
noinst_LTLIBRARIES = libpackets.la
-libpackets_la_SOURCES = HostStatusPacket.cpp NameListPacket.cpp
-noinst_HEADERS = HostStatusPacket.h NameListPacket.h
+libpackets_la_SOURCES = ErrorPacket.cpp HostStatusPacket.cpp NameListPacket.cpp
+noinst_HEADERS = ErrorPacket.cpp HostStatusPacket.h NameListPacket.h
all: all-am
.SUFFIXES:
@@ -237,6 +238,7 @@ mostlyclean-compile:
distclean-compile:
-rm -f *.tab.c
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ErrorPacket.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/HostStatusPacket.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/NameListPacket.Plo@am__quote@