OSDN Git Service

Fix #36821: Allow to customize maximum lenght of a login indentifier
authorDaigo Moriwaki <daigo@debian.org>
Sat, 26 Nov 2016 09:01:39 +0000 (18:01 +0900)
committerDaigo Moriwaki <daigo@debian.org>
Sat, 26 Nov 2016 09:01:39 +0000 (18:01 +0900)
changelog
shogi-server
shogi_server.rb
shogi_server/login.rb
test/TC_game_least_0.rb
test/TC_login.rb

index 6402a91..da428cd 100644 (file)
--- a/changelog
+++ b/changelog
@@ -1,3 +1,13 @@
+2016-11-26  Daigo Moriwaki <daigo at debian dot org>
+
+       * [shogi-server] Allow to customize maximum lenght of a login indentifier
+         (Closes #36821)
+         - The current maximum length of a login identifier is 32. Some
+           private uses require longer player names to distinguish each other
+           by specifying randomly generated tokens. It would of help to add a
+           new command line option --max-identifier to overwrite the default
+           maximum length.
+
 2016-04-09  Daigo Moriwaki <daigo at debian dot org>
 
        * utils/eval_graph.rb
 2016-04-09  Daigo Moriwaki <daigo at debian dot org>
 
        * utils/eval_graph.rb
index b5e1ecf..530dbb1 100755 (executable)
@@ -82,6 +82,8 @@ OPTIONS
                 Least time in second per move: 0, 1 (default 1).
                   - 0: The new rule that CSA introduced in November 2014.
                   - 1: The old rule before it.
                 Least time in second per move: 0, 1 (default 1).
                   - 0: The new rule that CSA introduced in November 2014.
                   - 1: The old rule before it.
+        --max-identifier n
+               maximum length of an identifier
         --max-moves n
                 when a game with the n-th move played does not end, make the game a draw.
                 Default 256. 0 disables this feature.
         --max-moves n
                 when a game with the n-th move played does not end, make the game a draw.
                 Default 256. 0 disables this feature.
@@ -206,6 +208,7 @@ def parse_command_line
     ["--daemon",              GetoptLong::REQUIRED_ARGUMENT],
     ["--floodgate-games",     GetoptLong::REQUIRED_ARGUMENT],
     ["--least-time-per-move", GetoptLong::REQUIRED_ARGUMENT],
     ["--daemon",              GetoptLong::REQUIRED_ARGUMENT],
     ["--floodgate-games",     GetoptLong::REQUIRED_ARGUMENT],
     ["--least-time-per-move", GetoptLong::REQUIRED_ARGUMENT],
+    ["--max-identifier",      GetoptLong::REQUIRED_ARGUMENT],
     ["--max-moves",           GetoptLong::REQUIRED_ARGUMENT],
     ["--pid-file",            GetoptLong::REQUIRED_ARGUMENT],
     ["--player-log-dir",      GetoptLong::REQUIRED_ARGUMENT])
     ["--max-moves",           GetoptLong::REQUIRED_ARGUMENT],
     ["--pid-file",            GetoptLong::REQUIRED_ARGUMENT],
     ["--player-log-dir",      GetoptLong::REQUIRED_ARGUMENT])
@@ -281,6 +284,9 @@ def check_command_line
   $options["max-moves"] ||= ShogiServer::Default_Max_Moves
   $options["max-moves"] = $options["max-moves"].to_i
 
   $options["max-moves"] ||= ShogiServer::Default_Max_Moves
   $options["max-moves"] = $options["max-moves"].to_i
 
+  $options["max-identifier"] ||= ShogiServer::Default_Max_Identifier_Length
+  $options["max-identifier"] = $options["max-identifier"].to_i
+
   $options["least-time-per-move"] ||= ShogiServer::Default_Least_Time_Per_Move
   $options["least-time-per-move"] = $options["least-time-per-move"].to_i
 end
   $options["least-time-per-move"] ||= ShogiServer::Default_Least_Time_Per_Move
   $options["least-time-per-move"] = $options["least-time-per-move"].to_i
 end
index 6c722cf..20d63d6 100644 (file)
@@ -45,14 +45,14 @@ require 'shogi_server/buoy'
 
 module ShogiServer # for a namespace
 
 
 module ShogiServer # for a namespace
 
-Max_Identifier_Length = 32
+Default_Max_Identifier_Length = 32
 Default_Timeout = 60            # for single socket operation
 Default_Game_Name = "default-1500-0"
 Default_Max_Moves = 256
 Default_Least_Time_Per_Move = 0
 One_Time = 10
 Login_Time = 300                # time for LOGIN
 Default_Timeout = 60            # for single socket operation
 Default_Game_Name = "default-1500-0"
 Default_Max_Moves = 256
 Default_Least_Time_Per_Move = 0
 One_Time = 10
 Login_Time = 300                # time for LOGIN
-Revision = "20160409"
+Revision = "20161126"
 
 RELOAD_FILES = ["shogi_server/league/floodgate.rb",
                 "shogi_server/league/persistent.rb",
 
 RELOAD_FILES = ["shogi_server/league/floodgate.rb",
                 "shogi_server/league/persistent.rb",
index 1f6f47f..38866d4 100644 (file)
@@ -79,7 +79,8 @@ class Login
   end
 
   def Login.good_identifier?(str)
   end
 
   def Login.good_identifier?(str)
-    if str =~ /\A[\w@\-\.]{1,#{Max_Identifier_Length}}\z/
+    max = $options["max-identifier"]
+    if str =~ /\A[\w@\-\.]{1,#{max}}\z/
       return true
     else
       return false
       return true
     else
       return false
index 3506eb5..19ff9bb 100644 (file)
@@ -5,7 +5,7 @@ require 'shogi_server/board'
 require 'shogi_server/game'
 require 'shogi_server/player'
 
 require 'shogi_server/game'
 require 'shogi_server/player'
 
-$options = {}
+$options ||= {}
 $options["least-time-per-move"] = 0
 $options["max-moves"] = 256
 
 $options["least-time-per-move"] = 0
 $options["max-moves"] = 256
 
index 2cbf060..a792e53 100644 (file)
@@ -5,6 +5,8 @@ require 'shogi_server/player'
 require 'shogi_server/login'
 require 'shogi_server/handicapped_boards'
 
 require 'shogi_server/login'
 require 'shogi_server/handicapped_boards'
 
+$options ||= {}
+
 class ShogiServer::BasicPlayer
   attr_accessor :protocol
 end
 class ShogiServer::BasicPlayer
   attr_accessor :protocol
 end
@@ -18,12 +20,23 @@ class TestLogin < Test::Unit::TestCase
     @p_x1.name = "hoge"
     @csa = ShogiServer::LoginCSA.new(@p_csa,"floodgate-900-0,xyz")
     @x1 = ShogiServer::Loginx1.new(@p_x1, "xyz")
     @p_x1.name = "hoge"
     @csa = ShogiServer::LoginCSA.new(@p_csa,"floodgate-900-0,xyz")
     @x1 = ShogiServer::Loginx1.new(@p_x1, "xyz")
+
+    $options["max-identifier"] = ShogiServer::Default_Max_Identifier_Length
   end
 
   def test_player_id
     assert(@p_x1.player_id == @p_csa.player_id)
   end
 
   end
 
   def test_player_id
     assert(@p_x1.player_id == @p_csa.player_id)
   end
 
+  def test_good_identifier
+    assert_true(ShogiServer::Login::good_identifier? "hoge")
+    assert_true(ShogiServer::Login::good_identifier? "12345678901234567890123456789012")
+
+    $options["max-identifier"] = 128
+    assert_true(ShogiServer::Login::good_identifier? "0"*128)
+    assert_false(ShogiServer::Login::good_identifier? "0"*129)
+  end
+
   def test_login_factory_x1
     player = ShogiServer::BasicPlayer.new
     player.name = "hoge"
   def test_login_factory_x1
     player = ShogiServer::BasicPlayer.new
     player.name = "hoge"
@@ -97,7 +110,7 @@ class TestLogin < Test::Unit::TestCase
     assert_equal("floodgate-900-0", login.gamename)
   end
 
     assert_equal("floodgate-900-0", login.gamename)
   end
 
-  def test_login_factory_csa_with_white
+  def test_login_factory_csa_with_white_fischer
     player = ShogiServer::BasicPlayer.new
     player.name = "hoge"
     login = ShogiServer::Login::factory("LOGIN hoge floodgate-900-10F-W,xyz", player)
     player = ShogiServer::BasicPlayer.new
     player.name = "hoge"
     login = ShogiServer::Login::factory("LOGIN hoge floodgate-900-10F-W,xyz", player)