/** * Implements #prpl->add_buddy(). This adds a buddy. * * @param ic The #im_connection. * @param name The name of the buddy to add. * @param group The group of the buddy. (Irrelevant to this plugin) **/ static void steam_add_buddy(struct im_connection *ic, char *name, char *group) { SteamData *sata = ic->proto_data; SteamApiReq *req; gchar *str; if (g_ascii_strncasecmp(name, "steamid:", 8) != 0) { req = steam_api_req_new(sata->api, steam_cb_user_search, sata); steam_api_req_user_search(req, name, 5); return; } str = strchr(name, ':'); if ((str != NULL) && ((++str)[0] != 0)) { req = steam_api_req_new(sata->api, steam_cb_user_action, sata); steam_api_req_user_add(req, STEAM_ID_NEW_STR(str)); } else { imcb_error(sata->ic, "No Steam ID specified"); } }
static void steam_cb_user_search(SteamApiReq *req, gpointer data) { const gchar *tag; gchar sid[STEAM_ID_STRMAX]; GList *l; guint i; SteamData *sata = data; SteamUserInfo *info; if (steam_req_error(sata, req, TRUE)) { return; } for (l = req->infs->head, i = 0; (l != NULL) && (i < 2); l = l->next, i++); switch (i) { case 0: imcb_error(sata->ic, "Failed to find any friend(s)"); return; case 1: info = req->infs->head->data; req = steam_api_req_new(req->api, steam_cb_user_action, sata); steam_api_req_user_add(req, info->id); return; } imcb_log(sata->ic, "Select from one of the following Steam Friends:"); tag = sata->ic->acc->tag; for (l = req->infs->head, i = 1; l != NULL; l = l->next, i++) { info = l->data; STEAM_ID_STR(info->id, sid); imcb_log(sata->ic, "%u. `%s' %s", i, info->nick, info->profile); imcb_log(sata->ic, "-- add %s steamid:%s", tag, sid); } }