• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

shogi-server source


Commit MetaInfo

Revisionfd33baf3cba2786e693ae8d7b93d7b13636a6070 (tree)
Zeit2010-09-05 23:27:23
Autordaigo <beatles@user...>
CommiterDaigo Moriwaki

Log Message

Enhanced the CSA Login mode to accept a turn preference.

Logging in the server with the CSA mode, users are now allowed to
specify a turn preference in an enhanced gamename string which
looks like <gamename>-<time>-<time>-<turn>. The first three
parts are a regular game definition. The last "-<turn>"
part is optional.
+ Without -<turn> (i.e. same as the previous behavior), there

is no turn preference. A user's turn will be defined randomly.

+ <turn> is either "B" for black or "W" for white.

Ändern Zusammenfassung

Diff

--- a/changelog
+++ b/changelog
@@ -1,3 +1,16 @@
1+2010-09-05 Daigo Moriwaki <daigo at debian dot org>
2+
3+ * [shogi-server]
4+ - shogi_server/login.rb: Enhanced the CSA Login mode.
5+ Logging in the server with the CSA mode, users are now allowed to
6+ specify a turn preference in an enhanced gamename string which
7+ looks like <gamename>-<time>-<time>-<turn>. The first three
8+ parts are a regular game definition. The last "-<turn>"
9+ part is optional.
10+ + Without -<turn> (i.e. same as the previous behavior), there
11+ is no turn preference. A user's turn will be defined randomly.
12+ + <turn> is either "B" for black or "W" for white.
13+
114 2010-09-04 Daigo Moriwaki <daigo at debian dot org>
215
316 * [shogi-server]
--- a/shogi_server/login.rb
+++ b/shogi_server/login.rb
@@ -127,14 +127,40 @@ end
127127 class LoginCSA < Login
128128 PROTOCOL = "CSA"
129129
130+ attr_reader :gamename
131+
132+ # A turn preference string: "+", "-" or default "*"
133+ attr_reader :turn_preference
134+
130135 def initialize(player, password)
131136 @gamename = nil
137+ @turn_preference = "*"
132138 super
133139 @player.protocol = PROTOCOL
134140 end
135141
142+ # Parse a gamename str and see if it includes an optional turn
143+ # preference.
144+ # ex. foo-1500-0-B for black
145+ # ex. foo-1500-0-W for white
146+ #
147+ # Return an array of a valid gamename without an turn preference and a
148+ # turn character "+" or "-"; false otherwise
149+ #
150+ def parse_gamename_turn(str)
151+ if str =~ /^(.+)-\d+-\d+-(\w)$/
152+ case $2
153+ when "b","B"
154+ return [str[0, str.length-2], "+"]
155+ when "w","W"
156+ return [str[0, str.length-2], "-"]
157+ end
158+ end
159+ return false
160+ end
161+
136162 def parse_password(password)
137- if Login.good_game_name?(password)
163+ if Login.good_game_name?(password) || parse_gamename_turn(password)
138164 @gamename = password
139165 @player.set_password(nil)
140166 elsif password.split(",").size > 1
@@ -144,12 +170,17 @@ class LoginCSA < Login
144170 @player.set_password(password)
145171 @gamename = Default_Game_Name
146172 end
147- @gamename = self.class.good_game_name?(@gamename) ? @gamename : Default_Game_Name
173+ array = parse_gamename_turn(@gamename)
174+ if array
175+ @gamename = array.first
176+ @turn_preference = array.last
177+ end
178+ @gamename = Login.good_game_name?(@gamename) ? @gamename : Default_Game_Name
148179 end
149180
150181 def process
151182 super
152- @csa_1st_str = "%%GAME #{@gamename} *"
183+ @csa_1st_str = "%%GAME #{@gamename} #{@turn_preference}"
153184 end
154185 end
155186
--- a/test/TC_login.rb
+++ b/test/TC_login.rb
@@ -40,15 +40,73 @@ class TestLogin < Test::Unit::TestCase
4040 assert_instance_of(ShogiServer::LoginCSA, login)
4141 assert_equal("xyz", player.password)
4242 assert_equal(@p_csa.player_id, player.player_id)
43+ assert_equal("*", login.turn_preference)
44+ end
45+
46+ def test_login_factory_csa_no_gamename
47+ player = ShogiServer::BasicPlayer.new
48+ player.name = "hoge"
49+ login = ShogiServer::Login::factory("LOGIN hoge xyz", player)
50+ assert_instance_of(ShogiServer::LoginCSA, login)
51+ assert_equal("xyz", player.password)
52+ assert_equal(@p_csa.player_id, player.player_id)
53+ assert_equal("*", login.turn_preference)
54+ assert_equal(ShogiServer::Default_Game_Name, login.gamename)
55+ end
56+
57+ def test_login_factory_csa_with_black
58+ player = ShogiServer::BasicPlayer.new
59+ player.name = "hoge"
60+ login = ShogiServer::Login::factory("LOGIN hoge floodgate-900-0-B,xyz", player)
61+ assert_instance_of(ShogiServer::LoginCSA, login)
62+ assert_equal("xyz", player.password)
63+ assert_equal(@p_csa.player_id, player.player_id)
64+ assert_equal("+", login.turn_preference)
65+ assert_equal("floodgate-900-0", login.gamename)
66+ end
67+
68+ def test_login_factory_csa_with_white
69+ player = ShogiServer::BasicPlayer.new
70+ player.name = "hoge"
71+ login = ShogiServer::Login::factory("LOGIN hoge floodgate-900-0-W,xyz", player)
72+ assert_instance_of(ShogiServer::LoginCSA, login)
73+ assert_equal("xyz", player.password)
74+ assert_equal(@p_csa.player_id, player.player_id)
75+ assert_equal("-", login.turn_preference)
76+ assert_equal("floodgate-900-0", login.gamename)
4377 end
4478
4579 def test_login_factory_csa_without_trip
4680 player = ShogiServer::BasicPlayer.new
4781 player.name = "hoge"
48- login = ShogiServer::Login::factory("LOGIN hoge floodagate-900-0", player)
82+ login = ShogiServer::Login::factory("LOGIN hoge floodgate-900-0", player)
83+ assert_instance_of(ShogiServer::LoginCSA, login)
84+ assert_nil(player.password)
85+ assert_equal(nil, player.player_id)
86+ assert_equal("*", login.turn_preference)
87+ assert_equal("floodgate-900-0", login.gamename)
88+ end
89+
90+ def test_login_factory_csa_without_trip_with_black
91+ player = ShogiServer::BasicPlayer.new
92+ player.name = "hoge"
93+ login = ShogiServer::Login::factory("LOGIN hoge floodgate-900-0-B", player)
94+ assert_instance_of(ShogiServer::LoginCSA, login)
95+ assert_nil(player.password)
96+ assert_equal(nil, player.player_id)
97+ assert_equal("+", login.turn_preference)
98+ assert_equal("floodgate-900-0", login.gamename)
99+ end
100+
101+ def test_login_factory_csa_without_trip_with_white
102+ player = ShogiServer::BasicPlayer.new
103+ player.name = "hoge"
104+ login = ShogiServer::Login::factory("LOGIN hoge floodgate-900-0-W", player)
49105 assert_instance_of(ShogiServer::LoginCSA, login)
50106 assert_nil(player.password)
51107 assert_equal(nil, player.player_id)
108+ assert_equal("-", login.turn_preference)
109+ assert_equal("floodgate-900-0", login.gamename)
52110 end
53111 end
54112