app/controllers/game_passings.rb
# TODO: must be a critical section, double creation is possible!
must be a critical section, double creation is possible!
must be a critical section double creation is possible!
def find_or_create_game_passing
    @game_passing = GamePassing.of(@team,@game)
    if @game_passing.nil?
      @game_passing = GamePassing.create! :team => @team,
        :game => @game,
        :current_level => @game.levels.first
    endpovk-patch-1
  end
  def find_team
    @team = current_user.team
  end
  def ensure_game_is_started
    raise Unauthorized, "Negalima žaisti žaidimo prieš jam prasidedant. Ir apskritai, iš kur gavote šią nuorodą?" unless @game.started? unless @game.is_testing?
  end
  def ensure_not_author_of_the_game
    raise Unauthorized, "Negalima žaisti savo kurtame žaidime, sorry." if @game.created_by?(current_user) unless @game.is_testing?
  end
  def author_finished_at
    raise Unauthorized, "Autorius uždarė žaidimą, ir jūs nebegalite jo žaisti" if @game.author_finished?
  end
  def ensure_captain_exited
    raise Unauthorized, "Komanda pasitraukė iš žaidimo" if @game_passing.exited?
  end
  def ensure_not_finished
    self.author_finished_at
    self.ensure_captain_exited
  end
end
def find_or_create_game_passing @game_passing = GamePassing . of ( @team , @game ) if @game_passing . nil? @game_passing = GamePassing . create! :team => @team , :game => @game , :current_level => @game . levels . first endpovk - patch - 1 end def find_team @team = current_user . team end def ensure_game_is_started raise Unauthorized , "Negalima žaisti žaidimo prieš jam prasidedant. Ir apskritai, iš kur gavote šią nuorodą?" unless @game. tarte d ? unless @game. s_tes t ing? end def ensure_not_author_of_the_game raise Unauthorized , "Negalima žaisti savo kurtame žaidime, sorry." i  @ ame.c r eated_by?(c u rrent_user)  u less @ ame.i s _testing? end def author_finished_at raise Unauthorized , "Autorius uždarė žaidimą, ir jūs nebegalite jo žaisti" if @g me autho r _finished? end def ensure_captain_exited raise Unauthorized , "Komanda pasitraukė iš žaidimo" if @g me_passing.ex i ted? end def ensure_not_finished self . author_finished_at self . ensure_captain_exited end end
TODO: must be a critical section, double creation is possible!
TODO : must be a critical section double creation is possible!