chatchannel.cpp

Go to the documentation of this file.
00001 /*
00002  *  The Mana World Server
00003  *  Copyright 2004 The Mana World Development Team
00004  *
00005  *  This file is part of The Mana World.
00006  *
00007  *  The Mana World is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation; either version 2 of the License, or
00010  *  any later version.
00011  *
00012  *  The Mana World is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *  GNU General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU General Public License
00018  *  along with The Mana World; if not, write to the Free Software
00019  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  *
00021  *  $Id: chatchannel.cpp 3185 2007-03-12 23:49:33Z rogier_polak $
00022  */
00023 
00024 #include "chat-server/chatchannel.hpp"
00025 
00026 ChatChannel::ChatChannel(const std::string &channelName,
00027                          const std::string &channelAnnouncement = "None",
00028                          const std::string &channelPassword = "None",
00029                          bool channelPrivacy = true):
00030     mChannelName(channelName),
00031     mChannelAnnouncement(channelAnnouncement),
00032     mChannelPassword(channelPassword),
00033     mChannelPrivate(channelPrivacy)
00034 {
00035     if (channelAnnouncement == "")
00036         mChannelAnnouncement = "None";
00037     if (channelPassword == "")
00038         mChannelPassword = "None";
00039     mRegisteredUsers.clear();
00040 }
00041 
00042 ChatChannel::~ChatChannel()
00043 {
00044     mRegisteredUsers.clear();
00045 }
00046 
00047 
00048 const std::string&
00049 ChatChannel::getName() const
00050 {
00051     return mChannelName;
00052 }
00053 
00054 const std::string&
00055 ChatChannel::getAnnouncement() const
00056 {
00057     return mChannelAnnouncement;
00058 }
00059 
00060 const std::string&
00061 ChatChannel::getPassword() const
00062 {
00063     return mChannelPassword;
00064 }
00065 
00066 bool
00067 ChatChannel::getPrivacy() const
00068 {
00069     return mChannelPrivate;
00070 }
00071 
00072 void
00073 ChatChannel::setName(const std::string &channelName)
00074 {
00075     mChannelName = channelName;
00076 }
00077 
00078 void
00079 ChatChannel::setAnnouncement(const std::string &channelAnnouncement)
00080 {
00081     if (channelAnnouncement == "")
00082         mChannelAnnouncement = "None";
00083     else
00084         mChannelAnnouncement = channelAnnouncement;
00085 }
00086 
00087 void
00088 ChatChannel::setPassword(const std::string &channelPassword)
00089 {
00090     if (channelPassword == "")
00091         mChannelPassword = "None";
00092     else
00093         mChannelPassword = channelPassword;
00094 }
00095 
00096 ChatChannel::ChannelUsers const &ChatChannel::getUserList() const
00097 {
00098     return mRegisteredUsers;
00099 }
00100 
00101 
00102 bool ChatChannel::addUserInChannel(std::string const &user)
00103 {
00104     // Check if the user already exists in the channel
00105     ChannelUsers::const_iterator i = mRegisteredUsers.begin(),
00106                                  i_end = mRegisteredUsers.end();
00107     if (std::find(i, i_end, user) != i_end) return false;
00108     mRegisteredUsers.push_back(user);
00109     return true;
00110 }
00111 
00112 
00113 bool ChatChannel::removeUserFromChannel(std::string const &user)
00114 {
00115     ChannelUsers::iterator i_end = mRegisteredUsers.end(),
00116                            i = std::find(mRegisteredUsers.begin(), i_end, user);
00117     if (i == i_end) return false;
00118     mRegisteredUsers.erase(i);
00119     return true;
00120 }
00121 
00122 void ChatChannel::removeEveryUsersFromChannel()
00123 {
00124     mRegisteredUsers.clear();
00125 }

Generated on Fri Mar 30 15:39:16 2007 for TMW Server by  doxygen 1.3.9.1