From: Dario Z. <ev...@us...> - 2005-09-26 09:24:05
|
Update of /cvsroot/gaim-bnet/gaim-bnet/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2641 Modified Files: bnet.c bnet.h chat.c chat.h proto.c proto.h Log Message: Implemented Feature Requests #1185004 - Slash Commands + error/info messages are shown in chat windows (if any) Index: chat.h =================================================================== RCS file: /cvsroot/gaim-bnet/gaim-bnet/src/chat.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** chat.h 9 Jan 2005 03:35:24 -0000 1.2 --- chat.h 26 Sep 2005 09:23:56 -0000 1.3 *************** *** 28,31 **** --- 28,32 ---- #endif /* __cplusplus */ + void bnet_register_commands(); gint bnet_chat_send_im(GaimConnection *gc, const gchar *who, const gchar *what, GaimConvImFlags imflags); GList *bnet_chat_info(GaimConnection *gc); Index: chat.c =================================================================== RCS file: /cvsroot/gaim-bnet/gaim-bnet/src/chat.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** chat.c 18 Feb 2005 09:46:46 -0000 1.6 --- chat.c 26 Sep 2005 09:23:56 -0000 1.7 *************** *** 26,29 **** --- 26,143 ---- #include "intl.h" + /****************************************************************************** + * Commands callbacks + *****************************************************************************/ + typedef GaimCmdRet (*BNetCmdCallback)(GaimConversation *conv, const gchar *cmd, + gchar **args, gchar **error, void *data); + typedef struct _bnet_command BNetCmdInfo; + + static GaimCmdRet bnet_cmd_stats(GaimConversation *conv, const gchar *cmd, + gchar **args, gchar **error, void *data); + static GaimCmdRet bnet_cmd_time(GaimConversation *conv, const gchar *cmd, + gchar **args, gchar **error, void *data); + static GaimCmdRet bnet_cmd_whois(GaimConversation *conv, const gchar *cmd, + gchar **args, gchar **error, void *data); + + static struct _bnet_command { + gchar *name; + gchar *format; + BNetCmdCallback cb; + gchar *help; + } _bnet_cmds[] = { + { "stats", "ww", bnet_cmd_stats, N_("Retrieve info about an user stats") }, + { "time", "", bnet_cmd_time, N_("Get server time") }, + { "whois", "w", bnet_cmd_whois, N_("Whois an user") }, + { NULL, NULL, NULL } + }; + + static GaimCmdRet + bnet_cmd_stats(GaimConversation *conv, const gchar *cmd, + gchar **args, gchar **error, void *data) { + GaimConnection *gc; + BNetConn *conn; + + gaim_debug_info("bnet", "bnet_cmd_stats\n"); + + gc = gaim_conversation_get_gc(conv); + if (!gc) + return GAIM_CMD_RET_FAILED; + + conn = BNET_CONN(gc->proto_data); + + if (args[0] && args[1] && !args[2]) { + bnet_conn_send(conn, "/stats %s %s\n", args[0], args[1]); + return GAIM_CMD_RET_OK; + } + else + return GAIM_CMD_RET_FAILED; + } + + static GaimCmdRet + bnet_cmd_time(GaimConversation *conv, const gchar *cmd, + gchar **args, gchar **error, void *data) { + GaimConnection *gc; + BNetConn *conn; + + gaim_debug_info("bnet", "bnet_cmd_time\n"); + + gc = gaim_conversation_get_gc(conv); + if (!gc) + return GAIM_CMD_RET_FAILED; + + conn = BNET_CONN(gc->proto_data); + + if (!args[0]) { + bnet_conn_send(conn, "/time\n"); + return GAIM_CMD_RET_OK; + } + else + return GAIM_CMD_RET_FAILED; + + return GAIM_CMD_RET_OK; + } + + static GaimCmdRet + bnet_cmd_whois(GaimConversation *conv, const gchar *cmd, + gchar **args, gchar **error, void *data) { + GaimConnection *gc; + BNetConn *conn; + + gaim_debug_info("bnet", "bnet_cmd_whois\n"); + + gc = gaim_conversation_get_gc(conv); + if (!gc) + return GAIM_CMD_RET_FAILED; + + conn = BNET_CONN(gc->proto_data); + + if (args[0] && !args[1]) { + bnet_conn_send(conn, "/whois %s\n", args[0]); + return GAIM_CMD_RET_OK; + } + else + return GAIM_CMD_RET_FAILED; + + return GAIM_CMD_RET_OK; + } + + void + bnet_register_commands() { + GaimCmdFlag f; + BNetCmdInfo *cmd; + gint i; + + f = GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_PRPL_ONLY + | GAIM_CMD_FLAG_ALLOW_WRONG_ARGS; + + for (i=0, cmd=_bnet_cmds; cmd->name; cmd++) { + gaim_cmd_register(cmd->name, cmd->format, GAIM_CMD_P_PRPL, f, "prpl-bnet", + cmd->cb, _(cmd->help), NULL); + } + } + + /****************************************************************************** + * Raw Procedures + *****************************************************************************/ void bnet_hash_join_all(gpointer key, gpointer value, gpointer user_data) { *************** *** 34,37 **** --- 148,154 ---- } + /****************************************************************************** + * Raw Procedures + *****************************************************************************/ gint bnet_chat_send_im(GaimConnection *gc, const gchar *who, const gchar *what, Index: bnet.c =================================================================== RCS file: /cvsroot/gaim-bnet/gaim-bnet/src/bnet.c,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** bnet.c 18 Feb 2005 09:46:46 -0000 1.38 --- bnet.c 26 Sep 2005 09:23:56 -0000 1.39 *************** *** 341,344 **** --- 341,346 ---- prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);*/ + bnet_register_commands(); + _bnet_plugin = plugin; }; Index: proto.h =================================================================== RCS file: /cvsroot/gaim-bnet/gaim-bnet/src/proto.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** proto.h 27 Jan 2005 21:26:41 -0000 1.8 --- proto.h 26 Sep 2005 09:23:56 -0000 1.9 *************** *** 49,53 **** }; ! typedef void (*BNetInfoProcFunc)(BNetConn *, GList *args); struct _BNetInfoProcInfo { --- 49,53 ---- }; ! typedef gboolean (*BNetInfoProcFunc)(BNetConn *, GList *args); struct _BNetInfoProcInfo { Index: bnet.h =================================================================== RCS file: /cvsroot/gaim-bnet/gaim-bnet/src/bnet.h,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** bnet.h 2 Mar 2005 22:39:47 -0000 1.12 --- bnet.h 26 Sep 2005 09:23:56 -0000 1.13 *************** *** 52,55 **** --- 52,56 ---- #include <debug.h> #include <blist.h> + #include <cmds.h> #include <util.h> #include <gaim.h> Index: proto.c =================================================================== RCS file: /cvsroot/gaim-bnet/gaim-bnet/src/proto.c,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** proto.c 3 Mar 2005 12:29:11 -0000 1.26 --- proto.c 26 Sep 2005 09:23:56 -0000 1.27 *************** *** 212,216 **** * Info Processing *****************************************************************************/ ! static void bnet_proto_info_welcome(BNetConn *conn, GList *args) { gaim_debug_info("bnet", "bnet_proto_info_welcome\n"); --- 212,216 ---- * Info Processing *****************************************************************************/ ! static gboolean bnet_proto_info_welcome(BNetConn *conn, GList *args) { gaim_debug_info("bnet", "bnet_proto_info_welcome\n"); *************** *** 221,227 **** conn->timer = gaim_timeout_add(BNET_FRIENDLIST_TIMEOUT, bnet_timeout_get_friendlist, conn); } ! static void bnet_proto_info_fl(BNetConn *conn, gboolean online, gchar *const *info) { GaimConnection *gc; --- 221,234 ---- conn->timer = gaim_timeout_add(BNET_FRIENDLIST_TIMEOUT, bnet_timeout_get_friendlist, conn); + + return TRUE; } ! static gboolean ! bnet_proto_info_ignore(BNetConn *conn, GList *args) { ! return FALSE; ! } ! ! static gboolean bnet_proto_info_fl(BNetConn *conn, gboolean online, gchar *const *info) { GaimConnection *gc; *************** *** 236,240 **** b = bnet_buddy_hard_lookup(conn, nick); ! g_return_if_fail(b); sscanf(n, "%u", &b->fl_position); --- 243,247 ---- b = bnet_buddy_hard_lookup(conn, nick); ! g_return_val_if_fail(b, FALSE); sscanf(n, "%u", &b->fl_position); *************** *** 243,249 **** gc = gaim_account_get_connection(conn->account); serv_got_update(gc, nick, online, 0, 0, 0, 0); } ! static void bnet_proto_info_fl_online(BNetConn *conn, GList *args) { GList *w = args; --- 250,258 ---- gc = gaim_account_get_connection(conn->account); serv_got_update(gc, nick, online, 0, 0, 0, 0); + + return FALSE; } ! static gboolean bnet_proto_info_fl_online(BNetConn *conn, GList *args) { GList *w = args; *************** *** 261,267 **** bnet_proto_info_fl(conn, TRUE, info); } ! static void bnet_proto_info_fl_offline(BNetConn *conn, GList *args) { GList *w = args; --- 270,278 ---- bnet_proto_info_fl(conn, TRUE, info); + + return FALSE; } ! static gboolean bnet_proto_info_fl_offline(BNetConn *conn, GList *args) { GList *w = args; *************** *** 275,281 **** bnet_proto_info_fl(conn, FALSE, info); } ! static void bnet_proto_info_fl_end(BNetConn *conn, GList *args) { gaim_debug_info("bnet", "bnet_proto_info_fl_end\n"); --- 286,294 ---- bnet_proto_info_fl(conn, FALSE, info); + + return FALSE; } ! static gboolean bnet_proto_info_fl_end(BNetConn *conn, GList *args) { gaim_debug_info("bnet", "bnet_proto_info_fl_end\n"); *************** *** 285,291 **** */ conn->fl_listing = FALSE; } ! static void bnet_proto_info_fl_added(BNetConn *conn, GList *args) { GList *w = args; --- 298,306 ---- */ conn->fl_listing = FALSE; + + return FALSE; } ! static gboolean bnet_proto_info_fl_added(BNetConn *conn, GList *args) { GList *w = args; *************** *** 299,308 **** b = bnet_buddy_hard_lookup(conn, nick); ! g_return_if_fail(b); bnet_conn_send(conn, "/where %s\n", nick); } ! static void bnet_proto_info_fl_removed(BNetConn *conn, GList *args) { GList *w = args; --- 314,325 ---- b = bnet_buddy_hard_lookup(conn, nick); ! g_return_val_if_fail(b, FALSE); bnet_conn_send(conn, "/where %s\n", nick); + + return FALSE; } ! static gboolean bnet_proto_info_fl_removed(BNetConn *conn, GList *args) { GList *w = args; *************** *** 316,325 **** b = bnet_buddy_lookup(conn, nick); ! g_return_if_fail(b); bnet_buddies_remove(conn->buddies, b); } ! static void bnet_proto_info_where(BNetConn *conn, GList *args) { GaimConnection *gc; --- 333,344 ---- b = bnet_buddy_lookup(conn, nick); ! g_return_val_if_fail(b, FALSE); bnet_buddies_remove(conn->buddies, b); + + return FALSE; } ! static gboolean bnet_proto_info_where(BNetConn *conn, GList *args) { GaimConnection *gc; *************** *** 365,372 **** g_free(conn->vw_nick); conn->vw_nick = 0; } } ! static void bnet_proto_info_whoami(BNetConn *conn, GList *args) { GList *w = args; --- 384,395 ---- g_free(conn->vw_nick); conn->vw_nick = 0; + } else { + return TRUE; } + + return FALSE; } ! static gboolean bnet_proto_info_whoami(BNetConn *conn, GList *args) { GList *w = args; *************** *** 386,393 **** } ! conn->fl_listing = FALSE; } ! static void bnet_proto_info_record_bg(BNetConn *conn, GList *args) { gchar *nick; --- 409,423 ---- } ! if (conn->fl_listing) { ! conn->fl_listing = FALSE; ! } ! else { ! return TRUE; ! } ! ! return FALSE; } ! static gboolean bnet_proto_info_record_bg(BNetConn *conn, GList *args) { gchar *nick; *************** *** 401,407 **** conn->last_stat.nick = g_strdup(nick); } ! static void bnet_proto_info_record_n(BNetConn *conn, GList *args) { BNetGameStat *stat; --- 431,439 ---- conn->last_stat.nick = g_strdup(nick); + + return FALSE; } ! static gboolean bnet_proto_info_record_n(BNetConn *conn, GList *args) { BNetGameStat *stat; *************** *** 414,420 **** stat = &conn->last_stat.normal; bnet_stat_resolve(stat, msg); } ! static void bnet_proto_info_record_l(BNetConn *conn, GList *args) { BNetGameStat *normal; --- 446,454 ---- stat = &conn->last_stat.normal; bnet_stat_resolve(stat, msg); + + return FALSE; } ! static gboolean bnet_proto_info_record_l(BNetConn *conn, GList *args) { BNetGameStat *normal; *************** *** 456,463 **** --- 490,500 ---- g_free(notice); + + return FALSE; } static BNetInfoProcInfo ipi[] = { { "Welcome to Battle.net!", bnet_proto_info_welcome }, + { "Your friends are:", bnet_proto_info_ignore }, { "$x: $x, (mutual) using $x in the channel $x.", bnet_proto_info_fl_online }, { "$x: $x, using $x in the channel $x.", bnet_proto_info_fl_online }, *************** *** 484,488 **** * Error Processing *****************************************************************************/ ! static void bnet_proto_error_not_logged(BNetConn *conn, GList *args) { gaim_debug_info("bnet", "bnet_proto_info_welcome\n"); --- 521,525 ---- * Error Processing *****************************************************************************/ ! static gboolean bnet_proto_error_not_logged(BNetConn *conn, GList *args) { gaim_debug_info("bnet", "bnet_proto_info_welcome\n"); *************** *** 502,506 **** --- 539,547 ---- g_free(conn->vw_nick); conn->vw_nick = 0; + } else { + return TRUE; } + + return FALSE; } *************** *** 671,674 **** --- 712,716 ---- GList *w_args; gint i; + gboolean verb = FALSE; gaim_debug_info("bnet", "INFO %s\n", args[0]); *************** *** 677,681 **** if (bnet_proto_model_compare(conn, ipi[i].model, (const gchar**)info, &w_args)) { ! ipi[i].func(conn, w_args); if (w_args) { --- 719,723 ---- if (bnet_proto_model_compare(conn, ipi[i].model, (const gchar**)info, &w_args)) { ! verb = ipi[i].func(conn, w_args); if (w_args) { *************** *** 687,690 **** --- 729,742 ---- } } + + if (i == PROTO_INFO_MSGS_N || verb) { + GaimConversation *conv; + + conv = gaim_find_conversation_with_account(conn->chan, conn->account); + if (conv) { + gaim_conv_chat_write(GAIM_CONV_CHAT(conv), "", + args[0], GAIM_MESSAGE_SYSTEM, time(0)); + } + } } *************** *** 695,698 **** --- 747,751 ---- GList *w_args; gint i; + gboolean verb = FALSE; gaim_debug_info("bnet", "ERROR %s\n", error); *************** *** 701,705 **** if (bnet_proto_model_compare(conn, epi[i].model, (const gchar**)info, &w_args)) { ! epi[i].func(conn, w_args); if (w_args) { --- 754,758 ---- if (bnet_proto_model_compare(conn, epi[i].model, (const gchar**)info, &w_args)) { ! verb = epi[i].func(conn, w_args); if (w_args) { *************** *** 711,714 **** --- 764,777 ---- } } + + if (i == PROTO_ERROR_MSGS_N || verb) { + GaimConversation *conv; + + conv = gaim_find_conversation_with_account(conn->chan, conn->account); + if (conv) { + gaim_conv_chat_write(GAIM_CONV_CHAT(conv), "", error, + GAIM_MESSAGE_SYSTEM, time(0)); + } + } } |