3 ## Copyright (C) 2004 NABEYA Kenichi (aka nanami@2ch)
4 ## Copyright (C) 2007-2008 Daigo Moriwaki (daigo at debian dot org)
6 ## This program is free software; you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation; either version 2 of the License, or
9 ## (at your option) any later version.
11 ## This program is distributed in the hope that it will be useful,
12 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ## GNU General Public License for more details.
16 ## You should have received a copy of the GNU General Public License
17 ## along with this program; if not, write to the Free Software
18 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #require 'shogi_server/league/floodgate'
21 #require 'shogi_server/league/persistent'
23 module ShogiServer # for a namespace
25 ######################################################
31 @mutex = Monitor.new # guard @players
35 @dir = File.dirname(__FILE__)
36 @floodgate = Floodgate.new(self)
39 attr_accessor :players, :games, :event, :dir
43 @players.each do |name, player|
44 @persistent.save(player)
51 @floodgate = Floodgate.new(self)
55 # this should be called just after instanciating a League object.
56 def setup_players_database
57 filename = File.join(@dir, "players.yaml")
58 @persistent = Persistent.new(filename)
62 @persistent.load_player(player)
64 @players[player.name] = player
69 @persistent.save(player)
71 @players.delete(player.name)
76 @persistent.save(player)
81 @players.each do |name, player|
82 @persistent.load_player(player)
90 found = @players.find_all do |name, player|
94 return found.map {|a| a.last}
100 found = @players[player_name]
105 def get_player(status, game_name, sente, searcher)
107 @mutex.synchronize do
108 found = @players.find do |name, player|
109 (player.status == status) &&
110 (player.game_name == game_name) &&
112 (player.sente == nil) ||
113 (player.sente == sente) ) &&
114 (player.name != searcher.name)
117 return found ? found.last : nil
121 return @persistent.get_players