summaryrefslogtreecommitdiffstats
path: root/src/chat-server/chatchannel.cpp
diff options
context:
space:
mode:
authorGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-07-28 20:14:23 +0000
committerGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-07-28 20:14:23 +0000
commite166458f5425316f4f48aadd7007917ab876be17 (patch)
tree7ccc27db50bb6600cc4fee074485e3b886e58049 /src/chat-server/chatchannel.cpp
parent32337eb103384ed8bdb7a43ee54ab550680db62b (diff)
downloadmanaserv-e166458f5425316f4f48aadd7007917ab876be17.tar.gz
manaserv-e166458f5425316f4f48aadd7007917ab876be17.tar.xz
manaserv-e166458f5425316f4f48aadd7007917ab876be17.zip
Replaced user names by client pointers when handling channels, in order to reduce lookups in ChatHandler::sendInChannel.
Diffstat (limited to 'src/chat-server/chatchannel.cpp')
-rw-r--r--src/chat-server/chatchannel.cpp50
1 files changed, 15 insertions, 35 deletions
diff --git a/src/chat-server/chatchannel.cpp b/src/chat-server/chatchannel.cpp
index e8afda1..073a802 100644
--- a/src/chat-server/chatchannel.cpp
+++ b/src/chat-server/chatchannel.cpp
@@ -22,68 +22,48 @@
*/
#include "chat-server/chatchannel.hpp"
+#include "chat-server/chatclient.hpp"
-ChatChannel::ChatChannel(short id,
+ChatChannel::ChatChannel(int id,
const std::string &name,
const std::string &announcement,
- const std::string &password,
- bool privacy):
+ const std::string &password):
mId(id),
mName(name),
mAnnouncement(announcement),
- mPassword(password),
- mPrivate(privacy)
+ mPassword(password)
{
- if (announcement == "")
- mAnnouncement = "None";
- if (password == "")
- mPassword = "None";
}
-void
-ChatChannel::setName(const std::string &name)
-{
- mName = name;
-}
-
-void
-ChatChannel::setAnnouncement(const std::string &announcement)
-{
- if (announcement == "")
- mAnnouncement = "None";
- else
- mAnnouncement = announcement;
-}
-
-void
-ChatChannel::setPassword(const std::string &password)
-{
- if (password == "")
- mPassword = "None";
- else
- mPassword = password;
-}
-
-bool ChatChannel::addUser(const std::string &user)
+bool ChatChannel::addUser(ChatClient *user)
{
// Check if the user already exists in the channel
ChannelUsers::const_iterator i = mRegisteredUsers.begin(),
i_end = mRegisteredUsers.end();
if (std::find(i, i_end, user) != i_end) return false;
mRegisteredUsers.push_back(user);
+ user->channels.push_back(this);
return true;
}
-bool ChatChannel::removeUser(const std::string &user)
+bool ChatChannel::removeUser(ChatClient *user)
{
ChannelUsers::iterator i_end = mRegisteredUsers.end(),
i = std::find(mRegisteredUsers.begin(), i_end, user);
if (i == i_end) return false;
mRegisteredUsers.erase(i);
+ std::vector< ChatChannel * > &channels = user->channels;
+ channels.erase(std::find(channels.begin(), channels.end(), this));
return true;
}
void ChatChannel::removeAllUsers()
{
+ for (ChannelUsers::const_iterator i = mRegisteredUsers.begin(),
+ i_end = mRegisteredUsers.end(); i != i_end; ++i)
+ {
+ std::vector< ChatChannel * > &channels = (*i)->channels;
+ channels.erase(std::find(channels.begin(), channels.end(), this));
+ }
mRegisteredUsers.clear();
}