Sends a message to a buddy in the current user's buddies list.

Namespace: Sfs2X.Requests.Buddylist
Assembly: SmartFox2X (in SmartFox2X.dll) Version: 1.7.3.0 (1.7.3)

Syntax

C#
public class BuddyMessageRequest : GenericMessageRequest

Remarks

Messages sent to buddies using the BuddyMessageRequest request are similar to the standard private messages (see the PrivateMessageRequest request) but are specifically designed for the Buddy List system: they don't require any Room parameter, nor they require that users joined a Room. Additionally, buddy messages are subject to specific validation, such as making sure that the recipient is in the sender's buddies list and the sender is not blocked by the recipient.

If the operation is successful, a BUDDY_MESSAGE event is dispatched in both the sender and recipient clients.

This request can be sent if the Buddy List system was previously initialized only (see the InitBuddyListRequest request description).

Examples

The following example sends a message to a buddy and handles the related event:
 Copy imageCopy
void SomeMethod() {
    sfs.AddEventListener(SFSBuddyEvent.BUDDY_MESSAGE, OnBuddyMessage);
    // Obtain the recipient of the message
    Buddy kermitTheFrog = sfs.BuddyListManager.GetBuddyByName("KermitTheFrog");
    // Block a buddy in the current buddy list
    sfs.Send(new BuddyMessageRequest("Hello Kermit!", kermitTheFrog));
}
void OnBuddyMessage(BaseEvent evt) {
    bool isItMe = (bool)evt.Params["isItMe"];
    Buddy buddy = (Buddy)evt.Params["buddy"];
    if (isItMe)
    {
        Console.WriteLine("I said: " + (string)evt.Params["message"]);                      // .Net / Unity
        System.Diagnostics.Debug.WriteLine("I said: " + (string)evt.Params["message"]);     // Windows Universal
    }
    else
    {
        Console.WriteLine(buddy.Name + " said: " + (string)evt.Params["message"]);                      // .Net / Unity
        System.Diagnostics.Debug.WriteLine(buddy.Name + " said: " + (string)evt.Params["message"]);     // Windows Universal
    }
}

Inheritance Hierarchy

System..::..Object
  BaseRequest
    GenericMessageRequest
      Sfs2X.Requests.Buddylist..::..BuddyMessageRequest

See Also