diff options
Diffstat (limited to 'src/Net/Packets')
-rw-r--r-- | src/Net/Packets/HostStatusPacket.h | 1 | ||||
-rw-r--r-- | src/Net/Packets/Makefile.am | 4 | ||||
-rw-r--r-- | src/Net/Packets/Makefile.in | 7 | ||||
-rw-r--r-- | src/Net/Packets/NameListPacket.cpp | 56 | ||||
-rw-r--r-- | src/Net/Packets/NameListPacket.h | 65 |
5 files changed, 127 insertions, 6 deletions
diff --git a/src/Net/Packets/HostStatusPacket.h b/src/Net/Packets/HostStatusPacket.h index f023917..0de63de 100644 --- a/src/Net/Packets/HostStatusPacket.h +++ b/src/Net/Packets/HostStatusPacket.h @@ -50,7 +50,6 @@ class HostStatusPacket : public Packet { } HostStatusPacket(const HostStatusPacket &p) : Packet(p) { - setLength(sizeof(CoreStatusData)); coreStatusData = (CoreStatusData*)&rawData->data; } diff --git a/src/Net/Packets/Makefile.am b/src/Net/Packets/Makefile.am index e65e543..9e1f589 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 +libpackets_la_SOURCES = HostStatusPacket.cpp NameListPacket.cpp -noinst_HEADERS = HostStatusPacket.h +noinst_HEADERS = HostStatusPacket.h NameListPacket.h diff --git a/src/Net/Packets/Makefile.in b/src/Net/Packets/Makefile.in index b6a7338..6a7e39f 100644 --- a/src/Net/Packets/Makefile.in +++ b/src/Net/Packets/Makefile.in @@ -45,7 +45,7 @@ CONFIG_HEADER = $(top_builddir)/src/config.h CONFIG_CLEAN_FILES = LTLIBRARIES = $(noinst_LTLIBRARIES) libpackets_la_LIBADD = -am_libpackets_la_OBJECTS = HostStatusPacket.lo +am_libpackets_la_OBJECTS = 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 +184,8 @@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ noinst_LTLIBRARIES = libpackets.la -libpackets_la_SOURCES = HostStatusPacket.cpp -noinst_HEADERS = HostStatusPacket.h +libpackets_la_SOURCES = HostStatusPacket.cpp NameListPacket.cpp +noinst_HEADERS = HostStatusPacket.h NameListPacket.h all: all-am .SUFFIXES: @@ -238,6 +238,7 @@ distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/HostStatusPacket.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/NameListPacket.Plo@am__quote@ .cpp.o: @am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< diff --git a/src/Net/Packets/NameListPacket.cpp b/src/Net/Packets/NameListPacket.cpp new file mode 100644 index 0000000..19f588a --- /dev/null +++ b/src/Net/Packets/NameListPacket.cpp @@ -0,0 +1,56 @@ +/* + * NameListPacket.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 "NameListPacket.h" +#include <cstring> +#include <sstream> + +namespace Mad { +namespace Net { +namespace Packets { + +void NameListPacket::assemblePacket() { + std::ostringstream stream; + + for(std::vector<std::string>::iterator name = nameList.begin(); name != nameList.end(); ++name) + stream << *name << std::endl; + + std::string str = stream.str(); + + setLength(str.length()); + std::memcpy(rawData->data, str.c_str(), str.length()); +} + +void NameListPacket::parsePacket() { + nameList.clear(); + + std::istringstream stream(std::string((char*)getData(), getLength())); + + while(!stream.eof()) { + std::string str; + std::getline(stream, str); + + if(!str.empty()) + nameList.push_back(str); + } +} + +} +} +} diff --git a/src/Net/Packets/NameListPacket.h b/src/Net/Packets/NameListPacket.h new file mode 100644 index 0000000..89cc040 --- /dev/null +++ b/src/Net/Packets/NameListPacket.h @@ -0,0 +1,65 @@ +/* + * NameListPacket.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_NAMELISTPACKET_H_ +#define MAD_NET_PACKETS_NAMELISTPACKET_H_ + +#include "../Packet.h" + +#include <vector> +#include <string> + + +namespace Mad { +namespace Net { +namespace Packets { + +class NameListPacket : public Packet { + protected: + std::vector<std::string> nameList; + + void assemblePacket(); + void parsePacket(); + + public: + NameListPacket(Type type, uint16_t requestId, const std::vector<std::string> &nameList0) : Packet(type, requestId), nameList(nameList0) { + assemblePacket(); + } + + NameListPacket(const Packet &p) : Packet(p) { + parsePacket(); + } + + NameListPacket& operator=(const Packet &p) { + Packet::operator=(p); + parsePacket(); + + return *this; + } + + const std::vector<std::string>& getNameList() const { + return nameList; + } +}; + +} +} +} + +#endif /* MAD_NET_PACKETS_NAMELISTPACKET_H_ */ |