Click or drag to resize

BuddyMessageRequest Class

Sends a message to a buddy in the current user's buddies list.
Inheritance Hierarchy
SystemObject
  BaseRequest
    GenericMessageRequest
      Sfs2X.Requests.BuddylistBuddyMessageRequest

Namespace:  Sfs2X.Requests.Buddylist
Assembly:  SmartFox2X (in SmartFox2X.dll) Version: 1.8.0.0 (1.8.0)
Syntax
C#
public class BuddyMessageRequest : GenericMessageRequest
Constructors
  NameDescription
Public methodBuddyMessageRequest(String, Buddy)
See BuddyMessageRequest(String, Buddy, ISFSObject) constructor.
Public methodBuddyMessageRequest(String, Buddy, ISFSObject)
Creates a new BuddyMessageRequest instance.
Top
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:
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"]);     // UWP
    }
    else
    {
        Console.WriteLine(buddy.Name + " said: " + (string)evt.Params["message"]);                      // .Net / Unity
        System.Diagnostics.Debug.WriteLine(buddy.Name + " said: " + (string)evt.Params["message"]);     // UWP
    }
}
See Also