[ejabberd] how to pass custom messages to one of the clients in a chat

Abhishek Ranjan abhishek at blacklightsw.com
Fri May 26 14:03:26 MSK 2017

Thank you for the reply but no probably I didn't asked clearly, sorry my bad. here is what I have done.

I have a source code written in erlang for a simple tic-tac-toe game.I then used Pidgin IM client to set up a Instant Messaging system between two users.

A basic tic-tac-toe game can be seen as 3x3 matrix as [a1,a2,a3
and I have maintained this as a game state in a list as [a1,a2,a3,b1,b2,b3,c1,c2,c3]
users can send only messages like a1,a2,c3,b3 etc and hence the game state keeps on changing till a user wins.

I have copied the erl files of the game in to the lib/ejabberd/ebin folder of ejabberd and I have made a hook tic_hook.erl using user_send_packet and written a code in the tic_hook.erl such that when a user1 sends a message(in the form a1,a2,b3 etc) I can see the output of the game on ejabberd live. same for the user2 when he responds to the chat. So far no problems everything worked good.

But under this arrangement since only I have a access to ejabberd live only i can see the output of the game on ejabberd live and also the game state [a1,a2,a3,b1,b2,b3,c1,c2,c3] can only be seen by me only an

And the user keeps on getting the messages and receiving them like simple b3,c2 etc.
But I also want to send the game state to the second user after the first user has sent a message say "b3" then game state would be [a1,a2,a3,b1,b2, o,c1,c2,c3].

So along with the message "b3" i also wanted to send the state [a1,a2,a3,b1,b2, o,c1,c2,c3] so that the second user can see the remaining places where he can place his moves.

So I started looking for the message "b3" in the message stanza and found it inside
message stanza->body->text->"b3"

and hence I was asking for a way so that I can also place the game state here too if possible(allowed by xmpp and ejabberd).

Best regards,

> On May 26, 2017 at 4:01 PM Badlop <badlop at gmail.com> wrote:
> Do you mean, how a client can add to the Message stanza additional
> information for the destination client?
> <message id='15:593671' type='chat' to='user2 at localhost/tka'>
> <body>new move</body>
> <tic xmlns='urn:xmpp:tictatoe' current='J8'/>
> </message>
> In your case, maybe you want to use subelements of Tic, instead of an attribute.
> <message id='15:593671' type='chat' to='user2 at localhost/tka'>
> <body>new move</body>
> <tic xmlns='urn:xmpp:tictatoe'>
> <move order='1' player='1' position='J8'/>
> <move order='2' player='2' position='A3'/>
> <move order='3' player='1' position='C1'/>
> </tic>
> </message>
> ---
> Badlop
> ProcessOne
> On 25 May 2017 at 10:13, Abhishek Ranjan <abhishek at blacklightsw.com> wrote:
> > Hi,
> >
> > I have placed the erlang code of a simple tic-tac-toe game inside ejabberd,
> > and
> >
> > I have made a set up using ejabberd and Pidgin where when user sends a
> > message to the the other user in an xmpp chat I can see the game running in
> > ejabberd live. But under this scenario the other user is just getting the
> > message sent by the first user and nothing else. I wanted to send the
> > receiving user with game state like a list or tuple also along with the
> > message on Pidgin.
> >
> > what I have found till now is that the xmpp message stanza has a body
> > attribute and a text attribute where the simple message sent by any user is
> > present.
> >
> > But how can I inject a custom list or a tuple there to send it to the other
> > user so that he can also see the game's state.
> >
> >
> > Regards,
> >
> > Abhishek
> >
> >
> > _______________________________________________
> > ejabberd mailing list
> > ejabberd at jabber.ru
> > http://lists.jabber.ru/mailman/listinfo/ejabberd
> >
> _______________________________________________
> ejabberd mailing list
> ejabberd at jabber.ru
> http://lists.jabber.ru/mailman/listinfo/ejabberd
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.jabber.ru/pipermail/ejabberd/attachments/20170526/5c11f6bd/attachment.html>

More information about the ejabberd mailing list