summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2007-07-15 14:39:36 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2007-07-15 14:39:36 +0000
commit2359f42b667f9f0ac182bb1dccd26bd5c034717a (patch)
tree9d55917dbd42c4d4a7dfc5c706dd3105490077b9
parented74e6e2525f43c6b71e2daa4c3c23108a7516d3 (diff)
downloadmanaserv-2359f42b667f9f0ac182bb1dccd26bd5c034717a.tar.gz
manaserv-2359f42b667f9f0ac182bb1dccd26bd5c034717a.tar.bz2
manaserv-2359f42b667f9f0ac182bb1dccd26bd5c034717a.tar.xz
manaserv-2359f42b667f9f0ac182bb1dccd26bd5c034717a.zip
Some cleaning up of the chat channel manager code.
-rw-r--r--ChangeLog39
-rw-r--r--src/chat-server/chatchannelmanager.cpp77
-rw-r--r--src/chat-server/chatchannelmanager.hpp314
-rw-r--r--src/chat-server/chathandler.cpp62
-rw-r--r--src/game-server/monster.cpp46
5 files changed, 286 insertions, 252 deletions
diff --git a/ChangeLog b/ChangeLog
index fb4b1e75..56a0bd9e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,9 +1,16 @@
-2007-07-14 Guillaume Melquiond <guillaume.melquiond@gmail.com>
+2007-07-15 Bjørn Lindeijer <bjorn@lindeijer.nl>
+
+ * src/chat-server/chatchannelmanager.cpp,
+ src/chat-server/chatchannelmanager.hpp,
+ src/chat-server/chathandler.cpp: Some cleaning up of the chat channel
+ manager code.
+
+2007-07-14 Guillaume Melquiond <guillaume.melquiond@gmail.com>
* src/defines.h, src/game-server/state.cpp: Reduced size of equipment
packets. Fixed packet sending on object distance change.
-2007-07-12 Guillaume Melquiond <guillaume.melquiond@gmail.com>
+2007-07-12 Guillaume Melquiond <guillaume.melquiond@gmail.com>
* src/game-server/item.hpp, src/game-server/inventory.cpp,
src/game-server/inventory.hpp: Fixed naming of equipment slot.
@@ -12,7 +19,7 @@
* src/defines.h, src/game-server/state.cpp: Added support for visible
equipment.
-2007-07-08 Guillaume Melquiond <guillaume.melquiond@gmail.com>
+2007-07-08 Guillaume Melquiond <guillaume.melquiond@gmail.com>
* src/game-server/being.cpp: Lowered messages to debug level.
* src/game-server/deathlistener.hpp: Made members non-abstract, so that
@@ -27,7 +34,7 @@
* src/game-server/gamehandler.cpp: Update account database on
unexpected client disconnection.
-2007-07-07 Guillaume Melquiond <guillaume.melquiond@gmail.com>
+2007-07-07 Guillaume Melquiond <guillaume.melquiond@gmail.com>
* src/common/inventorydata.hpp: Fixed missing include.
* src/game-server/mapcomposite.cpp, src/game-server/mapcomposite.hpp:
@@ -54,13 +61,13 @@
src/game-server/movingobject.cpp, src/game-server/movingobject.hpp:
Fixed teleportation hack caused by caching of pathfinder results.
-2007-07-03 Guillaume Melquiond <guillaume.melquiond@gmail.com>
+2007-07-03 Guillaume Melquiond <guillaume.melquiond@gmail.com>
* src/account-server/dalstorage.cpp: Added error messages for failed
SQL requests when retrieving character. Added check for failed
character when retrieving account. Added check for corrupted inventory.
-2007-07-02 Guillaume Melquiond <guillaume.melquiond@gmail.com>
+2007-07-02 Guillaume Melquiond <guillaume.melquiond@gmail.com>
* src/account-server/storage.cpp, src/account-server/storage.hpp: Moved
trivial accessors to header file. Removed C-like prototypes and harmful
@@ -75,7 +82,7 @@
* accountserver.cbp, gameserver.cbp: Updated project files.
-2007-07-01 Guillaume Melquiond <guillaume.melquiond@gmail.com>
+2007-07-01 Guillaume Melquiond <guillaume.melquiond@gmail.com>
* src/abstractcharacterdata.cpp, src/abstractcharacterdata.hpp,
src/serialize/characterdata.hpp, src/account-server/serverhandler.cpp,
@@ -131,7 +138,7 @@
* src/game-server/spawnarea.cpp: Monsters are no longer spawned on
unwalkable tiles.
-2007-06-28 Guillaume Melquiond <guillaume.melquiond@gmail.com>
+2007-06-28 Guillaume Melquiond <guillaume.melquiond@gmail.com>
* src/game-server/spawnarea.cpp: Delegated creature insertion to the
State class so that it does not disturb object updating.
@@ -145,7 +152,7 @@
* accountserver.cbp, gameserver.cbp: Fixed include directories and
updated project files.
-2007-06-16 Guillaume Melquiond <guillaume.melquiond@gmail.com>
+2007-06-16 Guillaume Melquiond <guillaume.melquiond@gmail.com>
* src/utils/mathutils.cpp: Fixed miscompilation of rsqrt due to type
aliasing and sped up sqrt.
@@ -556,7 +563,7 @@
always have highest log level.
* docs/tmwserv.xml: Added some documentation to example config file.
-2007-01-05 Guillaume Melquiond <guillaume.melquiond@gmail.com>
+2007-01-05 Guillaume Melquiond <guillaume.melquiond@gmail.com>
* src/game-server/player.cpp, src/game-server/state.cpp: Delayed
update of persistent position and put it into state handling, so that
@@ -589,7 +596,7 @@
Updated accordingly. Removed some unworthy debug messages.
* src/Makefile.am: Removed useless dependencies.
-2007-01-04 Guillaume Melquiond <guillaume.melquiond@gmail.com>
+2007-01-04 Guillaume Melquiond <guillaume.melquiond@gmail.com>
* src/playerdata.hpp, src/playerdata.cpp, src/defines.h,
src/Makefile.am: Factored serialization of PlayerData into a new file.
@@ -630,7 +637,7 @@
* src/utils/timer.cpp: Removed extra semicolons that break builds with
--pedantic.
-2007-01-03 Guillaume Melquiond <guillaume.melquiond@gmail.com>
+2007-01-03 Guillaume Melquiond <guillaume.melquiond@gmail.com>
* src/debug.h, src/debug.cpp, src/Makefile.am: Removed obsolete debug
helpers.
@@ -671,7 +678,7 @@
floor items to clients.
* src/game-server/testing.cpp: Added a Xmas cake for testing purpose.
-2007-01-02 Guillaume Melquiond <guillaume.melquiond@gmail.com>
+2007-01-02 Guillaume Melquiond <guillaume.melquiond@gmail.com>
* tmwserv.cbp, tmwserv.dev, runserv.sh: Removed obsolete project files
and shell script.
@@ -705,7 +712,7 @@
* accountserver.cbp, gameserver.cbp, runsrv.bat: Added Code::Blocks
project files and windows start script.
-2006-12-31 Guillaume Melquiond <guillaume.melquiond@gmail.com>
+2006-12-31 Guillaume Melquiond <guillaume.melquiond@gmail.com>
* src/account-server/dalstorage.hpp,
src/account-server/dalstorage.cpp, src/account-server/storage.hpp:
@@ -713,7 +720,7 @@
* src/account-server/serverhandler.cpp: Finished implementation for
warping players around servers.
-2006-12-30 Guillaume Melquiond <guillaume.melquiond@gmail.com>
+2006-12-30 Guillaume Melquiond <guillaume.melquiond@gmail.com>
* src/mapcomposite.h, src/mapcomposite.cpp: Moved to src/game-server
directory and changed header extension to hpp.
@@ -753,7 +760,7 @@
server communications to update player data and to warp players
around.
-2006-12-29 Guillaume Melquiond <guillaume.melquiond@gmail.com>
+2006-12-29 Guillaume Melquiond <guillaume.melquiond@gmail.com>
* src/account.h, src/account.cpp, src/accountclient.h,
src/accountclient.cpp, src/storage.h, src/storage.cpp,
diff --git a/src/chat-server/chatchannelmanager.cpp b/src/chat-server/chatchannelmanager.cpp
index eb21ca50..6150769c 100644
--- a/src/chat-server/chatchannelmanager.cpp
+++ b/src/chat-server/chatchannelmanager.cpp
@@ -42,69 +42,73 @@ ChatChannelManager::~ChatChannelManager()
}
short
-ChatChannelManager::registerPublicChannel(const std::string& channelName,
- const std::string& channelAnnouncement, const std::string& channelPassword)
+ChatChannelManager::registerPublicChannel(const std::string &channelName,
+ const std::string &channelAnnouncement,
+ const std::string &channelPassword)
{
short channelId = 1;
- for (std::map<short, ChatChannel>::iterator i = mChatChannels.begin(),
+ for (ChatChannelIterator i = mChatChannels.begin(),
end = mChatChannels.end(); i != end; ++i)
{
- if ( i->second.getName() == channelName ) return 0;
+ if (i->second.getName() == channelName) return 0;
// We seek the highest channelId in the public range
if (channelId <= i->first && i->first < (signed)MAX_PUBLIC_CHANNELS_RANGE)
channelId = i->first + 1;
}
// Too much channels registered
- if (channelId >= (signed)MAX_PUBLIC_CHANNELS_RANGE) return 0;
+ if (channelId >= (signed) MAX_PUBLIC_CHANNELS_RANGE) return 0;
// Register Channel
- mChatChannels.insert(std::make_pair(channelId,ChatChannel(channelName,
+ mChatChannels.insert(std::make_pair(channelId, ChatChannel(channelName,
channelAnnouncement, channelPassword, false)));
return channelId;
}
short
-ChatChannelManager::registerPrivateChannel(const std::string& channelName,
- const std::string& channelAnnouncement, const std::string& channelPassword)
+ChatChannelManager::registerPrivateChannel(const std::string &channelName,
+ const std::string &channelAnnouncement,
+ const std::string &channelPassword)
{
short channelId = MAX_PUBLIC_CHANNELS_RANGE;
- for (std::map<short, ChatChannel>::iterator i = mChatChannels.begin(),
+ for (ChatChannelIterator i = mChatChannels.begin(),
end = mChatChannels.end(); i != end; ++i)
{
- if ( i->second.getName() == channelName ) return 0;
+ if (i->second.getName() == channelName) return 0;
// We seek the highest channelId in the private range
if (channelId <= i->first)
channelId = i->first + 1;
}
// Too much channels registered
- if (channelId >= (signed)MAX_PRIVATE_CHANNELS_RANGE) return 0;
+ if (channelId >= (signed) MAX_PRIVATE_CHANNELS_RANGE) return 0;
// Register Channel
- mChatChannels.insert(std::make_pair(channelId,ChatChannel(channelName,
+ mChatChannels.insert(std::make_pair(channelId, ChatChannel(channelName,
channelAnnouncement, channelPassword, true)));
return channelId;
}
bool ChatChannelManager::removeChannel(short channelId)
{
- std::map<short, ChatChannel>::iterator i = mChatChannels.find(channelId);
+ ChatChannelIterator i = mChatChannels.find(channelId);
if (i == mChatChannels.end()) return false;
i->second.removeEveryUsersFromChannel();
mChatChannels.erase(i);
return true;
}
-std::string ChatChannelManager::getPublicChannelNames(short *numChannels)
+std::string ChatChannelManager::getPublicChannelNames(short &numChannels)
{
std::string channels;
- for (std::map<short, ChatChannel>::const_iterator i = mChatChannels.begin(), i_end = mChatChannels.end();
- i != i_end; ++i) {
- if(!i->second.getPrivacy())
+ for (ChatChannels::const_iterator i = mChatChannels.begin(),
+ i_end = mChatChannels.end();
+ i != i_end; ++i)
+ {
+ if (!i->second.getPrivacy())
{
channels.append(i->second.getName());
channels += " ";
- (*numChannels)++;
+ numChannels++;
}
}
return channels;
@@ -119,41 +123,42 @@ short ChatChannelManager::getNumberOfChannelUsers(const std::string &channelName
short ChatChannelManager::getChannelId(std::string const &channelName)
{
- for (std::map<short, ChatChannel>::const_iterator i = mChatChannels.begin(), i_end = mChatChannels.end();
- i != i_end; ++i) {
+ for (ChatChannels::const_iterator i = mChatChannels.begin(),
+ i_end = mChatChannels.end();
+ i != i_end; ++i)
+ {
if (i->second.getName() == channelName) return i->first;
}
return 0;
}
-
std::string ChatChannelManager::getChannelName(short channelId)
{
- std::map<short, ChatChannel>::iterator i = mChatChannels.find(channelId);
+ ChatChannelIterator i = mChatChannels.find(channelId);
return (i != mChatChannels.end()) ? i->second.getName() : std::string();
}
std::string ChatChannelManager::getChannelAnnouncement(short channelId)
{
- std::map<short, ChatChannel>::iterator i = mChatChannels.find(channelId);
+ ChatChannelIterator i = mChatChannels.find(channelId);
return (i != mChatChannels.end()) ? i->second.getAnnouncement() : std::string();
}
std::string ChatChannelManager::getChannelPassword(short channelId)
{
- std::map<short, ChatChannel>::iterator i = mChatChannels.find(channelId);
+ ChatChannelIterator i = mChatChannels.find(channelId);
return (i != mChatChannels.end()) ? i->second.getPassword() : std::string();
}
bool ChatChannelManager::getChannelPrivacy(short channelId)
{
- std::map<short, ChatChannel>::iterator i = mChatChannels.find(channelId);
+ ChatChannelIterator i = mChatChannels.find(channelId);
return (i != mChatChannels.end()) ? i->second.getPrivacy() : true;
}
bool ChatChannelManager::setChannelAnnouncement(short channelId, std::string const &channelAnnouncement)
{
- std::map<short, ChatChannel>::iterator i = mChatChannels.find(channelId);
+ ChatChannelIterator i = mChatChannels.find(channelId);
if (i == mChatChannels.end()) return false;
i->second.setAnnouncement(channelAnnouncement);
return true;
@@ -161,7 +166,7 @@ bool ChatChannelManager::setChannelAnnouncement(short channelId, std::string con
bool ChatChannelManager::setChannelPassword(short channelId, std::string const &channelPassword)
{
- std::map<short, ChatChannel>::iterator i = mChatChannels.find(channelId);
+ ChatChannelIterator i = mChatChannels.find(channelId);
if (i == mChatChannels.end()) return false;
i->second.setPassword(channelPassword);
return true;
@@ -169,7 +174,7 @@ bool ChatChannelManager::setChannelPassword(short channelId, std::string const &
ChatChannel ChatChannelManager::_getChannel(short channelId)
{
- std::map<short, ChatChannel>::iterator i = mChatChannels.find(channelId);
+ ChatChannelIterator i = mChatChannels.find(channelId);
if (i != mChatChannels.end()) return i->second;
return ChatChannel("", "", "", true);
}
@@ -185,23 +190,25 @@ bool ChatChannelManager::addUserInChannel(std::string const &user, short channel
bool ChatChannelManager::removeUserFromChannel(std::string const &user, short channelId)
{
- std::map<short, ChatChannel>::iterator i = mChatChannels.find(channelId);
+ ChatChannelIterator i = mChatChannels.find(channelId);
if (i == mChatChannels.end()) return false;
return i->second.removeUserFromChannel(user);
}
-void ChatChannelManager::removeUserFromEveryChannels(std::string const &user)
+void ChatChannelManager::removeUserFromAllChannels(std::string const &user)
{
- for (std::map<short, ChatChannel>::iterator i = mChatChannels.begin(), i_end = mChatChannels.end();
- i != i_end; ++i) {
+ for (ChatChannelIterator i = mChatChannels.begin(),
+ i_end = mChatChannels.end();
+ i != i_end; ++i)
+ {
i->second.removeUserFromChannel(user);
}
}
-std::vector< std::string > const &
+std::vector<std::string> const &
ChatChannelManager::getUserListInChannel(short channelId)
{
- std::map<short, ChatChannel>::iterator i = mChatChannels.find(channelId);
+ ChatChannelIterator i = mChatChannels.find(channelId);
if (i != mChatChannels.end()) return i->second.getUserList();
static std::vector< std::string > emptyList;
return emptyList;
@@ -209,6 +216,6 @@ ChatChannelManager::getUserListInChannel(short channelId)
bool ChatChannelManager::isChannelRegistered(short channelId)
{
- std::map<short, ChatChannel>::iterator i = mChatChannels.find(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 9134c83f..63a626fc 100644
--- a/src/chat-server/chatchannelmanager.hpp
+++ b/src/chat-server/chatchannelmanager.hpp
@@ -21,158 +21,178 @@
* $Id$
*/
-#ifndef _TMWSERV_CHATCHANNELHANDLER_H_
-#define _TMWSERV_CHATCHANNELHANDLER_H_
+#ifndef _TMWSERV_CHATCHANNELMANAGER_H_
+#define _TMWSERV_CHATCHANNELMANAGER_H_
#include <map>
#include "chat-server/chatchannel.hpp"
-class ChatChannelManager {
-
-public:
-
- /**
- * Constructor
- */
- ChatChannelManager();
-
- /**
- * Destructor
- */
- ~ChatChannelManager();
-
- /**
- * Add a public channel.
- *
- * @return the number of the channel registered.
- * 0 if the registering was unsuccessful.
- */
- short registerPublicChannel(const std::string& channelName,
- const std::string& channelAnnouncement,
- const std::string& channelPassword);
-
- /**
- * Add a private channel.
- *
- * @return the number of the channel registered.
- * 0 if the registering was unsuccessful.
- */
- short registerPrivateChannel(const std::string& channelName,
- const std::string& channelAnnouncement,
- const std::string& channelPassword);
-
- /**
- * Remove a channel.
- */
- bool removeChannel(short channelId);
-
- /**
- * Get all public channels
- *
- * @return a list of channel names
- */
- std::string getPublicChannelNames(short *numChannels);
-
- /**
- * Get the number of channels that have been registered
- *
- * @return the number of registered channels
- */
- short getNumberOfChannelUsers(const std::string &channelName);
-
- /**
- * Get the id of a channel from its name.
- *
- * @return the id of the channel
- * 0 if it was unsuccessful.
- */
- short getChannelId(const std::string& channelName);
-
- /**
- * Get the name of a channel from its id.
- *
- * @return the name of the channel
- */
- std::string getChannelName(short channelId);
-
- /**
- * Get the announcement string of a channel from its id.
- *
- * @return the announcement string of the channel
- */
- std::string getChannelAnnouncement(short channelId);
-
- /**
- * Set the announcement string of a channel from its id.
- *
- * @return the announcement string of the channel
- */
- bool setChannelAnnouncement(short channelId, std::string const &channelAnnouncement);
-
- /**
- * Set the announcement string of a channel from its id.
- *
- * @return the announcement string of the channel
- */
- bool setChannelPassword(short channelId, const std::string& channelPassword);
-
- /**
- * Get the password of a channel from its id.
- *
- * @return the password of the channel
- */
- std::string getChannelPassword(short channelId);
-
- /**
- * Get the privacy of the channel from its id.
- *
- * @return the privacy of the channel
- */
- bool getChannelPrivacy(short channelId);
-
- /**
- * get the ChatChannel object from its id.
- *
- * @return the ChatChannel object
- */
- ChatChannel _getChannel(short channelId);
-
- /**
- * Add a user in a channel
- */
- bool addUserInChannel(std::string const &, short channelId);
-
- /**
- * Remove a user from a channel.
- */
- bool removeUserFromChannel(std::string const &, short channelId);
-
- /**
- * Remove a user from every channels.
- * Used at logout.
- */
- void removeUserFromEveryChannels(std::string const &);
-
- /**
- * Get the list of the users registered in a channel
- */
- std::vector< std::string > const &getUserListInChannel(short channelId);
-
- /**
- * tells if a channel exists
- */
- bool isChannelRegistered(short channelId);
-
-private:
-
- /**
- * The list keeping all the chat channels.
- *
- * The channel id must be unique.
- */
- std::map<short, ChatChannel> mChatChannels;
-
+class ChatChannelManager
+{
+ public:
+ /**
+ * Constructor.
+ */
+ ChatChannelManager();
+
+ /**
+ * Destructor.
+ */
+ ~ChatChannelManager();
+
+ /**
+ * Registers a public channel. Can fail if the maximum of public
+ * channels has already been reached or when a channel with the same
+ * name already exists.
+ *
+ * @return the ID of the registered channel, or 0 if the registering
+ * was unsuccessful.
+ */
+ short registerPublicChannel(const std::string &channelName,
+ const std::string &channelAnnouncement,
+ const std::string &channelPassword);
+
+ /**
+ * Registers a private channel. Can fail if the maximum of private
+ * 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?
+ *
+ * @return the ID of the registered channel, or 0 if the registering
+ * was unsuccessful.
+ */
+ short registerPrivateChannel(const std::string &channelName,
+ const std::string &channelAnnouncement,
+ const std::string &channelPassword);
+
+ /**
+ * Remove a channel.
+ */
+ bool removeChannel(short channelId);
+
+ /**
+ * Get all public channels.
+ * TODO: Why not return an actual std::list?
+ *
+ * @param numChannels The number of channels returned is stored here
+ * @return a list of channel names
+ */
+ std::string getPublicChannelNames(short &numChannels);
+
+ /**
+ * Get the number of channels that have been registered.
+ * TODO: Documentation doesn't match function name, needs fixing.
+ *
+ * @return the number of registered channels
+ */
+ short getNumberOfChannelUsers(const std::string &channelName);
+
+ /**
+ * Get the id of a channel from its name.
+ *
+ * @return the id of the channel, 0 if it was unsuccessful.
+ */
+ short getChannelId(const std::string &channelName);
+
+ /**
+ * 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
+ */
+ 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
+ */
+ 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
+ */
+ 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
+ */
+ 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
+ */
+ std::string getChannelPassword(short channelId);
+
+ /**
+ * Get the privacy of the channel from its id.
+ * TODO: Rename to isPrivate?
+ *
+ * @return the privacy of the channel
+ */
+ bool getChannelPrivacy(short channelId);
+
+ /**
+ * Get the ChatChannel object from its id.
+ * TODO: If we have a channel object, why not use that to set
+ * announcement, password, private status, add/remove users, etc?
+ *
+ * @return the ChatChannel object
+ */
+ ChatChannel _getChannel(short channelId);
+
+ /**
+ * Add a user in a channel.
+ */
+ bool addUserInChannel(std::string const &, short channelId);
+
+ /**
+ * Remove a user from a channel.
+ */
+ bool removeUserFromChannel(std::string const &, short channelId);
+
+ /**
+ * Remove a user from all channels. Used at logout.
+ */
+ void removeUserFromAllChannels(std::string const &userName);
+
+ /**
+ * Get the list of the users registered in a channel.
+ */
+ std::vector<std::string> const &getUserListInChannel(short channelId);
+
+ /**
+ * Tells if a channel exists.
+ */
+ bool isChannelRegistered(short channelId);
+
+ private:
+ typedef std::map<short, ChatChannel> ChatChannels;
+ typedef ChatChannels::iterator ChatChannelIterator;
+
+ /**
+ * The map keeping all the chat channels. The channel id must be
+ * unique.
+ */
+ ChatChannels mChatChannels;
};
extern ChatChannelManager *chatChannelManager;
diff --git a/src/chat-server/chathandler.cpp b/src/chat-server/chathandler.cpp
index d9c2360f..61f71c11 100644
--- a/src/chat-server/chathandler.cpp
+++ b/src/chat-server/chathandler.cpp
@@ -118,7 +118,7 @@ NetComputer *ChatHandler::computerConnected(ENetPeer *peer)
void ChatHandler::computerDisconnected(NetComputer *computer)
{
// Remove user from all channels
- chatChannelManager->removeUserFromEveryChannels(((ChatClient*)computer)->characterName);
+ chatChannelManager->removeUserFromAllChannels(((ChatClient*)computer)->characterName);
ChatPendingClients::iterator i_end = pendingClients.end();
for (ChatPendingClients::iterator i = pendingClients.begin();
i != i_end; ++i)
@@ -213,8 +213,8 @@ void ChatHandler::processMessage(NetComputer *comp, MessageIn &message)
// If it's slang's free.
if (stringFilter->filterContent(text))
{
- // We send the message to every players in the default
- // channel as it is an annouce.
+ // We send the message to all players in the default
+ // channel as it is an announce.
announce(computer, text);
}
else
@@ -340,10 +340,10 @@ void ChatHandler::processMessage(NetComputer *comp, MessageIn &message)
short channelId = message.readShort();
std::string channelName = chatChannelManager->getChannelName(channelId);
-
+
// Get character based on name.
CharacterPtr character = serverHandler->getCharacter(computer.characterName);
-
+
if (!chatChannelManager->isChannelRegistered(channelId))
{
result.writeByte(ERRMSG_INVALID_ARGUMENT);
@@ -378,10 +378,10 @@ void ChatHandler::processMessage(NetComputer *comp, MessageIn &message)
{ // Private channel
// We first see if the user is the admin (first user) of
// the channel
- std::vector< std::string > const &userList =
+ std::vector<std::string> const &userList =
chatChannelManager->getUserListInChannel(channelId);
- std::vector< std::string >::const_iterator i = userList.begin();
- // if it's actually the private channel's admin
+ std::vector<std::string>::const_iterator i = userList.begin();
+ // If it's actually the private channel's admin
if (*i == computer.characterName)
{
// Make every user quit the channel
@@ -419,7 +419,7 @@ void ChatHandler::processMessage(NetComputer *comp, MessageIn &message)
break;
}
}
-
+
if (guildManager->doesExist(channelName))
{
Guild *guild = guildManager->findByName(channelName);
@@ -433,8 +433,8 @@ void ChatHandler::processMessage(NetComputer *comp, MessageIn &message)
if (chatChannelManager->addUserInChannel(computer.characterName, channelId))
{
result.writeByte(ERRMSG_OK);
- // The user entered the channel, now give him the channel id, the announcement string
- // and the user list.
+ // The user entered the channel, now give him the channel
+ // id, the announcement string and the user list.
result.writeShort(channelId);
result.writeString(channelName);
result.writeString(chatChannelManager->getChannelAnnouncement(channelId));
@@ -468,7 +468,7 @@ void ChatHandler::processMessage(NetComputer *comp, MessageIn &message)
result.writeShort(CPMSG_QUIT_CHANNEL_RESPONSE);
short channelId = message.readShort();
std::string channelName = chatChannelManager->getChannelName(channelId);
-
+
if (channelId != 0 && chatChannelManager->isChannelRegistered(channelId))
{
if (chatChannelManager->removeUserFromChannel(computer.characterName, channelId))
@@ -480,7 +480,7 @@ void ChatHandler::processMessage(NetComputer *comp, MessageIn &message)
warnUsersAboutPlayerEventInChat(channelId,
computer.characterName,
CHAT_EVENT_LEAVING_PLAYER);
- if(guildManager->doesExist(channelName))
+ if (guildManager->doesExist(channelName))
{
// Send a user left message
sendUserLeft(channelId, computer.characterName);
@@ -503,48 +503,50 @@ void ChatHandler::processMessage(NetComputer *comp, MessageIn &message)
result.writeShort(CPMSG_LIST_CHANNELS_RESPONSE);
short numberOfPublicChannels;
- std::istringstream channels(chatChannelManager->getPublicChannelNames(
- &numberOfPublicChannels));
+ std::istringstream channels(
+ chatChannelManager->getPublicChannelNames(
+ numberOfPublicChannels));
- for(int i = 0; i < numberOfPublicChannels; ++i)
+ for (int i = 0; i < numberOfPublicChannels; ++i)
{
std::string channel;
channels >> channel;
// Send only public channels
result.writeString(channel);
- result.writeShort(chatChannelManager->getNumberOfChannelUsers(channel));
+ result.writeShort(
+ chatChannelManager->getNumberOfChannelUsers(channel));
}
}
break;
-
+
case PCMSG_LIST_CHANNELUSERS:
{
result.writeShort(CPMSG_LIST_CHANNELUSERS_RESPONSE);
-
+
std::string channelName = message.readString();
-
+
result.writeString(channelName);
-
- // get user list
+
+ // Get user list
std::vector<std::string> channelList;
channelList = chatChannelManager->getUserListInChannel(
chatChannelManager->getChannelId(channelName));
-
- // add a user at a time
- for(int i = 0; i < channelList.size(); ++i)
+
+ // Add a user at a time
+ for (int i = 0; i < channelList.size(); ++i)
{
result.writeString(channelList[i]);
}
-
} break;
case PCMSG_DISCONNECT:
{
result.writeShort(CPMSG_DISCONNECT_RESPONSE);
result.writeByte(ERRMSG_OK);
- chatChannelManager->removeUserFromEveryChannels(computer.characterName);
- break;
+ chatChannelManager->removeUserFromAllChannels(
+ computer.characterName);
}
+ break;
default:
LOG_WARN("ChatHandler::processMessage, Invalid message type"
@@ -587,7 +589,7 @@ ChatHandler::announce(ChatClient &computer, std::string const &text)
computer.accountLevel == AL_GM )
{
LOG_INFO("ANNOUNCE: " << text);
- // Send it to every beings.
+ // Send it to all beings.
result.writeShort(CPMSG_ANNOUNCEMENT);
result.writeString(text);
sendToEveryone(result);
@@ -630,7 +632,7 @@ ChatHandler::sayInChannel(ChatClient &computer, short channel,
MessageOut result;
LOG_DEBUG(computer.characterName << " says in channel " << channel << ": "
<< text);
- // Send it to every beings in channel
+ // Send it to all beings in channel
result.writeShort(CPMSG_PUBMSG);
result.writeShort(channel);
result.writeString(computer.characterName);
diff --git a/src/game-server/monster.cpp b/src/game-server/monster.cpp
index 30f3a909..d22c60b2 100644
--- a/src/game-server/monster.cpp
+++ b/src/game-server/monster.cpp
@@ -51,15 +51,16 @@ Monster::Monster(MonsterClass *specy):
mAttackAftDelay(10)
{
LOG_DEBUG("Monster spawned!");
- mAgressive = false; // TODO: get from monster database
- mAgressionRange = 10; // TODO: get from monster database
- mAttributes.resize(NB_ATTRIBUTES_CONTROLLED, 1); // TODO: fill with the real attributes
+ mAgressive = false; // TODO: Get from monster database
+ mAgressionRange = 10; // TODO: Get from monster database
+ // TODO: Fill with the real attributes
+ mAttributes.resize(NB_ATTRIBUTES_CONTROLLED, 1);
- // some bogus values for testing monster attacks on players
+ // Some bogus values for testing monster attacks on players
setAttribute(BASE_ATTR_STRENGTH, 10);
setAttribute(MONSTER_SKILL_WEAPON, 3);
- // set positions relative to target from which the monster can attack
+ // Set positions relative to target from which the monster can attack
mAttackPositions.push_back(AttackPosition(+32, 0, DIRECTION_LEFT));
mAttackPositions.push_back(AttackPosition(-32, 0, DIRECTION_RIGHT));
mAttackPositions.push_back(AttackPosition(0, +32, DIRECTION_DOWN));
@@ -78,7 +79,7 @@ Monster::~Monster()
void Monster::update()
{
- // if dead do nothing but rot
+ // If dead do nothing but rot
if (mAction == DEAD)
{
mCountDown--;
@@ -89,7 +90,7 @@ void Monster::update()
return;
}
- // if currently attacking finish attack;
+ // If currently attacking finish attack;
if (mAttackTime)
{
if (mAttackTime == mAttackAftDelay)
@@ -101,24 +102,24 @@ void Monster::update()
return;
}
- // check potential attack positions
+ // Check potential attack positions
Being *bestAttackTarget = NULL;
int bestTargetPriority = 0;
Point bestAttackPosition;
Direction bestAttackDirection = DIRECTION_DOWN;
- // iterate through objects nearby
+ // Iterate through objects nearby
for (MovingObjectIterator i(getMap()->getAroundCharacterIterator(this, AROUND_AREA)); i; ++i)
{
- // we only want to attack player characters
+ // We only want to attack player characters
if ((*i)->getType() != OBJECT_CHARACTER) continue;
Being *target = static_cast<Being *> (*i);
- // dead characters are ignored
+ // Dead characters are ignored
if (target->getAction() == DEAD) continue;
- // determine how much we hate the target
+ // Determine how much we hate the target
int targetPriority = 0;
std::map<Being *, int, std::greater<Being *> >::iterator angerIterator;
angerIterator = mAnger.find(target);
@@ -135,7 +136,7 @@ void Monster::update()
continue;
}
- // check all attack positions
+ // Check all attack positions
for (std::list<AttackPosition>::iterator j = mAttackPositions.begin();
j != mAttackPositions.end();
j++)
@@ -156,25 +157,25 @@ void Monster::update()
}
}
- // check if an attack position has been found
+ // Check if an attack position has been found
if (bestAttackTarget)
{
- // check if we are there
+ // Check if we are there
if (bestAttackPosition == getPosition())
{
- // we are there - let's get ready to beat the crap out of the target
+ // We are there - let's get ready to beat the crap out of the target
setDirection(bestAttackDirection);
mAttackTime = mAttackPreDelay + mAttackAftDelay;
}
else
{
- // we aren't there yet - let's move
+ // We aren't there yet - let's move
setDestination(bestAttackPosition);
}
}
else
{
- // we have no target - let's wander around
+ // We have no target - let's wander around
mCountDown--;
if (mCountDown <= 0)
{
@@ -182,9 +183,6 @@ void Monster::update()
rand() % 160 - 80 + getPosition().y);
setDestination(randomPos);
mCountDown = 10 + rand() % 10;
-
- LOG_DEBUG("Setting new random destination " << randomPos.x << ","
- << randomPos.y << " for being " << getPublicID());
}
}
}
@@ -193,7 +191,7 @@ int Monster::calculatePositionPriority(Point position, int targetPriority)
{
Point thisPos = getPosition();
- // check if we already are on this position
+ // Check if we already are on this position
if (thisPos.x / 32 == position.x / 32 &&
thisPos.y / 32 == position.y / 32)
{
@@ -215,7 +213,7 @@ int Monster::calculatePositionPriority(Point position, int targetPriority)
}
}
-void Monster::died (Being *being)
+void Monster::died(Being *being)
{
mAnger.erase(being);
mDeathListeners.remove((DeathListener *)being);
@@ -244,7 +242,7 @@ int Monster::damage(Damage damage)
void Monster::die()
{
- mCountDown = 50; // sets remove time to 5 seconds
+ mCountDown = 50; // Sets remove time to 5 seconds
Being::die();
if (ItemClass *drop = mSpecy->getRandomDrop())
{