# a current user
player.name = hash['name']
player.rate = hash['rate']
- player.modified_at = hash['modified_at']
+ player.modified_at = hash['last_modified']
end
end
end
end
return players.collect do |id|
- p = RatedPlayer.new
+ p = BasicPlayer.new
p.id = id
self.load(p)
p
end
-class RatedPlayer
+class BasicPlayer
# Idetifier of the player in the rating system
attr_accessor :id
+
# Name of the player
attr_accessor :name
+
+ # Password of the player, which does not include a trip
+ attr_accessor :password
+
# Score in the rating sysem
attr_accessor :rate
+
# Last timestamp when the rate was modified
attr_accessor :modified_at
+
+
+ def initialize
+ @name = nil
+ @password = nil
+ end
+
def modified_at
@modified_at || Time.now
end
def rated?
@id != nil
end
+
+ def simple_id
+ if @trip
+ simple_name = @name.gsub(/@.*?$/, '')
+ "%s+%s" % [simple_name, @trip[0..8]]
+ else
+ @name
+ end
+ end
+
+ ##
+ # Parses str in the LOGIN command, sets up @id and @trip
+ #
+ def set_password(str)
+ if str && !str.empty?
+ @password = str.strip
+ @id = "%s+%s" % [@name, Digest::MD5.hexdigest(@password)]
+ else
+ @id = @password = nil
+ end
+ end
end
-class Player < RatedPlayer
+class Player < BasicPlayer
def initialize(str, socket)
- @name = nil
- @password = nil
+ super()
@socket = socket
@status = "connected" # game_waiting -> agree_waiting -> start_waiting -> game -> finished
login(str)
end
- attr_accessor :password, :socket, :status
+ attr_accessor :socket, :status
attr_accessor :protocol, :eol, :game, :mytime, :game_name, :sente
attr_accessor :main_thread, :writer_thread, :write_queue
str =~ /([\r\n]*)$/
@eol = $1
str.chomp!
- (login, @name, @password, ext) = str.split
- @name, trip = @name.split(",") # used by rating
- @id = trip ? "%s+%s" % [@name, Digest::MD5.hexdigest(trip)] : nil
+ (login, @name, password, ext) = str.split
+ set_password(password)
if (ext)
@protocol = "x1"
else
when /^%%RATING/
players = LEAGUE.rated_players
players.sort {|a,b| b.rate <=> a.rate}.each do |p|
- write_safe("%s (%s) \t %4d @%s\n" %
- [p.name, p.id, p.rate, p.modified_at.strftime("%Y-%m-%d")])
+ write_safe("##[RATING] %s \t %4d @%s\n" %
+ [p.simple_id, p.rate, p.modified_at.strftime("%Y-%m-%d")])
end
+ write_safe("##[RATING] +OK\n")
+ when /^%%VERSION/
+ write_safe "##[VERSION] Shogi Server revision #{Revision}\n"
+ write_safe("##[VERSION] +OK\n")
when /^%%GAME\s*$/
if ((@status == "connected") || (@status == "game_waiting"))
@status = "connected"
y1 = $5.to_i
name = $6
elsif (str =~ /^%KACHI/)
- raise ArgumentError, "sente is null", caller unless sente
+ raise ArgumentError, "sente is null", caller if sente == nil
if (good_kachi?(sente))
return :kachi_win
else
end
end
-# TODO This is also checked by good_game_name?().
def good_identifier?(str)
if str =~ /\A[\w\d_@\-\.]{1,#{Max_Identifier_Length}}\z/
return true
- elsif str =~ /\A[\w\d_@\-\.]{1,#{Max_Identifier_Length}},[\w\d_@\-\.]{1,#{Max_Identifier_Length}}\z/
- return true
else
return false
end