Samples

Basic

Connecting

using GGSharp;
(...)
GG mojeGadu = new GG();
mojeGadu.Number = 6666666;
mojeGadu.Password = "secret";
mojeGadu.Show = ShowType.AvailableDescription;
mojeGadu.ShowDescription = "My new, better description";
//Here insert EventHadlers
mojeGadu.Login();

Changing status

mojeGadu.SendPresence(ShowType.BusyDescription, "My newer, better description");

Sending message

mojeGadu.Send(new GGSharp.Packets.MessagePacket(454354, "Text"));

Receiving message

mojeGadu.MessageReceived += new GG.MessageReceivedDelegate(mojeGadu_MessageReceived);

Receiving presence

mojeGadu.PresenceReceived += new GG.PresenceReceivedDelegate(mojeGadu_PresenceReceived);

Event handlers

OnLogin

mojeGadu.LoggedIn += new EventHandler(mojeGadu_LoggedIn);
(...)
void mojeGadu_LoggedIn(object sender, EventArgs e) { }

OnPacketReceived

mojeGadu.PacketReceived += new GGReceiver.PacketReceivedDelegate(Receiver_PacketReceived);
(...)
void Receiver_PacketReceived(object sender, GGSharp.Packets.HeaderPacket packet) { }

OnPacketSent

mojeGadu.PacketSent += new GGSender.PacketSentDelegate(Sender_PacketSent);
(...)
void Sender_PacketSent(object sender, GGSharp.Packets.HeaderPacket packet) { }

Sending our user list to server so that we can receive status notifications

You must send your list to the server after login, otherwise the server will not respond to any other commands and disconnect us after 5min

AutoNotifyServer

You can use autoserver notifying. in order to do that you need to fiil up UserList with your contacts before logging in and left AutoServerNotify left set to true
mojeGadu.UserList.Add(new GGContact() { Number = 666666 });
///(...)
mojeGadu.Login();
Or you can do this on your own
mojeGadu.UserList.AutoServerNotify = false;
///(...)
mojeGadu.Login();
///(...)
mojeGadu.UserList.NotifyServer();
After you notify server once you must not do that again. It won't work. In order to add or remove contacts later you must use this:
///Adding
mojeGadu.UserList.NotifyServer(new GGSharp.Structures.NotifyStruct(5435445));
///Removing
mojeGadu.UserList.NotifyServerRemove(new GGSharp.Structures.NotifyStruct(5435445));

Managing user list

Importing from server

mojeGadu.UserList.UserListImported += new EventHandler(UserList_UserListImported);
mojeGadu.UserList.ImportFromServer();
(...)
void UserList_UserListImported(object sender, EventArgs e)
{
    foreach (GGSharp.GGContact contact in mojeGadu.UserList)
    {
        //do sth
    }
}

Exporting to server

mojeGadu.UserList.Add(new GGContact());
mojeGadu.UserList.ExportToServer();

Last edited Feb 1, 2009 at 6:17 PM by dra9ula, version 6

Comments

No comments yet.