#!/usr/bin/env ruby # encoding: utf-8 require 'rubygems' require 'dragongoserver' require 'choice' version = Dragongoserver::VERSION Choice.options do # header '' # header 'Specific options:' #... #separator '' separator 'Common options: ' option :help do short '-h' long '--help' desc 'Show this message' end option :version do short '-v' long '--version' desc 'Show version' action do puts "dgs #{version}" exit end end option :waiting do short '-w' long '--waiting' desc 'Show waiting games' end option :waitingloop do short '-wl' long '--waiting-loop' desc 'Show waiting games in an intelligent endless loop' end option :running do short '-r' long '--running' desc 'Show running games' end option :osd do short '-osd' long '--osd' desc 'Show messages as an on-screen-display, "osd_cat" must be installed (see http://www.ignavus.net/software.html for further details)' end option :finished_games do short '-fg' long '--finished-games' desc 'display the most recent finished games' #cast Integer #default 10 end # listet auf, wie oft ein Spieler in den beendeten Spielen # durch Timeout verloren hat option :check_timeout_finished do short '-ctf' long '--check-timeout-finished' cast Integer # User-id end option :with_name do short '-wn' long '--with-name' desc 'Show games with name' end option :min_wait do short '-mw' long '--min-wait' desc 'Minimum wait time in minutes' cast Integer default 1 end option :threshold do short '-s' long '--threshold' desc 'Minimum number of waiting games' cast Integer default 1 end option :add_game do short '-a' long '--add-game' desc 'Add a new game in the waiting room' end end if Choice.choices['check_timeout_finished'] puts "timeout check for user #{Choice.choices['check_timeout_finished']}" dgs_username = ENV['DGS_USERNAME'] dgs_password = ENV['DGS_PASSWORD'] @dgs = Dgs.new(dgs_username, dgs_password) finished = @dgs.finished_games_for_user(Choice.choices['check_timeout_finished']) count = 0 finished.each {|g| if g[:reason] == 'Time' and g[:winner] != g[:player_color] #p g[:winner] # #g[:winner] != g[:player_color] count += 1 end } puts "at least #{finished.size} finished games" puts "#{count} games finished with timeout (#{count.to_f/finished.size.to_f*100.0} %)" exit end @cache_gameinfos = {} #p Choice.choices opt_waiting = Choice.choices['waiting'] # true/false opt_running = Choice.choices['running'] # true/false opt_finished_games = Choice.choices['finished_games'] # true/false $opt_with_name = Choice.choices['with_name'] # true/false @opt_osd = Choice.choices['osd'] # true/false opt_waitingloop = Choice.choices['waitingloop'] # true/false opt_add_game = Choice.choices['add_game'] # true/false if opt_waiting dgs = Dgs.new waiting_games = dgs.waiting_games puts "you have to move in the following games:" if waiting_games.size > 0 puts "goto: http://www.dragongoserver.net/status.php" if waiting_games.size > 0 waiting_games.each { |game_id| puts game_id } end if opt_running dgs = Dgs.new running_games = dgs.running_games if running_games.size > 0 puts "you have a total of #{running_games.size} running games" puts "running games:" running_games.each { |game_id| puts game_id } else puts "you have no running games" end end if opt_finished_games =begin