summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--AUTHORS2
-rw-r--r--ChangeLog14
-rw-r--r--src/account-server/dalstorage.cpp18
-rw-r--r--src/account-server/serverhandler.cpp56
-rw-r--r--src/chat-server/chatchannel.cpp84
-rw-r--r--src/chat-server/chatchannel.hpp204
-rw-r--r--src/chat-server/chatchannelmanager.cpp25
-rw-r--r--src/chat-server/chatchannelmanager.hpp48
-rw-r--r--src/chat-server/chathandler.cpp41
-rw-r--r--src/chat-server/chathandler.hpp24
-rw-r--r--src/game-server/accountconnection.hpp2
11 files changed, 254 insertions, 264 deletions
diff --git a/AUTHORS b/AUTHORS
index 6dafbd8..97ac494 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -1,5 +1,5 @@
Aaron Marks <nymacro@gmail.com>
-Bjørn Lindeijer <bjorn@lindeijer.nl>
+Bjørn Lindeijer <bjorn lindeijer nl>
Björn Steinbrink <B.Steinbrink@gmx.de>
Eugenio Favalli <elvenprogrammer@gmail.com>
Guillaume Melquiond <guillaume.melquiond@gmail.com>
diff --git a/ChangeLog b/ChangeLog
index 9517b25..68d21dd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,16 @@
-2007-07-17 Eugenio Favalli <elvenprogrammer@gmail.com>
+2007-07-17 Bjørn Lindeijer <bjorn@lindeijer.nl>
+
+ * src/chat-server/chathandler.hpp,
+ src/chat-server/chatchannelmanager.cpp,
+ src/chat-server/chatchannel.cpp,
+ src/chat-server/chatchannelmanager.hpp,
+ src/chat-server/chatchannel.hpp, src/chat-server/chathandler.cpp,
+ src/account-server/serverhandler.cpp,
+ src/account-server/dalstorage.cpp,
+ src/game-server/accountconnection.hpp: Some more cleanup of chat
+ handler related code.
+
+2007-07-17 Eugenio Favalli <elvenprogrammer@gmail.com>
* gameserver.cbp, src/game-server/mapmanager.cpp,
src/game-server/mapreader.cpp, src/game-server/mapreader.hpp,
diff --git a/src/account-server/dalstorage.cpp b/src/account-server/dalstorage.cpp
index e053905..01b6ea6 100644
--- a/src/account-server/dalstorage.cpp
+++ b/src/account-server/dalstorage.cpp
@@ -70,7 +70,7 @@ class character_by_id
};
/**
-* Functor used to search a character by name in Characters.
+ * Functor used to search a character by name in Characters.
*/
class character_by_name
{
@@ -78,10 +78,10 @@ public:
character_by_name(const std::string &name)
: mName(name)
{}
-
+
bool operator()(CharacterPtr const &elem) const
{ return elem->getName() == mName; }
-
+
private:
std::string mName; /**< the name to look for */
};
@@ -264,11 +264,11 @@ AccountPtr DALStorage::getAccountBySQL(std::string const &query)
CharacterPtr ptr = getCharacter(characterIDs[k]);
if (ptr.get())
{
- characters.push_back(getCharacter(characterIDs[k]));
+ characters.push_back(getCharacter(characterIDs[k]));
}
else
{
- LOG_ERROR("Failed to get character " << characterIDs[k] << " for account " << id << '.');
+ LOG_ERROR("Failed to get character " << characterIDs[k] << " for account " << id << '.');
}
}
@@ -461,10 +461,10 @@ CharacterPtr DALStorage::getCharacter(const std::string &name)
// look for the character in the list first.
Characters::iterator it_end = mCharacters.end(),
it = std::find_if(mCharacters.begin(), it_end, character_by_name(name));
-
+
if (it != it_end)
return *it;
-
+
// the account was not in the list, look for it in the database.
std::ostringstream sql;
sql << "select * from " << CHARACTERS_TBL_NAME << " where name = '" << name << "';";
@@ -687,7 +687,7 @@ DALStorage::updateCharacter(CharacterPtr character)
LOG_ERROR("(DALStorage::updateCharacter #3) SQL query failure: " << e.what());
return false;
}
-
+
return true;
}
@@ -776,7 +776,7 @@ DALStorage::updateChannels(std::map<short, ChatChannel>& channelList)
<< i->second.getName() << "\", \""
<< i->second.getAnnouncement() << "\", \""
<< i->second.getPassword() << "\", \""
- << i->second.getPrivacy() << "\");";
+ << i->second.isPrivate() << "\");";
LOG_DEBUG("Channel (" << i->first << ") saved: "
<< i->second.getName()
diff --git a/src/account-server/serverhandler.cpp b/src/account-server/serverhandler.cpp
index db7b903..d9995f5 100644
--- a/src/account-server/serverhandler.cpp
+++ b/src/account-server/serverhandler.cpp
@@ -188,11 +188,11 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg)
mTokenCollector.addPendingConnect(magic_token, accountID);
} break;
-
+
case GAMSG_GUILD_CREATE:
{
LOG_DEBUG("GAMSG_GUILD_CREATE");
-
+
result.writeShort(AGMSG_GUILD_CREATE_RESPONSE);
// Check if the guild name is taken already
int playerId = msg.readLong();
@@ -203,23 +203,23 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg)
break;
}
result.writeByte(ERRMSG_OK);
-
+
Storage &store = Storage::instance("tmw");
CharacterPtr ptr = store.getCharacter(playerId);
-
+
// Add guild to character data.
ptr->addGuild(guildName);
// Who to send data to at the other end
result.writeLong(playerId);
-
+
short guildId = guildManager->createGuild(guildName, ptr.get());
result.writeShort(guildId);
result.writeString(guildName);
result.writeShort(1);
enterChannel(guildName, ptr.get());
} break;
-
+
case GAMSG_GUILD_INVITE:
{
// Add Inviting member to guild here
@@ -230,24 +230,24 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg)
short id = msg.readShort();
std::string member = msg.readString();
Guild *guild = guildManager->findById(id);
-
+
Storage &store = Storage::instance("tmw");
CharacterPtr ptr = store.getCharacter(playerId);
-
+
if (!guild->checkLeader(ptr.get()))
{
// Return that the user doesnt have the rights to invite.
result.writeByte(ERRMSG_INSUFFICIENT_RIGHTS);
break;
}
-
+
if (guild->checkInGuild(member))
{
// Return that invited member already in guild.
result.writeByte(ERRMSG_ALREADY_TAKEN);
break;
}
-
+
// Send invite to player using chat server
if (store.doesCharacterNameExist(member))
{
@@ -257,7 +257,7 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg)
guild->addInvited(member);
result.writeByte(ERRMSG_OK);
} break;
-
+
case GAMSG_GUILD_ACCEPT:
{
// Add accepting into guild
@@ -272,43 +272,43 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg)
result.writeByte(ERRMSG_INVALID_ARGUMENT);
break;
}
-
+
Storage &store = Storage::instance("tmw");
CharacterPtr ptr = store.getCharacter(playerId);
-
+
if (!guild->checkInvited(ptr->getName()))
{
// Return the user was not invited.
result.writeByte(ERRMSG_INSUFFICIENT_RIGHTS);
break;
}
-
+
if (guild->checkInGuild(ptr->getName()))
{
// Return that the player is already in the guild.
result.writeByte(ERRMSG_ALREADY_TAKEN);
break;
}
-
+
result.writeByte(ERRMSG_OK);
-
+
// Who to send data to at the other end
result.writeLong(playerId);
-
+
// The guild id and guild name they have joined
result.writeShort(guild->getId());
result.writeString(guildName);
-
+
// Add member to guild
guildManager->addGuildMember(guild->getId(), ptr.get());
-
+
// Add guild to character
ptr->addGuild(guildName);
-
+
// Enter Guild Channel
enterChannel(guildName, ptr.get());
} break;
-
+
case GAMSG_GUILD_GET_MEMBERS:
{
LOG_DEBUG("Received msg ... GAMSG_GUILD_GET_MEMBERS");
@@ -329,7 +329,7 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg)
result.writeString(guild->getMember(i));
}
} break;
-
+
case GAMSG_GUILD_QUIT:
{
LOG_DEBUG("Received msg ... GAMSG_GUILD_QUIT");
@@ -366,19 +366,19 @@ void ServerHandler::enterChannel(const std::string &name, CharacterData *player)
{
MessageOut result(CPMSG_ENTER_CHANNEL_RESPONSE);
short channelId = chatChannelManager->getChannelId(name);
- if (!chatChannelManager->isChannelRegistered(channelId))
+ if (!chatChannelManager->channelExists(channelId))
{
- // Channel doesnt exist yet so create one
+ // Channel doesn't exist yet so create one
channelId = chatChannelManager->registerPrivateChannel(
name,
"Guild Channel",
"");
}
-
+
if (chatChannelManager->addUserInChannel(player->getName(), channelId))
{
result.writeByte(ERRMSG_OK);
-
+
// The user entered the channel, now give him the channel id, the announcement string
// and the user list.
result.writeShort(channelId);
@@ -392,7 +392,7 @@ void ServerHandler::enterChannel(const std::string &name, CharacterData *player)
{
result.writeString(*i);
}
-
+
// Send an CPMSG_UPDATE_CHANNEL to warn other clients a user went
// in the channel.
chatHandler->warnUsersAboutPlayerEventInChat(channelId,
@@ -400,7 +400,7 @@ void ServerHandler::enterChannel(const std::string &name, CharacterData *player)
CHAT_EVENT_NEW_PLAYER);
}
-
+
chatHandler->sendGuildEnterChannel(result, player->getName());
}
diff --git a/src/chat-server/chatchannel.cpp b/src/chat-server/chatchannel.cpp
index 9814375..bf8bce5 100644
--- a/src/chat-server/chatchannel.cpp
+++ b/src/chat-server/chatchannel.cpp
@@ -23,82 +23,45 @@
#include "chat-server/chatchannel.hpp"
-ChatChannel::ChatChannel(const std::string &channelName,
- const std::string &channelAnnouncement = "None",
- const std::string &channelPassword = "None",
- bool channelPrivacy = true):
- mChannelName(channelName),
- mChannelAnnouncement(channelAnnouncement),
- mChannelPassword(channelPassword),
- mChannelPrivate(channelPrivacy)
+ChatChannel::ChatChannel(const std::string &name,
+ const std::string &announcement,
+ const std::string &password,
+ bool privacy):
+ mName(name),
+ mAnnouncement(announcement),
+ mPassword(password),
+ mPrivate(privacy)
{
- if (channelAnnouncement == "")
- mChannelAnnouncement = "None";
- if (channelPassword == "")
- mChannelPassword = "None";
- mRegisteredUsers.clear();
-}
-
-ChatChannel::~ChatChannel()
-{
- mRegisteredUsers.clear();
-}
-
-
-const std::string&
-ChatChannel::getName() const
-{
- return mChannelName;
-}
-
-const std::string&
-ChatChannel::getAnnouncement() const
-{
- return mChannelAnnouncement;
-}
-
-const std::string&
-ChatChannel::getPassword() const
-{
- return mChannelPassword;
-}
-
-bool
-ChatChannel::getPrivacy() const
-{
- return mChannelPrivate;
+ if (announcement == "")
+ mAnnouncement = "None";
+ if (password == "")
+ mPassword = "None";
}
void
-ChatChannel::setName(const std::string &channelName)
+ChatChannel::setName(const std::string &name)
{
- mChannelName = channelName;
+ mName = name;
}
void
-ChatChannel::setAnnouncement(const std::string &channelAnnouncement)
+ChatChannel::setAnnouncement(const std::string &announcement)
{
- if (channelAnnouncement == "")
- mChannelAnnouncement = "None";
+ if (announcement == "")
+ mAnnouncement = "None";
else
- mChannelAnnouncement = channelAnnouncement;
+ mAnnouncement = announcement;
}
void
-ChatChannel::setPassword(const std::string &channelPassword)
+ChatChannel::setPassword(const std::string &password)
{
- if (channelPassword == "")
- mChannelPassword = "None";
+ if (password == "")
+ mPassword = "None";
else
- mChannelPassword = channelPassword;
+ mPassword = password;
}
-ChatChannel::ChannelUsers const &ChatChannel::getUserList() const
-{
- return mRegisteredUsers;
-}
-
-
bool ChatChannel::addUserInChannel(std::string const &user)
{
// Check if the user already exists in the channel
@@ -109,7 +72,6 @@ bool ChatChannel::addUserInChannel(std::string const &user)
return true;
}
-
bool ChatChannel::removeUserFromChannel(std::string const &user)
{
ChannelUsers::iterator i_end = mRegisteredUsers.end(),
@@ -119,7 +81,7 @@ bool ChatChannel::removeUserFromChannel(std::string const &user)
return true;
}
-void ChatChannel::removeEveryUsersFromChannel()
+void ChatChannel::removeAllUsersFromChannel()
{
mRegisteredUsers.clear();
}
diff --git a/src/chat-server/chatchannel.hpp b/src/chat-server/chatchannel.hpp
index 268f135..fd2bff3 100644
--- a/src/chat-server/chatchannel.hpp
+++ b/src/chat-server/chatchannel.hpp
@@ -27,104 +27,112 @@
#include <string>
#include <vector>
-class ChatChannel {
- public:
- typedef std::vector< std::string > ChannelUsers;
-
- /**
- * Constructors
- */
- ChatChannel(const std::string &channelName,
- const std::string &channelAnnouncement,
- const std::string &channelPassword,
- bool channelPrivacy);
-
- /**
- * Destructor
- */
- ~ChatChannel();
-
- /**
- * Get the name of the channel
- */
- const std::string& getName() const;
-
- /**
- * Get the Announcement string of the channel
- */
- const std::string& getAnnouncement() const;
-
- /**
- * Get the password of the channel
- */
- const std::string& getPassword() const;
-
- /**
- * Get the password of the channel
- */
- bool getPrivacy() const;
-
- /**
- * Set the name of the channel
- */
- void setName(const std::string &channelName);
-
- /**
- * Set the Announcement string of the channel
- */
- void setAnnouncement(const std::string &channelAnnouncement);
-
- /**
- * Set the password of the channel
- */
- void setPassword(const std::string &channelPassword);
-
- /**
- * Get the list of the users registered in the channel
- */
- ChannelUsers const &getUserList() const;
-
- /**
- * Add a user in the channel
- */
- bool addUserInChannel(std::string const &);
-
- /**
- * Remove a user from the channel.
- */
- bool removeUserFromChannel(std::string const &);
-
- /**
- * Empties a channel from its users (admin included).
- */
- void removeEveryUsersFromChannel();
-
- private:
- /**
- * The Channel's name.
- */
- std::string mChannelName;
-
- /**
- * The Channel's announcement.
- */
- std::string mChannelAnnouncement;
-
- /**
- * The Channel's password.
- */
- std::string mChannelPassword;
-
- /**
- * The registered user list
- */
- ChannelUsers mRegisteredUsers;
-
- /**
- * Whether the channel is private
- */
- bool mChannelPrivate;
-
+/**
+ * A chat channel. Optionally a channel is private, in which case a password is
+ * required to join it.
+ *
+ * No logic is currently associated with a chat channel except for making sure
+ * that no user joins the channel twice and checking that a user who leaves
+ * actually existed in the channel.
+ *
+ * TODO: b_lindeijer: It would be nicer when some more logic could be placed
+ * in this class to remove some weight from the ChatHandler. Referencing
+ * ChatClient instances would also be nicer than to store only the names
+ * of the characters.
+ */
+class ChatChannel
+{
+ public:
+ typedef std::vector<std::string> ChannelUsers;
+
+ /**
+ * Constructor.
+ *
+ * TODO: b_lindeijer: I would say a channel can be defined as private
+ * when a non-empty password is set, in which case we can get
+ * rid of the privacy parameter.
+ *
+ * @param name the name of the channel.
+ * @param announcement a welcome message.
+ * @param password password (for private channels).
+ * @param privacy whether this channel is private.
+ */
+ ChatChannel(const std::string &name,
+ const std::string &announcement = "",
+ const std::string &password = "",
+ bool privacy = false);
+
+ /**
+ * Get the name of the channel.
+ */
+ const std::string& getName() const
+ { return mName; }
+
+ /**
+ * Get the announcement string of the channel.
+ */
+ const std::string& getAnnouncement() const
+ { return mAnnouncement; }
+
+ /**
+ * Get the password of the channel.
+ */
+ const std::string& getPassword() const
+ { return mPassword; }
+
+ /**
+ * Returns whether this channel is private.
+ */
+ bool isPrivate() const
+ { return mPrivate; }
+
+ /**
+ * Sets the name of the channel.
+ */
+ void setName(const std::string &channelName);
+
+ /**
+ * Sets the announcement string of the channel.
+ */
+ void setAnnouncement(const std::string &channelAnnouncement);
+
+ /**
+ * Sets the password of the channel.
+ */
+ void setPassword(const std::string &channelPassword);
+
+ /**
+ * Gets the list of the users registered in the channel.
+ */
+ const ChannelUsers& getUserList() const
+ { return mRegisteredUsers; }
+
+ /**
+ * Adds a user in the channel.
+ *
+ * @return whether the user was successfully added
+ */
+ bool addUserInChannel(std::string const &);
+
+ /**
+ * Removes a user from the channel.
+ *
+ * @return whether the user was successfully removed
+ */
+ bool removeUserFromChannel(std::string const &);
+
+ /**
+ * Empties a channel from its users (admin included).
+ */
+ void removeAllUsersFromChannel();
+
+ private:
+ std::string mName; /**< The name of the channel. */
+ std::string mAnnouncement; /**< Welcome message. */
+ std::string mPassword; /**< The channel password. */
+ ChannelUsers mRegisteredUsers; /**< Users in this channel. */
+
+ bool mPrivate; /**< Whether the channel is private. */
};
#endif
diff --git a/src/chat-server/chatchannelmanager.cpp b/src/chat-server/chatchannelmanager.cpp
index 6150769..77f1c39 100644
--- a/src/chat-server/chatchannelmanager.cpp
+++ b/src/chat-server/chatchannelmanager.cpp
@@ -21,7 +21,7 @@
* $Id$
*/
-#include <map>
+#include <list>
#include "account-server/storage.hpp"
#include "chat-server/chatchannelmanager.hpp"
@@ -92,25 +92,26 @@ bool ChatChannelManager::removeChannel(short channelId)
{
ChatChannelIterator i = mChatChannels.find(channelId);
if (i == mChatChannels.end()) return false;
- i->second.removeEveryUsersFromChannel();
+ i->second.removeAllUsersFromChannel();
mChatChannels.erase(i);
return true;
}
-std::string ChatChannelManager::getPublicChannelNames(short &numChannels)
+std::list<std::string>
+ChatChannelManager::getPublicChannelNames()
{
- std::string channels;
+ std::list<std::string> channels;
+
for (ChatChannels::const_iterator i = mChatChannels.begin(),
i_end = mChatChannels.end();
i != i_end; ++i)
{
- if (!i->second.getPrivacy())
+ if (!i->second.isPrivate())
{
- channels.append(i->second.getName());
- channels += " ";
- numChannels++;
+ channels.push_back(i->second.getName());
}
}
+
return channels;
}
@@ -141,19 +142,19 @@ std::string ChatChannelManager::getChannelName(short channelId)
std::string ChatChannelManager::getChannelAnnouncement(short channelId)
{
ChatChannelIterator i = mChatChannels.find(channelId);
- return (i != mChatChannels.end()) ? i->second.getAnnouncement() : std::string();
+ return (i != mChatChannels.end()) ? i->second.getAnnouncement() : "";
}
std::string ChatChannelManager::getChannelPassword(short channelId)
{
ChatChannelIterator i = mChatChannels.find(channelId);
- return (i != mChatChannels.end()) ? i->second.getPassword() : std::string();
+ return (i != mChatChannels.end()) ? i->second.getPassword() : "";
}
bool ChatChannelManager::getChannelPrivacy(short channelId)
{
ChatChannelIterator i = mChatChannels.find(channelId);
- return (i != mChatChannels.end()) ? i->second.getPrivacy() : true;
+ return (i != mChatChannels.end()) ? i->second.isPrivate() : true;
}
bool ChatChannelManager::setChannelAnnouncement(short channelId, std::string const &channelAnnouncement)
@@ -214,7 +215,7 @@ ChatChannelManager::getUserListInChannel(short channelId)
return emptyList;
}
-bool ChatChannelManager::isChannelRegistered(short channelId)
+bool ChatChannelManager::channelExists(short channelId)
{
ChatChannelIterator i = mChatChannels.find(channelId);
return i != mChatChannels.end();
diff --git a/src/chat-server/chatchannelmanager.hpp b/src/chat-server/chatchannelmanager.hpp
index 63a626f..ecc1252 100644
--- a/src/chat-server/chatchannelmanager.hpp
+++ b/src/chat-server/chatchannelmanager.hpp
@@ -28,6 +28,10 @@
#include "chat-server/chatchannel.hpp"
+/**
+ * The chat channel manager takes care of registering and removing public and
+ * private chat channels. Every channel gets a unique channel ID.
+ */
class ChatChannelManager
{
public:
@@ -58,9 +62,9 @@ class ChatChannelManager
* channels has already been reached or when a channel with the same
* name already exists.
*
- * TODO: Pretty much the same as registering public channel. Maybe they
- * should be merged and private/public should be passed as a
- * boolean?
+ * TODO: b_lindeijer: Pretty much the same as registering public
+ * channel. Maybe they should be merged and private/public
+ * should be passed as a boolean?
*
* @return the ID of the registered channel, or 0 if the registering
* was unsuccessful.
@@ -75,19 +79,17 @@ class ChatChannelManager
bool removeChannel(short channelId);
/**
- * Get all public channels.
- * TODO: Why not return an actual std::list?
+ * Returns a list containing the names of all public channels.
*
- * @param numChannels The number of channels returned is stored here
- * @return a list of channel names
+ * @return a list of public channel names
*/
- std::string getPublicChannelNames(short &numChannels);
+ std::list<std::string> getPublicChannelNames();
/**
- * Get the number of channels that have been registered.
- * TODO: Documentation doesn't match function name, needs fixing.
+ * Get the number of users that have joined a channel.
*
- * @return the number of registered channels
+ * @param channelName the name of the channel
+ * @return the number of users in the channel
*/
short getNumberOfChannelUsers(const std::string &channelName);
@@ -100,53 +102,51 @@ class ChatChannelManager
/**
* Get the name of a channel from its id.
- * TODO: Can probably return a const std::string&
- * TODO: Possibly throw exception when id doesn't exist
*
* @return the name of the channel
+ * @deprecated Use ChatChannel::getName instead
*/
std::string getChannelName(short channelId);
/**
* Get the announcement string of a channel from its id.
- * TODO: Can probably return a const std::string&
- * TODO: Possibly throw exception when id doesn't exist
*
* @return the announcement string of the channel
+ * @deprecated Use ChatChannel::getAnnouncement instead
*/
std::string getChannelAnnouncement(short channelId);
/**
* Set the announcement string of a channel from its id.
- * TODO: Documentation about returned value is broken
*
- * @return the announcement string of the channel
+ * @return whether the channel exists
+ * @deprecated Use ChatChannel::setAnnouncement instead
*/
bool setChannelAnnouncement(short channelId,
std::string const &channelAnnouncement);
/**
* Set the password of a channel by its id.
- * TODO: Documentation about returned value is broken
*
- * @return the password of the channel
+ * @return whether the channel exists
+ * @deprecated Use ChatChannel::setPassword instead
*/
bool setChannelPassword(short channelId,
const std::string &channelPassword);
/**
* Get the password of a channel from its id.
- * TODO: Can probably return a const std::string &
*
* @return the password of the channel
+ * @deprecated Use ChatChannel::getPassword instead
*/
std::string getChannelPassword(short channelId);
/**
* Get the privacy of the channel from its id.
- * TODO: Rename to isPrivate?
*
* @return the privacy of the channel
+ * @deprecated Use ChatChannel::isPrivate instead
*/
bool getChannelPrivacy(short channelId);
@@ -180,9 +180,11 @@ class ChatChannelManager
std::vector<std::string> const &getUserListInChannel(short channelId);
/**
- * Tells if a channel exists.
+ * Returns whether a channel exists.
+ *
+ * @param channelId a channel ID
*/
- bool isChannelRegistered(short channelId);
+ bool channelExists(short channelId);
private:
typedef std::map<short, ChatChannel> ChatChannels;
diff --git a/src/chat-server/chathandler.cpp b/src/chat-server/chathandler.cpp
index 61f71c1..6413881 100644
--- a/src/chat-server/chathandler.cpp
+++ b/src/chat-server/chathandler.cpp
@@ -21,6 +21,8 @@
* $Id$
*/
+#include <list>
+
#include "defines.h"
#include "account-server/characterdata.hpp"
#include "account-server/guild.hpp"
@@ -37,7 +39,7 @@
#include "utils/tokendispenser.hpp"
-class ChatClient: public NetComputer
+class ChatClient : public NetComputer
{
public:
/**
@@ -159,7 +161,7 @@ void ChatHandler::processMessage(NetComputer *comp, MessageIn &message)
pendingClients.insert(std::make_pair(magic_token, &computer));
return;
}
-
+
computer.characterName = i->second.character;
computer.accountLevel = i->second.level;
pendingLogins.erase(i);
@@ -280,8 +282,8 @@ void ChatHandler::processMessage(NetComputer *comp, MessageIn &message)
result.writeByte(ERRMSG_INVALID_ARGUMENT);
break;
}
-
- if(guildManager->doesExist(channelName))
+
+ if (guildManager->doesExist(channelName))
{
result.writeByte(ERRMSG_INVALID_ARGUMENT);
break;
@@ -344,11 +346,11 @@ void ChatHandler::processMessage(NetComputer *comp, MessageIn &message)
// Get character based on name.
CharacterPtr character = serverHandler->getCharacter(computer.characterName);
- if (!chatChannelManager->isChannelRegistered(channelId))
+ if (!chatChannelManager->channelExists(channelId))
{
result.writeByte(ERRMSG_INVALID_ARGUMENT);
}
- else if (channelId < (signed)MAX_PUBLIC_CHANNELS_RANGE)
+ else if (channelId < (signed) MAX_PUBLIC_CHANNELS_RANGE)
{ // Public channel
if (computer.accountLevel == AL_ADMIN || computer.accountLevel == AL_GM)
{
@@ -408,7 +410,7 @@ void ChatHandler::processMessage(NetComputer *comp, MessageIn &message)
std::string channelName = message.readString();
std::string givenPassword = message.readString();
short channelId = chatChannelManager->getChannelId(channelName);
- if (channelId != 0 && chatChannelManager->isChannelRegistered(channelId))
+ if (channelId != 0 && chatChannelManager->channelExists(channelId))
{
std::string channelPassword = chatChannelManager->getChannelPassword(channelId);
if (!channelPassword.empty())
@@ -469,7 +471,7 @@ void ChatHandler::processMessage(NetComputer *comp, MessageIn &message)
short channelId = message.readShort();
std::string channelName = chatChannelManager->getChannelName(channelId);
- if (channelId != 0 && chatChannelManager->isChannelRegistered(channelId))
+ if (channelId != 0 && chatChannelManager->channelExists(channelId))
{
if (chatChannelManager->removeUserFromChannel(computer.characterName, channelId))
{
@@ -502,19 +504,16 @@ void ChatHandler::processMessage(NetComputer *comp, MessageIn &message)
{
result.writeShort(CPMSG_LIST_CHANNELS_RESPONSE);
- short numberOfPublicChannels;
- std::istringstream channels(
- chatChannelManager->getPublicChannelNames(
- numberOfPublicChannels));
+ std::list<std::string> publicChannels =
+ chatChannelManager->getPublicChannelNames();
+ std::list<std::string>::iterator i, i_end;
- for (int i = 0; i < numberOfPublicChannels; ++i)
+ for (i = publicChannels.begin(), i_end = publicChannels.end();
+ i != i_end; ++i)
{
- std::string channel;
- channels >> channel;
- // Send only public channels
- result.writeString(channel);
- result.writeShort(
- chatChannelManager->getNumberOfChannelUsers(channel));
+ short users = chatChannelManager->getNumberOfChannelUsers(*i);
+ result.writeString(*i);
+ result.writeShort(users);
}
}
break;
@@ -678,7 +677,7 @@ void ChatHandler::sendGuildEnterChannel(const MessageOut &msg, const std::string
(*i)->send(msg);
break;
}
- }
+ }
}
void ChatHandler::sendGuildInvite(const std::string &invitedName, const std::string &inviterName,
@@ -701,7 +700,7 @@ void ChatHandler::sendGuildRejoin(ChatClient &computer)
{
// Get character based on name.
CharacterPtr character = serverHandler->getCharacter(computer.characterName);
-
+
// Get list of guilds and check what rights they have.
std::vector<std::string> guilds = character->getGuilds();
for(unsigned int i = 0; i != guilds.size(); ++i)
diff --git a/src/chat-server/chathandler.hpp b/src/chat-server/chathandler.hpp
index cda3f27..19d2fc3 100644
--- a/src/chat-server/chathandler.hpp
+++ b/src/chat-server/chathandler.hpp
@@ -31,7 +31,11 @@
class ChatClient;
/**
- * Manages all chat related
+ * Manages chat related things like private messaging, chat channel handling
+ * as well as guild chat. The only form of chat not handled by this server is
+ * local chat, which is handled by the game server.
+ *
+ * TODO: Extend with handling of team chat once teams are implemented.
*/
class ChatHandler : public ConnectionHandler
{
@@ -49,9 +53,9 @@ class ChatHandler : public ConnectionHandler
*/
bool
startListen(enet_uint16 port);
-
+
/**
- * Tell a list of user about an event in a chatchannel about a player.
+ * Tell a list of users about an event in a chatchannel about a player.
*/
void warnUsersAboutPlayerEventInChat(short channelId,
std::string const &userName,
@@ -61,12 +65,14 @@ class ChatHandler : public ConnectionHandler
* Send Chat and Guild Info to chat client, so that they can
* join the correct channels.
*/
- void sendGuildEnterChannel(const MessageOut &msg, const std::string &name);
-
+ void sendGuildEnterChannel(const MessageOut &msg,
+ const std::string &name);
+
/**
* Send guild invite.
*/
- void sendGuildInvite(const std::string &invitedName, const std::string &inviterName,
+ void sendGuildInvite(const std::string &invitedName,
+ const std::string &inviterName,
const std::string &guildName);
protected:
@@ -76,7 +82,7 @@ class ChatHandler : public ConnectionHandler
void processMessage(NetComputer *computer, MessageIn &message);
NetComputer *computerConnected(ENetPeer *);
void computerDisconnected(NetComputer *);
-
+
/**
* Send messages for each guild the character belongs to.
*/
@@ -120,12 +126,12 @@ class ChatHandler : public ConnectionHandler
* still haven't sent in their magic token.
*/
void removeOutdatedPending();
-
+
/**
* Send user joined message.
*/
void sendUserJoined(short channelId, const std::string &name);
-
+
/**
* Send user left message.
*/
diff --git a/src/game-server/accountconnection.hpp b/src/game-server/accountconnection.hpp
index 700a85c..e06966d 100644
--- a/src/game-server/accountconnection.hpp
+++ b/src/game-server/accountconnection.hpp
@@ -31,7 +31,7 @@ class Character;
/**
* A connection to the account server.
*/
-class AccountConnection: public Connection
+class AccountConnection : public Connection
{
public:
/**