fix(server.go) fix incorrect stateChangeEvent dispatching

Fix a bug introduced by race fix. The setState function will be called even if there is no actual stateChange. Check the previous state before dispatching the event.