summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--src/account-server/dalstorage.cpp96
-rw-r--r--src/account-server/dalstorage.hpp25
-rw-r--r--src/account-server/dalstoragesql.hpp28
-rw-r--r--src/chat-server/chatchannelmanager.cpp3
-rw-r--r--src/chat-server/chathandler.cpp27
-rw-r--r--src/chat-server/chathandler.hpp4
7 files changed, 24 insertions, 168 deletions
diff --git a/ChangeLog b/ChangeLog
index ec0ab874..5865eda5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2008-06-03 Roderic Morris <roderic@ccs.neu.edu>
+
+ * src/account-server/dalstorage.cpp, src/account-server/dalstorage.hpp,
+ src/chat-server/chatchannelmanager.cpp, src/account-server/dalstoragesql.hpp:
+ Stop storing chat channels in the db
+ * src/chat-server/chathandler.hpp, src/chat-server/chathandler.cpp:
+ Have joinGuildChannel return a ChatChannel in case we need it
+ constructing a packet. Send channel announcements.
+
2008-06-02 Philipp Sehmisch <tmw@crushnet.org>
* data/test.lua: Used an example for schedule_in which is more in step with
diff --git a/src/account-server/dalstorage.cpp b/src/account-server/dalstorage.cpp
index 02b095dd..8f6feb53 100644
--- a/src/account-server/dalstorage.cpp
+++ b/src/account-server/dalstorage.cpp
@@ -127,7 +127,6 @@ void DALStorage::open()
createTable(ACCOUNTS_TBL_NAME, SQL_ACCOUNTS_TABLE);
createTable(CHARACTERS_TBL_NAME, SQL_CHARACTERS_TABLE);
createTable(INVENTORIES_TBL_NAME, SQL_INVENTORIES_TABLE);
- createTable(CHANNELS_TBL_NAME, SQL_CHANNELS_TABLE);
createTable(GUILDS_TBL_NAME, SQL_GUILDS_TABLE);
createTable(GUILD_MEMBERS_TBL_NAME, SQL_GUILD_MEMBERS_TABLE);
createTable(QUESTS_TBL_NAME, SQL_QUESTS_TABLE);
@@ -628,101 +627,6 @@ bool DALStorage::updateCharacter(Character *character)
return true;
}
-std::map<unsigned short, ChatChannel>
-DALStorage::getChannelList()
-{
- // specialize the string_to functor to convert
- // a string to a short.
- string_to<int> toInt;
-
- // The formatted datas
- std::map<unsigned short, ChatChannel> channels;
-
- try {
- std::stringstream sql;
- sql << "select id, name, announcement, password from ";
- sql << CHANNELS_TBL_NAME;
- sql << ";";
-
- const dal::RecordSet& channelInfo = mDb->execSql(sql.str());
-
- // If the map return is empty then we have no choice but to return false.
- if (channelInfo.isEmpty()) {
- return channels;
- }
-
- for (unsigned int i = 0; i < channelInfo.rows(); ++i)
- {
- unsigned short channelId = toInt(channelInfo(i, 0));
- channels.insert(
- std::make_pair(channelId,
- ChatChannel(channelId,
- channelInfo(i, 1),
- channelInfo(i, 2),
- channelInfo(i, 3))));
-
- LOG_DEBUG("Channel (" << channelId << ") loaded: "
- << channelInfo(i, 1) << ": " << channelInfo(i, 2));
- }
-
- return channels;
- }
- catch (const dal::DbSqlQueryExecFailure& e) {
- // TODO: throw an exception.
- LOG_ERROR("(DALStorage::getChannelList) SQL query failure: " << e.what());
- }
-
- return channels;
-}
-
-void
-DALStorage::updateChannels(std::map<unsigned short, ChatChannel>& channelList)
-{
- try {
- // Empties the table
- std::stringstream sql;
- sql << "delete from "
- << CHANNELS_TBL_NAME
- << ";";
-
- mDb->execSql(sql.str());
-
- for (std::map<unsigned short, ChatChannel>::iterator i = channelList.begin();
- i != channelList.end();)
- {
- // insert registered channel if id < MAX_PUBLIC_CHANNELS_RANGE;
- if (i->first < MAX_PUBLIC_CHANNELS_RANGE)
- {
- if (i->second.getName() != "")
- {
- sql.str("");
- sql << "insert into "
- << CHANNELS_TBL_NAME
- << " (id, name, announcement, password, joinable)"
- << " values ("
- << i->first << ", \""
- << i->second.getName() << "\", \""
- << i->second.getAnnouncement() << "\", \""
- << i->second.getPassword() << "\", \""
- << i->second.canJoin() << "\");";
-
- LOG_DEBUG("Channel (" << i->first << ") saved: "
- << i->second.getName()
- << ": " << i->second.getAnnouncement());
- }
-
- mDb->execSql(sql.str());
- }
- ++i;
- }
-
- }
- catch (const dal::DbSqlQueryExecFailure& e) {
- // TODO: throw an exception.
- LOG_ERROR("(DALStorage::updateChannels) SQL query failure: " << e.what());
- }
-}
-
/**
* Create the specified table.
diff --git a/src/account-server/dalstorage.hpp b/src/account-server/dalstorage.hpp
index 587f996a..e9a15af8 100644
--- a/src/account-server/dalstorage.hpp
+++ b/src/account-server/dalstorage.hpp
@@ -125,15 +125,6 @@ class DALStorage
*/
void banCharacter(int id, int duration);
-#if 0
- /**
- * Get the list of Emails in the accounts list.
- * @return the list of Email's Addresses.
- */
- std::list<std::string>
- getEmailList();
-#endif
-
/**
* Tells if the user name already exists.
* @return true if the user name exists.
@@ -163,20 +154,6 @@ class DALStorage
updateCharacter(Character *ptr);
/**
- * Gives the list of opened public channels registered in database
- * @return a map of the public channels
- */
- std::map<unsigned short, ChatChannel>
- getChannelList();
-
- /**
- * apply channel differences from the list in memory
- * to the one in db.
- */
- void
- updateChannels(std::map<unsigned short, ChatChannel>& channelList);
-
- /**
* Add a new guild
*
*/
@@ -197,7 +174,7 @@ class DALStorage
void
addGuildMember(int guild_id, const std::string &member_name);
- /*
+ /**
* Remove member from guild
*/
void
diff --git a/src/account-server/dalstoragesql.hpp b/src/account-server/dalstoragesql.hpp
index ea7f620e..ee77d8f2 100644
--- a/src/account-server/dalstoragesql.hpp
+++ b/src/account-server/dalstoragesql.hpp
@@ -253,34 +253,6 @@ static char const *SQL_INVENTORIES_TABLE =
");";
/**
- * TABLE: tmw_channels.
- * Keeps opened public Channel list
- */
-static char const *CHANNELS_TBL_NAME = "tmw_channels";
-static char const *SQL_CHANNELS_TABLE =
- "CREATE TABLE tmw_channels ("
-#if defined (MYSQL_SUPPORT)
- "id INTEGER PRIMARY KEY,"
- "name VARCHAR(32) NOT NULL UNIQUE,"
- "announcement VARCHAR(256) NOT NULL,"
- "password VARCHAR(32) NOT NULL,"
- "joinable INTEGER NOT NULL"
-#elif defined (SQLITE_SUPPORT)
- "id INTEGER PRIMARY KEY,"
- "name TEXT NOT NULL UNIQUE,"
- "announcement TEXT NOT NULL,"
- "password TEXT NOT NULL,"
- "joinable INTEGER NOT NULL"
-#elif defined (POSTGRESQL_SUPPORT)
- "id SERIAL PRIMARY KEY,"
- "name TEXT NOT NULL UNIQUE,"
- "announcement TEXT NOT NULL,"
- "password TEXT NOT NULL,"
- "joinable INTEGER NOT NULL"
-#endif
- ");";
-
-/**
* TABLE: tmw_guilds.
* Store player guilds
*/
diff --git a/src/chat-server/chatchannelmanager.cpp b/src/chat-server/chatchannelmanager.cpp
index 43cfdb44..e9ba7708 100644
--- a/src/chat-server/chatchannelmanager.cpp
+++ b/src/chat-server/chatchannelmanager.cpp
@@ -31,14 +31,11 @@
ChatChannelManager::ChatChannelManager() : mNextChannelId(1)
{
- // Load stored public chat channels from db
- mChatChannels = storage->getChannelList();
}
ChatChannelManager::~ChatChannelManager()
{
- storage->updateChannels(mChatChannels);
}
int
diff --git a/src/chat-server/chathandler.cpp b/src/chat-server/chathandler.cpp
index 7218cb9d..482e1b2f 100644
--- a/src/chat-server/chathandler.cpp
+++ b/src/chat-server/chathandler.cpp
@@ -340,7 +340,8 @@ ChatHandler::handleRegisterChannelMessage(ChatClient &client, MessageIn &msg)
{
reply.writeByte(ERRMSG_INVALID_ARGUMENT);
}
- else if (guildManager->doesExist(channelName) || chatChannelManager->channelExists(channelName))
+ else if (guildManager->doesExist(channelName) ||
+ chatChannelManager->channelExists(channelName))
{
// Channel already exists
reply.writeByte(ERRMSG_ALREADY_TAKEN);
@@ -368,6 +369,7 @@ ChatHandler::handleRegisterChannelMessage(ChatClient &client, MessageIn &msg)
reply.writeByte(ERRMSG_OK);
reply.writeShort(channelId);
reply.writeString(channelName);
+ reply.writeString(channelAnnouncement);
}
else
{
@@ -582,8 +584,8 @@ ChatHandler::handleGuildCreation(ChatClient &client, MessageIn &msg)
reply.writeByte(true);
// Send autocreated channel id
- short channelId = joinGuildChannel(guildName, client);
- reply.writeShort(channelId);
+ ChatChannel* channel = joinGuildChannel(guildName, client);
+ reply.writeShort(channel->getId());
}
else
{
@@ -661,8 +663,8 @@ ChatHandler::handleGuildAcceptInvite(ChatClient &client, MessageIn &msg)
reply.writeShort(guild->getId());
reply.writeByte(false);
- short id = joinGuildChannel(guild->getName(), client);
- reply.writeShort(id);
+ ChatChannel *channel = joinGuildChannel(guild->getName(), client);
+ reply.writeShort(channel->getId());
}
else
{
@@ -829,10 +831,10 @@ void ChatHandler::sendGuildRejoin(ChatClient &client)
msg.writeByte(leader);
// get channel id of guild channel
- short channelId = joinGuildChannel(guildName, client);
+ ChatChannel *channel = joinGuildChannel(guildName, client);
// send the channel id for the autojoined channel
- msg.writeShort(channelId);
+ msg.writeShort(channel->getId());
client.send(msg);
@@ -857,22 +859,17 @@ void ChatHandler::sendUserLeft(ChatChannel *channel, const std::string &name)
sendInChannel(channel, msg);
}
-int ChatHandler::joinGuildChannel(const std::string &guildName, ChatClient &client)
+ChatChannel* ChatHandler::joinGuildChannel(const std::string &guildName, ChatClient &client)
{
- int channelId = 0;
// Automatically make the character join the guild chat channel
ChatChannel *channel = chatChannelManager->getChannel(guildName);
if (!channel)
{
// Channel doesnt exist so create it
- channelId = chatChannelManager->createNewChannel(guildName,
+ int channelId = chatChannelManager->createNewChannel(guildName,
"Guild Channel", "", false);
channel = chatChannelManager->getChannel(channelId);
}
- else
- {
- channelId = channel->getId();
- }
// Add user to the channel
if (channel->addUser(&client))
@@ -885,7 +882,7 @@ int ChatHandler::joinGuildChannel(const std::string &guildName, ChatClient &clie
sendGuildListUpdate(guildName, client.characterName);
}
- return channelId;
+ return channel;
}
void ChatHandler::sendGuildListUpdate(const std::string &guildName,
diff --git a/src/chat-server/chathandler.hpp b/src/chat-server/chathandler.hpp
index fd51db4e..4e5b48b0 100644
--- a/src/chat-server/chathandler.hpp
+++ b/src/chat-server/chathandler.hpp
@@ -297,9 +297,9 @@ class ChatHandler : public ConnectionHandler
* Automatically makes client join it
* @param The name of the guild (and therefore the channel)
* @param The client to join the channel
- * @return Returns the channel Id
+ * @return Returns the channel joined
*/
- int joinGuildChannel(const std::string &name, ChatClient &client);
+ ChatChannel* joinGuildChannel(const std::string &name, ChatClient &client);
/**
* Returns ChatClient from the Player Map