public async Task LeaveLobby(LobbyConnection connection, bool silent) { log.Debug("removing connection " + connection + " from lobby " + connection.Lobby); using (var alock = await Data.Synchronizer.SetStateAsync(ModuleState.Writing)) { var lobby = connection.Lobby; if (lobby == null) { throw new LobbyStateException("Connection is not member in any lobby!"); } log.Debug("connection " + connection.Connection.Id + " leaving lobby " + lobby.Id); if (PlayerStorage.IsSynchronized(connection.Connection)) { var players = PlayerStorage.GetPlayerOfConnection(connection.Connection).Where(p => lobby.Players.Contains(p)).ToArray(); await RemovePlayerFromLobby(players, lobby, silent); } lobby.Connections.Remove(connection.Connection.Id); if (!silent && connection.Connection.State != ConnectionState.Disconnected) { await Messenger.SendMessage(connection.Connection, Messages.LobbyLeft()); } connection.Lobby = null; connection.PendingUpdates = 0; if (lobby.Host == connection) { await MigrateHost(lobby); } } }