Just a small tutorial to guide you through the first steps …
Connecting
xfirelib::Client *client = new xfirelib::Client();
client->connect("username","password");
client->addPacketListener( new MyOwnXFirePacketListener() );
This will allow you to log into an xfire account. after this you should be able to send
and receive packets.
Listener
xfirelib uses a event/listener approach to let you know of new packets. so you need to
subclass PacketListener:
class MyOwnXFirePacketListener : public xfirelib::PacketListener {
virtual void receivedPacket( xfirelib::XFirePacket *packet );
};
an implementation might look like:
void MyOwnXFirePacketListener::receivedPacket( xfirelib::XFirePacket *packet ) {
// First retrieve the packet content ...
xfirelib::XFirePacketContent *content = packet->getContent(); // Now see what kind of packet it actually is...switch(content->getPacketId()) {
case XFIRE_MESSAGE_ID:
// we got a message.. but by whom ? let's look into our buddylist
xfirelib::BuddyListEntry buddy = client->getBuddyList()->getBuddyBySid( ((xfirelib::MessagePacket*)content)->getSid() );
std::cout << "Hey cool, we got a message from " <<
buddy->username << endl;
break;
}
}
Sending Packets
To send xfire packets you simply create a new packet content packet and send it through
your client object. e.g. if you want to send a message you can use the
SendMessagePacket:
SendMessagePacket msg;
// msg.init is a convenience method which will convert the username to a sid for you// (since a message requires a sid as target, not a username)
msg.init(client, "username", "Hi, how are you ? :)" );
client->send( &msg );