Creating server side game logic - where to start
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 ?
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 ?
0
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.0 -
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) likeprotected 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".0 -
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.0
-
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.0 -
Ok, after a lot of digging I have found a bug in your template code.
In MyGameCache there is a linepublic 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 template0 -
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.0