1 # Copyright (c) 2009 Paolo Capriotti <p.capriotti@gmail.com>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 require 'interaction/match'
9 require_bundle 'ics', 'icsplayer'
10 require_bundle 'ics', 'match_helper'
15 # Handler for ICS games.
17 # Responds to ICS protocol events creating and updating matches.
18 # Matches are stored in the @matches instance variable. It is possible to
19 # have more than one match running on ICS because of the observe feature.
26 def initialize(user, protocol)
31 protocol.add_observer(self)
34 def on_creating_game(data)
35 match = Match.new(data[:game],
38 :time_running => true)
39 @matches[data[:number]] = [match, data.merge(:type => :played)]
43 entry = @matches.delete(data[:game_number])
46 match.close(data[:result], data[:message])
50 def on_end_examination(number)
51 on_end_game(:game_number => number,
56 def on_examination_revert(data)
57 match, match_info = @matches[data[:game_number]]
59 match_info[:about_to_revert_to] = data[:index]
63 def on_style12(style12)
64 # retrieve match and helper
65 match, match_info = @matches[style12.game_number]
66 helper = MatchHelper.create(style12)
68 warn "Unsupported style12. Skipping"
72 # update match using helper and save it back to the @matches array
73 match = helper.get_match(@protocol, match, match_info, style12)
74 @matches[style12.game_number] = [match, match_info]
79 match_info[:icsplayer].on_style12(style12)
81 helper.start(@protocol, @user, match, match_info, style12)