OSDN Git Service

* [shogi-server]
authorbeatles <beatles@b8c68f68-1e22-0410-b08e-880e1f8202b4>
Thu, 7 Sep 2006 23:40:11 +0000 (23:40 +0000)
committerbeatles <beatles@b8c68f68-1e22-0410-b08e-880e1f8202b4>
Thu, 7 Sep 2006 23:40:11 +0000 (23:40 +0000)
  - Re-design: trip is now a suffix of the password, not name.
  - Sipmlyfiled the output of %%RATING.
* [mk_rate]
  - Support "@" indentificaton in a name; players with same
    before-@-names are mapped to one.

changelog
mk_rate
shogi-server

index ac90841..e1fa356 100644 (file)
--- a/changelog
+++ b/changelog
@@ -1,3 +1,12 @@
+2006-09-07  Daigo Moriwaki <daigo at debian dot org>
+
+       * [shogi-server]
+         - Re-design: trip is now a suffix of the password, not name.
+         - Sipmlyfiled the output of %%RATING.
+       * [mk_rate]
+         - Support "@" indentificaton in a name; players with same
+           before-@-names are mapped to one.
+
 2006-09-05  Daigo Moriwaki <daigo at debian dot org>
 
        * [mk_rate] Fix a bug. It solves the correct rate.
 2006-09-05  Daigo Moriwaki <daigo at debian dot org>
 
        * [mk_rate] Fix a bug. It solves the correct rate.
diff --git a/mk_rate b/mk_rate
index 29310ba..67fae39 100755 (executable)
--- a/mk_rate
+++ b/mk_rate
@@ -389,6 +389,10 @@ def add(black_mark, black_name, white_name, white_mark, time)
   _add_time(white_name, time)
 end
 
   _add_time(white_name, time)
 end
 
+def identify_id(id)
+  id.gsub(/@.*?\+/,"+")
+end
+
 def grep(file)
   str = File.open(file).read
 
 def grep(file)
   str = File.open(file).read
 
@@ -414,7 +418,8 @@ def grep(file)
   end
   if /^'rating:(.*)$/ =~ str
     black_id, white_id = $1.split(":").map {|a| a.strip}
   end
   if /^'rating:(.*)$/ =~ str
     black_id, white_id = $1.split(":").map {|a| a.strip}
-    add(black_mark, black_id, white_id, white_mark, time)
+    add(black_mark, identify_id(black_id),
+        identify_id(white_id), white_mark, time)
   end
 end
 
   end
 end
 
index d5f04b2..e3b0902 100755 (executable)
@@ -123,7 +123,7 @@ class League
       # a current user
       player.name = hash['name']
       player.rate = hash['rate']
       # 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
 
@@ -176,6 +176,16 @@ class RatedPlayer
   def rated?
     @id != nil
   end
   def rated?
     @id != nil
   end
+
+  def simple_id
+    name, trip = @id.split("+")
+    if trip
+      name.gsub!(/@.*?$/, '')
+      "%s+%s" % [name, trip[0..8]]
+    else
+      name
+    end
+  end
 end
 
 class Player < RatedPlayer
 end
 
 class Player < RatedPlayer
@@ -259,8 +269,9 @@ class Player < RatedPlayer
     @eol = $1
     str.chomp!
     (login, @name, @password, ext) = str.split
     @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
+    @password, *trip = @password.split(",") # used by rating
+    trip = trip.join(",") # if no trip, *trip -> []; [].join(",") -> "";
+    @id = trip.empty? ? nil : "%s+%s" % [@name, Digest::MD5.hexdigest(trip)]
     if (ext)
       @protocol = "x1"
     else
     if (ext)
       @protocol = "x1"
     else
@@ -362,8 +373,8 @@ class Player < RatedPlayer
         when /^%%RATING/
           players = LEAGUE.rated_players
           players.sort {|a,b| b.rate <=> a.rate}.each do |p|
         when /^%%RATING/
           players = LEAGUE.rated_players
           players.sort {|a,b| b.rate <=> a.rate}.each do |p|
-            write_safe("##[RATING] %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 /^%%GAME\s*$/
           end
           write_safe("##[RATING] +OK\n")
         when /^%%GAME\s*$/
@@ -1846,12 +1857,9 @@ def good_game_name?(str)
   end
 end
 
   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
 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
   else
     return false
   end