OSDN Git Service

Added test cases.
[shogi-server/shogi-server.git] / shogi_server / command.rb
index ee81965..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
@@ -139,6 +155,11 @@ module ShogiServer
       if (@player.status == "game")
         array_str = @str.split(",")
         move = array_str.shift
+        if @player.game.last_move &&
+           @player.game.last_move.split(",").first == move
+          log_warning("Received two sequencial identical moves [#{move}] from #{@player.name}. The last one was ignored.")
+          return :continue
+        end
         additional = array_str.shift
         comment = nil
         if /^'(.*)/ =~ additional
@@ -283,8 +304,8 @@ module ShogiServer
     def ==(rhs)
       return rhs != nil &&
              rhs.is_a?(MonitorHandler) &&
-             @player = rhs.player &&
-             @type   = rhs.type
+             @player == rhs.player &&
+             @type   == rhs.type
     end
 
     def write_safe(game_id, str)
@@ -369,10 +390,17 @@ module ShogiServer
     end
   end
 
-  class Monitor2OffCommand < MonitorOffCommand # same
+  class Monitor2OffCommand < MonitorOffCommand
     def initialize(str, player, game)
       super
     end
+
+    def call
+      if (@game)
+        @game.monitoroff(MonitorHandler2.new(@player))
+      end
+      return :continue
+    end
   end
 
   # Command of HELP
@@ -681,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