summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorDukePyrolator <DukePyrolator@anope.org>2013-12-09 05:57:36 +0100
committerDukePyrolator <DukePyrolator@anope.org>2013-12-09 05:57:36 +0100
commit1b4d62e2bc8b146d19a683f0cef936ce706fef79 (patch)
tree2331193439b7bbdb8dd5a8c7c48589cddd94d076 /modules
parent43f608ff2bd08683c71ad089ebab68b324c8605e (diff)
irc2sql: fixed incorrect usercount for channels and servers after netsplit, fixed not displaying the channelmodes
Diffstat (limited to 'modules')
-rw-r--r--modules/stats/irc2sql/irc2sql.cpp53
-rw-r--r--modules/stats/irc2sql/irc2sql.h7
-rw-r--r--modules/stats/irc2sql/tables.cpp19
3 files changed, 66 insertions, 13 deletions
diff --git a/modules/stats/irc2sql/irc2sql.cpp b/modules/stats/irc2sql/irc2sql.cpp
index e47abf34a..2b3de59e7 100644
--- a/modules/stats/irc2sql/irc2sql.cpp
+++ b/modules/stats/irc2sql/irc2sql.cpp
@@ -29,6 +29,33 @@ void IRC2SQL::OnReload(Configuration::Conf *conf) anope_override
StatServ = BotInfo::Find(snick, true);
if (!StatServ)
throw ConfigException(Module::name + ": no bot named " + snick);
+
+ if (firstrun)
+ {
+ firstrun = false;
+
+ for (Anope::map<Server *>::const_iterator it = Servers::ByName.begin(); it != Servers::ByName.end(); ++it)
+ {
+ this->OnNewServer(it->second);
+ }
+
+ for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it)
+ {
+ this->OnChannelCreate(it->second);
+ }
+
+ for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
+ {
+ User *u = it->second;
+ bool exempt = false;
+ this->OnUserConnect(u, exempt);
+ for (User::ChanUserList::const_iterator cit = u->chans.begin(), cit_end = u->chans.end(); cit != cit_end; ++cit)
+ {
+ this->OnJoinChannel(u, cit->second->chan);
+ }
+ }
+ }
+
}
void IRC2SQL::OnNewServer(Server *server) anope_override
@@ -50,7 +77,8 @@ void IRC2SQL::OnServerQuit(Server *server) anope_override
return;
query = "UPDATE `" + prefix + "server` "
- "SET currentusers = 0, online = 'N', split_time = now()";
+ "SET currentusers = 0, online = 'N', split_time = now() "
+ "WHERE name = @name@";
query.SetValue("name", server->GetName());
this->RunQuery(query);
}
@@ -83,7 +111,7 @@ void IRC2SQL::OnUserConnect(User *u, bool &exempt) anope_override
query.SetValue("oper", u->HasMode("OPER") ? "Y" : "N");
this->RunQuery(query);
- if (ctcpuser && (Me->IsSynced() || ctcpeob))
+ if (ctcpuser && (Me->IsSynced() || ctcpeob) && u->server != Me)
IRCD->SendPrivmsg(StatServ, u->GetUID(), "\1VERSION\1");
}
@@ -187,10 +215,31 @@ void IRC2SQL::OnJoinChannel(User *u, Channel *c) anope_override
this->RunQuery(query);
}
+EventReturn IRC2SQL::OnChannelModeSet(Channel *c, MessageSource &setter, ChannelMode *mode, const Anope::string &param) anope_override
+{
+ query = "UPDATE `" + prefix + "chan` SET modes=@modes@ WHERE channel=@channel@";
+ query.SetValue("channel", c->name);
+ query.SetValue("modes", c->GetModes(true,true));
+ this->RunQuery(query);
+ return EVENT_CONTINUE;
+}
+
+EventReturn IRC2SQL::OnChannelModeUnset(Channel *c, MessageSource &setter, ChannelMode *mode, const Anope::string &param) anope_override
+{
+ this->OnChannelModeSet(c, setter, mode, param);
+ return EVENT_CONTINUE;
+}
+
void IRC2SQL::OnLeaveChannel(User *u, Channel *c) anope_override
{
if (quitting)
return;
+ /*
+ * user is quitting, we already received a OnUserQuit()
+ * at this point the user is already removed from SQL and all channels
+ */
+ if (u->Quitting());
+ return;
query = "CALL " + prefix + "PartUser(@nick@,@channel@)";
query.SetValue("nick", u->nick);
diff --git a/modules/stats/irc2sql/irc2sql.h b/modules/stats/irc2sql/irc2sql.h
index d2fcd7aca..b5fc8c37f 100644
--- a/modules/stats/irc2sql/irc2sql.h
+++ b/modules/stats/irc2sql/irc2sql.h
@@ -26,7 +26,7 @@ class IRC2SQL : public Module
SQL::Query query;
std::vector<Anope::string> TableList, ProcedureList, EventList;
Anope::string prefix, GeoIPDB;
- bool quitting, introduced_myself, UseGeoIP, ctcpuser, ctcpeob;
+ bool quitting, introduced_myself, UseGeoIP, ctcpuser, ctcpeob, firstrun;
BotInfo *StatServ;
PrimitiveExtensibleItem<bool> versionreply;
@@ -41,8 +41,9 @@ class IRC2SQL : public Module
public:
IRC2SQL(const Anope::string &modname, const Anope::string &creator) :
- Module(modname, creator, EXTRA | THIRD), sql("", ""), sqlinterface(this), versionreply(this, "CTCPVERSION")
+ Module(modname, creator, EXTRA | VENDOR), sql("", ""), sqlinterface(this), versionreply(this, "CTCPVERSION")
{
+ firstrun = true;
quitting = false;
introduced_myself = false;
}
@@ -65,6 +66,8 @@ class IRC2SQL : public Module
void OnChannelDelete(Channel *c) anope_override;
void OnLeaveChannel(User *u, Channel *c) anope_override;
void OnJoinChannel(User *u, Channel *c) anope_override;
+ EventReturn OnChannelModeSet(Channel *c, MessageSource &setter, ChannelMode *mode, const Anope::string &param) anope_override;
+ EventReturn OnChannelModeUnset(Channel *c, MessageSource &setter, ChannelMode *mode, const Anope::string &param) anope_override;
void OnTopicUpdated(Channel *c, const Anope::string &user, const Anope::string &topic) anope_override;
diff --git a/modules/stats/irc2sql/tables.cpp b/modules/stats/irc2sql/tables.cpp
index 8b339f406..5bbdf9252 100644
--- a/modules/stats/irc2sql/tables.cpp
+++ b/modules/stats/irc2sql/tables.cpp
@@ -4,15 +4,16 @@ void IRC2SQL::CheckTables()
{
Anope::string geoquery("");
- /* TODO: remove the DropTable commands when the table layout is done
- * perhaps we should drop/recreate some tables by default in case anope crashed
- * and was unable to clear the content (ison)
- * TRUNCATE could perform better for this?
- */
- SQL::Result r;
- r = this->sql->RunQuery(SQL::Query("DROP TABLE " + prefix + "user"));
- r = this->sql->RunQuery(SQL::Query("DROP TABLE " + prefix + "chan"));
- r = this->sql->RunQuery(SQL::Query("DROP TABLE " + prefix + "ison"));
+ if (firstrun)
+ {
+ /*
+ * drop/recreate some tables in case anope crashed
+ * and was unable to clear the content (ison)
+ */
+ this->sql->RunQuery(SQL::Query("DROP TABLE " + prefix + "user"));
+ this->sql->RunQuery(SQL::Query("DROP TABLE " + prefix + "chan"));
+ this->sql->RunQuery(SQL::Query("DROP TABLE " + prefix + "ison"));
+ }
this->GetTables();