Exemplo n.º 1
0
void session_free(void)
{
    free(session.online.jid.k01);
    free(session.online.jid.ms);
    free(session.online.jid.muc);
    free(session.online.jid.wfc);
    free(session.online.jid.host);

    friend_list_free();
    clanmate_list_free();
    mission_list_free();
    gameroom_sync_free();
    room_list_free();
    masterserver_list_free();
    profile_item_list_free();

    free(session.xmpp.jid);

    free(session.online.id);
    free(session.online.channel);
    free(session.online.channel_type);
    free(session.online.active_token);

    free(session.online.place_token);
    free(session.online.place_info_token);
    free(session.online.mode_info_token);
    free(session.online.mission_info_token);

    free(session.gameroom.jid);
    free(session.gameroom.group_id);

    free(session.profile.id);
    free(session.profile.nickname);
    free(session.profile.clan.name);
    free(session.profile.primary_weapon);

    querycache_items_free();
    querycache_shop_get_offers_free();
    querycache_quickplay_maplist_free();
    querycache_get_configs_free();

#ifdef DEBUG
    querydump_free();
#endif /* DEBUG */

    memset(&session, 0, sizeof (struct session));
}
Exemplo n.º 2
0
static void xmpp_iq_gameroom_open_cb(const char *msg,
                                     enum xmpp_msg_type type,
                                     void *args)
{
    /* Answer :
       <iq to='masterserver@warface/pve_2' type='get'>
        <query xmlns='urn:cryonline:k01'>
         <data query_name='gameroom_open' compressedData='...'
               originalSize='42'/>
        </query>
       </iq>
     */

    struct cb_args *a = (struct cb_args *) args;

    if (type & XMPP_TYPE_ERROR)
    {
        int code = get_info_int(msg, "code='", "'", NULL);
        int custom_code = get_info_int(msg, "custom_code='", "'", NULL);
        const char *reason = NULL;

        switch (code)
        {
            case 1006:
                reason = "QoS limit reached";
                break;
            case 8:
                switch (custom_code)
                {
                    case 0: /* Expired mission, update and try again */
                        if (++a->tries < 2)
                        {
                            struct mission *m =
                                mission_list_get_by_key(a->mission_key);

                            if (m != NULL)
                            {
                                a->mission_name = strdup(m->name);
                                mission_list_update(
                                    _open_updated_list,
                                    args);

                                return;
                            }
                        }

                        reason = "Expired missions";
                        break;
                    case 1:
                        reason = "Invalid or expired mission";
                        break;
                    case 12:
                        reason = "Rank restricted";
                        break;
                    case 21:
                        reason = "Invalid room name";
                        break;
                    default:
                        break;
                }
                break;
            default:
                break;
        }

        if (reason != NULL)
            eprintf("Failed to open room (%s)\n", reason);
        else
            eprintf("Failed to open room (%i:%i)\n", code, custom_code);
    }
    else
    {
        char *data = wf_get_query_content(msg);

        if (data == NULL)
        {
            free(a);
            return;
        }

        /* Leave previous room if any */
        if (session.gameroom.jid != NULL)
        {
            xmpp_presence(session.gameroom.jid, XMPP_PRESENCE_LEAVE, NULL, NULL);
            free(session.gameroom.group_id);
            session.gameroom.group_id = NULL;
            free(session.gameroom.jid);
            session.gameroom.jid = NULL;

            gameroom_sync_free();
        }

        char *room = get_info(data, "room_id='", "'", "Room ID");

        if (room != NULL)
        {
            /* Join XMPP room */
            char *room_jid;

            FORMAT(room_jid, "*****@*****.**",
                   session.online.channel, room);
            xmpp_presence(room_jid, XMPP_PRESENCE_JOIN, NULL, NULL);
            session.gameroom.jid = room_jid;

            /* Reset auto-ready */
            session.gameroom.desired_status = GAMEROOM_READY;

            gameroom_sync_init();
            gameroom_sync(data);

            status_set(STATUS_ONLINE | STATUS_ROOM);
        }

        if (a->fun != NULL)
            a->fun(room, a->args);

        free(room);

        free(data);
    }

    free(a->mission_name);
    a->mission_name = NULL;
    free(a->mission_key);
    a->mission_key = NULL;
    free(a);
}