Event from the server to a single client

zoultrex
zoultrex
edited November 2010 in Photon Server
Why is that when I use the code below to send a message from photon only and directly to the Item I want it happens exactly the opposite?
var eventInstance = new Damage { ItemId = this.Id, ItemType = this.Type, Ammount = 1 };
var message = new ItemEventMessage(this, eventInstance.GetEventData((byte)EventCode.Damage, Reliability.Reliable, Settings.ItemEventChannel));
this.EventChannel.Publish(message);

This code is called from within the MmoItem class, and I was hoping that It would reach just this client, but what is happening is that when this message is sent, the client does not receive it, but all other clients connected receive a message from this item, what I wanted is the oposite, no one else but this item that I am using the send the message that would receive.

This may have sounded confusing, let me know if its not clear :lol:

Comments

  • I was able to make the Item that never received the message to also receive it, I made it subscribe to its own interest area, but I dont know if thats a good idea, there is a lot of info going on there that I dont want it to be exposed, also I think that this increase the data that the server sends right?
  • A quick explanation why the owner of the item does not receive the event:
    The item event channel is automatically subscribed by interest areas when the item appears in it's view radius. But at the same time Interest areas ignore the item they are attached to.
    EnterWorld creates an avatar Item and attaches an interest area to the item.
    If you detached the interest area you would receive your own events the same way every other subscribed client does.

    If you want to send the event just to the Item owner and to no body else use the following code:
    var eventInstance = new Damage { ItemId = this.Id, ItemType = this.Type, Ammount = 1 };
    var eventData = eventInstance.GetEventData((byte)EventCode.Damage, Reliability.Reliable, Settings.ItemEventChannel);
    this.Owner.Peer.PublishEvent(eventData);
    
  • zoultrex wrote:
    I was able to make the Item that never received the message to also receive it, I made it subscribe to its own interest area, but I dont know if thats a good idea, there is a lot of info going on there that I dont want it to be exposed, also I think that this increase the data that the server sends right?
    I hope my last post answered this as well
  • Yep you did, as always saving my life =)

    TBH I tried this before but I was failing to convert the itemEventMessage to EventMessage, that actually are 2 different classes so thats why the error.
  • Well now that made me think... is there a way to send an event broadcasted to all,
    since if an event is sent as an itemEvent and the item is used to publish the message, this message will reach everyone but the client
    and in the other hand if an event is sent as an EventData using the Peer it will reach only the client that is the peer owner.

    Is there a way to do both in one message?
    I think that this would have no impact on data traffic right? Since the number of outgoing messages will be the same, lets say there are 10 clients in total, 1 message has to be split in 9 different ways to reach those 9 clients, then another one goes to only 1, it is 10 sent messages anyway right?
    Same way if there would be a broadcast to all, it would be one message that would have to be split in 10 ways to reach all 10 clients.
  • not really, the owner would have to subscribe to his own item - but then he receives all events, not just a few.
    you can use the same EventData object though:
    var eventData = eventInstance.GetEventData((byte)EventCode.Damage, Reliability.Reliable, Settings.ItemEventChannel);
    this.Owner.Peer.PublishEvent(eventData);
    this.EventChannel.Publish(new ItemEventMessage(this, eventData));