The constructor is also called every time you perform an AJAX call.
And I discovered that it's not only the constructor that is called twice, but whole queries performed entirely multiple times.
I'm stuck with this in the game I'm working on. When a player does something (like moving a piece), I do some server side controls to check it that action is allowed (eg. check if the the target tile is empty) and throw an exception if it's not (which means a red message client side)
I notice that each action is performed a variable amount of times. Sometimes it's only one, but sometimes it's two, three, or even more ! The result is :
- The first action is performed correctly (I get all the expected behaviours, both server-side and client-side)
- All following identical actions fail, because whatever the player did is not a legal move anymore (eg. the target tile is no longer empty because the piece already moved). This results in one or more messages like "This move is not allowed" or "It's not your turn"
The exceptions stacks prove that the exact same query is performed multiple times : method calls in the stack are always identical and match whatever action the player performed. At first, I believed my JS code was wrong and I was sending AJAX calls multiple times, but I'm not. I added console logs before every AJAX call and I'm 100% certain I never send any of them more than once.
I have no idea what to do now. I don't want to decrease code quality by removing server side controls (this would probably allow some cheating by sending AJAX calls with a third-party HTTP client instead of using the game GUI), but the game is unplayable right now because you get walls of messages almost everytime you perform an action. Is this something specific to the studio that wouldn't happen on the main server ? How do you guys handle this (if you ever had to) ?