<commit_before>/**
 * WarfaceBot, a blind XMPP client for Warface (FPS)
 * Copyright (C) 2015 <NAME> <<EMAIL>>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#include <wb_tools.h>
#include <wb_stream.h>
#include <wb_session.h>
#include <wb_xmpp.h>
#include <wb_xmpp_wf.h>

#include <stdio.h>
#include <stdlib.h>

struct cb_args
{
    f_gameroom_open_cb fun;
    void *args;
};

static void xmpp_iq_gameroom_open_cb(const char *msg, 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 (xmpp_is_error(msg))
    {
        free(a);
        return;
    }

    session.ingameroom = 1;

    /* Leave previous room if any */
    if (session.gameroom_jid != NULL)
    {
        xmpp_presence(session.gameroom_jid, 1, NULL, NULL);
        free(session.gameroom_jid);
        session.gameroom_jid = NULL;
    }

    xmpp_iq_player_status(STATUS_ONLINE | STATUS_ROOM);

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

    free(data);

    /* Join XMPP room */
    char *room_jid;

    FORMAT(room_jid, "room.%s.%s@conference.warface", session.channel, room);
    xmpp_presence(room_jid, 0, NULL, NULL);
    session.gameroom_jid = room_jid;

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

    free(room);

    free(a);
}

void xmpp_iq_gameroom_open(const char *mission_key, enum e_room_type type,
                           f_gameroom_open_cb fun, void *args)
{
    struct cb_args *a = calloc(1, sizeof (struct cb_args));
    a->fun = fun;
    a->args = args;

    t_uid id;

    idh_generate_unique_id(&id);
    idh_register(&id, 0, xmpp_iq_gameroom_open_cb, a);

    /* Open the game room */
    send_stream_format(session.wfs,
                       "<iq id='%s' to='masterserver@warface/%s' type='get'>"
                       " <query xmlns='urn:cryonline:k01'>"
                       "  <gameroom_open"
                       "      room_name='Room' team_id='1' status='1'"
                       "      class_id='1' room_type='%d' private='1'"
                       "      mission='%s' inventory_slot='0'>"
                       "  </gameroom_open>"
                       " </query>"
                       "</iq>",
                       &id, session.channel, type, mission_key);
}<commit_msg>Fix `open` command for PvE maps<commit_after>/**
 * WarfaceBot, a blind XMPP client for Warface (FPS)
 * Copyright (C) 2015 <NAME> <<EMAIL>>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#include <wb_tools.h>
#include <wb_stream.h>
#include <wb_session.h>
#include <wb_xmpp.h>
#include <wb_xmpp_wf.h>

#include <stdio.h>
#include <stdlib.h>

struct cb_args
{
    f_gameroom_open_cb fun;
    void *args;
};

static void xmpp_iq_gameroom_open_cb(const char *msg, 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 (xmpp_is_error(msg))
    {
        free(a);
        return;
    }

    session.ingameroom = 1;

    /* Leave previous room if any */
    if (session.gameroom_jid != NULL)
    {
        xmpp_presence(session.gameroom_jid, 1, NULL, NULL);
        free(session.gameroom_jid);
        session.gameroom_jid = NULL;
    }

    xmpp_iq_player_status(STATUS_ONLINE | STATUS_ROOM);

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

    free(data);

    /* Join XMPP room */
    char *room_jid;

    FORMAT(room_jid, "<EMAIL>", session.channel, room);
    xmpp_presence(room_jid, 0, NULL, NULL);
    session.gameroom_jid = room_jid;

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

    free(room);

    free(a);
}

void xmpp_iq_gameroom_open(const char *mission_key, enum e_room_type type,
                           f_gameroom_open_cb fun, void *args)
{
    struct cb_args *a = calloc(1, sizeof (struct cb_args));
    a->fun = fun;
    a->args = args;

    t_uid id;

    idh_generate_unique_id(&id);
    idh_register(&id, 0, xmpp_iq_gameroom_open_cb, a);

    /* Open the game room */
    send_stream_format(session.wfs,
                       "<iq id='%s' to='masterserver@warface/%s' type='get'>"
                       " <query xmlns='urn:cryonline:k01'>"
                       "  <gameroom_open"
                       "      room_name='Room' team_id='%d' status='1'"
                       "      class_id='1' room_type='%d' private='1'"
                       "      mission='%s' inventory_slot='0'>"
                       "  </gameroom_open>"
                       " </query>"
                       "</iq>",
                       &id, session.channel,
                       type == ROOM_PVP ? 1 : 0, type, mission_key);
}
{'fraction_non_alphanumeric': 0.12507916402786573, 'fraction_numerical': 0.007124762507916403, 'mean_word_length': 2.347641759406465, 'pattern_counts': {'":': 0, '<': 48, '<?xml version=': 0, '>': 58, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4028196', 'n_tokens_mistral': 2207, 'n_tokens_neox': 2112, 'n_words': 547}