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 module ShogiServer # for a namespace
22 ######################################################
28 @mutex = Monitor.new # guard @players
32 @dir = File.dirname(__FILE__)
34 attr_accessor :players, :games, :event, :dir
38 @players.each do |name, player|
39 @persistent.save(player)
44 # this should be called just after instanciating a League object.
45 def setup_players_database
46 filename = File.join(@dir, "players.yaml")
47 @persistent = Persistent.new(filename)
51 @persistent.load_player(player)
53 @players[player.name] = player
58 @persistent.save(player)
60 @players.delete(player.name)
65 @persistent.save(player)
70 @players.each do |name, player|
71 @persistent.load_player(player)
79 found = @players.find_all do |name, player|
83 return found.map {|a| a.last}
89 found = @players[player_name]
94 def get_player(status, game_name, sente, searcher)
97 found = @players.find do |name, player|
98 (player.status == status) &&
99 (player.game_name == game_name) &&
101 (player.sente == nil) ||
102 (player.sente == sente) ) &&
103 (player.name != searcher.name)
106 return found ? found.last : nil
110 return @persistent.get_players