Example #1
0
/**
 * Implemented #SteamApiFunc for #steam_api_req_user_chatlog().
 *
 * @param req  The #SteamApiReq.
 * @param data The user defined data, which is #SteamData.
 **/
static void steam_cb_user_chatlog(SteamApiReq *req, gpointer data)
{
    SteamData     *sata = data;
    SteamUser     *user;
    SteamUserInfo *info;
    SteamUserMsg  *msg;
    bee_user_t    *bu;
    GList         *l;
    gchar          sid[STEAM_ID_STR_MAX];

    if (steam_req_error(sata, req, TRUE))
        return;

    for (bu = NULL, l = req->msgs->head; l != NULL; l = l->next) {
        msg  = l->data;
        info = msg->info;
        STEAM_ID_STR(info->id, sid);

        if ((bu == NULL) || (g_strcmp0(sid, bu->handle) != 0)) {
            bu = bee_user_by_handle(sata->ic->bee, sata->ic, sid);

            if (G_UNLIKELY(bu == NULL))
                continue;

            user = bu->data;
        }

        if (msg->time > user->vtime)
            steam_user_msg(sata, msg, msg->time);
    }
}
Example #2
0
static void
steam_cb_friends(SteamApiReq *req, gpointer data)
{
    bee_user_t *bu;
    gchar sid[STEAM_ID_STRMAX];
    GList *l;
    SteamData *sata = data;
    SteamUser *user;
    SteamUserInfo *info;
    struct im_connection *ic = sata->ic;

    if (steam_req_error(sata, req, TRUE)) {
        return;
    }

    if (!(ic->flags & BEE_USER_ONLINE)) {
        imcb_connected(ic);
    }

    for (l = req->infs->head; l != NULL; l = l->next) {
        info = l->data;
        STEAM_ID_STR(info->id, sid);

        /* Attempt to grab the buddy before adding */
        bu = bee_user_by_handle(sata->ic->bee, sata->ic, sid);

        if (bu == NULL) {
            imcb_add_buddy(sata->ic, sid, NULL);
            imcb_buddy_nick_hint(sata->ic, sid, info->nick);
            imcb_rename_buddy(sata->ic, sid, info->fullname);
        }

        bu = bee_user_by_handle(sata->ic->bee, sata->ic, sid);

        if (G_UNLIKELY(bu == NULL)) {
            continue;
        }

        user = bu->data;
        user->vtime = info->vtime;

        switch (info->rel) {
        case STEAM_USER_REL_FRIEND:
            steam_user_status(sata, info, bu);
            break;

        case STEAM_USER_REL_IGNORE:
            ic->deny = g_slist_prepend(ic->deny, g_strdup(bu->handle));
            break;
        }

        if (info->unread > 0) {
            req = steam_api_req_new(req->api, steam_cb_msgs, sata);
            steam_api_req_msgs(req, info->id, info->vtime);
        }
    }

    req = steam_api_req_new(req->api, steam_cb_poll, sata);
    steam_api_req_poll(req);
}
Example #3
0
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);
    }
}
Example #4
0
/**
 * Processes a #SteamApiMsg.
 *
 * @param sata The #SteamData.
 * @param msg  The #SteamUserMsg.
 * @param time The timestamp (UTC) of the message, or 0 for now.
 **/
static void steam_user_msg(SteamData *sata, SteamUserMsg *msg, gint64 time)
{
    SteamUserInfo *info = msg->info;
    bee_user_t    *bu;
    gchar         *str;
    guint32        f;
    gchar          sid[STEAM_ID_STR_MAX];

    STEAM_ID_STR(info->id, sid);
    STEAM_UTIL_DEBUGLN("Incoming message from %s (Type: %u, Act: %u)",
                       sid, msg->type, info->act);

    switch (msg->type) {
    case STEAM_USER_MSG_TYPE_EMOTE:
    case STEAM_USER_MSG_TYPE_SAYTEXT:
        bu = imcb_buddy_by_handle(sata->ic, sid);

        if ((bu != NULL) && (bu->flags & OPT_TYPING))
            imcb_buddy_typing(sata->ic, sid, 0);

        if (msg->type == STEAM_USER_MSG_TYPE_EMOTE)
            str = g_strconcat("/me ", msg->text, NULL);
        else
            str = g_strdup(msg->text);

        imcb_buddy_msg(sata->ic, sid, str, 0, time);
        g_free(str);
        return;

    case STEAM_USER_MSG_TYPE_LEFT_CONV:
        imcb_buddy_typing(sata->ic, sid, 0);
        return;

    case STEAM_USER_MSG_TYPE_RELATIONSHIP:
        goto relationship;

    case STEAM_USER_MSG_TYPE_TYPING:
        bu = imcb_buddy_by_handle(sata->ic, sid);

        if (G_UNLIKELY(bu == NULL))
            return;

        f = (bu->flags & OPT_TYPING) ? 0 : OPT_TYPING;
        imcb_buddy_typing(sata->ic, sid, f);
        return;

    default:
        steam_user_status(sata, info, NULL);
        return;
    }

relationship:
    switch (info->act) {
    case STEAM_USER_ACT_REMOVE:
    case STEAM_USER_ACT_IGNORE:
        imcb_remove_buddy(sata->ic, sid, NULL);
        return;

    case STEAM_USER_ACT_REQUEST:
        imcb_ask_auth(sata->ic, sid, info->nick);
        return;

    case STEAM_USER_ACT_ADD:
        imcb_add_buddy(sata->ic, sid, NULL);
        imcb_buddy_nick_hint(sata->ic, sid, info->nick);
        imcb_rename_buddy(sata->ic, sid, info->fullname);
        steam_user_status(sata, info, NULL);
        return;

    default:
        return;
    }
}
Example #5
0
/**
 * Updates the status of a #bee_user_t based on a #SteamUserInfo.
 *
 * @param sata The #SteamData.
 * @param info The #SteamUserInfo.
 * @param bu   The #bee_user_t or NULL.
 **/
static void steam_user_status(SteamData *sata, const SteamUserInfo *info,
                              bee_user_t *bu)
{
    SteamUser   *user;
    const gchar *m;
    gchar       *game;
    gint         f;
    gboolean     cgm;
    gboolean     csv;
    gchar        sid[STEAM_ID_STR_MAX];

    STEAM_ID_STR(info->id, sid);

    if (bu == NULL) {
        bu = imcb_buddy_by_handle(sata->ic, sid);

        if (G_UNLIKELY(bu == NULL))
            return;
    }

    if (info->state == STEAM_USER_STATE_OFFLINE) {
        imcb_buddy_status(sata->ic, sid, 0, NULL, NULL);
        return;
    }

    f = BEE_USER_ONLINE;
    m = steam_user_state_str(info->state);

    if (info->state != STEAM_USER_STATE_ONLINE)
        f |= BEE_USER_AWAY;

    user = bu->data;
    cgm  = g_strcmp0(info->game,   user->game)   != 0;
    csv  = g_strcmp0(info->server, user->server) != 0;

    if (!cgm && !csv) {
        if (user->game == NULL) {
            imcb_buddy_status(sata->ic, sid, f, m, bu->status_msg);
        }

        return;
    }

    if (info->server != NULL)
        game = g_strdup_printf("%s (%s)", info->game, info->server);
    else
        game = g_strdup(info->game);

    if (cgm) {
        imcb_buddy_status(sata->ic, sid, f, m, game);

        if (info->game != NULL)
            steam_user_chans_umode(user, sata->show_playing, TRUE);

        g_free(user->game);
        user->game = g_strdup(info->game);
    }

    if (csv) {
        g_free(user->server);
        user->server = g_strdup(info->server);
    }

    if (sata->game_status && (game != NULL))
        steam_user_chans_msg(user, "/me is now playing: %s", game);

    g_free(game);
}