static void _xmpp_iq_gameroom_open(const char *mission_key,
                                   enum e_room_type type,
                                   int tries,
                                   f_gameroom_open_cb fun,
                                   void *args)
{
    struct cb_args *a = calloc(1, sizeof (struct cb_args));

    a->fun = fun;
    a->args = args;
    a->tries = tries;

    if (mission_key != NULL)
        a->mission_key = strdup(mission_key);

    a->type = type;

    /* Open the game room */
    xmpp_send_iq_get(
        JID_MS(session.online.channel),
        xmpp_iq_gameroom_open_cb, a,
        "<query xmlns='urn:cryonline:k01'>"
        " <gameroom_open"
        "     room_name='Room' team_id='0' status='%d'"
        "     class_id='%d' room_type='%d' private='1'"
        "     mission='%s' inventory_slot='0'>"
        " </gameroom_open>"
        "</query>",
        GAMEROOM_UNREADY,
        session.profile.curr_class,
        type,
        mission_key);
}
void xmpp_iq_player_status(int status)
{
    xmpp_send_iq_get(
        JID_K01,
        NULL, NULL,
        "<query xmlns='urn:cryonline:k01'>"
        "<player_status prev_status='%u' new_status='%u' to='%s'/>"
        "</query>",
        session.online.status,
        status,
        session.gameroom.jid != NULL ? session.online.channel : "");

    session.online.status = status;
    session.online.last_status_update = time(NULL);

    /* Broadcast to every buddy */

    list_foreach(session.profile.friends,
                 (f_list_callback) xmpp_iq_peer_status_update_friend,
                 NULL);

    list_foreach(session.profile.clanmates,
                 (f_list_callback) xmpp_iq_peer_clan_member_update_clanmate,
                 NULL);
#ifdef DBUS_API
    dbus_api_emit_status_update(session.profile.nickname,
                                session.online.status,
                                session.profile.experience,
                                session.profile.clan.points);
#endif
}
void xmpp_iq_send_invitation(const char *nickname, enum e_notif_type type)
{
    xmpp_send_iq_get(
        JID_MS(session.online.channel),
        NULL, NULL,
        "<query xmlns='urn:cryonline:k01'>"
        "<send_invitation target='%s' type='%d'/>"
        "</query>",
        nickname,
        type);
}
void xmpp_iq_missions_get_list(f_missions_get_list_cb fun, void *args)
{
    struct cb_args *a = calloc(1, sizeof (struct cb_args));

    a->fun = fun;
    a->args = args;

    xmpp_send_iq_get(
        JID_MS(session.online.channel),
        xmpp_iq_missions_get_list_cb, a,
        "<query xmlns='urn:cryonline:k01'>"
        " <missions_get_list/>"
        "</query>",
        NULL);
}
void xmpp_iq_get_master_servers(f_get_master_servers_cb cb, void *args)
{
    struct cb_args *a = calloc(1, sizeof (struct cb_args));

    a->cb = cb;
    a->args = args;

    xmpp_send_iq_get(
        JID_K01,
        xmpp_iq_get_master_servers_cb, a,
        "<query xmlns='urn:cryonline:k01'>"
        "<get_master_servers/>"
        "</query>",
        NULL);
}
void xmpp_iq_peer_player_info(const char *online_id,
                              f_peer_player_info_cb f, void *args)
{
    struct cb_args *a = calloc(1, sizeof (struct cb_args));

    a->cb = f;
    a->args = args;

    xmpp_send_iq_get(
        JID(online_id),
        xmpp_iq_peer_player_info_cb, a,
        "<query xmlns='urn:cryonline:k01'>"
        "<peer_player_info/>"
        "</query>",
        NULL);
}
void xmpp_iq_gameroom_update_pvp(const char *mission_key,
                                 enum pvp_mode flags,
                                 int max_players,
                                 int inventory_slot,
                                 f_gameroom_update_pvp_cb cb,
                                 void *args)
{
    if (mission_key == NULL)
        return;

    struct cb_args *a = calloc(1, sizeof (struct cb_args));

    a->cb = cb;
    a->args = args;

    xmpp_send_iq_get(
        JID_MS(session.online.channel),
        xmpp_iq_gameroom_update_pvp_cb, a,
        "<query xmlns='urn:cryonline:k01'>"
        " <gameroom_update_pvp by_mission_key='1' mission_key='%s'"
        "    private='%d'"
        "    friendly_fire='%d'"
        "    enemy_outlines='%d'"
        "    auto_team_balance='%d'"
        "    dead_can_chat='%d'"
        "    join_in_the_process='%d'"
        "    max_players='%d' inventory_slot='%d'>"
        "  <class_rifleman enabled='1' class_id='0'/>"
        "  <class_engineer enabled='1' class_id='4'/>"
        "  <class_medic enabled='1' class_id='3'/>"
        "  <class_sniper enabled='1' class_id='2'/>"
        " </gameroom_update_pvp>"
        "</query>",
        mission_key,
        flags & PVP_PRIVATE ? 1 : 0,
        flags & PVP_FRIENDLY_FIRE ? 1 : 0,
        flags & PVP_ENEMY_OUTLINES ? 1 : 0,
        flags & PVP_AUTOBALANCE ? 1 : 0,
        flags & PVP_DEADCHAT ? 1 : 0,
        flags & PVP_ALLOWJOIN ? 1 : 0,
        max_players,
        inventory_slot);
}
void xmpp_iq_create_profile(void)
{
    xmpp_send_iq_get(
        JID_K01,
        xmpp_iq_create_profile_cb, NULL,
        "<query xmlns='urn:cryonline:k01'>"
        "<create_profile"
        " hw_id='%s' build_type='--release'"
        " version='%s' region_id='%s'"
        " user_id='%s' token='%s'"
        " nickname='' resource='%s'/>"
        "</query>",
        cvar.game_hwid,
        cvar.game_version,
        cvar.online_region_id,
        session.online.id,
        session.online.active_token,
        session.online.channel);
}
void xmpp_iq_get_achievements(const char *profile_id,
                              f_id_callback cb,
                              void *args)
{
    struct cb_args *a = calloc(1, sizeof (struct cb_args));

    a->cb = cb;
    a->args = args;

    xmpp_send_iq_get(
        JID_MS(session.online.channel),
        xmpp_iq_get_achievements_cb, a,
        "<query xmlns='urn:cryonline:k01'>"
        "<get_achievements>"
        "<achievement profile_id='%s'/>"
        "</get_achievements>"
        "</query>",
        profile_id);
}
static void xmpp_iq_peer_clan_member_update_(struct clanmate *c)
{
    /* Inform to our clanmates our status */
    xmpp_send_iq_get(
        JID(c->jid),
        xmpp_iq_peer_clan_member_update_cb, c,
        "<query xmlns='urn:cryonline:k01'>"
        " <peer_clan_member_update nickname='%s'"
        "    profile_id='%s' status='%u' experience='%u'"
        "    place_token='%s' place_info_token='%s'"
        "    mode_info_token='%s' mission_info_token='%s'"
        "    clan_points='%u' clan_role='%u'/>"
        "</query>",
        session.profile.nickname,
        session.profile.id,
        session.online.status,
        session.profile.experience,
        NULL_CHECK(session.online.place_token),
        NULL_CHECK(session.online.place_info_token),
        NULL_CHECK(session.online.mode_info_token),
        NULL_CHECK(session.online.mission_info_token),
        session.profile.clan.points,
        session.profile.clan.role);
}
void xmpp_iq_preinvite_invite(const char *online_id,
                              const char *uid,
                              f_preinvite_invite_cb cb,
                              void *args)
{
    struct cb_args *a = calloc(1, sizeof (struct cb_args));

    a->cb = cb;
    a->args = args;

    xmpp_send_iq_get(
        JID(online_id),
        xmpp_iq_preinvite_invite_cb, a,
        "<query xmlns='urn:cryonline:k01'>"
        " <preinvite_invite from='%s' uid='%s'"
        " ms_resource='%s' channel_type='%s'"
        " mission_id='%s'/>"
        "</query>",
        session.profile.nickname,
        uid,
        session.online.channel,
        session.online.channel_type,
        session.quickplay.mission_id ? session.quickplay.mission_id : "");
}
static void _xmpp_iq_gameroom_quickplay(const char *uid,
                                        const char *mission_key,
                                        enum e_room_type type,
                                        const char *game_mode,
                                        int channel_switches,
                                        int tries,
                                        f_gameroom_quickplay_cb cb,
                                        void *args)
{
    if (uid == NULL)
        return;

    char *query_mode;
    if (type == ROOM_PVE_QUICKPLAY)
    {
        if (mission_key == NULL)
            return;

        FORMAT(query_mode,
               "mission_id='%s' missions_hash='%i' content_hash='%i'",
               mission_key,
               session.wf.missions.hash,
               session.wf.missions.content_hash);
    }
    else if (type == ROOM_PVP_RATING)
    {
        query_mode = strdup("mission_id='' game_mode=''");
    }
    else if (mission_key != NULL)
    {
        FORMAT(query_mode, "mission_id='%s'", mission_key);
    }
    else if (game_mode != NULL)
    {
        FORMAT(query_mode, "game_mode='%s'", game_mode);
    }
    else
        return;

    struct cb_args *a = calloc(1, sizeof (struct cb_args));

    a->uid = strdup(uid);
    a->cb = cb;
    a->args = args;
    a->tries = tries;

    a->channel_switches = channel_switches;
    a->type = type;

    if (mission_key != NULL)
        a->mission_key = strdup(mission_key);

    if (game_mode != NULL)
        a->game_mode = strdup(game_mode);

    char *player_group = strdup("");
    if (session.quickplay.group != NULL)
    {
        list_foreach(session.quickplay.group,
                     (f_list_callback) _concat_players,
                     &player_group);
    }

    /* Request a new game room */
    xmpp_send_iq_get(
        JID_MS(session.online.channel),
        xmpp_iq_gameroom_quickplay_cb, a,
        "<query xmlns='urn:cryonline:k01'>"
        " <gameroom_quickplay"
        "     team_id='0' status='%d'"
        "     class_id='%d' room_type='%d'"
        "     channel_switches='%d' uid='%s' timestamp='0'"
        "     %s>"
        "  <group>%s</group>"
        " </gameroom_quickplay>"
        "</query>",
        GAMEROOM_READY,
        session.profile.curr_class,
        type,
        channel_switches,
        uid,
        query_mode,
        player_group);

    free(query_mode);
    free(player_group);
}
Exemple #13
0
void cmd_randombox(const char *name, unsigned int count)
{
    init_rb_items();

    if (name == NULL)
    {
        xprintf("Random boxes available:\n");

       unsigned int i = 0;
       for (; i < sizeof (random_box_items) / sizeof (random_box_items[0]);
            ++i)
       {
           if (random_box_items[i].shop_id != 0)
           {
                const struct shop_offer *o =
                    list_get(session.wf.shop_offers, random_box_items[i].shop_name);

                if (o == NULL)
                    continue;

                const char *currency = "";
                unsigned int price = 0;

                if (o->price.cry.curr != 0)
                {
                    currency = "K";
                    price = o->price.cry.curr;
                }
                else if (o->price.crown.curr != 0)
                {
                    currency = "crown";
                    price = o->price.crown.curr;
                }
                else if (o->price.game.curr != 0)
                {
                    currency = "wfd";
                    price = o->price.game.curr;
                }
                else if (o->price.key.curr != 0)
                {
                    currency = " key";
                    price = o->price.key.curr;
                }

                xprintf(" - %11s %u %s\n",
                        random_box_items[i].name,
                        price,
                        currency);
           }
       }

       return;
    }

    if (count <= 0 || count > 5)
    {
        eprintf("Invalid amount\n");
        return;
    }

    unsigned int rid = 0;
    unsigned int i = 0;

    for (; i < sizeof (random_box_items) / sizeof (random_box_items[0]);
         ++i)
    {
        if (strcmp(name, random_box_items[i].name) == 0
            || strcmp(name, random_box_items[i].shop_name) == 0)
        {
            rid = random_box_items[i].shop_id;
            break;
        }
    }

    if (rid == 0)
    {
        eprintf("Unknown randombox\n");
        return;
    }

    {
        char *offers = NULL;
        unsigned int i = 0;

        for (; i < count; ++i)
        {
            char *s;
            FORMAT(s, "%s<offer id='%d'/>", offers ? offers : "", rid + i);
            free(offers);
            offers = s;
        }

        xmpp_send_iq_get(
            JID_MS(session.online.channel),
            _randombox_cb, NULL,
            "<query xmlns='urn:cryonline:k01'>"
            "<shop_buy_multiple_offer supplier_id='1'>"
            "%s"
            "</shop_buy_multiple_offer>"
            "</query>",
            offers);

        free(offers);
    }
}