Exemplo n.º 1
0
static void flist_get_profile_cb(FListWebRequestData *req_data, gpointer user_data,
        JsonObject *root, const gchar *error_message) {
    FListAccount *fla = user_data;
    FListProfiles *flp = _flist_profiles(fla);
    gboolean success;

    flp->profile_request = NULL;

    if(!root) {
        purple_debug_warning(FLIST_DEBUG, "We requested a profile from the Web API, but failed. Error Message: %s\n", error_message);
        success = FALSE;
    } else {
        success = flist_process_profile(fla, root);
    }

    if(success) {
        g_free(flp->character); flp->character = NULL;
        purple_notify_user_info_destroy(flp->profile_info); flp->profile_info = NULL;
    } else {
        JsonObject *json = json_object_new();
        json_object_set_string_member(json, "character", flp->character);
        flist_request(fla->pc, "PRO", json);
        json_object_unref(json);
    }
}
Exemplo n.º 2
0
void flist_get_profile(PurpleConnection *pc, const char *who) {
    FListAccount *fla;
    FListProfiles *flp;
    GString *link_str;
    gchar *link;
    FListCharacter *character;

    g_return_if_fail((fla = pc->proto_data));
    flp = _flist_profiles(fla);

    if(flp->character) g_free(flp->character);
    flp->character = NULL;
    if(flp->profile_info) purple_notify_user_info_destroy(flp->profile_info);
    flp->profile_info = NULL;
    if(flp->table) g_hash_table_destroy(flp->table);
    flp->table = NULL;
    if(flp->profile_request) {
        flist_web_request_cancel(flp->profile_request);
        flp->profile_request = NULL;
    }

    flp->character = g_strdup(who);
    flp->profile_info = purple_notify_user_info_new();

    link_str = g_string_new(NULL);
    g_string_append_printf(link_str, "http://www.f-list.net/c/%s", purple_url_encode(who));
    link = g_string_free(link_str, FALSE);

    character = flist_get_character(fla, who);
    if(!character) {
        purple_notify_user_info_add_pair(flp->profile_info, "Status", "Offline");
    } else {
        gchar *clean_message = flist_html_unescape_utf8(character->status_message);
        gchar *parsed_message = flist_bbcode_to_html(fla, NULL, clean_message);
        purple_notify_user_info_add_pair(flp->profile_info, "Status", flist_format_status(character->status));
        purple_notify_user_info_add_pair(flp->profile_info, "Gender", flist_format_gender(character->gender));
        purple_notify_user_info_add_pair(flp->profile_info, "Message", parsed_message);
        g_free(parsed_message);
        g_free(clean_message);
    }
    purple_notify_user_info_add_pair(flp->profile_info, "Link", link);
    purple_notify_userinfo(pc, flp->character, flp->profile_info, NULL, NULL);

    if(!character) {
        //The character is offline. There's nothing more we should do.
        g_free(flp->character); flp->character = NULL;
        purple_notify_user_info_destroy(flp->profile_info); flp->profile_info = NULL;
    } else if(flp->category_table) { /* Try to get the profile through the website API first. */
        GHashTable *args = flist_web_request_args(fla);
        g_hash_table_insert(args, "name", g_strdup(flp->character));
        flp->profile_request = flist_web_request(JSON_CHARACTER_INFO, args, NULL, TRUE, fla->secure, flist_get_profile_cb, fla);
        g_hash_table_destroy(args);
    } else { /* Try to get the profile through F-Chat. */
        JsonObject *json = json_object_new();
        json_object_set_string_member(json, "character", flp->character);
        flist_request(pc, "PRO", json);
        json_object_unref(json);
    }
    g_free(link);
}
Exemplo n.º 3
0
PurpleCmdRet flist_create_kill_channel_cmd(PurpleConversation *convo, const gchar *cmd, gchar **args, gchar **error, void *data) {
    PurpleConnection *pc = purple_conversation_get_gc(convo);
    FListAccount *fla = pc->proto_data;
    const gchar *channel, *code;
    JsonObject *json;
    FListFlags flags;

    flags = flist_get_flags(fla, NULL, fla->proper_character);
    if(!(flags & (FLIST_FLAG_ADMIN | FLIST_FLAG_GLOBAL_OP))) {
        *error = g_strdup(_("You must be a global operator to create or delete public channels."));
        return PURPLE_CMD_STATUS_FAILED;
    }

    if(!purple_utf8_strcasecmp(cmd, "createchannel")) code = FLIST_PUBLIC_CHANNEL_CREATE;
    if(!purple_utf8_strcasecmp(cmd, "killchannel")) code = FLIST_PUBLIC_CHANNEL_DELETE;
    if(!code) return PURPLE_CMD_STATUS_NOT_FOUND;

    channel = args[0];

    json = json_object_new();
    json_object_set_string_member(json, "channel", channel);
    flist_request(pc, code, json);
    json_object_unref(json);

    return PURPLE_CMD_STATUS_OK;
}
Exemplo n.º 4
0
PurpleCmdRet flist_global_kick_ban_unban_cmd(PurpleConversation *convo, const gchar *cmd, gchar **args, gchar **error, void *data) {
    PurpleConnection *pc = purple_conversation_get_gc(convo);
    FListAccount *fla = pc->proto_data;
    const gchar *character, *code;
    JsonObject *json;
    FListFlags flags;

    flags = flist_get_flags(fla, NULL, fla->proper_character);
    if(!(flags & (FLIST_FLAG_ADMIN | FLIST_FLAG_GLOBAL_OP))) {
        *error = g_strdup(_("You must be a global operator to globally kick, ban, or unban."));
        return PURPLE_CMD_STATUS_FAILED;
    }

    if(!purple_utf8_strcasecmp(cmd, "gkick")) code = FLIST_GLOBAL_KICK;
    if(!purple_utf8_strcasecmp(cmd, "ipban")) code = FLIST_GLOBAL_IP_BAN;
    if(!purple_utf8_strcasecmp(cmd, "accountban")) code = FLIST_GLOBAL_ACCOUNT_BAN;
    if(!purple_utf8_strcasecmp(cmd, "gunban")) code = FLIST_GLOBAL_UNBAN;
    if(!code) return PURPLE_CMD_STATUS_NOT_FOUND;

    character = args[0];

    json = json_object_new();
    json_object_set_string_member(json, "character", character);
    flist_request(pc, code, json);
    json_object_unref(json);

    return PURPLE_CMD_STATUS_OK;
}
Exemplo n.º 5
0
PurpleCmdRet flist_admin_op_deop_cmd(PurpleConversation *convo, const gchar *cmd, gchar **args, gchar **error, void *data) {
    PurpleConnection *pc = purple_conversation_get_gc(convo);
    FListAccount *fla = pc->proto_data;
    const gchar *character, *code;
    JsonObject *json;
    FListFlags flags;

    flags = flist_get_flags(fla, NULL, fla->proper_character);
    if(!(flags & FLIST_FLAG_ADMIN)) {
        *error = g_strdup(_("You must be an administrator to add or remove global operators."));
        return PURPLE_CMD_STATUS_FAILED;
    }

    if(!purple_utf8_strcasecmp(cmd, "op")) code = FLIST_CHANNEL_BAN;
    if(!purple_utf8_strcasecmp(cmd, "deop")) code = FLIST_CHANNEL_UNBAN;
    if(!code) return PURPLE_CMD_STATUS_NOT_FOUND;

    character = args[0];

    json = json_object_new();
    json_object_set_string_member(json, "character", character);
    flist_request(pc, code, json);
    json_object_unref(json);

    return PURPLE_CMD_STATUS_OK;
}
Exemplo n.º 6
0
void flist_update_server_status(FListAccount *fla) {
    JsonObject *json = json_object_new();
    const gchar *status = purple_account_get_string(fla->pa, "_status", "online");
    const gchar *status_message = purple_account_get_string(fla->pa, "_status_message", "");
    json_object_set_string_member(json, "status", status);
    json_object_set_string_member(json, "statusmsg", status_message);
    flist_request(fla->pc, FLIST_SET_STATUS, json);

    json_object_unref(json);
}
Exemplo n.º 7
0
void flist_send_sfc_confirm(PurpleConnection *pc, const gchar *callid) {
    FListAccount *fla = pc->proto_data;
    JsonObject *json;

    json = json_object_new();
    json_object_set_string_member(json, "action", "confirm");
    json_object_set_string_member(json, "moderator", fla->proper_character);
    json_object_set_string_member(json, "callid", callid);
    flist_request(pc, "SFC", json);
    json_object_unref(json);
}
Exemplo n.º 8
0
static void flist_delete_public_channel_cb(gpointer user_data, const gchar *name) {
    PurpleConnection *pc = user_data;
    FListAccount *fla = pc->proto_data;
    JsonObject *json;

    g_return_if_fail(fla);
    json = json_object_new();
    json_object_set_string_member(json, "channel", name);
    flist_request(pc, FLIST_PUBLIC_CHANNEL_DELETE, json);
    json_object_unref(json);

    fla->input_request = FALSE;
}
Exemplo n.º 9
0
static void flist_add_global_operator_cb(gpointer user_data, const gchar *name) {
    PurpleConnection *pc = user_data;
    FListAccount *fla = pc->proto_data;
    JsonObject *json;

    g_return_if_fail(fla);

    json = json_object_new();
    json_object_set_string_member(json, "character", name);
    flist_request(pc, FLIST_ADD_GLOBAL_OPERATOR, json);
    json_object_unref(json);

    fla->input_request = FALSE;
}
Exemplo n.º 10
0
static void flist_broadcast_action_cb(gpointer user_data, const gchar *message) {
    PurpleConnection *pc = user_data;
    FListAccount *fla = pc->proto_data;
    JsonObject *json;

    g_return_if_fail(fla);

    json = json_object_new();
    json_object_set_string_member(json, "message", message);
    flist_request(pc, FLIST_BROADCAST, json);
    json_object_unref(json);

    fla->input_request = FALSE;
}
Exemplo n.º 11
0
PurpleCmdRet flist_timeout_cmd(PurpleConversation *convo, const gchar *cmd, gchar **args, gchar **error, void *data) {
    PurpleConnection *pc = purple_conversation_get_gc(convo);
    FListAccount *fla = pc->proto_data;
    gchar **split; guint count;
    const gchar *character, *time, *reason;
    gulong time_parsed; gchar *endptr;
    JsonObject *json;
    FListFlags flags;

    flags = flist_get_flags(fla, NULL, fla->proper_character);
    if(!(flags & (FLIST_FLAG_ADMIN | FLIST_FLAG_GLOBAL_OP))) {
        *error = g_strdup(_("You must be a global operator to timeban."));
        return PURPLE_CMD_STATUS_FAILED;
    }

    split = g_strsplit(args[0], ",", 3);
    count = g_strv_length(split);

    if(count < 3) {
        g_strfreev(split);
        *error = g_strdup(_("You must enter a character, a time, and a reason."));
        return PURPLE_CMD_STATUS_WRONG_ARGS;
    }

    character = split[0];
    time = g_strchug(split[1]);
    reason = g_strchug(split[2]);

    time_parsed = strtoul(time, &endptr, 10);
    if(time_parsed == 0 || endptr != time + strlen(time)) {
        g_strfreev(split);
        *error = g_strdup(_("You must enter a valid length of time."));
        return PURPLE_CMD_STATUS_WRONG_ARGS;
    }
    
    json = json_object_new();
    json_object_set_string_member(json, "character", character);
    json_object_set_string_member(json, "reason", reason);
    json_object_set_int_member(json, "time", time_parsed);
    flist_request(pc, FLIST_GLOBAL_TIMEOUT, json);
    json_object_unref(json);
    g_strfreev(split);
    return PURPLE_CMD_STATUS_OK;
}
Exemplo n.º 12
0
PurpleCmdRet flist_reward_cmd(PurpleConversation *convo, const gchar *cmd, gchar **args, gchar **error, void *data) {
    PurpleConnection *pc = purple_conversation_get_gc(convo);
    FListAccount *fla = pc->proto_data;
    const gchar *character;
    JsonObject *json;
    FListFlags flags;

    flags = flist_get_flags(fla, NULL, fla->proper_character);
    if(!(flags & (FLIST_FLAG_ADMIN | FLIST_FLAG_GLOBAL_OP))) {
        *error = g_strdup(_("You must be a global operator to reward a user."));
        return PURPLE_CMD_STATUS_FAILED;
    }

    character = args[0];

    json = json_object_new();
    json_object_set_string_member(json, "character", character);
    flist_request(pc, FLIST_REWARD, json);
    json_object_unref(json);

    return PURPLE_CMD_STATUS_OK;
}
Exemplo n.º 13
0
PurpleCmdRet flist_broadcast_cmd(PurpleConversation *convo, const gchar *cmd, gchar **args, gchar **error, void *data) {
    PurpleConnection *pc = purple_conversation_get_gc(convo);
    FListAccount *fla = pc->proto_data;
    const gchar *message;
    JsonObject *json;
    FListFlags flags;

    flags = flist_get_flags(fla, NULL, fla->proper_character);
    if(!(flags & (FLIST_FLAG_ADMIN))) {
        *error = g_strdup(_("You must be an administrator to send a global broadcast."));
        return PURPLE_CMD_STATUS_FAILED;
    }

    message = args[0];

    json = json_object_new();
    json_object_set_string_member(json, "message", message);
    flist_request(pc, FLIST_BROADCAST, json);
    json_object_unref(json);

    return PURPLE_CMD_STATUS_OK;
}