changeset 17913:7e4e3f6582d2

Add MSIM_FAKE_SELF_ONLINE preprocessor definition (which I define) to fake one's own user account always being online. This is needed because msim does not allow adding yourself to your buddy list. (Other prpls do this too, btw.)
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Tue, 26 Jun 2007 05:53:52 +0000
parents d727fda5a8e1
children c5645d80aedc
files libpurple/protocols/myspace/CHANGES libpurple/protocols/myspace/myspace.c libpurple/protocols/myspace/myspace.h
diffstat 3 files changed, 34 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/myspace/CHANGES	Tue Jun 26 05:33:00 2007 +0000
+++ b/libpurple/protocols/myspace/CHANGES	Tue Jun 26 05:53:52 2007 +0000
@@ -2,6 +2,7 @@
 * Allow "Get Info" on all users, by uid or username
 * Fix crash when re-logging in, if login failed.
 * Show descriptive error message if login password is too long.
+* Fake self from being online, since can't add self to buddy list.
 * Update for Libpurple 2.0.2.
 
 2007-06-14 Jeff Connelly <jeff2@homing.pidgin.im> - 0.7
--- a/libpurple/protocols/myspace/myspace.c	Tue Jun 26 05:33:00 2007 +0000
+++ b/libpurple/protocols/myspace/myspace.c	Tue Jun 26 05:53:52 2007 +0000
@@ -1430,7 +1430,6 @@
     {
         return msim_login_challenge(session, msg);
     } else if (msim_msg_get(msg, "sesskey")) {
-
         purple_connection_update_progress(session->gc, _("Connected"), 3, 4);
 
         session->sesskey = msim_msg_get_integer(msg, "sesskey");
@@ -1440,9 +1439,19 @@
 		 * some of the time, but can vary. This is our own user ID. */
         session->userid = msim_msg_get_integer(msg, "userid");
 
-		/* TODO: fake our own userid being online */
 
         purple_connection_set_state(session->gc, PURPLE_CONNECTED);
+	
+
+		/* We now know are our own username, only after we're logged in..
+		 * which is weird, but happens because you login with your email
+		 * address and not username. Will be freed in msim_session_destroy(). */
+		session->username = msim_msg_get_string(msg, "uniquenick");
+
+#ifdef MSIM_FAKE_SELF_ONLINE
+		/* Fake our self coming online. */
+		purple_prpl_got_user_status(session->account, session->username, purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE), NULL);
+#endif
 
         return TRUE;
     } else if (msim_msg_get(msg, "bm"))  {
@@ -1736,7 +1745,17 @@
 						username, status_code);
 				purple_status_code = PURPLE_STATUS_AVAILABLE;
 	}
-	purple_prpl_got_user_status(session->account, username, purple_primitive_get_id_from_type(purple_status_code), NULL);
+
+#ifdef MSIM_FAKE_SELF_ONLINE
+	if (!strcmp(username, session->username) && purple_status_code == PURPLE_STATUS_OFFLINE)
+	{
+		/* Hack to ignore offline status notices on self. */
+	} else {
+#endif
+		purple_prpl_got_user_status(session->account, username, purple_primitive_get_id_from_type(purple_status_code), NULL);
+#ifdef MSIM_FAKE_SELF_ONLINE
+	}
+#endif
 
     g_strfreev(status_array);
 	g_free(status_str);
@@ -2230,6 +2249,8 @@
     session->fd = source; 
 
     gc->inpa = purple_input_add(source, PURPLE_INPUT_READ, msim_input_cb, gc);
+
+
 }
 
 /* Session methods */
@@ -2253,6 +2274,9 @@
     session->magic = MSIM_SESSION_STRUCT_MAGIC;
     session->account = acct;
     session->gc = purple_account_get_connection(acct);
+	session->sesskey = 0;
+	session->userid = 0;
+	session->username = NULL;
     session->fd = -1;
 
 	/* TODO: Remove. */
@@ -2283,6 +2307,7 @@
     session->magic = -1;
 
     g_free(session->rxbuf);
+	g_free(session->username);
 
 	/* TODO: Remove. */
 	g_hash_table_destroy(session->user_lookup_cb);
--- a/libpurple/protocols/myspace/myspace.h	Tue Jun 26 05:33:00 2007 +0000
+++ b/libpurple/protocols/myspace/myspace.h	Tue Jun 26 05:53:52 2007 +0000
@@ -69,6 +69,10 @@
 /* RC4 is in Libpurple 2.0.1, so define this. */
 #define MSIM_USE_PURPLE_RC4			
 
+/* Define to fake our own user account always being online. Needed
+ * because msim doesn't allow adding oneself to ones list. */
+#define MSIM_FAKE_SELF_ONLINE
+
 /* TODO: (one release after) when RC4 makes it into libpurple, use the PURPLE_VERSION_CHECK 
  * macro to conditionally compile. And then later, get rid of our own
  * RC4 code and only support libpurple with RC4. */
@@ -136,6 +140,7 @@
     PurpleConnection *gc;
     guint sesskey;                      /**< Session key from server */
     guint userid;                       /**< This user's numeric user ID */
+	gchar *username;					/**< This user's unique username */
     gint fd;                            /**< File descriptor to/from server */
 
 	/* TODO: Remove. */