Cast system

Cast system version 0.1, its not completed yet.
It bugs on logout if there are viewers.

#ifdef CAST_SYSTEM
	if (clients.size() > 0) {
		for (auto& client : clients) { <-----
			client->logout(true, true); <------
		}
#else
	if (client) {
		client->logout(true, true);
#endif
	} else {
 		g_game.removeCreature(this, true);
	}

Somhow it does not serialize correctly here. (i marked the parts with an arrow.)
I assume it has to do with the order the steamer/viewers are logged out however am not sure.
Logging out with no viewers howver goes correctly even if there is a cast started.

some input to direct me to work further would be great as i am a beginning CPP coder. 

Source was obtained from : https://github.com/CastSystem/forgottenserver/commits/master so all credits go to them for distributing the source.