From: Gary K. <amc...@us...> - 2005-01-17 01:57:01
|
Update of /cvsroot/gaim-bnet/gaim-bnet/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24966/src Modified Files: bnet.c buddy.c conn.c conn.h proto.c Log Message: Adding dario's latest patch... Index: bnet.c =================================================================== RCS file: /cvsroot/gaim-bnet/gaim-bnet/src/bnet.c,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** bnet.c 15 Jan 2005 02:27:01 -0000 1.31 --- bnet.c 17 Jan 2005 01:56:50 -0000 1.32 *************** *** 54,59 **** } ! static void bnet_send_raw_cmd(GaimPluginAction *action) ! { GaimConnection *gc = (GaimConnection*)action->context; --- 54,58 ---- } ! static void bnet_send_raw_cmd(GaimPluginAction *action) { GaimConnection *gc = (GaimConnection*)action->context; *************** *** 68,73 **** } ! static GList *bnet_actions(GaimPlugin *plugin, gpointer context) ! { //GaimConnection *gc = (GaimConnection*)context; GList *m = NULL; --- 67,71 ---- } ! static GList *bnet_actions(GaimPlugin *plugin, gpointer context) { //GaimConnection *gc = (GaimConnection*)context; GList *m = NULL; Index: buddy.c =================================================================== RCS file: /cvsroot/gaim-bnet/gaim-bnet/src/buddy.c,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** buddy.c 13 Jan 2005 22:43:25 -0000 1.11 --- buddy.c 17 Jan 2005 01:56:50 -0000 1.12 *************** *** 79,83 **** } - void bnet_user_info(GaimConnection *gc, const gchar *who) { --- 79,82 ---- *************** *** 160,164 **** const gchar *norm; ! gaim_debug_info("bnet", "bnet_buddy_add_default\n"); g_return_val_if_fail(conn, NULL); --- 159,163 ---- const gchar *norm; ! gaim_debug_info("bnet", "bnet_buddy_hard_lookup\n"); g_return_val_if_fail(conn, NULL); Index: proto.c =================================================================== RCS file: /cvsroot/gaim-bnet/gaim-bnet/src/proto.c,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** proto.c 13 Jan 2005 15:50:54 -0000 1.14 --- proto.c 17 Jan 2005 01:56:50 -0000 1.15 *************** *** 62,65 **** --- 62,74 ---- } + static void + bnet_stat_resolve(BNetGameStat *stat, const gchar *msg) + { + bzero(stat, sizeof(BNetGameStat)); + + gaim_debug_info("bnet", "msg(%s)\n", msg); + sscanf(msg, "%u-%u-%u", &stat->win, &stat->loss, &stat->disc); + } + static gboolean bnet_proto_model_compare(BNetConn *conn, const gchar* model, *************** *** 100,110 **** case 'x': if (!(p = strchr(k, '$'))) ! tt = strlen(k) - 1; else tt = p-k - 1; ! if (!(p = memmem(w, strlen(w), k+1, tt))) { ! err = TRUE; ! break; } --- 109,123 ---- case 'x': if (!(p = strchr(k, '$'))) ! tt = strlen(k+1); else tt = p-k - 1; ! if (!tt) ! p = (gchar *)(w + strlen(w)); ! else { ! if (!(p = memmem(w, strlen(w), k+1, tt))) { ! err = TRUE; ! break; ! } } *************** *** 282,285 **** --- 295,367 ---- } + static void + bnet_proto_info_record_bg(BNetConn *conn, GList *args) { + gchar *nick; + + gaim_debug_info("bnet", "bnet_proto_info_record_bg\n"); + + nick = args->data; + + if (conn->last_stat.nick) + g_free(conn->last_stat.nick); + + conn->last_stat.nick = g_strdup(nick); + } + + static void + bnet_proto_info_record_n(BNetConn *conn, GList *args) { + BNetGameStat *stat; + gchar *msg; + + gaim_debug_info("bnet", "bnet_proto_info_record_n\n"); + + msg = args->data; + + stat = &conn->last_stat.normal; + bnet_stat_resolve(stat, msg); + } + + static void + bnet_proto_info_record_l(BNetConn *conn, GList *args) { + BNetGameStat *normal; + BNetGameStat ladder; + gchar *msg; + gchar *notice; + + gaim_debug_info("bnet", "bnet_proto_info_record_l\n"); + + normal = &conn->last_stat.normal; + + msg = args->data; + bnet_stat_resolve(&ladder, msg); + + notice = g_strdup_printf("%s stats are:\n" + "Normal games:\n" + " %u win\n" + " %u loss\n" + " %u disc\n" + "Ladder games:\n" + " %u win\n" + " %u loss\n" + " %u disc\n", + conn->last_stat.nick, + normal->win, + normal->loss, + normal->disc, + ladder.win, + ladder.loss, + ladder.disc); + + gaim_notify_message(NULL, + GAIM_NOTIFY_MSG_INFO, + "Information", + "User stats", + notice, + NULL, + NULL); + + g_free(notice); + } + static BNetInfoProcInfo ipi[] = { { "Welcome to Battle.net!", bnet_proto_info_welcome }, *************** *** 290,294 **** { "$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 } }; --- 372,379 ---- { "$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 }, ! { "$x's record:", bnet_proto_info_record_bg }, ! { "Normal games: $x", bnet_proto_info_record_n }, ! { "Ladder games: $x", bnet_proto_info_record_l } }; *************** *** 544,547 **** --- 629,639 ---- gchar* args[PROTO_MAX_ARGS]; + if (!strcmp(msg, "You have been disconnected for flooding.")) { + GaimConnection *gc; + gc = gaim_account_get_connection(conn->account); + gaim_connection_error(gc, _("You have been disconnected for flooding")); + return; + } + for (i=0,l=0,b=0,e=strlen(msg); i < PROTO_MAX_ARGS; i++,l++,b=l) { if (msg[l]=='"') Index: conn.c =================================================================== RCS file: /cvsroot/gaim-bnet/gaim-bnet/src/conn.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** conn.c 13 Jan 2005 08:25:39 -0000 1.7 --- conn.c 17 Jan 2005 01:56:50 -0000 1.8 *************** *** 24,27 **** --- 24,30 ---- #include "proto.h" + #define BNET_FLOOD_CHARPERSEC 10 + #define BNET_FLOOD_MAX 50 + static const gchar *status[] = { N_("Connection to server"), *************** *** 33,56 **** }; ! gint bnet_conn_send(BNetConn *conn, const gchar *fmt, ...) { va_list args; ! gchar *buff; ! gint ret; ! g_return_val_if_fail(conn, -1); ! g_return_val_if_fail(fmt, -1); va_start(args, fmt); ! buff = g_strdup_vprintf(fmt, args); va_end(args); ! if (!buff) ! return -1; ! ret = send(conn->fd, buff, strlen(buff), 0); ! g_free(buff); ! return ret; } --- 36,101 ---- }; ! void bnet_conn_send(BNetConn *conn, const gchar *fmt, ...) { va_list args; ! gchar *buf; ! g_return_if_fail(conn); ! g_return_if_fail(fmt); va_start(args, fmt); ! buf = g_strdup_vprintf(fmt, args); va_end(args); ! if (buf) ! bnet_conn_out_queue_push(conn, buf); ! } ! void ! bnet_conn_out_queue_push(BNetConn *conn, gchar *msg) { ! conn->out_queue = g_list_append(conn->out_queue, msg); ! bnet_conn_out_queue_check(conn); ! } ! void ! bnet_conn_out_queue_check(BNetConn *conn) { ! GList *queue; ! gchar *cur; ! gint ret; ! ! queue = conn->out_queue; ! ! while (queue && conn->flood_sent + strlen(cur = queue->data) < BNET_FLOOD_MAX) { ! ret = send(conn->fd, cur, strlen(cur), 0); ! if (ret > 0) ! conn->flood_sent += ret; ! ! g_free(cur); ! queue = g_list_remove_link(queue, queue); ! } ! ! conn->out_queue = queue; ! ! if (conn->flood_sent && !conn->flood_timer) ! conn->flood_timer = gaim_timeout_add(1000, bnet_conn_out_queue_to, conn); ! } ! ! gboolean ! bnet_conn_out_queue_to(gpointer p) { ! BNetConn *conn = BNET_CONN(p); ! ! if (conn->flood_sent >= BNET_FLOOD_CHARPERSEC) ! conn->flood_sent -= BNET_FLOOD_CHARPERSEC; ! else ! conn->flood_sent = 0; ! gaim_debug_info("bnet", "conn->flood_sent now %u (queue %p)\n", ! conn->flood_sent, conn->out_queue); ! ! bnet_conn_out_queue_check(conn); ! ! if (!conn->flood_sent) ! conn->flood_timer = 0; ! ! return conn->flood_sent != 0; } *************** *** 146,150 **** return; } else if (len == 0) { ! /* Remote probably closed the connection */ return; } --- 191,195 ---- return; } else if (len == 0) { ! gaim_connection_error(gc, _("Server has disconnected")); return; } *************** *** 153,157 **** conn->inbuf[conn->inbuf_used] = '\0'; ! /* We must swtich between the two cases beacuse input is _NOT_ line * buffered in the BNET_CS_USER and BNET_CS_PASS states */ --- 198,202 ---- conn->inbuf[conn->inbuf_used] = '\0'; ! /* We must switch between the two cases beacuse input is _NOT_ line * buffered in the BNET_CS_USER and BNET_CS_PASS states */ *************** *** 160,166 **** cur = conn->inbuf; ! while(cur < conn->inbuf + conn->inbuf_used && ! ((end = strstr(cur, "\r\n")) || (end = strstr(cur, "\n")))) ! { gint step = (*end == '\r' ? 2 : 1); --- 205,210 ---- cur = conn->inbuf; ! while (cur < conn->inbuf + conn->inbuf_used && ! ((end = strstr(cur, "\r\n")) || (end = strstr(cur, "\n")))) { gint step = (*end == '\r' ? 2 : 1); *************** *** 173,177 **** } - /* mmm leftovers */ if (cur != conn->inbuf + conn->inbuf_used) { conn->inbuf_used -= (cur - conn->inbuf); --- 217,220 ---- *************** *** 256,264 **** /* we need to remove the input cb that we created... */ ! if(gc->inpa > 0) gaim_input_remove(gc->inpa); conn = BNET_CONN(gc->proto_data); g_free(conn); ! conn = NULL; } --- 299,327 ---- /* we need to remove the input cb that we created... */ ! if (gc->inpa > 0) gaim_input_remove(gc->inpa); conn = BNET_CONN(gc->proto_data); + g_return_if_fail(conn); + + g_free(conn->inbuf); + + if (conn->nick) + g_free(conn->nick); + if (conn->chan) + g_free(conn->chan); + if (conn->away) + g_free(conn->away); + if (conn->last_stat.nick) + g_free(conn->last_stat.nick); + + g_hash_table_destroy(conn->users); + g_hash_table_destroy(conn->buddies); + + if (conn->flood_timer) + gaim_timeout_remove(conn->flood_timer); + g_free(conn); ! ! gc->proto_data = NULL; } Index: conn.h =================================================================== RCS file: /cvsroot/gaim-bnet/gaim-bnet/src/conn.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** conn.h 13 Jan 2005 08:25:39 -0000 1.4 --- conn.h 17 Jan 2005 01:56:50 -0000 1.5 *************** *** 25,28 **** --- 25,29 ---- typedef struct _BNetConn BNetConn; + typedef struct _BNetGameStat BNetGameStat; typedef enum _BNetConnState BNetConnState; *************** *** 38,41 **** --- 39,46 ---- }; + struct _BNetGameStat { + guint win, loss, disc; + }; + struct _BNetConn { GaimAccount *account; *************** *** 51,54 **** --- 56,63 ---- guint inbuf_used; + guint flood_timer; + guint flood_sent; + GList *out_queue; + gchar *nick; gchar *chan; *************** *** 57,60 **** --- 66,74 ---- gchar *away; + struct { + gchar *nick; + BNetGameStat normal; + } last_stat; + GHashTable *buddies; *************** *** 66,70 **** #endif /* __cplusplus */ ! gint bnet_conn_send(BNetConn *conn, const gchar *fmt, ...); void bnet_conn_update_progress(BNetConn *conn, BNetConnState cs); void bnet_conn_request_friends_list(BNetConn *conn); --- 80,87 ---- #endif /* __cplusplus */ ! void bnet_conn_send(BNetConn *conn, const gchar *fmt, ...); ! void bnet_conn_out_queue_push(BNetConn *conn, gchar *msg); ! void bnet_conn_out_queue_check(BNetConn *conn); ! gboolean bnet_conn_out_queue_to(gpointer p); void bnet_conn_update_progress(BNetConn *conn, BNetConnState cs); void bnet_conn_request_friends_list(BNetConn *conn); |