OSDN Git Service

Merge branch 'logger'
authordaigo <beatles@users.sourceforge.jp>
Sun, 25 Jul 2010 06:17:43 +0000 (15:17 +0900)
committerDaigo Moriwaki <daigo@debian.org>
Sun, 25 Jul 2010 06:17:43 +0000 (15:17 +0900)
Conflicts:
changelog

changelog
shogi_server/command.rb
test/TC_command.rb

index 66b4cd3..7c72303 100644 (file)
--- a/changelog
+++ b/changelog
@@ -1,6 +1,10 @@
 2010-07-25  Daigo Moriwaki <daigo at debian dot org>
 
        * [shogi-server]
+         - shogi_server/command.rb: 
+           + For an unknown error command log, an empty line is no longer logged.
+           + Commands specific to 81Dojo, starting with '%%%', are just
+             ignored instead of unknown command errors.
          - shogi_server.rb: Refactoring. Added test/TC_logger.rb to test
            ShogiServer::Logger class.
 
index d661f90..f604ea9 100644 (file)
@@ -96,6 +96,10 @@ module ShogiServer
         cmd = GetBuoyCountCommand.new(str, player, game_name)
       when /^\s*$/
         cmd = SpaceCommand.new(str, player)
+      when /^%%%[^%]/
+        # TODO: just ignore commands specific to 81Dojo.
+        # Need to discuss with 81Dojo people.
+        cmd = VoidCommand.new(str, player)
       else
         cmd = ErrorCommand.new(str, player)
       end
@@ -112,6 +116,18 @@ module ShogiServer
     attr_accessor :time
   end
 
+  # Dummy command which does nothing.
+  #
+  class VoidCommand < Command
+    def initialize(str, player)
+      super
+    end
+
+    def call
+      return :continue
+    end
+  end
+
   # Application-level protocol for Keep-Alive.
   # If the server receives an LF, it sends back an LF.  Note that the 30 sec
   # rule (client may not send LF again within 30 sec) is not implemented
@@ -693,7 +709,7 @@ module ShogiServer
     end
 
     def call
-      msg = "##[ERROR] unknown command %s\n" % [@str]
+      msg = "##[ERROR] unknown command %s\n" % [@str.chomp]
       @player.write_safe(msg)
       log_error(msg)
       return :continue
index db3b333..455fdd8 100644 (file)
@@ -202,6 +202,11 @@ class TestFactoryMethod < Test::Unit::TestCase
     assert_instance_of(ShogiServer::GetBuoyCountCommand, cmd)
   end
 
+  def test_void_command
+    cmd = ShogiServer::Command.factory("%%%HOGE", @p)
+    assert_instance_of(ShogiServer::VoidCommand, cmd)
+  end
+
   def test_error
     cmd = ShogiServer::Command.factory("should_be_error", @p)
     assert_instance_of(ShogiServer::ErrorCommand, cmd)