Pun 2 RemoveFromRoomCache for only local player

Options
Hi team,
I would like to clear the received event for only the local player when in case of disconnection and he is reconnected but I don't want him to receive the old events which are already executed.
I tried the following method when I receive and execute the event, but it looks like it clears the event for all the players.
 RaiseEvent(photonEvent.Code, photonEvent.CustomData, new RaiseEventOptions()
                        {
                            CachingOption = EventCaching.RemoveFromRoomCache,
                            TargetActors = new int[] { PhotonNetwork.LocalPlayer.ActorNumber }
                        });

What is the correct suggested approach to using "RemoveFromRoomCache"?

Comments

  • Sathyaraj
    Sathyaraj
    edited June 2020
    Options
    [Edit]
    Here is the CachingOption used.
    new RaiseEventOptions() { CachingOption = EventCaching.AddToRoomCache, Receivers = ReceiverGroup.All }
    

    I am trying to use just object<T> in customData. Does that affect how the filter works? Somewhere I read it works only if hashtables are used

    tried the following as well with no luck
    RaiseEvent(0, (Hashtable)photonEvent.CustomData, new RaiseEventOptions()
                            {
                                CachingOption = EventCaching.RemoveFromRoomCache,
                            });
    
    If a player gets reconnected old events are fired again.

    here is the common RaiseEvent method
     public void RaiseEvent(byte eventCode, object content, RaiseEventOptions options)
        {
                  Hashtable hash = new Hashtable() { { "data", content } };
            PhotonNetwork.RaiseEvent(eventCode, hash, options, SendOptions.SendReliable);
            PhotonNetwork.SendAllOutgoingCommands();
        }
    
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @Sathyaraj,

    Unfortunately you cannot remove cached events based on the receiving actor.
    RaiseEvent(photonEvent.Code, photonEvent.CustomData, new RaiseEventOptions()
                            {
                                CachingOption = EventCaching.RemoveFromRoomCache,
                                TargetActors = new int[] { PhotonNetwork.LocalPlayer.ActorNumber }
                            });
    
    What you have tried here is removing all events that are cached (raised/sent) by the local actor.
    I don't want him to receive the old events which are already executed
    So if you want to achieve this you could:

    - make each even unique (assign auto increment event ID?) or add meta data to event payload, anything to be able to identify received events
    - locally store (client cache, file or memory) information of already processed events (last processed event ID for example)
    - when an event is received, check if it's already processed or not, if it's already processed ignore it

    About what data types/structures that can be used as filters, I will have to check if we support other types than Hashtable.
  • Sathyaraj
    Sathyaraj
    edited June 2020
    Options
    @JohnTube
                        string data = (string)((Hashtable)photonEvent.CustomData)["data"];
                        string time = (string)((Hashtable)photonEvent.CustomData)["time"];
    
                        string eventStr = $"{photonEvent.Code}{photonEvent.Sender}{time}";
                        if (!_receievedEvents.Contains(eventStr))
                        {
                            _receievedEvents.Add(eventStr);
                            //TODO: Process event
                        }
    

    This crude method works as expected. But hoping to find a better-optimized solution from experts.
    Did anyone go through such use case?
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    I think the solution is fine.
  • nilesh123shripal
    edited May 2021
    Options
    Hello Sathyaraj, I'm also facing the same problem.
    Please tell me how do you solved it with code.

    thanks
  • Sathyaraj
    Options
    Hello Sathyaraj, I'm also facing the same problem.
    Please tell me how do you solved it with code.

    thanks

    Use the following line in OnEvent method to cache it in a list. Clear it when the game is over.
    HashSet<string> _receievedEvents = new HashSet<string>();

    //inside OnEvent
    string data = (string)((Hashtable)photonEvent.CustomData)["data"];
    string time = (string)((Hashtable)photonEvent.CustomData)["time"];

    string eventStr = $"{photonEvent.Code}{photonEvent.Sender}{time}";
    if (!_receievedEvents.Contains(eventStr))
    {
    _receievedEvents.Add(eventStr);
    //TODO: Process event
    }