static void xmpp_iq_preinvite_invite_cb(const char *msg_id,
                                        const char *msg,
                                        void *args)
{
    /* Accept any preinvite
       <iq from='xxxx@warface/GameClient' id='uid000000e9' type='get'>
        <query xmlns='urn:cryonline:k01'>
         <preinvite_invite from='xxxxxxxx' uid='xxxxxxx'
                 ms_resource='pve_11' channel_type='pve'/>
        </query>
       </iq>
     */

    char *jid = get_info(msg, "from='", "'", NULL);
    char *data = wf_get_query_content(msg);

    if (!data)
        return;

    char *resource = get_info(data, "ms_resource='", "'", "Resource");
    char *uid = get_info(data, "uid='", "'", "UUID");

    if (jid && resource && uid)
    {
        send_stream_format(session.wfs,
                           "<iq to='%s' type='result'>"
                           " <query xmlns='urn:cryonline:k01'>"
                           "  <preinvite_invite uid='%s'/>"
                           " </query>"
                           "</iq>",
                           msg_id, uid);

        send_stream_format(session.wfs,
                           "<iq to='%s' type='get'>"
                           " <query xmlns='urn:cryonline:k01'>"
                           "  <preinvite_response uid='%s' accepted='1'"
                           "          pid='%s' from='%s'/>"
                           " </query>"
                           "</iq>",
                           jid, uid,
                           session.profile_id, session.nickname);
        free(uid);
        free(resource);
    }

    free(data);
    free(jid);
}
Пример #2
0
void xmpp_iq_player_status(int status)
{
    send_stream_format(session.wfs,
                       "<iq to='k01.warface' type='get'>"
                       "<query xmlns='urn:cryonline:k01'>"
                       "<player_status prev_status='%u' new_status='%u'"
                       "               to='%s'/>"
                       "</query>"
                       "</iq>",
                       session.status, status, "");

    session.status = status;

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

    list_foreach(session.clanmates,
                 (f_list_callback) xmpp_iq_peer_clan_member_update_clanmate,
                 NULL);
#ifdef DBUS_API
    dbus_api_emit_status_update(session.nickname,
                                session.status,
                                session.experience,
                                session.clan_points);
#endif
}
Пример #3
0
void *thread_buyboxes ( void *args )
{
	signal ( SIGINT, sigint_handler__ );

	struct cmd_randombox_args_cb_t *randombox_args = ( struct cmd_randombox_args_cb_t* ) args;

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

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

	idh_generate_unique_id ( &id );
	idh_register ( &id, 0, _randombox_cb, randombox_args );

	send_stream_format ( session.wfs,
							"<iq id='%s' to='masterserver@warface/%s' type='get'>"
							"<query xmlns='urn:cryonline:k01'>"
							"<shop_buy_multiple_offer supplier_id='1'>"
							"%s"
							"</shop_buy_multiple_offer>"
							"</query>"
							"</iq>",
							&id, session.online.channel, offers );

	free ( offers );
	pthread_exit ( NULL );
}
Пример #4
0
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.online.channel,
						 type ^ ROOM_PVE_PRIVATE ? 1 : 0, type, mission_key );
}
Пример #5
0
void xmpp_iq_join_channel(const char *channel, f_join_channel_cb f, void *args)
{
    int is_switch = session.status >= STATUS_LOBBY;
    struct cb_args *a = calloc(1, sizeof (struct cb_args));

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

    if (channel == NULL)
        channel = session.channel;

    if (channel)
        a->channel = strdup(channel);
    else
        a->channel = NULL;

    t_uid id;

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

    /* Join CryOnline channel */
    send_stream_format(session.wfs,
                       "<iq id='%s' to='k01.warface' type='get'>"
                       "<query xmlns='urn:cryonline:k01'>"
                       "<%s_channel version='%s' token='%s' region_id='global'"
                       "     profile_id='%s' user_id='%s' resource='%s'"
                       "     user_data='' hw_id='' build_type='--release'/>"
                       "</query>"
                       "</iq>",
                       &id, is_switch ? "switch" : "join",
                       game_version_get(),
                       session.active_token, session.profile_id,
                       session.online_id, a->channel);
}
Пример #6
0
void xmpp_stream ( const char *login, const char *password,
				   f_stream_cb cb, void *args )
{
	if ( login == NULL || password == NULL )
		return;

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

	a->login = strdup ( login );
	a->password = strdup ( password );
	a->f = cb;
	a->args = args;

	qh_register ( "stream:stream", 0, xmpp_stream_cb_, (void *) a );
	qh_register ( "?xml", 0, xmpp_stream_cb_, (void *) a );
	qh_register ( "stream:features", 0, xmpp_features_cb_, (void *) a );

	/* Send Handshake */
	send_stream_format ( session.wfs,
						 "<?xml version='1.0' ?>"
						 "<stream:stream to='warface'"
						 " xmlns='jabber:client'"
						 " xmlns:stream='http://etherx.jabber.org/streams'"
						 " xml:lang='en' version='1.0'>" );
}
Пример #7
0
void xmpp_sasl(const char *login, const char *password,
               f_sasl_cb cb, void *args)
{
    if (login == NULL || password == NULL)
        return;

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

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

    qh_register("success", 0, xmpp_sasl_cb_, a);

    /* SASL Authentification */

    char *logins_b64 = sasl_combine_logins(login, password);

    send_stream_format(session.wfs,
                       "<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl'"
                       " mechanism='WARFACE'>"
                       "%s"
                       "</auth>",
                       logins_b64);

    free(logins_b64);
}
static void xmpp_iq_gameroom_sync_cb(const char *msg_id,
                                     const char *msg,
                                     void *args)
{
    char *data = wf_get_query_content(msg);
    int room_status = get_info_int(data, "status='", "'", NULL);

    if (room_status == 2)
    {
        t_uid id;

        idh_generate_unique_id(&id);
        idh_register(&id, 0, xmpp_iq_session_join_cb, NULL);

        send_stream_format(session.wfs,
                           "<iq id='%s' to='masterserver@warface/%s' type='get'>"
                           " <query xmlns='urn:cryonline:k01'>"
                           "  <session_join/>"
                           " </query>"
                           "</iq>",
                           &id, session.channel);

        char *sessionid = get_info(data, "session id='", "'", NULL);

        if (sessionid != NULL && sessionid[0])
            printf("Session id: %s\n", sessionid);

        free(sessionid);
    }

    free(data);
}
void xmpp_iq_confirm_notification(const char *notif)
{
    char *notif_id = get_info(notif, "id='", "'", NULL);
    enum e_notif_type notif_type = get_info_int(notif, "type='", "'", NULL);

    switch (notif_type)
    {
        /* Confirm consecutive logins */
        case NOTIF_CONS_LOGIN:
            puts("Getting consecutive reward");
        /* Accept any friend requests */
        case NOTIF_FRIEND_REQUEST:
            send_stream_format(session.wfs,
                               "<iq to='masterserver@warface/%s' type='get'>"
                               " <query xmlns='urn:cryonline:k01'>"
                               "  <confirm_notification>"
                               "   <notif id='%s' type='%d'>"
                               "    <confirmation result='0' status='%d'"
                               "                  location=''/>"
                               "   </notif>"
                               "  </confirm_notification>"
                               " </query>"
                               "</iq>",
                               session.channel, notif_id,
                               notif_type, session.status);
            break;
        /* Old fashion peer_status_update */
        case NOTIF_STATUS_UPDATE:
        {
            char *jid = get_info(notif, "jid='", "'", NULL);
            char *nick = get_info(notif, "nickname='", "'", NULL);
            char *pid = get_info(notif, "profile_id='", "'", NULL);
            int status = get_info_int(notif, "status='", "'", NULL);
            int exp = get_info_int(notif, "experience='", "'", NULL);

            if (status <= STATUS_OFFLINE)
                jid = NULL;

            friend_list_add(jid, nick, pid, status, exp);
            xmpp_iq_peer_status_update(jid);

            free(jid);
            free(nick);
            free(pid);
        }
        break;
        default:
            break;
    }

    free(notif_id);
}
void xmpp_print_number_of_occupants ( int wfs, char *room )
{
	t_uid id;

	idh_generate_unique_id ( &id );
	idh_register ( &id, 0, xmpp_print_number_of_occupants_cb, NULL );

	send_stream_format ( wfs,
						 "<iq to='%s' type='get' id='%s'>"
						 " <query xmlns='http://jabber.org/protocol/disco#info'/>"
						 "</iq>",
						 room, &id );
}
Пример #11
0
void xmpp_iq_ping(void)
{
    t_uid id;

    idh_generate_unique_id(&id);
    idh_register(&id, 0, xmpp_iq_ping_cb, NULL);

    send_stream_format(session.wfs,
                       "<iq id='%s' from='%s' to='warface' type='get'>"
                       " <ping xmlns='urn:xmpp:ping'/>"
                       "</iq>",
                       &id, session.jid);
}
Пример #12
0
void xmpp_room_message ( const char *room_jid, const char *msg )
{
	if ( room_jid == NULL )
		return;

	char *serialized = xml_serialize ( msg );

	send_stream_format ( session.wfs,
						 "<message to='%s' type='groupchat'>"
						 "<body>%s</body>"
						 "</message>",
						 room_jid, serialized );

	free ( serialized );
}
Пример #13
0
void cmd_stats(f_cmd_stats_cb cb, void *args)
{
    t_uid id;
    struct cb_args *a = calloc(1, sizeof (struct cb_args));

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

    idh_generate_unique_id(&id);
    idh_register(&id, 1, cmd_stats_cb, a);

    send_stream_format(session.wfs,
                       "<iq to='k01.warface' type='get' id='%s'>"
                       "<query xmlns='urn:cryonline:k01'>"
                       "<get_master_servers/>"
                       "</query>"
                       "</iq>", &id);
}
void xmpp_iq_get_account_profiles(void)
{
    t_uid id;

    idh_generate_unique_id(&id);
    idh_register(&id, 0, xmpp_iq_get_account_profiles_cb, NULL);

    /* Get CryOnline profile */
    send_stream_format(session.wfs,
                       "<iq id='%s' to='ms.warface' type='get'>"
                       " <query xmlns='urn:cryonline:k01'>"
                       "  <get_account_profiles version='%s'"
                       "    user_id='%s' token='%s'/>"
                       " </query>"
                       "</iq>",
                       &id, game_version_get(),
                       session.online_id, session.active_token);
}
Пример #15
0
static void xmpp_sasl_cb_(const char *msg_id, const char *msg, void *args)
{
    /* Answer :
       <success xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/>
     */

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

    send_stream_format(session.wfs,
                       "<stream:stream to='warface'"
                       " xmlns='jabber:client'"
                       " xmlns:stream='http://etherx.jabber.org/streams'"
                       " xml:lang='en' version='1.0'>");

    xmpp_bind("GameClient", a->f, a->args);

    free(a);
}
Пример #16
0
static void xmpp_iq_gameroom_join_(void *args)
{
    struct cb_args *a = (struct cb_args *) args;

    t_uid id;

    idh_generate_unique_id(&id);
    idh_register(&id, 0, xmpp_iq_gameroom_join_cb, args);

    /* Open the game room */
    send_stream_format(session.wfs,
                       "<iq id='%s' to='masterserver@warface/%s' type='get'>"
                       " <query xmlns='urn:cryonline:k01'>"
                       "  <gameroom_join room_id='%s' team_id='0'"
                       "     status='1' class_id='1' join_reason='0'/>"
                       " </query>"
                       "</iq>",
                       &id, session.channel, a->room_id);
}
void xmpp_iq_gameroom_setname ( const char *room_name,
								f_id_callback cb, void *args )
{
	t_uid id;

	idh_generate_unique_id ( &id );
	idh_register ( &id, 0, cb, args );

	char *serialized = xml_serialize ( room_name );

	send_stream_format ( session.wfs,
						 "<iq id='%s' to='masterserver@warface/%s' type='get'>"
						 " <query xmlns='urn:cryonline:k01'>"
						 "  <gameroom_setname room_name='%s'/>"
						 " </query>"
						 "</iq>",
						 &id, session.online.channel, serialized );

	free ( serialized );
}
Пример #18
0
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;

    t_uid id;

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

    send_stream_format(session.wfs,
                       "<iq to='%s' type='get' id='%s'>"
                       "<query xmlns='urn:cryonline:k01'>"
                       "<peer_player_info/>"
                       "</query>"
                       "</iq>",
                       online_id, &id);
}
void xmpp_iq_profile_info_get_status(const char *nickname,
                                     const char *nick_to,
                                     const char *jid_to)
{
    struct cb_args *a = calloc(1, sizeof (struct cb_args));

    a->nick_to = strdup(nick_to);
    a->jid_to = strdup(jid_to);

    t_uid id;

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

    send_stream_format(session.wfs,
                       "<iq to='k01.warface' type='get' id='%s'>"
                       "<query xmlns='urn:cryonline:k01'>"
                       "<profile_info_get_status nickname='%s'/>"
                       "</query>"
                       "</iq>",
                       &id, nickname);
}
static void xmpp_promote_room_master_cb(const char *info,
                                        void *args)
{
    /* Answer
       <info nickname='xxxxx' online_id='xxxxx@warface/GameClient'
             status='13' profile_id='xxx' user_id='xxxxxx' rank='xx'
             tags='' login_time='xxxxxxxxxxx'/>
     */

    if (info != NULL)
    {
        char *profile_id = get_info(info, "profile_id='", "'", "PROFILE ID");

        send_stream_format(session.wfs,
                           "<iq to='masterserver@warface/%s' type='get'>"
                           " <query xmlns='urn:cryonline:k01'>"
                           "  <gameroom_promote_to_host new_host_profile_id='%s'/>"
                           " </query>"
                           "</iq>",
                           session.channel, profile_id);

        free(profile_id);
    }
}
static void xmpp_iq_peer_player_info_cb(const char *msg_id,
                                        const char *msg,
                                        void *args)
{
    /* Answer
       <iq from="xxx@warface/GameClient" id="xxxxxx" type="get">
        <query xmlns="urn:cryonline:k01">
         <peer_player_info/>
        </query>
       </iq>
    */

    char *jid = get_info(msg, "from='", "'", NULL);
    char *clan_stats;

    if (session.clan_id != 0)
    {
        FORMAT(clan_stats,
               "    clan_name='%s' clan_role='%i'"
               "    clan_position='%i' clan_points='%i'"
               "    clan_member_since='%X'",
               session.clan_name,
               session.clan_role,
               1 /* TODO: session.clan_own_position */,
               session.clan_points,
               session.clan_joined);
    }
    else
        clan_stats = strdup("");

    send_stream_format(session.wfs,
                       "<iq to='%s' id='%s' type='result'>"
                       " <query xmlns='urn:cryonline:k01'>"
                       "  <peer_player_info online_id='%s' nickname='%s'"
                       "    primary_weapon='%s'"
                       "    banner_badge='%u' banner_mark='%u'"
                       "    banner_stripe='%u' experience='%u'"
                       "    items_unlocked='%u'"
                       "    challenges_completed='%u'"
                       "    missions_completed='%u'"
                       "    pvp_wins='%u' pvp_loses='%u'"
                       "    pvp_kills='%u' pvp_deaths='%u'"
                       "    playtime_seconds='%u'"
                       "    leavings_percentage='%f'"
                       "    coop_climbs_performed='%u'"
                       "    coop_assists_performed='%u'"
                       "    favorite_pvp_class='0' favorite_pve_class='0'"
                       "    %s />"
                       " </query>"
                       "</iq>",
                       jid, msg_id, session.jid, session.nickname,
                       "ar03_bundle_shop",
                       (unsigned) -1, (unsigned) -1,
                       (unsigned) -1, session.experience,
                       (unsigned) (rand() % 10 + 10) /* items_unlocked */,
                       (unsigned) (rand() % 10 + 10) /* challenges_completed */,
                       (unsigned) (rand() % 10 + 10) /* missions_completed */,
                       (unsigned) (rand() % 10 + 10) /* pvp_wins */,
                       (unsigned) (rand() % 10 + 10) /* pvp_loses */,
                       (unsigned) (rand() % 10 + 10) /* pvp_kills */,
                       (unsigned) (rand() % 10 + 10) /* pvp_deaths */,
                       (unsigned) (rand() % 10000 + 10000) /* playtime_seconds */,
                       1.0f / ((float) rand()) + 1.0f /* leavings_percentage */,
                       (unsigned) (rand() % 10 + 10) /* coop_climbs_performed */,
                       (unsigned) (rand() % 10 + 10) /* coop_assists_performe */,
                       clan_stats);

    free(clan_stats);
    free(jid);
}
Пример #22
0
static void _randombox_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'>
	<shop_buy_multiple_offer error_status="0">
	<purchased_item>
	<exp name="exp_item_01" added="50" total="40014" offerId="9870"/>
	<profile_item name="flashbang" profile_item_id="xxxxx"
	offerId="9870" added_expiration="1 day"
	added_quantity="0" error_status="0">
	<item id="xxxxx" name="flashbang" attached_to="0"
	config="dm=0;material=;pocket_index=3246082"
	slot="0" equipped="0" default="0"
	permanent="0" expired_confirmed="0"
	buy_time_utc="1429646487"
	expiration_time_utc="1449778407"
	seconds_left="172628"/>
	</profile_item>
	<exp name="exp_item_01" added="50" total="40064" offerId="9871"/>
	...
	</purchased_item>
	<money game_money="AAA" cry_money="BBB" crown_money="CCC"/>
	</shop_buy_multiple_offer>
	</query>
	</iq>
	*/
	
	struct cmd_randombox_args_cb_t *randombox_args = (struct cmd_randombox_args_cb_t*) args;

	if ( type & XMPP_TYPE_ERROR )
	{
		LOGPRINT ( KRED BOLD "Error while purchasing items\n" );
		return;
	}

	char *data = wf_get_query_content ( msg );

	if ( data != NULL )
	{
		//printf ( "Answer: \n---------\n%s\n--------\n\n", data );

		unsigned int error_code = get_info_int ( data, "error_status='", "'", NULL );
		unsigned int money_left = get_info_int ( data, "game_money='", "'", NULL );

		const char *m = strstr ( data, "<shop_buy_multiple_offer" );

		if ( m != NULL && ( error_code == 1 || error_code == 0 ) )
		{
			unsigned total_xp = 0;

			m += sizeof ( "<shop_buy_multiple_offer" );

			do
			{

				const char *exp_s = strstr ( m, "<exp" );
				const char *profile_item_s = strstr ( m, "<profile_item" );

				if ( exp_s != NULL
					 && ( profile_item_s == NULL || exp_s < profile_item_s ) )
				{
					m = exp_s + sizeof ( "<exp" );

					total_xp += get_info_int ( m, "added='", "'", NULL );
				}
				else if ( profile_item_s != NULL )
				{
					m = profile_item_s + sizeof ( "<profile_item" );

					char *name = get_info ( m, "name='", "'", NULL );
					char *expir = get_info ( m, "added_expiration='", "'", NULL );
					char *quant = get_info ( m, "added_quantity='", "'", NULL );

					LOGPRINT ( "%-20s %-10s %s\n", "ITEM",
							   expir && expir[ 0 ] != '0' ? expir : quant,
							   name );

					if ( randombox_args->needed && strstr ( name, randombox_args->needed ) )
					{
						LOGPRINT ( KGRN BOLD "%-20s %s\a\n" KRST KWHT, "GOT ITEM", name );
						randombox_args->gotNeeded = 1;
					}

					free ( quant );
					free ( expir );
					free ( name );
				}
				else
				{
					break;
				}

			} while ( 1 );

			randombox_args->moneyLeft = money_left;
			randombox_args->xp += total_xp;

			LOGPRINT ( "%-20s " BOLD "%d\n", "MONEY LEFT", money_left );

			if ( randombox_args->moneyLeft < randombox_args->stopMoney || randombox_args->gotNeeded )
			{
				session.profile.money.game = randombox_args->moneyLeft;
				session.profile.experience += randombox_args->xp;
				LOGPRINT ( "%-20s " BOLD "%d\n", "TOTAL XP EARNED", randombox_args->xp );
				free ( randombox_args->needed );
				free ( randombox_args );
				return;
			}

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

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

			t_uid id;

			idh_generate_unique_id ( &id );
			idh_register ( &id, 0, _randombox_cb, randombox_args );

			send_stream_format ( session.wfs,
								 "<iq id='%s' to='masterserver@warface/%s' type='get'>"
								 "<query xmlns='urn:cryonline:k01'>"
								 "<shop_buy_multiple_offer supplier_id='1'>"
								 "%s"
								 "</shop_buy_multiple_offer>"
								 "</query>"
								 "</iq>",
								 &id, session.online.channel, offers );

			free ( offers );
		}
		else
		{
			switch ( error_code )
			{
				case 2:
					LOGPRINT ( KRED BOLD "Restricted purchase\n" );
					break;
				default:
					break;
			}
			session.profile.money.game = randombox_args->moneyLeft;
			session.profile.experience += randombox_args->xp;
			LOGPRINT ( "%-20s " BOLD "%d\n", "TOTAL XP EARNED", randombox_args->xp );
			free ( randombox_args->needed );
			free ( randombox_args );
		}
	}

	free ( data );

	return;
}