Smartfox card game timer logic

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

Sarevok
Posts: 75
Joined: 12 Apr 2011, 22:12

Post by Sarevok »

Well, I am not sure if it is default server behavior, but it is very likely. I don't have access to my game to check it right now whether I get those events fired in my zone extension. Nevertheless, just ignore it for now, and if you don't notice any problem about it later you are fine :D

What about sync? I told you that you have to synchronize it. Check that request dispatching section in the "cookbook", to help you organize your request inside extension. When you have fine grained requests it is much easier to synchronize them. For example, at the beginning you can put all game related requests in synchronized methods, so that there is no chance of two users running concurrently through requests (they are practically serialized). On the other hand you don't want your chat request methods synchronized, since they have no effect on game data.

That way you got your game extension synchronized with almost no effort. I think this kind of sync scheme will work good for any kind of turn based game. If you write real time game, then you need finer sync scheme, where you have shorter sync blocks around specific parts of code. This will improve performance, but it is harder to implement correctly, and it can produce errors that are hard to find if you make a mistake :)
arun8483
Posts: 33
Joined: 15 Dec 2010, 02:35
Contact:

Post by arun8483 »

Sure I will look at it ... Thanks a lot Sarevok...
Sarevok
Posts: 75
Joined: 12 Apr 2011, 22:12

Post by Sarevok »

You are welcome. Just make sure that when you are synchronizing game request you use the same lock all the time. For example if you divide your game in RummyModule and ChatModule, make sure that your RummyModule handleRequest and handleInternalEvent are using the same lock.
You can leave ChatModule non synchronized.
arun8483
Posts: 33
Joined: 15 Dec 2010, 02:35
Contact:

Post by arun8483 »

Sarevok,
I have one more doubt... :) I am seeing SFSTris2.java, in that the same startGame() function logic is implemented there..But I cant see any syn logic involved in that file... Since its 2 player game they avoided that????? any reason???
Sarevok
Posts: 75
Joined: 12 Apr 2011, 22:12

Post by Sarevok »

I don't know that game, but if there is chance that at least two different threads will access the same data, there must be synchronization if you want to avoid errors. If the game you mention have some state (class member variables in extension) that is read/write by more than one thread that code is buggy. Of course errors may not emerge immediately, but it will sooner or later. Also, I think that SFS by default have only one thread working on requests. Try to set it to more than one threads, and start playing game. And you will see errors emerge.

SFS do not do synchronization for you, so don't hope for that :)
Post Reply