SendPrivateMessage

Post here all your questions related with SmartFoxServer .Net/Unity3D API

Moderators: Lapo, Bax

Asynth
Posts: 2
Joined: 30 Jun 2010, 14:47

SendPrivateMessage

Postby Asynth » 30 Jun 2010, 14:58

Hello,

I would like to know why OnPrivateMessage event doest not fired event I send the message to myself.

Here is the code :

// ----- ChatController.cs

private void SendChatMessage(String message)
{
SmartFoxClient client = NetworkController.GetClient();
client.SendPrivateMessage(message, client.myUserId);
}

// ----- NetworkController.cs

private void SubscribeEvents()
{
...
SFSEvent.onPrivateMessage += OnPrivateMessage;
}

public void OnPrivateMessage(string message, User sender, int roomId, int userId)
{
Debug.Log("User " + sender.GetName() + " sent the following private message: " + message);
}
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 30 Jun 2010, 17:52

If I recall, then the server filters private messages so you dont get a copy yourself (as sender).

There are various other commands that do the same - where you cannot send these things to yourself.
Asynth
Posts: 2
Joined: 30 Jun 2010, 14:47

Postby Asynth » 01 Jul 2010, 13:33

In fact, even I send the massage to another user in the room, the event OnPrivateMessage is not triggered. Is there a tool that I can track these messages from console or a tool?

Thanks.
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 01 Aug 2010, 13:31

Found a bug in the API.

Replace in SmartFoxClient.cs with this

Code: Select all

                    case SFSEvent.onPrivateMessageEvent:
                        if (SFSEvent.onPrivateMessage != null)
                        {
                            SFSEvent.onPrivateMessage((string)evt.GetParameter("message"), (User)evt.GetParameter("sender"), (int)evt.GetParameter("roomId"), (int)evt.GetParameter("userId"));


and private messages should work.

Will be added to next API release
matrix211v1
Posts: 61
Joined: 16 Jan 2009, 14:48

Same Issue

Postby matrix211v1 » 22 Aug 2010, 16:16

The code you said to paste seems to already be exactly in the SmartFoxClient.cs file already.

What else should I look for?

Thanks!

EDIT
A followup test shows that the:

Code: Select all

    public void OnPrivateMessage(string message, User sender, int roomId, int userId)
    {
        Debug.Log("sender" + sender.GetId());
        Debug.Log("userId" + userId);
    }


Both sender and userID are the same one that sent the message. Even if I hardcode it such as:

Code: Select all

    // Send the chat message to all other users
    public void SendPrivateMsg(string message, int SFSUserID)
    {
        SmartFoxClient client = NetworkController.GetClient();
        client.SendPrivateMessage(message, 0);
    }


Both sender and userID will be whatever number the sender is (in my case 7)

Hope this helps solve it!
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 22 Aug 2010, 19:51

In my head version of the API that fix was not there - subtle diffrerence which made it work on my end.

Not sure why you already had/have it. The previous code failed totally with a wrong cast - so thats why it was never triggered.

/Thomas
matrix211v1
Posts: 61
Joined: 16 Jan 2009, 14:48

Same Issue

Postby matrix211v1 » 22 Aug 2010, 22:49

That fine.

But why is it still not showing the receiver id?

Return to “.Net / Unity3D API”

Who is online

Users browsing this forum: No registered users and 16 guests