diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2009-09-23 09:44:02 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2009-09-23 09:44:02 +0200 |
commit | 0eddc28a331437ef95a60418ed1fc6de4e9b63c1 (patch) | |
tree | 17dcb71adbca54b47e12b32fb313597f971709f5 /src/Server/RequestHandlers/UserListDiffUploadRequestHandler.cpp | |
parent | d6844595c9b47dab1db4b970ff6cc7fb3f64f107 (diff) | |
download | mad-0eddc28a331437ef95a60418ed1fc6de4e9b63c1.tar mad-0eddc28a331437ef95a60418ed1fc6de4e9b63c1.zip |
UserListManager: Moved module into libCommon and libServer
Diffstat (limited to 'src/Server/RequestHandlers/UserListDiffUploadRequestHandler.cpp')
-rw-r--r-- | src/Server/RequestHandlers/UserListDiffUploadRequestHandler.cpp | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/Server/RequestHandlers/UserListDiffUploadRequestHandler.cpp b/src/Server/RequestHandlers/UserListDiffUploadRequestHandler.cpp new file mode 100644 index 0000000..05aadf8 --- /dev/null +++ b/src/Server/RequestHandlers/UserListDiffUploadRequestHandler.cpp @@ -0,0 +1,84 @@ +/* + * UserListDiffUploadRequestHandler.cpp + * + * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de> + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "UserListDiffUploadRequestHandler.h" +#include "../Application.h" +#include "../UserListManager.h" + +#include <Common/UserLists/Util.h> + +#include <boost/date_time/posix_time/posix_time.hpp> + +namespace Mad { +namespace Server { +namespace RequestHandlers { + +void UserListDiffUploadRequestHandler::handlePacket(boost::shared_ptr<const Common::XmlData> packet) { + if(packet->getType() == "Cancel") { + Common::XmlData ret; + ret.setType("OK"); + sendPacket(ret); + + signalFinished(); + return; + } + else if(packet->getType() != "UploadUserListDiff") { + getApplication()->log(Core::Logger::LOG_ERROR, "Received an unexpected packet."); + + Common::XmlData ret; + ret.setType("Error"); + ret.set("ErrorCode", Core::Exception::UNEXPECTED_PACKET); + + sendPacket(ret); + + signalFinished(); + return; + } + + if(!getConnection()->isAuthenticated()) + throw(Core::Exception(Core::Exception::PERMISSION)); + + UserListManager *userListManager = dynamic_cast<Application*>(getApplication())->getUserListManager(); + + if(name.empty()) { // Request + name = packet->get<const std::string&>("name"); + + if(name.empty()) + name = boost::posix_time::to_simple_string(boost::posix_time::second_clock::universal_time()); + + Common::XmlData ret; + ret.setType("Continue"); + ret.set("exists", userListManager->existsUserListDiff(name)); + sendPacket(ret); + } + else { // Upload + boost::shared_ptr<Common::UserLists::UserListDiff> diff = Common::UserLists::Util::deserializeUserListDiff(packet.get()); + userListManager->storeUserListDiff(name, diff.get()); + + Common::XmlData ret; + ret.setType("OK"); + sendPacket(ret); + + signalFinished(); + } +} + +} +} +} |