Creating server side game logic - where to start

quarion
edited September 2011 in Photon Server
Hi.
I am planing to create turn based game with separate, small rooms and server-side logic to prevent cheating. Right now I am testing the technology and learning Photon creating a tick-tack-toe game.

I want to create a server-side code based on the Lite app. But I am a little confused right now about where should I place my server-side logic.
I need to store some variables about the room and some about the players. I have created a service that sends an integer telling me that client wants to mark a certain board square. Based on the current state of the board and witch player sends the request I want to mark that board square with a cross, with a circle or do nothing and tell the client that the action is forbidden.

Should I place my code in class extending LiteGame in a method ExecuteOperation or in class extending LitePeer in a method OnOperationRequest ?

Comments

  • Anything that's game related should be done in the room. So, new operation like "place tile" should be there. If you have operations that are player-relevant only, like "get friend list" or "get my games" or something like it, then add it to the player.

    In your simple game, storing values when operations are executed is anything you need, I'd say.
  • Thanks for the answer. I am trying to implement it like that, but I am having some problems. My project is based on a MyApplication template from Lite server SDK.
    My server app is running an I am trying to call an operation like:
     var parameter = new Hashtable { { (byte)MyParameterCodes.boardId, boardId } };
    this.Peer.OpCustom( (byte)MyOperationCodes.MyOp, parameter, true ); 
    

    and trying to handle it (in a class MyRoom) like
    protected override void ExecuteOperation(Lite.LitePeer peer, OperationRequest operationRequest)
            {
                switch (operationRequest.OperationCode)
                {
                    case (short)MyOperationCodes.MyOp:
                        this.HandleMyGameOp(peer, operationRequest);
                        break;
                }
    }
    

    On the server side, I am getting a call and can handle it in the MyPeer.OnOperationRequest, but I am not getting a call in MyGame.ExecuteOperation and I am getting return message with error "Unknow operation code".
  • quarion wrote:
    Hi.Based on the current state of the board and witch player sends the request I want to mark that board square with a cross, with a circle or do nothing and tell the client that the action is forbidden.
    For testing and learning that's fine, but for the real game, you should also make this kind of checks client-side, so that the server-side checks are only needed in case, someone hacks his client some way, to cheat. As the client has all the information, in this szenario, it can already approve most of the turns locally. This will reduce visual reaction time of the game, as you skip latency and it will sav you bandwith, for examplke on simple misclicks, which would trigger sending an illeagal move to the server otherwise, also the client already knows, its illegal.
  • Yes, I am doing it like that. I want only use server to validate other player moves and prevent cheating.
    Right now i have a problem, because it seems that MyGame.ExecuteOperation is not getting called and server is using base LiteGame.ExecuteOperation, so I can Join, Leave etc. but cant add any custom operations.
  • Ok, after a lot of digging I have found a bug in your template code.
    In MyGameCache there is a line
    public static readonly LiteGameCache Instance = new LiteGameCache();
    

    While it should be:
    public static readonly MyGameCache Instance = new MyGameCache();
    

    Please fix that in your code repository, because it can give a lot of headache to someone who is trying to build around MyApplication template :)
  • Uh, that's mean. Thanks for the heads up, quarion.
    From what I see, Photon 3 won't have the MyApplication anymore - but we will avoid this in upcoming DevNet articles.
  • Tobias wrote:
    Uh, that's mean. Thanks for the heads up, quarion.
    From what I see, Photon 3 won't have the MyApplication anymore - but we will avoid this in upcoming DevNet articles.
    MyApplication is still there and the bug has been fixed.