From: Gary K. <amc...@us...> - 2005-01-13 08:25:57
|
Update of /cvsroot/gaim-bnet/gaim-bnet/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4426/src Modified Files: buddy.c buddy.h chat.c conn.c conn.h proto.c proto.h Log Message: Adding Dario's most recent patch, ran into some issues with the last one, hopefully this cleans it up otherwise I'll start hacking it.. Index: buddy.h =================================================================== RCS file: /cvsroot/gaim-bnet/gaim-bnet/src/buddy.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** buddy.h 9 Jan 2005 09:59:59 -0000 1.6 --- buddy.h 13 Jan 2005 08:25:39 -0000 1.7 *************** *** 39,45 **** struct _BNetBuddy { gchar* name; - gboolean online; gchar* flags; gchar* location; }; --- 39,45 ---- struct _BNetBuddy { gchar* name; gchar* flags; gchar* location; + gint fl_position; }; *************** *** 60,64 **** void bnet_buddy_free(BNetBuddy *buddy); void bnet_buddy_add(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group); ! void bnet_buddy_add_default(BNetConn *conn, const gchar *name); void bnet_buddy_remove(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group); void bnet_buddy_emblems(GaimBuddy *buddy, char **se, char **sw, char **nw, char **ne); --- 60,64 ---- void bnet_buddy_free(BNetBuddy *buddy); void bnet_buddy_add(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group); ! BNetBuddy *bnet_buddy_add_default(BNetConn *conn, const gchar *name); void bnet_buddy_remove(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group); void bnet_buddy_emblems(GaimBuddy *buddy, char **se, char **sw, char **nw, char **ne); Index: proto.h =================================================================== RCS file: /cvsroot/gaim-bnet/gaim-bnet/src/proto.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** proto.h 12 Jan 2005 23:27:48 -0000 1.6 --- proto.h 13 Jan 2005 08:25:39 -0000 1.7 *************** *** 29,33 **** typedef struct _BNetProtoProcInfo BNetProtoProcInfo; typedef struct _BNetWhispFromProcInfo BNetWhispFromProcInfo; ! //typedef struct _BNetInfoProcInfo BNetInfoProcInfo; #include "conn.h" --- 29,33 ---- typedef struct _BNetProtoProcInfo BNetProtoProcInfo; typedef struct _BNetWhispFromProcInfo BNetWhispFromProcInfo; ! typedef struct _BNetInfoProcInfo BNetInfoProcInfo; #include "conn.h" *************** *** 48,51 **** --- 48,58 ---- }; + typedef void (*BNetInfoProcFunc)(BNetConn *, GList *args); + + struct _BNetInfoProcInfo { + const gchar* model; + BNetInfoProcFunc func; + }; + #ifdef __cplusplus extern "C" { Index: buddy.c =================================================================== RCS file: /cvsroot/gaim-bnet/gaim-bnet/src/buddy.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** buddy.c 12 Jan 2005 23:27:47 -0000 1.8 --- buddy.c 13 Jan 2005 08:25:39 -0000 1.9 *************** *** 111,114 **** --- 111,117 ---- buddy->name = g_strdup(name); + buddy->flags = 0; + buddy->location = 0; + buddy->fl_position = -1; return buddy; *************** *** 133,149 **** const gchar *name; name = gaim_normalize(gc->account, buddy->name); if(!g_hash_table_lookup(conn->buddies, name)) g_hash_table_insert(conn->buddies, (gchar *)name, b); } ! void bnet_buddy_add_default(BNetConn *conn, const gchar *name) { GaimBuddy *buddy; GaimGroup *group; ! g_return_if_fail(conn); ! g_return_if_fail(name); buddy = gaim_buddy_new(conn->account, name, NULL); --- 136,159 ---- const gchar *name; + gaim_debug_info("bnet", "bnet_buddy_add\n"); + name = gaim_normalize(gc->account, buddy->name); if(!g_hash_table_lookup(conn->buddies, name)) g_hash_table_insert(conn->buddies, (gchar *)name, b); + + bnet_conn_request_friends_list(conn); } ! BNetBuddy * bnet_buddy_add_default(BNetConn *conn, const gchar *name) { GaimBuddy *buddy; GaimGroup *group; + BNetBuddy *b; ! gaim_debug_info("bnet", "bnet_buddy_add_default\n"); ! ! g_return_val_if_fail(conn, NULL); ! g_return_val_if_fail(name, NULL); buddy = gaim_buddy_new(conn->account, name, NULL); *************** *** 155,161 **** } - /* shouldn't we be adding the buddy to the hash table here? */ - gaim_blist_add_buddy(buddy, NULL, group, NULL); } --- 165,176 ---- } gaim_blist_add_buddy(buddy, NULL, group, NULL); + + /* We must add it also to our buddy list... */ + + b = bnet_buddy_new(name); + g_hash_table_insert(conn->buddies, b->name, b); + + return b; } *************** *** 164,168 **** --- 179,187 ---- BNetConn *conn = BNET_CONN(gc->proto_data); + gaim_debug_info("bnet", "bnet_buddy_remove\n"); + g_hash_table_remove(conn->buddies, buddy->name); + + bnet_conn_send(conn, "/friends remove %s\n", buddy->name); } Index: proto.c =================================================================== RCS file: /cvsroot/gaim-bnet/gaim-bnet/src/proto.c,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** proto.c 12 Jan 2005 23:27:47 -0000 1.11 --- proto.c 13 Jan 2005 08:25:39 -0000 1.12 *************** *** 46,80 **** static void ! bnet_list_destroy_all(gpointer data, gpointer user_data) { ! free(data); ! } ! ! /****************************************************************************** ! * Whispear From Processing ! *****************************************************************************/ ! static void ! bnet_proto_whispf_login(BNetConn *conn, const gchar *nick, GList *args) { ! GaimConnection *gc; ! gc = gaim_account_get_connection(conn->account); ! serv_got_update(gc, nick, TRUE, 0, 0, 0, 0); ! } ! static void ! bnet_proto_whispf_join(BNetConn *conn, const gchar *nick, GList *args) { ! /* Nothing to do here */ } static void ! bnet_proto_whispf_logout(BNetConn *conn, const gchar *nick, GList *args) { ! GaimConnection *gc; ! gc = gaim_account_get_connection(conn->account); ! serv_got_update(gc, nick, FALSE, 0, 0, 0, 0); } static gboolean ! bnet_proto_compare_whispf(BNetConn *conn, const gchar* model, const gchar **whisp, ! GList **args) { ! const gchar *nick = whisp[0]; ! const gchar *msg = whisp[1]; const gchar *w, *k; --- 46,69 ---- static void ! bnet_hash_check_buddy(gpointer key, gpointer value, gpointer user_data) { ! BNetConn *conn = BNET_CONN(user_data); ! BNetBuddy *buddy = BNET_BUDDY(value); ! if (buddy->fl_position == -1) { ! bnet_conn_send(conn, "/friends add %s\n", buddy->name); ! buddy->fl_position = 0; ! } } static void ! bnet_list_destroy_all(gpointer data, gpointer user_data) { ! free(data); } static gboolean ! bnet_proto_model_compare(BNetConn *conn, const gchar* model, ! const gchar **msginfo, GList **args) { ! const gchar *nick = msginfo[0]; ! const gchar *msg = msginfo[1]; const gchar *w, *k; *************** *** 126,131 **** /* Maybe err == TRUE here */ ! } ! else { if (*w != *k) { err = TRUE; --- 115,119 ---- /* Maybe err == TRUE here */ ! } else { if (*w != *k) { err = TRUE; *************** *** 148,158 **** } static BNetWhispFromProcInfo wfpi[] = { ! { "Your friend $n has entered Battle.net.", bnet_proto_whispf_login }, ! { "Your friend $n has entered a $x game called $x", bnet_proto_whispf_join }, ! { "Your friend $n has exited Battle.net.", bnet_proto_whispf_logout } }; ! #define PROTO_WHISP_MSG_N (sizeof(wfpi) / sizeof(wfpi[0])) /****************************************************************************** --- 136,297 ---- } + /****************************************************************************** + * Whispear From Processing + *****************************************************************************/ + static void + bnet_proto_whispf_login(BNetConn *conn, const gchar *nick, GList *args) { + GaimConnection *gc; + + gaim_debug_info("bnet", "bnet_proto_whispf_login\n"); + + gc = gaim_account_get_connection(conn->account); + serv_got_update(gc, nick, TRUE, 0, 0, 0, 0); + } + + static void + bnet_proto_whispf_join(BNetConn *conn, const gchar *nick, GList *args) { + /* Nothing to do here */ + gaim_debug_info("bnet", "bnet_proto_whispf_join\n"); + } + + static void + bnet_proto_whispf_logout(BNetConn *conn, const gchar *nick, GList *args) { + GaimConnection *gc; + + gaim_debug_info("bnet", "bnet_proto_whispf_logout\n"); + + gc = gaim_account_get_connection(conn->account); + serv_got_update(gc, nick, FALSE, 0, 0, 0, 0); + } + static BNetWhispFromProcInfo wfpi[] = { ! { "Your friend $n has entered Battle.net.", bnet_proto_whispf_login }, ! { "Your friend $n entered a $x game called $x.", bnet_proto_whispf_join }, ! { "Your friend $n has exited Battle.net.", bnet_proto_whispf_logout } }; ! #define PROTO_WHISP_MSGS_N (sizeof(wfpi) / sizeof(wfpi[0])) ! ! /****************************************************************************** ! * Info Processing ! *****************************************************************************/ ! static void ! bnet_proto_info_welcome(BNetConn *conn, GList *args) { ! gaim_debug_info("bnet", "bnet_proto_info_welcome\n"); ! } ! ! static void ! bnet_proto_info_fl_online(BNetConn *conn, GList *args) { ! GaimConnection *gc; ! BNetBuddy *b; ! GList *w = args; ! ! gchar *n, *nick; ! gchar *using, *chan; ! ! gaim_debug_info("bnet", "bnet_proto_info_fl_online\n"); ! ! n = w->data; ! w = g_list_next(w); ! nick = w->data; ! w = g_list_next(w); ! using = w->data; ! w = g_list_next(w); ! chan = w->data; ! ! b = g_hash_table_lookup(conn->buddies, nick); ! if (!b) ! b = bnet_buddy_add_default(conn, nick); ! ! sscanf(n, "%u", &b->fl_position); ! ! gc = gaim_account_get_connection(conn->account); ! serv_got_update(gc, nick, TRUE, 0, 0, 0, 0); ! } ! ! static void ! bnet_proto_info_fl_offline(BNetConn *conn, GList *args) { ! GaimConnection *gc; ! BNetBuddy *b; ! GList *w = args; ! ! gchar *n, *nick; ! ! gaim_debug_info("bnet", "bnet_proto_info_fl_offline\n"); ! ! n = w->data; ! w = g_list_next(w); ! nick = w->data; ! ! b = g_hash_table_lookup(conn->buddies, nick); ! if (!b) ! b = bnet_buddy_add_default(conn, nick); ! ! sscanf(n, "%u", &b->fl_position); ! ! gc = gaim_account_get_connection(conn->account); ! serv_got_update(gc, nick, FALSE, 0, 0, 0, 0); ! } ! ! static void ! bnet_proto_info_where(BNetConn *conn, GList *args) { ! GaimConnection *gc; ! GList *w = args; ! gchar *nick, *using, *chan; ! ! gaim_debug_info("bnet", "bnet_proto_info_where\n"); ! ! nick = w->data; ! w = g_list_next(w); ! using = w->data; ! w = g_list_next(w); ! chan = w->data; ! ! /* We receive this message in reply to a /WHERE or /WHOIS command ! * We can assume it as a confirmation that user is online ! */ ! ! gc = gaim_account_get_connection(conn->account); ! serv_got_update(gc, nick, TRUE, 0, 0, 0, 0); ! } ! ! static void ! bnet_proto_info_whoami(BNetConn *conn, GList *args) { ! GList *w = args; ! gchar *nick, *using, *chan; ! ! gaim_debug_info("bnet", "bnet_proto_info_whoami\n"); ! ! nick = w->data; ! w = g_list_next(w); ! using = w->data; ! w = g_list_next(w); ! chan = w->data; ! ! if (strcmp(nick, conn->nick)) { ! g_free(conn->nick); ! conn->nick = g_strdup(nick); ! } ! ! /* We receive all the server friend list! ! * We must compare our buddy list with it and, if those differ, update ! * the server one. ! */ ! ! g_hash_table_foreach(conn->buddies, bnet_hash_check_buddy, conn); ! ! conn->fl_listing = FALSE; ! } ! ! static BNetInfoProcInfo ipi[] = { ! { "Welcome to Battle.net!", bnet_proto_info_welcome }, ! { "$x: $x, (mutual) using $x in the channel $x.", bnet_proto_info_fl_online }, ! { "$x: $x, (mutual) using $x in the game $x.", bnet_proto_info_fl_online }, ! { "$x: $x, offline", bnet_proto_info_fl_offline }, ! { "$x is using $x in the channel $x.", bnet_proto_info_where }, ! { "You are $x, using $x in the channel $x.", bnet_proto_info_whoami } ! }; ! ! #define PROTO_INFO_MSGS_N (sizeof(ipi) / sizeof(ipi[0])) /****************************************************************************** *************** *** 166,171 **** u = BNET_USER(g_hash_table_lookup(conn->users, nick)); if (!u) { ! u = bnet_user_new(nick, game, flags); g_hash_table_insert(conn->users, u->nick, u); } --- 305,316 ---- u = BNET_USER(g_hash_table_lookup(conn->users, nick)); if (!u) { ! /* We can assume strlen(game) always > 2 because its format is ! * "[game_name]"... I hope :) ! */ ! gchar *game_snip = g_strdup(game); ! game_snip[strlen(game)-1] = 0; ! u = bnet_user_new(nick, game_snip+1, flags); g_hash_table_insert(conn->users, u->nick, u); + g_free(game_snip); } *************** *** 173,177 **** if (convo) { gaim_conv_chat_add_user(GAIM_CONV_CHAT(convo), ! nick, game, 0, new_arrival); } else { gaim_debug_info("bnet", "JOIN/USER %s\n", nick); --- 318,322 ---- if (convo) { gaim_conv_chat_add_user(GAIM_CONV_CHAT(convo), ! u->nick, u->game, 0, new_arrival); } else { gaim_debug_info("bnet", "JOIN/USER %s\n", nick); *************** *** 213,217 **** const gchar* msg = args[2]; ! const gchar *whisp[2] = { nick, msg }; GList *w_args; gint i; --- 358,362 ---- const gchar* msg = args[2]; ! const gchar *info[2] = { nick, msg }; GList *w_args; gint i; *************** *** 219,224 **** gaim_debug_info("bnet", "WHISP FROM %s - %s\n", nick, msg); ! for (i=0; i < PROTO_WHISP_MSG_N; i++) { ! if (bnet_proto_compare_whispf(conn, wfpi[i].model, (const gchar**)whisp, &w_args)) { wfpi[i].func(conn, nick, w_args); --- 364,369 ---- gaim_debug_info("bnet", "WHISP FROM %s - %s\n", nick, msg); ! for (i=0; i < PROTO_WHISP_MSGS_N; i++) { ! if (bnet_proto_model_compare(conn, wfpi[i].model, (const gchar**)info, &w_args)) { wfpi[i].func(conn, nick, w_args); *************** *** 233,237 **** } ! if (i == PROTO_WHISP_MSG_N) { GaimConnection *gc; gc = gaim_account_get_connection(conn->account); --- 378,382 ---- } ! if (i == PROTO_WHISP_MSGS_N) { GaimConnection *gc; gc = gaim_account_get_connection(conn->account); *************** *** 291,342 **** static void bnet_proto_msg_info(BNetConn *conn, const gchar** args) { ! const gchar* info = args[0]; ! guint len = strlen(info); ! ! GaimConnection *gc; ! gchar *p; ! ! gaim_debug_info("bnet", "INFO %s\n", info); ! ! gc = gaim_account_get_connection(conn->account); ! ! if (len > 4 && ! ((info[1] == ':' && IS_NUM(info[0])) || ! (info[2] == ':' && IS_NUM(info[0]) && IS_NUM(info[1])))) { ! BNetBuddy *b; ! gchar *nick, *state; ! ! p = strchr(info,' '); ! ! sscanf(p, " %a[^,], %as", &nick, &state); ! ! b = g_hash_table_lookup(conn->buddies, nick); ! if (!b) ! bnet_buddy_add_default(conn, nick); ! if (!strcmp(state,"offline")) ! serv_got_update(gc, nick, FALSE, 0, 0, 0, 0); ! else ! serv_got_update(gc, nick, TRUE, 0, 0, 0, 0); ! free(nick); ! free(state); ! } else if ((p = strchr(info, ' ')) && ! (strlen(p) > 10) && ! !memcmp(p, " is using ", 10)) { ! /* We receive this message in reply to a /WHERE or /WHOIS command ! * We can assume it as a confirmation that user is online ! */ ! gchar* nick = (gchar*)malloc(p-info+1); ! memcpy(nick,info,p-info); ! nick[p-info] = 0; ! gaim_debug_info("bnet", "ONLINE FROM /WHERE - \"%s\"\n", nick); ! serv_got_update(gc, nick, TRUE, 0, 0, 0, 0); ! free(nick); ! } ! else { ! gaim_debug_info("bnet", "UNKNOWN INFO\n"); } } --- 436,457 ---- static void bnet_proto_msg_info(BNetConn *conn, const gchar** args) { ! const gchar *info[2] = { NULL, args[0] }; ! GList *w_args; ! gint i; ! gaim_debug_info("bnet", "INFO %s\n", args[0]); ! for (i=0; i < PROTO_INFO_MSGS_N; i++) { ! if (bnet_proto_model_compare(conn, ipi[i].model, (const gchar**)info, ! &w_args)) { ! ipi[i].func(conn, w_args); ! if (w_args) { ! g_list_foreach(w_args, bnet_list_destroy_all, NULL); ! g_list_free(w_args); ! } ! break; ! } } } *************** *** 424,428 **** gchar* args[PROTO_MAX_ARGS]; ! for (i=0,l=0,b=0,e=strlen(msg); i<PROTO_MAX_ARGS; i++,l++,b=l) { if (msg[l]=='"') for (b=++l; l<e && msg[l]!='"'; l++); --- 539,543 ---- gchar* args[PROTO_MAX_ARGS]; ! for (i=0,l=0,b=0,e=strlen(msg); i < PROTO_MAX_ARGS; i++,l++,b=l) { if (msg[l]=='"') for (b=++l; l<e && msg[l]!='"'; l++); Index: chat.c =================================================================== RCS file: /cvsroot/gaim-bnet/gaim-bnet/src/chat.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** chat.c 11 Jan 2005 21:32:54 -0000 1.3 --- chat.c 13 Jan 2005 08:25:39 -0000 1.4 *************** *** 56,63 **** struct proto_chat_entry *pce; - gaim_debug_info("bnet", "bnet_chat_info\n"); - g_return_val_if_fail(gc, NULL); pce = g_new0(struct proto_chat_entry, 1); pce->label = _("_Channel:"); --- 56,63 ---- struct proto_chat_entry *pce; g_return_val_if_fail(gc, NULL); + gaim_debug_info("bnet", "bnet_chat_info\n"); + pce = g_new0(struct proto_chat_entry, 1); pce->label = _("_Channel:"); Index: conn.h =================================================================== RCS file: /cvsroot/gaim-bnet/gaim-bnet/src/conn.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** conn.h 9 Jan 2005 03:35:24 -0000 1.3 --- conn.h 13 Jan 2005 08:25:39 -0000 1.4 *************** *** 50,54 **** guint inbuf_len; guint inbuf_used; - GSList *exp; gchar *nick; --- 50,53 ---- *************** *** 59,62 **** --- 58,63 ---- GHashTable *buddies; + + gboolean fl_listing; }; Index: conn.c =================================================================== RCS file: /cvsroot/gaim-bnet/gaim-bnet/src/conn.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** conn.c 10 Jan 2005 02:09:13 -0000 1.6 --- conn.c 13 Jan 2005 08:25:39 -0000 1.7 *************** *** 70,74 **** g_return_if_fail(conn); ! bnet_conn_send(conn, "/f l\n"); } --- 70,80 ---- g_return_if_fail(conn); ! if (!conn->fl_listing) { ! bnet_conn_send(conn, "/friends list\n"); ! /* This is needed to check the end of list */ ! bnet_conn_send(conn, "/whoami\n"); ! ! conn->fl_listing = TRUE; ! } } *************** *** 228,231 **** --- 234,238 ---- conn->users = bnet_users_new(); conn->buddies = bnet_buddies_new(); + conn->fl_listing = FALSE; bnet_conn_update_progress(conn, BNET_CS_SOCK); |