Game (Room) extending from lite/litelobby

edited December 2010 in Photon Server
I have extended the lite lobby application. It seems to be working great connecting, join, and etc....

I have a customGame class where I want to put some game logic. My custom operations and events are being call correctly from my custom OperationRequestDispatcher. The problem I am having is that when I call a custom operation, the "ExecuteOperation" in my customGame class never gets called. It always falls to the LiteGame "ExecuteOperation" function. I am bit lost at this point.

customGame ExecuteOperation function is overrided. My customGame : LiteLobbyGame is extended this way.

My code to get the room reference looks like this.
           RoomReference roomReference = peer.State;

            // check if the peer have a reference to game 
            if (roomReference == null)
            {
                if (Log.IsDebugEnabled)
                {
                    Log.DebugFormat("Received leave operation on peer without a game: peerId={0}", peer.SessionId);
                }

                return;
            }

            // enqueue the leave operation into game queue. 
            roomReference.Room.EnqueueOperation(peer, operationRequest);

What am I missing? How do i get the "ExecuteOperation" function to fire in my customGame class?

Comments

  • The only thing I can't see is how you actually create your customGame.

    Did you override the OperationRequestDispatcher once more to instantiate your own class? In LiteLobby this is in HandleJoinOperation, which uses either HandleJoinGameWithLobby OR HandleJoinOperation. Maybe you didn't cover the right case here?
  • I have my own DispatchOperationRequest that looks like this:
    
    public virtual bool DispatchOperationRequest(KickBackPeer peer, OperationRequest operationRequest)
            {
    
                short i = operationRequest.OperationCode;
    
                if (i < (short)120)
                {
                    base.DispatchOperationRequest(peer, operationRequest);
                    return true;
                }
                else
                {
                    switch ((kbOperationCodes)operationRequest.OperationCode)
                    {
                        case kbOperationCodes.SaveQuestion:
                            this.HandleSQOperation(peer, operationRequest);
                            return true;
                    }
    
                    return false;
                }
            }
    

    It's dispatch is working correctly I know that. I am using this code to test it. Get response back.
    protected virtual void HandleSQOperation(KickBackPeer peer, OperationRequest operationRequest)
            {
    
                var sqOperation = new SaveQuestionOperation(operationRequest);
    
                if (peer.ValidateOperation(sqOperation) == false)
                {
                    OperationResponse response = sqOperation.GetOperationResponse(0, "Not Valid");
                    peer.PublishOperationResponse(response);
                }
                else
                {
                    OperationResponse response = sqOperation.GetOperationResponse(0, "Dispatch---" + peer.State.Room.Name);
                    peer.PublishOperationResponse(response);
    }
    }
    

    The code I am using to get a reference to the room so I can publish to all the actor looks like this:
    // get a lobby reference from the game cache 
                    // the lobby will be created by the cache if it does not exists allready
                    RoomReference lobbyReference = LiteLobbyGameCache.Instance.GetRoomReference(peer.State.Room.Name);
    
                    // enqueue the operation request into the games execution queue
                    lobbyReference.Room.EnqueueOperation(peer, operationRequest);
    
                    lobbyReference.Dispose();
    

    I get a reference correctly but it ends up running the "ExecuteOperation" in the LiteGame.cs class file. Do I need to create a "GameCache" for my customGame : LiteGame Class? I want it to go to my customGame Class to the "ExecuteOperation" so I can then get actor list and publish events to all actors. Am I going about this wrong?
  • After looking at my Dispatcher and at samples. You were correct, I didn't realize that I had to override the "HandleJoinOperation" function. I did two things to fix the program. Created a "customGameCache" and overrided the "HandleJoinOperation" and it's working the say I wanted to. :D
  • I don't have the code here just now, but I think you should have the source to LiteLobbyGameCache.GetRoomReference(). In it, you need to create your extended room instead of a LiteLobbyRoom or the LiteLobbyGame. Both are used for different tasks in the LiteLobby solution.

    I hope that helps.
Sign In or Register to comment.