Making sense of multiple packets containing dup data

I’m currently working on a query app for Battlefield 2142 and I’m
running into some troubles when I’m receiving multiple UDP packets from
a server. When there’s only one packet, I can decipher it without much
trouble, as it’s rather predictable. However, when the data has to
arrive in multiple packets things get much tougher, here’s why:

  • If it’s at the end of one packet and in the midst of transferring a
    piece of data (e.g. a player’s ID, a player’s name, etc) it will
    re-write that entire piece of data in the next packet, even the part
    that was previously written in the last packet.

  • Different parts of the packet are categorized, e.g. players_ precedes
    all of the player names, scores_ precedes player scores, etc. However,
    if it’s in the midst of reporting players_ at the end of a packet, it
    will re-write players_ again at the start of the next packet. This tends
    to make it difficult for me to have a pattern for parsing the packets as
    they can vary a bit between each query.

I’ve tossed together a basic script to query several servers and output
the results so you can see what it looks like when there’s varying
amounts of packets:

http://pastie.org/539099.txt

I’ve only been programming for a few days, so excuse any terrible coding
practices in there :wink:

Any assistance would be tremendously appreciated!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs