Returning null in an operation handler

edited August 2010 in Photon Server
So I've created a new operation in the MMO server demo called SwitchWorld. This operation basically needs to do the following (in order):
  1. Change the operation handler to MmoPeer.
  2. The current SwitchWorld operation request needs to be re-sent to that new operation handler (without sending a response yet)
  3. The SwitchWorld operation handler in MmoPeer needs to delete the current actor from his current world, delete the actor, and recreate the actor and put him in the newly requested world.

For step #2, I see that in some cases "return null;" is used in an operation handler, which based off of what I can tell, tells Photon to place that operation request back in its queue (at the back) so it can be handled again later. Is this correct?

I'm also curious how you guys would implement a SwitchWorld operation in your MMO server demo.

Thanks in advance.

Comments

  • BorisBoris ✭✭
    if you returned an OperationResponse instance the OperationQueue would send the response to the client. Returning null won't send anything, that's all.
    I would implement the SwitchWorld in MmoActor: Kill the current one and replace the current operation handler with a new MmoActor.
  • Boris wrote:
    if you returned an OperationResponse instance the OperationQueue would send the response to the client. Returning null won't send anything, that's all.
    I would implement the SwitchWorld in MmoActor: Kill the current one and replace the current operation handler with a new MmoActor.
    You say it won't send anything and that's all. However, inside of Peer's EnterWorld operation handler function, you have this:
    			while( world.ItemCache.AddItem( avatar ) == false )
    			{
    				Item otherAvatarItem;
    				if( world.ItemCache.TryGetItem( avatar.Type, avatar.Id, out otherAvatarItem ) )
    				{
    					avatar.Dispose();
    					actor.Dispose();
    					interestArea.Dispose();
    
    					((MmoItem)otherAvatarItem).Owner.Peer.DisconnectByOtherPeer( this.peer, request );
    
    					// request continued later, no response here
    					return null;
    				}
    			}
    

    I notice that if the player is still in the world, the EnterWorld handler is continuously called, which is why I thought returning NULL means re-queuing that operation. I had a bug where the DisconnectByOtherPeer was not removing the actor from the world, and EnterWorld would continue to be executed until it was completely removed.

    How was this happening?
  • this line will enqueue the request again
     ((MmoItem)otherAvatarItem).Owner.Peer.DisconnectByOtherPeer( this.peer, request );
    
Sign In or Register to comment.