adding extra data or attributes

L.J. Ruell
2001-09-26
2003-07-31
  • L.J. Ruell

    L.J. Ruell - 2001-09-26

    Hi all,

    I have been badgering Alon for tips with the flash client. My most pressing question was about adding some extra info for a graphical flash chat (like haircolor or eye color or things of that nature). Here is the question I asked...

        "Now the questions! Up until I found your chat I was building off of
    Colin
    Moocks simple chat client/server (www.moock.org), which is an ecellent
    tutorial, its very bare bones. no rooms, no private message, no user
    list..it just takes the text and makes xml/ sends it to the java server/java

    server boradcasts it back out to everyone and anyone who will listen. super
    simple...its lacking alot of the more advanced features. BUT....

        one of the great things about it (its simplicity), is how it writes
    the xml
    like this sort of..

    <name>Ponypower</name><message>hi, what fun chatting on the
    internet!!!</message>.

    So with not alot of work I was able to add some stuff right in there just
    before the client sends its message out like..

    name>Ponypower</name><hair_c>red</hair_c><hair_s>2</hair_s><eye_c>blue</eye_
    c><message>hi,
    what fun chatting on the internet!!!</message>

    some character attributes the user can set on log in..they get sent every
    time and broadcast with the message...the flash pulls apart all the nodes
    and creates a new little character icon of the user who sent the message on
    all clients.

    I'm looking and looking and looking....NFCchat is just too dang complicated
    for me to see my way thru....is there ANY simple way to get do something
    like this in NFC? would the server get angry if I just slipped some
    attributes in with the message? I'm assuming yeah... "

    Alon's answer should follow, we decided to post both the question and the answer in the forum here in case others had similar questions.

    thanks,

      l.j. ruell

     
    • Alon Salant

      Alon Salant - 2001-09-27

      Thanks LJ,

        To answer you questions about adding information to the chat messages, I have a couple comments.

        First, in order to make the nfc chat server work for flash I had to make it send and receive XML. There were two options
        I could see:

        1. Change the message format to send XML formatted messages (like the ones you describe below)
        2. Wrap the existing messages in a simple XML wrapper and parse the original message format
        I chose the latter as it was far less work and allows Taso, who maintains the chat server, to continue adding features
        without having to worry about the extensions I added to support flash.

        So the question is now how to add more information to the nfc server messages.

        It looks like you want to pass more information about the user than just their name which is different from adding new
        message types (like a game move, or sending a url). I mention this b/c the server architecture easily supports adding new
        message types. It does require writing a java class that inplements the message type interface and registering it with a
        properties file.  Just thinking about that, you could create a new message type that is a request for detailed user
        information and one that is the response. So from the flash you could request the detailed info for each user that the flash
        client knows about and then store it in the client to use when rending the UI. You would have to add handlers to the
        nfcEngine to support the new message types.

        It sounds like this is more than you want to get in to.

        You ask if you can sneak attributes in to the message and the answer is absolutely. I will preface what follows with the
        comment that if you think the additional bit of user info would be valuable to other users of the chat server, send a request
        to Taso to add those features. What follows is definitely a hack but it can be done without modifying the server at all.

        The nfc server uses a tab as the delimiter between the different parts of the messages sent by the server. You would have
        to use something else and make sure to handle the case where users type in that character. Since you are actually looking
        to include more information about the user, I'd actually include that as part of the username.

        It helps to understand the messages that the server sends:

        (In these lines, \t is a tab character)

        In the regular chat server a signon message looks like:

        /signon\t<username>

        A request for a list of users looks like:

        /users

        The response looks like:

        /users\t<uername1>\t<username2>\t..\t<usernameN>

        The nfcEngine.swf handles these messages and calls the appropriate handler methods in first the engine and then the
        nfcUI.swf (some don't make it to the UI and are handled only in the engine). It also wraps and unwraps them in a silly xml
        wrapper. So the messages on the flash chat server look more like:

        <message value="/users" />

        And the response looks like:

        <message value="/users\t<uername1>\t<username2>\t..\t<usernameN>" />

        The hack I would suggest is to include more info in the username and then parse that before displaying the username. So I
        might signon like

        /signon\talon:blue:red

        So usernames would include this info.

        You might have better luck handling special character and adding additional information if you used URL encoding of
        name=value pairs:

        /signon\tname=alon&hair=blonde&eyes=blue

        There's a encode function in flash somewhere that will URL encode the values for you. You'd then have to break the
        username sent by the server apart to have access the the values.

      This does raise an interesting point, and possibly a gotcha. If you are connecting to a server that different clients are
        using, your special username will not be parsed by other clients and will just show up as one ugly string. This isn't an
        issue for ajdigital.com as far as I'm concerned b/c it's there for experimentation, but it would matter if you wanted to
        distribute your client for other nfc servers.

      Alon

       
    • Tom Kiss

      Tom Kiss - 2003-07-31

      I wanted to add a small user flag in the users list, to display thier country flag and, look nice.

      I have very little experience with Java, so tinkering is out of the question and I am refined to using actionscript.

      I attached the country as a 3 digit abbreviation to the user name when they login, so their username for great britain rould be:
      gbr_tonynibbles.

      For the chat, user list and everything which displays thier username, I simply remove the first 4 characters.
      But the user list looks nice with a flag next to each persons name and so far, it seems to work fine.

       

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks