summaryrefslogtreecommitdiffstats
path: root/src/Server/UserListManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Server/UserListManager.cpp')
-rw-r--r--src/Server/UserListManager.cpp151
1 files changed, 151 insertions, 0 deletions
diff --git a/src/Server/UserListManager.cpp b/src/Server/UserListManager.cpp
new file mode 100644
index 0000000..d1a6e31
--- /dev/null
+++ b/src/Server/UserListManager.cpp
@@ -0,0 +1,151 @@
+/*
+ * UserListManager.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 "UserListManager.h"
+#include "Application.h"
+#include "RequestHandlers/UserListRequestHandlerGroup.h"
+#include "RequestHandlers/UserListUploadRequestHandler.h"
+#include "RequestHandlers/UserListDiffUploadRequestHandler.h"
+
+#include <Common/RequestManager.h>
+#include <Common/StorageManager.h>
+#include <Common/UserManager.h>
+#include <Common/UserLists/UserList.h>
+#include <Common/UserLists/Util.h>
+#include <Core/ConfigManager.h>
+
+namespace Mad {
+namespace Server {
+
+UserListManager::UserListManager(Application *application0) : application(application0), requestHandlerGroup(new RequestHandlers::UserListRequestHandlerGroup(application)) {
+ application->getConfigManager()->registerConfigurable(this);
+}
+
+UserListManager::~UserListManager() {
+ application->getRequestManager()->unregisterPacketType("UploadUserList");
+ application->getRequestManager()->unregisterPacketType("UploadUserListDiff");
+ application->getRequestManager()->unregisterRequestHandlerGroup(requestHandlerGroup);
+ application->getConfigManager()->unregisterConfigurable(this);
+}
+
+
+void UserListManager::configFinished() {
+ userLists = application->getStorageManager()->list("UserList");
+ userListDiffs = application->getStorageManager()->list("UserListDiff");
+
+ application->getRequestManager()->registerRequestHandlerGroup(requestHandlerGroup);
+ application->getRequestManager()->registerPacketType<RequestHandlers::UserListUploadRequestHandler>("UploadUserList");
+ application->getRequestManager()->registerPacketType<RequestHandlers::UserListDiffUploadRequestHandler>("UploadUserListDiff");
+}
+
+bool UserListManager::existsUserList(const std::string &name) {
+ return application->getStorageManager()->exists("UserList", name);
+}
+
+boost::shared_ptr<Common::UserLists::UserList> UserListManager::loadUserList(const std::string &name) {
+ boost::shared_ptr<Common::XmlData> data = application->getStorageManager()->load("UserList", name);
+
+ if(!data)
+ return boost::shared_ptr<Common::UserLists::UserList>();
+
+ return Common::UserLists::Util::deserializeUserList(data.get());
+}
+
+void UserListManager::storeUserList(const std::string &name, const Common::UserLists::UserList *list) {
+ Common::XmlData data;
+
+ Common::UserLists::Util::serializeUserList(list, &data);
+ application->getStorageManager()->store("UserList", name, &data);
+}
+
+void UserListManager::copyUserList(const std::string &fromName, const std::string &toName) {
+ application->getStorageManager()->copy("UserList", fromName, toName);
+}
+
+void UserListManager::renameUserList(const std::string &fromName, const std::string &toName) {
+ application->getStorageManager()->rename("UserList", fromName, toName);
+}
+
+void UserListManager::removeUserList(const std::string &name) {
+ application->getStorageManager()->remove("UserList", name);
+}
+
+
+bool UserListManager::existsUserListDiff(const std::string &name) {
+ return application->getStorageManager()->exists("UserListDiff", name);
+}
+
+boost::shared_ptr<Common::UserLists::UserListDiff> UserListManager::loadUserListDiff(const std::string &name) {
+ boost::shared_ptr<Common::XmlData> data = application->getStorageManager()->load("UserListDiff", name);
+
+ if(!data)
+ return boost::shared_ptr<Common::UserLists::UserListDiff>();
+
+ return Common::UserLists::Util::deserializeUserListDiff(data.get());
+}
+
+void UserListManager::storeUserListDiff(const std::string &name, const Common::UserLists::UserListDiff *list) {
+ Common::XmlData data;
+
+ Common::UserLists::Util::serializeUserListDiff(list, &data);
+ application->getStorageManager()->store("UserListDiff", name, &data);
+}
+
+void UserListManager::copyUserListDiff(const std::string &fromName, const std::string &toName) {
+ application->getStorageManager()->copy("UserListDiff", fromName, toName);
+}
+
+void UserListManager::renameUserListDiff(const std::string &fromName, const std::string &toName) {
+ application->getStorageManager()->rename("UserListDiff", fromName, toName);
+}
+
+void UserListManager::removeUserListDiff(const std::string &name) {
+ application->getStorageManager()->remove("UserListDiff", name);
+}
+
+boost::shared_ptr<Common::UserLists::UserList> UserListManager::getCurrentUserList() {
+ boost::shared_ptr<Common::UserLists::UserList> list(new Common::UserLists::UserList);
+
+ boost::shared_ptr<const std::map<unsigned long, Common::UserInfo> > userList = application->getUserManager()->getUserList();
+ boost::shared_ptr<const std::map<unsigned long, Common::GroupInfo> > groupList = application->getUserManager()->getGroupList();
+
+ for(std::map<unsigned long, Common::UserInfo>::const_iterator user = userList->begin(); user != userList->end(); ++user) {
+ std::map<unsigned long, Common::GroupInfo>::const_iterator group = groupList->find(user->second.getGid());
+ std::string groupname;
+
+ if(group != groupList->end()) {
+ groupname = group->second.getName();
+ }
+ else {
+ std::ostringstream stream;
+ stream << user->second.getGid();
+ groupname = stream.str();
+ }
+
+ Common::UserLists::UserListEntry entry(user->second.getUsername(), groupname);
+ entry.setDetail("Full name", user->second.getFullName());
+
+ list->push_back(entry);
+ }
+
+ return list;
+}
+
+}
+}