Why does OnOperationRequest need to have a peer passed in?

afuzzyllama
edited March 2012 in Photon Server
Why does the function:
public OperationResponse OnOperationRequest(PeerBase peer, OperationRequest operationRequest, SendParameters sendParameters)
need to have a peer passed in? It isn't a static class, so shouldn't the function realize that it is referencing itself? It seems when you want to manipulate the instance, you are manipulating the peer which could just be represented by this?

Am I missing something here?

Comments

  • You are looking at a method of IOperationHandler
    namespace Photon.SocketServer.Rpc
    {
        ...
        public interface IOperationHandler
        {
        ...
            OperationResponse OnOperationRequest(PeerBase peer, OperationRequest operationRequest, SendParameters sendParameters);
    

    an interface you may use to implement a state pattern based peer/operationhandler. We use it in a couple of our own projects and the mmo project you probably are looking into.

    The use/implementation of this interface is optional - see for instance the Lite demo code, where it's not used.
    namespace Lite
    {
    ...
        public class LitePeer : PeerBase
        {
        ...
            protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
            {
                if (log.IsDebugEnabled)
                {
                    log.DebugFormat("OnOperationRequest. Code={0}", operationRequest.OperationCode);
                }
    
                switch ((OperationCode)operationRequest.OperationCode)
                {
                    case OperationCode.Ping:
                        this.HandlePingOperation(operationRequest, sendParameters);
                        return;
             ...
    

    In dragagon's CJR gaming blog you'll find a set of really nice tutorials one explaining the use of IOperationHandler http://cjrgaming.com/node/13.
  • So in the MMO project example, would it have been valid to not use the interface? What is the benefit of using the interface vs just inheriting the PeerBase class?
  • You don't have to use the interface. The MMO demo only makes use of the interface to spererate the code for two states of a peer (Before entered a world and entered a world).