Not logged in. · Lost password · Register
Forum: agsXMPP SDK Support RSS
Avatar
VTXMaster #1
Member since Apr 2006 · 4 posts · Location: Australia
Group memberships: Members
Show profile · Link to this post
Subject: MessageType... can I add more?
Hi, this is my first post on this forum.

The agsXMPP library is excellent - I have just written my own (bot) client using these libraries and it works great!

My question is related to the types of messages that can be sent / received.

The enum MessageType provides normal, error, chat, groupchat and headline.
Is it possible to add new types, or are these fixed within the XMPP xml schema?

The reason I ask is because I am writing a simple game and I want to be able to send through structured xml to the client (not just chat data).
I can always embed the xml within the chat body but that seems a bit ummm not so right. Ideally I would like to add a new type, that only my clients would recognise and process.

Thanks for your help,  :-)
Daniel
Avatar
Jabberer #2
Member since Feb 2006 · 249 posts
Group memberships: Members
Show profile · Link to this post
Hi Daniel,

yes there is a XML Schema, and adding other message types would violate against the XMPP specs.
But the solution is very easy. Create your own packets with your own namespace and add them as child to the message element.

Example:
  1. <message type="normal" to="..." from="...">
  2.  <game xmlns="game:daniel:xxx">
  3.      <data>...</data>
  4.  </game>
  5. </message>

you can create your own agsXMPP Element classes for game and register them in the ElementFactory. If you do it this way then you don't violate against the XMPP specs, and you don't break existing jabber clients. They will just ignore your messages if you they don't know your custom XMPP extension. You don't need the body at all.
Software Developer
AG-Software
Avatar
VTXMaster #3
Member since Apr 2006 · 4 posts · Location: Australia
Group memberships: Members
Show profile · Link to this post
Makes sense. I'll give it a go, and thanks for your quick response.

Daniel
Avatar
Jabberer #4
Member since Feb 2006 · 249 posts
Group memberships: Members
Show profile · Link to this post
Hello,

let us know if you have problems with creating your own packet types. Once you have them created and registered in the Factory it's very handy and easy to use.

e.g in your OnMessageHandler you just check then

  1. if (msg.HasTag(typeof(myPacket))
  2. {
  3.     // handle your packet/extension
  4. }
Software Developer
AG-Software
Avatar
VTXMaster #5
Member since Apr 2006 · 4 posts · Location: Australia
Group memberships: Members
Show profile · Link to this post
Almost!?

When creating the new XmppPacket class, is it best to derive from the Message class so
that all the structure is there, and set the Type to Normal, and just add some extra tags?

The problem I have is that I created a new class and can send it ok, but I have obviously lost the...

<message type="normal" to="..." from="...">

And the server kicks me immediately, which I guess is justified!

I am probably missing something obvious but I am very new to c# .net and developing communication stuff.
Any help is greatly appreciated.

Daniel
Avatar
VTXMaster #6
Member since Apr 2006 · 4 posts · Location: Australia
Group memberships: Members
Show profile · Link to this post
I seem to have it working.

My class definition is.

public class TSMessage : Message
{
    public TSMessage()
    {
        this.Type=MessageType.normal;
        this.RequestType="Nothing";
    }
   
    public string RequestType
    {
        set { SetTag("requesttype", value, "tsconsole.tsrequest"); }
        get { return GetTag("requesttype"); }
    }
}

And the resulting XML is...

<message xmlns="jabber:client" to="daniel@daniel.hm/Spark"><requesttype xmlns="tsconsole.tsrequest">TestTSRequest1234</requesttype></message>

(I realise its being sent to the Spark client and will be ignored.)

Is this all correct? Thank you.

Daniel
Avatar
Alex #7
Member since Feb 2003 · 4245 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Hello,

yes this looks correct. Using Message as a base class is OK. If your own tags are small and dont have many children then this will be fine. If you own Tags are more complex then i woud create new classes for your custom extensions, and make them accessible in your derived message class.

Alex
Alexander Gnauck
AG-Software
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Forum: agsXMPP SDK Support RSS