diff options
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/matches_controller.rb | 61 | ||||
-rw-r--r-- | app/controllers/servers_controller.rb | 53 | ||||
-rw-r--r-- | app/controllers/tournaments_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/users_controller.rb | 2 |
4 files changed, 69 insertions, 49 deletions
diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index 31fc9ad..ee68e11 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -1,15 +1,22 @@ class MatchesController < ApplicationController - before_action :set_tournament, only: [:index] + before_action :set_tournament, only: [:index, :update] # GET /matches # GET /matches.json require 'httparty' require 'json' + require 'delayed_job' def index @matches = @tournament.matches + # width of SVG + @width = 300 * (Math.log2(@matches.count).floor + 1); + # height of SVG + @height = 200 * 2**Math.log2(@matches.count).floor + 100; end + + def get_riot_info if signed_in? @@ -114,14 +121,64 @@ class MatchesController < ApplicationController end #end def # GET /matches/1 # GET /matches/1.json + + def is_match_over + response = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/summoner/by-name/#{@first}?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") + riot_id = response["#{@first}"]['id'] + #recent game information + game_info = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/game/by-summoner/#{riot_id}/recent?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") + first_id = game_info["games"][0]["gameId"] + + while true do + sleep(240) #wait four minutes + + recent = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/game/by-summoner/#{riot_id}/recent?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") + current_id = recent["games"][0]["gameId"] + + if current_id != first_id + @match.status = 2 + end + end #while + end + handle_asynchronously :is_match_over + def show + if @match.id == 1 + is_match_over + end + + + end + + def update + case params[:update_action] + when "start" + check_permission(:edit, @tournament) + status = 1 + respond_to do |format| + if @match + format.html { redirect_to tournament_match_path(@tournament, self), notice: 'Match has started.' } + format.json { head :no_content } + else + format.html { redirect_to @tournament, notice: "You don't have permission to start this match." } + format.json { render json: "Permission denied", status: :forbidden } + end + end + else + respond_to do |format| + format.html { redirect_to @tournament, notice: "Invalid action", status: :unprocessable_entity } + format.json { render json: @tournament.errors, status: :unprocessable_entity } + end + end + end private # Use callbacks to share common setup or constraints between actions. def set_match set_tournament - @match = @tournament.matches.find(params[:id]); + @match = @tournament.matches.find(params[:id]) + @first = @match.teams.first.users.first.user_name.downcase end def set_tournament @tournament = Tournament.find(params[:tournament_id]) diff --git a/app/controllers/servers_controller.rb b/app/controllers/servers_controller.rb index 6596dc6..83a9f31 100644 --- a/app/controllers/servers_controller.rb +++ b/app/controllers/servers_controller.rb @@ -1,43 +1,15 @@ class ServersController < ApplicationController - - # GET /servers - # GET /servers.json - def index - @servers = Server.all - end - - # GET /servers/1 - # GET /servers/1.json + # GET /server + # GET /server.json def show end - # GET /servers/new - def new - @server = Server.new - end - - # GET /servers/1/edit + # GET /server/edit def edit end - # POST /servers - # POST /servers.json - def create - @server = Server.new(server_params) - - respond_to do |format| - if @server.save - format.html { redirect_to @server, notice: 'Server was successfully created.' } - format.json { render action: 'show', status: :created, location: @server } - else - format.html { render action: 'new' } - format.json { render json: @server.errors, status: :unprocessable_entity } - end - end - end - - # PATCH/PUT /servers/1 - # PATCH/PUT /servers/1.json + # PATCH/PUT /server + # PATCH/PUT /server.json def update respond_to do |format| if @server.update(server_params) @@ -50,24 +22,15 @@ class ServersController < ApplicationController end end - # DELETE /servers/1 - # DELETE /servers/1.json - def destroy - @server.destroy - respond_to do |format| - format.html { redirect_to servers_url } - format.json { head :no_content } - end - end - private + # Use callbacks to share common setup or constraints between actions. def set_server - @server = Server.find(params[:id]) + @server = Server.first end # Never trust parameters from the scary internet, only allow the white list through. def server_params - params[:server] + params.require(:server).permit(:default_user_permissions, :default_user_abilities => User.permission_bits.keys) end end diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index a9e91b0..2fc82ed 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -99,7 +99,7 @@ class TournamentsController < ApplicationController format.html { redirect_to @tournament, notice: 'You have joined this tournament.' } format.json { head :no_content } else - format.html { render action: 'permission_denied', status: :forbidden } + format.html { redirect_to @tournament, notice: "You don't have permission to start this tournament." } format.json { render json: "Permission denied", status: :forbidden } end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index dd66c18..637480f 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -33,7 +33,7 @@ class UsersController < ApplicationController return end - @user.permissions = 0 + @user.permissions = Server.first.default_user_permissions respond_to do |format| if @user.save sign_in @user |