Photon.SocketServer.RPC

Options
Sergiy
Sergiy
edited May 2012 in Photon Server
Hi

The help file is describing Photon.SocketServer.RPC namespace, which has very helpful classes and methods like Peer.SetCurrentOperationHandler, Peer.OnDisconnectByOtherPeer, etc. However I noticed that you are not using these methods in your samples. Does it mean that one should avoid using them because they are deprecated/not recommended or are they safe to use?

..................
..................

Gents, any comment? I'm on hold waiting for your answer...... :)

Comments

  • Philip
    Options
    Hi Sergiy,

    this namspace evolved during the development of MMO - we still use it there. We also use it in a couple of internal projects specifically IOperationHandler, search for it in the forum you will see other comments like:
    viewtopic.php?f=5&t=1479

    The rpc.peer is a very thin wrapper around the standard peer - if you find it useful use it. As long as it is in our framework we will support it - if some day we deprecate it we'll provide it as source.
  • Sergiy
    Options
    Thanks for response, Philip

    I went through the MMO code and have couple of questions:

    1. Consider following code:
    public OperationResponse OperationEnterWorld(PeerBase peer, OperationRequest request, SendParameters sendParameters)
    {
                ...........................................................................
                var actor = new MmoActor(peer, world, interestArea);
                ...........................................................................
                ((Peer)peer).SetCurrentOperationHandler(actor);
                ...........................................................................
    }
    
    As I understand, after completing OperationEnterWorld method actor variable will be lost, so it cannot handle operations.... What is I'm missing?

    2. Suppose the peer is in Lobby and has himself as operation handler (just like in MMO example). Then peer enters the room and game logic assigns RoomOperationHandler to him. Suppose peer gets disconnected while being in room. Will OnDisconnect event arise only in RoomOperationHandler or also in peer?

    3. some sort of offtopic.... Consider following code:
    private void ExitWorld()
            {
                var worldExited = new WorldExited { WorldName = ((MmoWorld)this.World).Name };
                this.Dispose();
    
                // set initial handler
                ((MmoPeer)this.Peer).SetCurrentOperationHandler((MmoPeer)this.Peer);
    
                var eventData = new EventData((byte)EventCode.WorldExited, worldExited);
    
                // use item channel to ensure that this event arrives in correct order with move/subscribe events
                this.Peer.SendEvent(eventData, new SendParameters { ChannelId = Settings.ItemEventChannel });
            }
    
    I always thought that one should place Dispose() call at the end of the method, because any code after that may not be executed.... ??
  • Sergiy
    Options
    Gents......

    Any comment? :roll:
  • Philip
    Options
    Re 1. the instance is not "lost" or destroyed because it is registered as callback and .net "knows" that.

    Re 2. setting the operationhandler again will replace the old one. See code:
    public void SetCurrentOperationHandler(IOperationHandler operationHandler)
            {
                if (operationHandler == null)
                {
                    operationHandler = OperationHandlerDisabled.Instance;
                }
    
                if (log.IsDebugEnabled)
                {
                    string currentHanderType = this.CurrentOperationHandler == null ? "{null}" : this.CurrentOperationHandler.GetType().ToString();
                    string newHandlerType = operationHandler == null ? "{null}" : operationHandler.GetType().ToString(); 
    
                    log.DebugFormat(
                        "set operation handler to {0}, was {1} - peer id {2}", 
                        newHandlerType, 
                        currentHanderType, 
                        this.ConnectionId);
                }
    
                this.CurrentOperationHandler = operationHandler;
            }
    
  • Philip
    Options
    Re 3. the dispose is "just a cleanup-routine" so in general you are right after calling dispose on an instance you shouldn't use that instance anymore.
    But in this case we are calling it from within the instance as part of our own cleanup.
  • Sergiy
    Options
    Thanks for answer, Philip.

    I guess I'll move Dispose() call to the end of the method.

    Everything clear. Thanks again