diff options
-rw-r--r-- | modules/database/db_sql.cpp | 2 | ||||
-rw-r--r-- | modules/database/db_sql_live_read.cpp | 172 | ||||
-rw-r--r-- | modules/database/db_sql_live_write.cpp | 10 | ||||
-rw-r--r-- | src/nickalias.cpp | 19 | ||||
-rw-r--r-- | src/nickcore.cpp | 7 | ||||
-rw-r--r-- | src/regchannel.cpp | 22 |
6 files changed, 105 insertions, 127 deletions
diff --git a/modules/database/db_sql.cpp b/modules/database/db_sql.cpp index 40b24b0aa..c32c12e2e 100644 --- a/modules/database/db_sql.cpp +++ b/modules/database/db_sql.cpp @@ -183,7 +183,7 @@ class DBSQL : public Module } } - return EVENT_CONTINUE; + return EVENT_STOP; } }; diff --git a/modules/database/db_sql_live_read.cpp b/modules/database/db_sql_live_read.cpp index ac7a0191c..90a36d10a 100644 --- a/modules/database/db_sql_live_read.cpp +++ b/modules/database/db_sql_live_read.cpp @@ -32,124 +32,6 @@ class SQLCache : public Timer } }; -static void ChanInfoUpdate(const Anope::string &name, const SQLResult &res) -{ - ChannelInfo *ci = cs_findchan(name); - if (res.Rows() == 0) - { - delete ci; - return; - } - - try - { - if (!ci) - ci = new ChannelInfo(name); - ci->SetFounder(findcore(res.Get(0, "founder"))); - ci->successor = findcore(res.Get(0, "successor")); - ci->desc = res.Get(0, "description"); - ci->time_registered = convertTo<time_t>(res.Get(0, "time_registered")); - ci->ClearFlags(); - ci->FromString(res.Get(0, "flags")); - ci->bantype = convertTo<int>(res.Get(0, "bantype")); - ci->memos.memomax = convertTo<unsigned>(res.Get(0, "memomax")); - - if (res.Get(0, "bi").equals_cs(ci->bi ? ci->bi->nick : "") == false) - { - if (ci->bi) - ci->bi->UnAssign(NULL, ci); - BotInfo *bi = findbot(res.Get(0, "bi")); - if (bi) - bi->Assign(NULL, ci); - } - - ci->capsmin = convertTo<int16_t>(res.Get(0, "capsmin")); - ci->capspercent = convertTo<int16_t>(res.Get(0, "capspercent")); - ci->floodlines = convertTo<int16_t>(res.Get(0, "floodlines")); - ci->floodsecs = convertTo<int16_t>(res.Get(0, "floodsecs")); - ci->repeattimes = convertTo<int16_t>(res.Get(0, "repeattimes")); - - if (ci->c) - check_modes(ci->c); - } - catch (const SQLException &ex) - { - Log() << ex.GetReason(); - } - catch (const ConvertException &) { } -} - -static void NickInfoUpdate(const Anope::string &name, const SQLResult &res) -{ - NickAlias *na = findnick(name); - if (res.Rows() == 0) - { - delete na; - return; - } - - try - { - NickCore *nc = findcore(res.Get(0, "nick")); - if (!nc) - return; - if (!na) - na = new NickAlias(name, nc); - - na->last_quit = res.Get(0, "last_quit"); - na->last_realname = res.Get(0, "last_realname"); - na->last_usermask = res.Get(0, "last_usermask"); - na->last_realhost = res.Get(0, "last_realhost"); - na->time_registered = convertTo<time_t>(res.Get(0, "time_registered")); - na->last_seen = convertTo<time_t>(res.Get(0, "last_seen")); - na->ClearFlags(); - na->FromString(res.Get(0, "flags")); - - if (na->nc != nc) - { - std::list<NickAlias *>::iterator it = std::find(na->nc->aliases.begin(), na->nc->aliases.end(), na); - if (it != na->nc->aliases.end()) - na->nc->aliases.erase(it); - - na->nc = nc; - na->nc->aliases.push_back(na); - } - } - catch (const SQLException &ex) - { - Log() << ex.GetReason(); - } - catch (const ConvertException &) { } -} - -static void NickCoreUpdate(const Anope::string &name, const SQLResult &res) -{ - NickCore *nc = findcore(name); - if (res.Rows() == 0) - { - delete nc; - return; - } - - try - { - if (!nc) - nc = new NickCore(name); - - nc->pass = res.Get(0, "pass"); - nc->email = res.Get(0, "email"); - nc->greet = res.Get(0, "greet"); - nc->ClearFlags(); - nc->FromString(res.Get(0, "flags")); - nc->language = res.Get(0, "language"); - } - catch (const SQLException &ex) - { - Log() << ex.GetReason(); - } - catch (const ConvertException &) { } -} - class MySQLLiveModule : public Module { service_reference<SQLProvider, Base> SQL; @@ -201,7 +83,23 @@ class MySQLLiveModule : public Module SQLQuery query("SELECT * FROM `ChannelInfo` WHERE `name` = @name@"); query.setValue("name", chname); SQLResult res = this->RunQuery(query); - ChanInfoUpdate(chname, res); + + if (res.Rows() == 0) + { + delete cs_findchan(chname); + return; + } + + SerializeType *sb = SerializeType::Find("ChannelInfo"); + if (sb == NULL) + return; + + Serializable::serialized_data data; + const std::map<Anope::string, Anope::string> &row = res.Row(0); + for (std::map<Anope::string, Anope::string>::const_iterator rit = row.begin(), rit_end = row.end(); rit != rit_end; ++rit) + data[rit->first] << rit->second; + + sb->Create(data); } catch (const SQLException &ex) { @@ -219,7 +117,23 @@ class MySQLLiveModule : public Module SQLQuery query("SELECT * FROM `NickAlias` WHERE `nick` = @nick@"); query.setValue("nick", nick); SQLResult res = this->RunQuery(query); - NickInfoUpdate(nick, res); + + if (res.Rows() == 0) + { + delete findnick(nick); + return; + } + + SerializeType *sb = SerializeType::Find("NickAlias"); + if (sb == NULL) + return; + + Serializable::serialized_data data; + const std::map<Anope::string, Anope::string> &row = res.Row(0); + for (std::map<Anope::string, Anope::string>::const_iterator rit = row.begin(), rit_end = row.end(); rit != rit_end; ++rit) + data[rit->first] << rit->second; + + sb->Create(data); } catch (const SQLException &ex) { @@ -237,7 +151,23 @@ class MySQLLiveModule : public Module SQLQuery query("SELECT * FROM `NickCore` WHERE `display` = @display@"); query.setValue("display", nick); SQLResult res = this->RunQuery(query); - NickCoreUpdate(nick, res); + + if (res.Rows() == 0) + { + delete findcore(nick); + return; + } + + SerializeType *sb = SerializeType::Find("NickCore"); + if (sb == NULL) + return; + + Serializable::serialized_data data; + const std::map<Anope::string, Anope::string> &row = res.Row(0); + for (std::map<Anope::string, Anope::string>::const_iterator rit = row.begin(), rit_end = row.end(); rit != rit_end; ++rit) + data[rit->first] << rit->second; + + sb->Create(data); } catch (const SQLException &ex) { diff --git a/modules/database/db_sql_live_write.cpp b/modules/database/db_sql_live_write.cpp index 6bb9b93d5..a97f57359 100644 --- a/modules/database/db_sql_live_write.cpp +++ b/modules/database/db_sql_live_write.cpp @@ -85,9 +85,15 @@ class DBMySQL : public Module void Delete(const Anope::string &table, const Serializable::serialized_data &data) { - Anope::string query_text = "DELETE FROM `" + table + "` WHERE "; + Anope::string query_text = "DELETE FROM `" + table + "` WHERE ", arg_text; for (Serializable::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it) - query_text += "`" + it->first + "` = @" + it->first + "@"; + { + if (!arg_text.empty()) + arg_text += " AND "; + arg_text += "`" + it->first + "` = @" + it->first + "@"; + } + + query_text += arg_text; SQLQuery query(query_text); for (Serializable::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it) diff --git a/src/nickalias.cpp b/src/nickalias.cpp index 24d3d6e2b..43a35d448 100644 --- a/src/nickalias.cpp +++ b/src/nickalias.cpp @@ -139,7 +139,24 @@ void NickAlias::unserialize(serialized_data &data) if (core == NULL) return; - NickAlias *na = new NickAlias(data["nick"].astr(), core); + NickAlias *na = findnick(data["nick"].astr()); + if (na == NULL) + na = new NickAlias(data["nick"].astr(), core); + else if (na->nc != core) + { + std::list<NickAlias *>::iterator it = std::find(na->nc->aliases.begin(), na->nc->aliases.end(), na); + if (it != na->nc->aliases.end()) + na->nc->aliases.erase(it); + + if (na->nc->aliases.empty()) + delete na->nc; + else if (na->nick.equals_ci(na->nc->display)) + change_core_display(na->nc); + + na->nc = core; + na->nc->aliases.push_back(na); + } + data["last_quit"] >> na->last_quit; data["last_realname"] >> na->last_realname; data["last_usermask"] >> na->last_usermask; diff --git a/src/nickcore.cpp b/src/nickcore.cpp index 836ffdda4..370d6b705 100644 --- a/src/nickcore.cpp +++ b/src/nickcore.cpp @@ -73,7 +73,9 @@ Serializable::serialized_data NickCore::serialize() void NickCore::unserialize(serialized_data &data) { - NickCore *nc = new NickCore(data["display"].astr()); + NickCore *nc = findcore(data["display"].astr()); + if (nc == NULL) + nc = new NickCore(data["display"].astr()); data["pass"] >> nc->pass; data["email"] >> nc->email; data["greet"] >> nc->greet; @@ -83,6 +85,7 @@ void NickCore::unserialize(serialized_data &data) Anope::string buf; data["access"] >> buf; spacesepstream sep(buf); + nc->access.clear(); while (sep.GetToken(buf)) nc->access.push_back(buf); } @@ -90,6 +93,7 @@ void NickCore::unserialize(serialized_data &data) Anope::string buf; data["cert"] >> buf; spacesepstream sep(buf); + nc->cert.clear(); while (sep.GetToken(buf)) nc->cert.push_back(buf); } @@ -98,6 +102,7 @@ void NickCore::unserialize(serialized_data &data) Anope::string buf; data["memoignores"] >> buf; spacesepstream sep(buf); + nc->memos.ignores.clear(); while (sep.GetToken(buf)) nc->memos.ignores.push_back(buf); } diff --git a/src/regchannel.cpp b/src/regchannel.cpp index 33131f059..b8cfbd4ba 100644 --- a/src/regchannel.cpp +++ b/src/regchannel.cpp @@ -355,11 +355,24 @@ Serializable::serialized_data ChannelInfo::serialize() void ChannelInfo::unserialize(serialized_data &data) { - ChannelInfo *ci = new ChannelInfo(data["name"].astr()); + ChannelInfo *ci = cs_findchan(data["name"].astr()); + if (ci == NULL) + new ChannelInfo(data["name"].astr()); + if (data.count("founder") > 0) + { + if (ci->founder) + ci->founder->channelcount--; ci->founder = findcore(data["founder"].astr()); + if (ci->founder) + ci->founder->channelcount++; + } if (data.count("successor") > 0) + { ci->successor = findcore(data["successor"].astr()); + if (ci->founder && ci->founder == ci->successor) + ci->successor = NULL; + } data["description"] >> ci->desc; data["time_registered"] >> ci->time_registered; data["last_used"] >> ci->last_used; @@ -375,7 +388,13 @@ void ChannelInfo::unserialize(serialized_data &data) ci->levels[v[i]] = convertTo<int16_t>(v[i + 1]); } if (data.count("bi") > 0) + { + if (ci->bi) + ci->bi->chancount--; ci->bi = findbot(data["bi"].astr()); + if (ci->bi) + ci->bi->chancount++; + } data["capsmin"] >> ci->capsmin; data["capspercent"] >> ci->capspercent; data["floodlines"] >> ci->floodlines; @@ -386,6 +405,7 @@ void ChannelInfo::unserialize(serialized_data &data) Anope::string buf; data["memoignores"] >> buf; spacesepstream sep(buf); + ci->memos.ignores.clear(); while (sep.GetToken(buf)) ci->memos.ignores.push_back(buf); } |