public
Fork of Oshuma/weewar-spy-web
Description: Sinatra app that utilizes the WeewarSpy library to spy on your Weewar games.
Homepage: http://github.com/Oshuma/weewar-spy-web/
Clone URL: git://github.com/melriffe/weewar-spy-web.git
weewar-spy-web / spyweb.rb
100644 55 lines (46 sloc) 1.401 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# WeewarSpy Web
%w{
rubygems
sinatra
haml
yaml
}.each {|dependency| require dependency}
 
# Load the vendor'ed weewar-spy library.
require File.dirname(__FILE__) + '/vendor/weewar-spy/lib/weewar-spy'
 
# Load the Operative.
require File.dirname(__FILE__) + '/lib/operative'
 
configure do
  Title = 'WeewarSpy Web'
 
  # Load the Weewar configuration.
  config_file = File.dirname(__FILE__) + '/config.yml'
  unless File.exists?(config_file)
    puts 'Cannot find config.yml!'
    puts '$ cp config.yml.example config.yml'
    puts 'Then edit config.yml.'
    exit
  end
  SpyConfig = YAML.load_file(config_file)
 
  # Create an operative.
  options = {:server => SpyConfig['server'],
             :username => SpyConfig['username'],
             :api_key => SpyConfig['api_key'] }
  Spy = Operative.new(options)
end
 
get '/' do
  @games = Spy.games.sort
  haml :index
end
 
get '/stylesheets/styles.css' do
  content_type 'text/css', :charset => 'utf-8'
  sass :stylesheet
end
 
get '/game/:id' do
  @game = Spy.infiltrate(params[:id].to_i)
  @report = Spy.debrief(@game, false) # Don't print the output, just return it.
  @game_button_label = 'View Game'
  unless @game.current_player.nil?
    @game_button_label = 'Play Game' if @game.current_player.name == Spy.director.name
  end
  @game_header = @game.name + '; Game is ' + (@game.rated == 'true' ? ' Rated ' : ' Unrated ')
  haml :game
end