soc.2009.transport: c2027ef2: support for NickServ on IRC
hanzz at soc.pidgin.im
hanzz at soc.pidgin.im
Tue Jul 14 13:05:49 EDT 2009
-----------------------------------------------------------------
Revision: c2027ef2f1afa212548ba9cfd30f85a1cca0d297
Ancestor: 3d70368154675b7ed891b78a3f32dc901cb54121
Author: hanzz at soc.pidgin.im
Date: 2009-07-14T06:19:01
Branch: im.pidgin.soc.2009.transport
URL: http://d.pidgin.im/viewmtn/revision/info/c2027ef2f1afa212548ba9cfd30f85a1cca0d297
Modified files:
protocols/abstractprotocol.h protocols/irc.cpp
protocols/irc.h user.cpp
ChangeLog:
support for NickServ on IRC
-------------- next part --------------
============================================================
--- protocols/abstractprotocol.h 100bcd8f7e0c099503fa2ce39983778594869ff0
+++ protocols/abstractprotocol.h 9df065a02dc9dc29df749a7e80a3d9fe51d60069
@@ -85,6 +85,17 @@ class AbstractProtocol
* Returns true if temporary accounts for MUC are allows (this is useful for IRC, if you want to connect more network from one account)
*/
virtual bool tempAccountsAllowed() { return false; }
+
+ // SIGNALS
+
+ /*
+ * Called when new user is created
+ */
+ virtual void onUserCreated(User *user) { }
+ /*
+ * Called when user gets connected
+ */
+ virtual void onConnected(User *user) { }
};
#endif
============================================================
--- protocols/irc.cpp 2b5e1ef5f11c60b7fb6d53ebe30d21559b3a2bf2
+++ protocols/irc.cpp c88d74f16c37e1318e0ef2ac7f309f584011aef0
@@ -52,7 +52,7 @@ Tag *IRCProtocol::getVCardTag(User *user
}
Tag *IRCProtocol::getVCardTag(User *user, GList *vcardEntries) {
- PurpleNotifyUserInfoEntry *vcardEntry;
+// PurpleNotifyUserInfoEntry *vcardEntry;
Tag *vcard = new Tag( "vCard" );
vcard->addAttribute( "xmlns", "vcard-temp" );
@@ -60,3 +60,22 @@ Tag *IRCProtocol::getVCardTag(User *user
return vcard;
}
+void IRCProtocol::onUserCreated(User *user) {
+ PurpleValue *value;
+ if ( (value = user->getSetting("nickserv")) == NULL ) {
+ m_main->sql()->addSetting(user->userKey(), "nickserv", "", PURPLE_TYPE_STRING);
+ value = purple_value_new(PURPLE_TYPE_STRING);
+ purple_value_set_string(value, "");
+ g_hash_table_replace(user->settings(), g_strdup("nickserv"), value);
+ }
+}
+
+void IRCProtocol::onConnected(User *user) {
+ std::string nickserv(purple_value_get_string(user->getSetting("nickserv")));
+ if (!nickserv.empty()) {
+ Message msg(Message::Chat, JID("NickServ at server.cz"), "identify " + nickserv);
+ msg.setFrom(user->jid());
+ user->receivedMessage(msg);
+ }
+}
+
============================================================
--- protocols/irc.h 62b1faa991624cab024b0d4cea82efa6b19acb08
+++ protocols/irc.h c9bac8219ffc068ba28eac96322789d31980ce31
@@ -41,6 +41,11 @@ class IRCProtocol : AbstractProtocol
Tag *getVCardTag(User *user, GList *vcardEntries);
bool isMUC(User *user, const std::string &jid) { return jid.find("#") == 0 && jid.find("%") != std::string::npos; }
bool tempAccountsAllowed() { return true; }
+
+ // SIGNALS
+
+ void onUserCreated(User *user);
+ void onConnected(User *user);
private:
GlooxMessageHandler *m_main;
============================================================
--- user.cpp 9710394a6ae94f9feae64ad2271b5e3ed0386f7d
+++ user.cpp 9eea50cb678ec74a140b43bf212b9d04872c9d74
@@ -98,6 +98,9 @@ User::User(GlooxMessageHandler *parent,
purple_value_set_boolean(value, true);
g_hash_table_replace(m_settings, g_strdup("enable_chatstate"), value);
}
+
+ p->protocol()->onUserCreated(this);
+
}
bool User::syncCallback() {
@@ -919,6 +922,8 @@ void User::connected() {
void User::connected() {
m_connected = true;
m_reconnectCount = 0;
+ p->protocol()->onConnected(this);
+ // TODO: move me to IRCProtocol
for (std::list <Tag*>::iterator it = m_autoConnectRooms.begin(); it != m_autoConnectRooms.end() ; it++ ) {
Presence stanza((*it));
MUCHandler *muc = new MUCHandler(this, stanza.to().bare(), stanza.from().full());
More information about the Commits
mailing list