diff options
author | Yohann Ferreira <bertram@cegetel.net> | 2006-01-20 23:17:19 +0000 |
---|---|---|
committer | Yohann Ferreira <bertram@cegetel.net> | 2006-01-20 23:17:19 +0000 |
commit | d318b2428878bd0e35b189b3e6d3bffd825da25c (patch) | |
tree | dc61bd08aec87a5293e1ca072079652ad6047423 /src/dalstorage.cpp | |
parent | 7960ff184f15a3b6029fef8e5100d24a6c556afe (diff) | |
download | manaserv-d318b2428878bd0e35b189b3e6d3bffd825da25c.tar.gz manaserv-d318b2428878bd0e35b189b3e6d3bffd825da25c.tar.xz manaserv-d318b2428878bd0e35b189b3e6d3bffd825da25c.zip |
Chat channeling commit part 3. Is now linked with the connection handler to chat in a specific channel. Also made some fixes on the chat channeling.
Diffstat (limited to 'src/dalstorage.cpp')
-rw-r--r-- | src/dalstorage.cpp | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/src/dalstorage.cpp b/src/dalstorage.cpp index 22b3d74..4fb245f 100644 --- a/src/dalstorage.cpp +++ b/src/dalstorage.cpp @@ -444,7 +444,7 @@ DALStorage::getSameEmailNumber(const std::string &email) * @return true if character's name exists. */ bool -DALStorage::doesCharacterNameExists(std::string name) +DALStorage::doesCharacterNameExists(const std::string& name) { // If not opened already open(); @@ -544,6 +544,10 @@ DALStorage::getChannelList() return channels; } + // We use this to handle correctly empty lines + std::string channelName; + std::string channelAnnouncement; + std::string channelPassword; for ( unsigned int i = 0; i < channelInfo.rows(); ++i) { channels.insert(std::make_pair(toShort(channelInfo(0,0)), @@ -551,8 +555,8 @@ DALStorage::getChannelList() channelInfo(0,2), channelInfo(0,3)))); - LOG_DEBUG("Channel loaded: " << channelInfo(0,1) - << ":" << channelInfo(0,2), 5) + LOG_DEBUG("Channel (" << channelInfo(0,0) << ") loaded: " << channelInfo(0,1) + << ": " << channelInfo(0,2), 5) } return channels; @@ -568,7 +572,11 @@ DALStorage::getChannelList() void DALStorage::updateChannels(std::map<short, ChatChannel>& channelList) { - // If not opened already +#if defined (SQLITE_SUPPORT) + // Reopen the db in this thread for sqlite, to avoid + // Library Call out of sequence problem due to thread safe. + close(); +#endif open(); try { @@ -580,24 +588,28 @@ DALStorage::updateChannels(std::map<short, ChatChannel>& channelList) mDb->execSql(sql.str()); + // TODO: See if ' don't make the SQL query fail. for ( std::map<short, ChatChannel>::iterator i = channelList.begin(); i != channelList.end();) { // insert registered channel if id < MAX_PUBLIC_CHANNELS_RANGE; if ( i->first < (signed)MAX_PUBLIC_CHANNELS_RANGE ) { - sql.str(""); - sql << "insert into " - << CHANNELS_TBL_NAME - << " (id, name, announcement, password)" - << " values (" - << i->first << ", '" - << i->second.getName() << "', '" - << i->second.getAnnouncement() << "', '" - << i->second.getPassword() << "');"; - - LOG_DEBUG("Channel saved: " << i->second.getName() - << ":" << i->second.getAnnouncement(), 5) + if (i->second.getName() != "") + { + sql.str(""); + sql << "insert into " + << CHANNELS_TBL_NAME + << " (id, name, announcement, password)" + << " values (" + << i->first << ", '" + << i->second.getName() << "', '" + << i->second.getAnnouncement() << "', '" + << i->second.getPassword() << "');"; + + LOG_DEBUG("Channel (" << i->first << ") saved: " << i->second.getName() + << ": " << i->second.getAnnouncement(), 5) + } mDb->execSql(sql.str()); } |