Refactor faction set up in multiplayer.

The code has been improved to switch from index lookups to lookups by
ids. This makes the implementation more flexible for future improvements
and easier for maintenance.