I'm working on a multiplayer game and it's currently set up like this. It accepts packets from the client on the fly and does whatever processing it needs to. There is also a main game tick which is set up like so:
for every online player
update every player in the region
for every online player
reset flags
The problem I see that can happen is that since it handles packets on the fly, it may modify something between the updating and the flag reset, which could cause it to completely ignore something. I don't think it's possible to synchronize it using the actual synchronize block since it can't update and reset flags at the same time - it needs to reset flags after it updates every player.
The only solution I see is not processing packets on the fly and doing it in the main loop, but this could hurt performance. Is this the best solution, or is there another option I'm not considering?
Thanks