Skip to content

Commit

Permalink
Factorized join_channel and switch_channel
Browse files Browse the repository at this point in the history
  • Loading branch information
Levak committed May 20, 2015
1 parent 7966dc4 commit d92f8fa
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 23 deletions.
2 changes: 1 addition & 1 deletion include/wb_xmpp_wf.h
Expand Up @@ -38,7 +38,7 @@ void xmpp_iq_create_profile(void);
void xmpp_iq_confirm_notification(const char *notif);
void xmpp_iq_get_account_profiles(void);
void xmpp_iq_get_master_server(const char *channel);
void xmpp_iq_join_channel(void);
void xmpp_iq_join_channel(const char *channel);
void xmpp_iq_peer_status_update(const char *to_jid);
void xmpp_promote_room_master(const char *nickname);
void xmpp_iq_player_status(int status);
Expand Down
2 changes: 1 addition & 1 deletion src/xmpp_wf/get/xmpp_iq_get_account_profiles.c
Expand Up @@ -45,7 +45,7 @@ static void xmpp_iq_get_account_profiles_cb(const char *msg)
if (!session.profile_id)
xmpp_iq_create_profile();
else
xmpp_iq_join_channel();
xmpp_iq_join_channel(NULL);
}

void xmpp_iq_get_account_profiles(void)
Expand Down
13 changes: 10 additions & 3 deletions src/xmpp_wf/get/xmpp_iq_join_channel.c
Expand Up @@ -71,23 +71,30 @@ static void xmpp_iq_join_channel_cb(const char *msg)
xmpp_iq_player_status(STATUS_ONLINE | STATUS_LOBBY);
}

void xmpp_iq_join_channel(void)
void xmpp_iq_join_channel(const char *channel)
{
int is_switch = session.channel != NULL;
t_uid id;

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

if (channel != NULL)
{
free(session.channel);
session.channel = strdup(channel);
}

/* Join CryOnline channel */
send_stream_format(session.wfs,
"<iq id='%s' to='k01.warface' type='get'>"
"<query xmlns='urn:cryonline:k01'>"
"<join_channel version='" GAME_VERSION "' token='%s'"
"<%s_channel version='" GAME_VERSION "' token='%s'"
" profile_id='%s' user_id='%s' resource='%s'"
" user_data='' hw_id='' build_type='--release'/>"
"</query>"
"</iq>",
&id,
&id, is_switch ? "switch" : "join",
session.active_token, session.profile_id,
session.online_id, session.channel);
}
20 changes: 2 additions & 18 deletions src/xmpp_wf/result/xmpp_iq_invitation_request.c
Expand Up @@ -50,21 +50,7 @@ static void xmpp_iq_invitation_request_cb(const char *msg_id, const char *msg)
{
/* 1. Change channel if invitation was not on the same server */
if (strcmp(session.channel, resource))
{
send_stream_format(session.wfs,
"<iq to='k01.warface' id='switch_1' type='get'>"
"<query xmlns='urn:cryonline:k01'>"
"<switch_channel "
" version='" GAME_VERSION "'"
" token='%s' profile_id='%s'"
" user_id='%s' resource='%s'"
" user_data='' hw_id=''"
" build_type='--release'/>"
"</query>"
"</iq>",
session.active_token, session.profile_id,
session.online_id, resource);
}
xmpp_iq_join_channel(resource);

/* 2. Confirm invitation */
send_stream_format(session.wfs,
Expand All @@ -91,9 +77,7 @@ static void xmpp_iq_invitation_request_cb(const char *msg_id, const char *msg)
free(server);
free(ticket);
free(room);

free(session.channel);
session.channel = resource;
free(resource);

free(session.group_id);
session.group_id = group;
Expand Down

0 comments on commit d92f8fa

Please sign in to comment.